diff options
author | Lukas Wirth <[email protected]> | 2021-05-08 21:34:55 +0100 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2021-05-08 21:34:55 +0100 |
commit | 41f470fea84998af65292f3c297c3e2b1d897848 (patch) | |
tree | 2dee702ff58dd614a559e9f4ef3080419cabd2c4 /crates/ide | |
parent | 96c5df9b171730ad69e130e074584684cee35014 (diff) |
Correctly support SelfType when searching for usages
Diffstat (limited to 'crates/ide')
-rw-r--r-- | crates/ide/src/references.rs | 55 | ||||
-rw-r--r-- | crates/ide/src/references/rename.rs | 17 |
2 files changed, 69 insertions, 3 deletions
diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs index 11ca7ec6b..1551cd2a8 100644 --- a/crates/ide/src/references.rs +++ b/crates/ide/src/references.rs | |||
@@ -65,7 +65,7 @@ pub(crate) fn find_all_refs( | |||
65 | (find_def(&sema, &syntax, position)?, false) | 65 | (find_def(&sema, &syntax, position)?, false) |
66 | }; | 66 | }; |
67 | 67 | ||
68 | let mut usages = def.usages(sema).set_scope(search_scope).all(); | 68 | let mut usages = def.usages(sema).set_scope(search_scope).include_self_refs().all(); |
69 | if is_literal_search { | 69 | if is_literal_search { |
70 | // filter for constructor-literals | 70 | // filter for constructor-literals |
71 | let refs = usages.references.values_mut(); | 71 | let refs = usages.references.values_mut(); |
@@ -1166,19 +1166,68 @@ fn foo<const FOO$0: usize>() -> usize { | |||
1166 | fn test_find_self_ty_in_trait_def() { | 1166 | fn test_find_self_ty_in_trait_def() { |
1167 | check( | 1167 | check( |
1168 | r#" | 1168 | r#" |
1169 | trait Foo { | 1169 | trait Foo where Self: { |
1170 | fn f() -> Self$0; | 1170 | fn f() -> Self$0; |
1171 | } | 1171 | } |
1172 | "#, | 1172 | "#, |
1173 | expect![[r#" | 1173 | expect![[r#" |
1174 | Self TypeParam FileId(0) 6..9 6..9 | 1174 | Self TypeParam FileId(0) 6..9 6..9 |
1175 | 1175 | ||
1176 | FileId(0) 26..30 | 1176 | FileId(0) 16..20 |
1177 | FileId(0) 38..42 | ||
1177 | "#]], | 1178 | "#]], |
1178 | ); | 1179 | ); |
1180 | // check( | ||
1181 | // r#" | ||
1182 | // trait Foo$0 where Self: { | ||
1183 | // fn f() -> Self; | ||
1184 | // } | ||
1185 | // "#, | ||
1186 | // expect![[r#" | ||
1187 | // Foo Trait FileId(0) 0..45 6..9 | ||
1188 | |||
1189 | // FileId(0) 16..20 | ||
1190 | // FileId(0) 38..42 | ||
1191 | // "#]], | ||
1192 | // ); | ||
1179 | } | 1193 | } |
1180 | 1194 | ||
1181 | #[test] | 1195 | #[test] |
1196 | fn test_self_ty() { | ||
1197 | check( | ||
1198 | r#" | ||
1199 | struct $0Foo; | ||
1200 | |||
1201 | impl Foo where Self: { | ||
1202 | fn f() -> Self; | ||
1203 | } | ||
1204 | "#, | ||
1205 | expect![[r#" | ||
1206 | Foo Struct FileId(0) 0..11 7..10 | ||
1207 | |||
1208 | FileId(0) 18..21 | ||
1209 | FileId(0) 28..32 | ||
1210 | FileId(0) 50..54 | ||
1211 | "#]], | ||
1212 | ); | ||
1213 | check( | ||
1214 | r#" | ||
1215 | struct Foo; | ||
1216 | |||
1217 | impl Foo where Self: { | ||
1218 | fn f() -> Self$0; | ||
1219 | } | ||
1220 | "#, | ||
1221 | expect![[r#" | ||
1222 | impl Impl FileId(0) 13..57 18..21 | ||
1223 | |||
1224 | FileId(0) 18..21 | ||
1225 | FileId(0) 28..32 | ||
1226 | FileId(0) 50..54 | ||
1227 | "#]], | ||
1228 | ); | ||
1229 | } | ||
1230 | #[test] | ||
1182 | fn test_self_variant_with_payload() { | 1231 | fn test_self_variant_with_payload() { |
1183 | check( | 1232 | check( |
1184 | r#" | 1233 | r#" |
diff --git a/crates/ide/src/references/rename.rs b/crates/ide/src/references/rename.rs index 175e7a31d..2bf953305 100644 --- a/crates/ide/src/references/rename.rs +++ b/crates/ide/src/references/rename.rs | |||
@@ -1888,4 +1888,21 @@ impl Foo { | |||
1888 | "error: Cannot rename `Self`", | 1888 | "error: Cannot rename `Self`", |
1889 | ); | 1889 | ); |
1890 | } | 1890 | } |
1891 | |||
1892 | #[test] | ||
1893 | fn test_rename_ignores_self_ty() { | ||
1894 | check( | ||
1895 | "Fo0", | ||
1896 | r#" | ||
1897 | struct $0Foo; | ||
1898 | |||
1899 | impl Foo where Self: {} | ||
1900 | "#, | ||
1901 | r#" | ||
1902 | struct Fo0; | ||
1903 | |||
1904 | impl Fo0 where Self: {} | ||
1905 | "#, | ||
1906 | ); | ||
1907 | } | ||
1891 | } | 1908 | } |