diff options
author | Florian Diebold <[email protected]> | 2019-09-17 22:06:05 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-09-17 22:06:05 +0100 |
commit | 69c8cfc4c17e9f4533437c757e754a140c0a9ebc (patch) | |
tree | f768700f3b924261910b44372976d4a9464f8690 /crates | |
parent | a040fde3ae5e339199237f24a7461812e74475bf (diff) |
Add test for `T::Item` cycles
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index fdcb3c37f..9a3faa9ab 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -4062,6 +4062,48 @@ fn test<F: FnOnce(u32) -> u64>(f: F) { | |||
4062 | ); | 4062 | ); |
4063 | } | 4063 | } |
4064 | 4064 | ||
4065 | #[test] | ||
4066 | fn unselected_projection_in_trait_env() { | ||
4067 | let t = type_at( | ||
4068 | r#" | ||
4069 | //- /main.rs | ||
4070 | trait Trait { | ||
4071 | type Item; | ||
4072 | } | ||
4073 | |||
4074 | trait Trait2 { | ||
4075 | fn foo(&self) -> u32; | ||
4076 | } | ||
4077 | |||
4078 | fn test<T: Trait>() where T::Item: Trait2 { | ||
4079 | let x: T::Item = no_matter; | ||
4080 | x.foo()<|>; | ||
4081 | } | ||
4082 | "#, | ||
4083 | ); | ||
4084 | assert_eq!(t, "u32"); | ||
4085 | } | ||
4086 | |||
4087 | #[test] | ||
4088 | fn unselected_projection_in_trait_env_cycle() { | ||
4089 | let t = type_at( | ||
4090 | r#" | ||
4091 | //- /main.rs | ||
4092 | trait Trait { | ||
4093 | type Item; | ||
4094 | } | ||
4095 | |||
4096 | trait Trait2<T> {} | ||
4097 | |||
4098 | fn test<T: Trait>() where T: Trait2<T::Item> { | ||
4099 | let x: T::Item = no_matter<|>; | ||
4100 | } | ||
4101 | "#, | ||
4102 | ); | ||
4103 | // this is a legitimate cycle | ||
4104 | assert_eq!(t, "{unknown}"); | ||
4105 | } | ||
4106 | |||
4065 | fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { | 4107 | fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { |
4066 | let file = db.parse(pos.file_id).ok().unwrap(); | 4108 | let file = db.parse(pos.file_id).ok().unwrap(); |
4067 | let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap(); | 4109 | let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap(); |