aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/ty/tests.rs42
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]
4066fn unselected_projection_in_trait_env() {
4067 let t = type_at(
4068 r#"
4069//- /main.rs
4070trait Trait {
4071 type Item;
4072}
4073
4074trait Trait2 {
4075 fn foo(&self) -> u32;
4076}
4077
4078fn 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]
4088fn unselected_projection_in_trait_env_cycle() {
4089 let t = type_at(
4090 r#"
4091//- /main.rs
4092trait Trait {
4093 type Item;
4094}
4095
4096trait Trait2<T> {}
4097
4098fn 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
4065fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { 4107fn 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();