diff options
author | Florian Diebold <[email protected]> | 2019-05-12 16:53:33 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-06-15 17:21:23 +0100 |
commit | 6f946f96563bac1f214f86f463287d94968e3688 (patch) | |
tree | 37919910c72aaa4ecdf10275e967b0efebe16b70 /crates/ra_hir/src/ty/tests.rs | |
parent | 41c56c8a0d01d395e49cd199e6050b02a91cff1d (diff) |
Add test for Deref
Diffstat (limited to 'crates/ra_hir/src/ty/tests.rs')
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 54b2a8c16..e587dca31 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -2737,6 +2737,35 @@ 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 | |||
2740 | fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { | 2769 | fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { |
2741 | let file = db.parse(pos.file_id).ok().unwrap(); | 2770 | let file = db.parse(pos.file_id).ok().unwrap(); |
2742 | let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap(); | 2771 | let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap(); |