diff options
Diffstat (limited to 'crates/ra_hir/src/ty')
6 files changed, 222 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_associated_const.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_associated_const.snap new file mode 100644 index 000000000..14ab8ba96 --- /dev/null +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_associated_const.snap | |||
@@ -0,0 +1,14 @@ | |||
1 | --- | ||
2 | created: "2019-02-20T11:04:56.553382800Z" | ||
3 | creator: [email protected] | ||
4 | source: crates/ra_hir/src/ty/tests.rs | ||
5 | expression: "&result" | ||
6 | --- | ||
7 | [227; 305) '{ ...:ID; }': () | ||
8 | [237; 238) 'x': u32 | ||
9 | [241; 252) 'Struct::FOO': u32 | ||
10 | [262; 263) 'y': u32 | ||
11 | [266; 275) 'Enum::BAR': u32 | ||
12 | [285; 286) 'z': u32 | ||
13 | [289; 302) 'TraitTest::ID': u32 | ||
14 | |||
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_associated_method_enum.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_associated_method_enum.snap new file mode 100644 index 000000000..8f27af88c --- /dev/null +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_associated_method_enum.snap | |||
@@ -0,0 +1,20 @@ | |||
1 | --- | ||
2 | created: "2019-02-20T11:04:56.553382800Z" | ||
3 | creator: [email protected] | ||
4 | source: crates/ra_hir/src/ty/tests.rs | ||
5 | expression: "&result" | ||
6 | --- | ||
7 | [48; 68) '{ ... }': A | ||
8 | [58; 62) 'A::B': A | ||
9 | [89; 109) '{ ... }': A | ||
10 | [99; 103) 'A::C': A | ||
11 | [122; 179) '{ ... c; }': () | ||
12 | [132; 133) 'a': A | ||
13 | [136; 140) 'A::b': fn b() -> A | ||
14 | [136; 142) 'A::b()': A | ||
15 | [148; 149) 'a': A | ||
16 | [159; 160) 'c': A | ||
17 | [163; 167) 'A::c': fn c() -> A | ||
18 | [163; 169) 'A::c()': A | ||
19 | [175; 176) 'c': A | ||
20 | |||
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_associated_method_generics.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_associated_method_generics.snap new file mode 100644 index 000000000..fe5d6590e --- /dev/null +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_associated_method_generics.snap | |||
@@ -0,0 +1,16 @@ | |||
1 | --- | ||
2 | created: "2019-02-21T10:25:18.568887300Z" | ||
3 | creator: [email protected] | ||
4 | source: crates/ra_hir/src/ty/tests.rs | ||
5 | expression: "&result" | ||
6 | --- | ||
7 | [64; 67) 'val': T | ||
8 | [82; 109) '{ ... }': Gen<T> | ||
9 | [92; 103) 'Gen { val }': Gen<T> | ||
10 | [98; 101) 'val': T | ||
11 | [123; 155) '{ ...32); }': () | ||
12 | [133; 134) 'a': Gen<[unknown]> | ||
13 | [137; 146) 'Gen::make': fn make<[unknown]>(T) -> Gen<T> | ||
14 | [137; 152) 'Gen::make(0u32)': Gen<[unknown]> | ||
15 | [147; 151) '0u32': u32 | ||
16 | |||
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_associated_method_struct.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_associated_method_struct.snap new file mode 100644 index 000000000..29ca9b0ea --- /dev/null +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_associated_method_struct.snap | |||
@@ -0,0 +1,16 @@ | |||
1 | --- | ||
2 | created: "2019-02-20T11:04:56.553382800Z" | ||
3 | creator: [email protected] | ||
4 | source: crates/ra_hir/src/ty/tests.rs | ||
5 | expression: "&result" | ||
6 | --- | ||
7 | [50; 76) '{ ... }': A | ||
8 | [60; 70) 'A { x: 0 }': A | ||
9 | [67; 68) '0': u32 | ||
10 | [89; 123) '{ ...a.x; }': () | ||
11 | [99; 100) 'a': A | ||
12 | [103; 109) 'A::new': fn new() -> A | ||
13 | [103; 111) 'A::new()': A | ||
14 | [117; 118) 'a': A | ||
15 | [117; 120) 'a.x': u32 | ||
16 | |||
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_associated_method_with_modules.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_associated_method_with_modules.snap new file mode 100644 index 000000000..6584bef39 --- /dev/null +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_associated_method_with_modules.snap | |||
@@ -0,0 +1,23 @@ | |||
1 | --- | ||
2 | created: "2019-02-21T08:55:53.926725400Z" | ||
3 | creator: [email protected] | ||
4 | source: crates/ra_hir/src/ty/tests.rs | ||
5 | expression: "&result" | ||
6 | --- | ||
7 | [56; 64) '{ A {} }': A | ||
8 | [58; 62) 'A {}': A | ||
9 | [126; 132) '{ 99 }': u32 | ||
10 | [128; 130) '99': u32 | ||
11 | [202; 210) '{ C {} }': C | ||
12 | [204; 208) 'C {}': C | ||
13 | [241; 325) '{ ...g(); }': () | ||
14 | [251; 252) 'x': A | ||
15 | [255; 266) 'a::A::thing': fn thing() -> A | ||
16 | [255; 268) 'a::A::thing()': A | ||
17 | [278; 279) 'y': u32 | ||
18 | [282; 293) 'b::B::thing': fn thing() -> u32 | ||
19 | [282; 295) 'b::B::thing()': u32 | ||
20 | [305; 306) 'z': C | ||
21 | [309; 320) 'c::C::thing': fn thing() -> C | ||
22 | [309; 322) 'c::C::thing()': C | ||
23 | |||
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", |