diff options
Diffstat (limited to 'crates/ra_hir/src/ty/tests.rs')
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 4ab442b8a..c4b452ba4 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -587,6 +587,139 @@ fn test() -> i128 { | |||
587 | } | 587 | } |
588 | 588 | ||
589 | #[test] | 589 | #[test] |
590 | fn infer_associated_const() { | ||
591 | check_inference( | ||
592 | "infer_associated_const", | ||
593 | r#" | ||
594 | struct Struct; | ||
595 | |||
596 | impl Struct { | ||
597 | const FOO: u32 = 1; | ||
598 | } | ||
599 | |||
600 | enum Enum; | ||
601 | |||
602 | impl Enum { | ||
603 | const BAR: u32 = 2; | ||
604 | } | ||
605 | |||
606 | trait Trait { | ||
607 | const ID: u32; | ||
608 | } | ||
609 | |||
610 | struct TraitTest; | ||
611 | |||
612 | impl Trait for TraitTest { | ||
613 | const ID: u32 = 5; | ||
614 | } | ||
615 | |||
616 | fn test() { | ||
617 | let x = Struct::FOO; | ||
618 | let y = Enum::BAR; | ||
619 | let z = TraitTest::ID; | ||
620 | } | ||
621 | "#, | ||
622 | ); | ||
623 | } | ||
624 | |||
625 | #[test] | ||
626 | fn infer_associated_method_struct() { | ||
627 | check_inference( | ||
628 | "infer_associated_method_struct", | ||
629 | r#" | ||
630 | struct A { x: u32 }; | ||
631 | |||
632 | impl A { | ||
633 | fn new() -> A { | ||
634 | A { x: 0 } | ||
635 | } | ||
636 | } | ||
637 | fn test() { | ||
638 | let a = A::new(); | ||
639 | a.x; | ||
640 | } | ||
641 | "#, | ||
642 | ); | ||
643 | } | ||
644 | |||
645 | #[test] | ||
646 | fn infer_associated_method_enum() { | ||
647 | check_inference( | ||
648 | "infer_associated_method_enum", | ||
649 | r#" | ||
650 | enum A { B, C }; | ||
651 | |||
652 | impl A { | ||
653 | pub fn b() -> A { | ||
654 | A::B | ||
655 | } | ||
656 | pub fn c() -> A { | ||
657 | A::C | ||
658 | } | ||
659 | } | ||
660 | fn test() { | ||
661 | let a = A::b(); | ||
662 | a; | ||
663 | let c = A::c(); | ||
664 | c; | ||
665 | } | ||
666 | "#, | ||
667 | ); | ||
668 | } | ||
669 | |||
670 | #[test] | ||
671 | fn infer_associated_method_with_modules() { | ||
672 | check_inference( | ||
673 | "infer_associated_method_with_modules", | ||
674 | r#" | ||
675 | mod a { | ||
676 | struct A; | ||
677 | impl A { pub fn thing() -> A { A {} }} | ||
678 | } | ||
679 | |||
680 | mod b { | ||
681 | struct B; | ||
682 | impl B { pub fn thing() -> u32 { 99 }} | ||
683 | |||
684 | mod c { | ||
685 | struct C; | ||
686 | impl C { pub fn thing() -> C { C {} }} | ||
687 | } | ||
688 | } | ||
689 | use b::c; | ||
690 | |||
691 | fn test() { | ||
692 | let x = a::A::thing(); | ||
693 | let y = b::B::thing(); | ||
694 | let z = c::C::thing(); | ||
695 | } | ||
696 | "#, | ||
697 | ); | ||
698 | } | ||
699 | |||
700 | #[test] | ||
701 | fn infer_associated_method_generics() { | ||
702 | check_inference( | ||
703 | "infer_associated_method_generics", | ||
704 | r#" | ||
705 | struct Gen<T> { | ||
706 | val: T | ||
707 | } | ||
708 | |||
709 | impl<T> Gen<T> { | ||
710 | pub fn make(val: T) -> Gen<T> { | ||
711 | Gen { val } | ||
712 | } | ||
713 | } | ||
714 | |||
715 | fn test() { | ||
716 | let a = Gen::make(0u32); | ||
717 | } | ||
718 | "#, | ||
719 | ); | ||
720 | } | ||
721 | |||
722 | #[test] | ||
590 | fn no_panic_on_field_of_enum() { | 723 | fn no_panic_on_field_of_enum() { |
591 | check_inference( | 724 | check_inference( |
592 | "no_panic_on_field_of_enum", | 725 | "no_panic_on_field_of_enum", |