diff options
Diffstat (limited to 'crates/ra_hir/src/ty/tests.rs')
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 54b2a8c16..0fe7805e2 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -2737,6 +2737,90 @@ fn main() { | |||
2737 | assert_eq!(t, "Foo"); | 2737 | assert_eq!(t, "Foo"); |
2738 | } | 2738 | } |
2739 | 2739 | ||
2740 | #[test] | ||
2741 | fn deref_trait() { | ||
2742 | let t = type_at( | ||
2743 | r#" | ||
2744 | //- /main.rs | ||
2745 | #[lang = "deref"] | ||
2746 | trait Deref { | ||
2747 | type Target; | ||
2748 | fn deref(&self) -> &Self::Target; | ||
2749 | } | ||
2750 | |||
2751 | struct Arc<T>; | ||
2752 | impl<T> Deref for Arc<T> { | ||
2753 | type Target = T; | ||
2754 | } | ||
2755 | |||
2756 | struct S; | ||
2757 | impl S { | ||
2758 | fn foo(&self) -> u128 {} | ||
2759 | } | ||
2760 | |||
2761 | fn test(s: Arc<S>) { | ||
2762 | (*s, s.foo())<|> | ||
2763 | } | ||
2764 | "#, | ||
2765 | ); | ||
2766 | assert_eq!(t, "(S, u128)"); | ||
2767 | } | ||
2768 | |||
2769 | #[test] | ||
2770 | fn deref_trait_with_inference_var() { | ||
2771 | let t = type_at( | ||
2772 | r#" | ||
2773 | //- /main.rs | ||
2774 | #[lang = "deref"] | ||
2775 | trait Deref { | ||
2776 | type Target; | ||
2777 | fn deref(&self) -> &Self::Target; | ||
2778 | } | ||
2779 | |||
2780 | struct Arc<T>; | ||
2781 | fn new_arc<T>() -> Arc<T> {} | ||
2782 | impl<T> Deref for Arc<T> { | ||
2783 | type Target = T; | ||
2784 | } | ||
2785 | |||
2786 | struct S; | ||
2787 | fn foo(a: Arc<S>) {} | ||
2788 | |||
2789 | fn test() { | ||
2790 | let a = new_arc(); | ||
2791 | let b = (*a)<|>; | ||
2792 | foo(a); | ||
2793 | } | ||
2794 | "#, | ||
2795 | ); | ||
2796 | assert_eq!(t, "S"); | ||
2797 | } | ||
2798 | |||
2799 | #[test] | ||
2800 | fn deref_trait_infinite_recursion() { | ||
2801 | let t = type_at( | ||
2802 | r#" | ||
2803 | //- /main.rs | ||
2804 | #[lang = "deref"] | ||
2805 | trait Deref { | ||
2806 | type Target; | ||
2807 | fn deref(&self) -> &Self::Target; | ||
2808 | } | ||
2809 | |||
2810 | struct S; | ||
2811 | |||
2812 | impl Deref for S { | ||
2813 | type Target = S; | ||
2814 | } | ||
2815 | |||
2816 | fn test(s: S) { | ||
2817 | s.foo()<|>; | ||
2818 | } | ||
2819 | "#, | ||
2820 | ); | ||
2821 | assert_eq!(t, "{unknown}"); | ||
2822 | } | ||
2823 | |||
2740 | fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { | 2824 | fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { |
2741 | let file = db.parse(pos.file_id).ok().unwrap(); | 2825 | let file = db.parse(pos.file_id).ok().unwrap(); |
2742 | let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap(); | 2826 | let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap(); |