aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-02-23 22:31:07 +0000
committerLukas Wirth <[email protected]>2021-02-23 22:31:53 +0000
commit9e8f4d31a40eca605a047ed95a98aac43a3e327f (patch)
tree7cd0ee2dfd328dd31db7ef7c25ebf3f4a8361e5f /crates
parenta307e4f31f3a66797628cee0645a38216398d9bd (diff)
Pickup ConstReference patterns in FindUsages
Diffstat (limited to 'crates')
-rw-r--r--crates/ide/src/references.rs25
-rw-r--r--crates/ide_db/src/search.rs15
2 files changed, 36 insertions, 4 deletions
diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs
index 55f95ebae..5d0449e56 100644
--- a/crates/ide/src/references.rs
+++ b/crates/ide/src/references.rs
@@ -1224,4 +1224,29 @@ fn test() {}
1224 "#]], 1224 "#]],
1225 ); 1225 );
1226 } 1226 }
1227
1228 #[test]
1229 fn test_const_in_pattern() {
1230 check(
1231 r#"
1232const A$0: i32 = 42;
1233
1234fn main() {
1235 match A {
1236 A => (),
1237 _ => (),
1238 }
1239 if let A = A {}
1240}
1241"#,
1242 expect![[r#"
1243 A Const FileId(0) 0..18 6..7
1244
1245 FileId(0) 42..43
1246 FileId(0) 54..55
1247 FileId(0) 97..98
1248 FileId(0) 101..102
1249 "#]],
1250 );
1251 }
1227} 1252}
diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs
index ba8bea002..ddcfbd3f3 100644
--- a/crates/ide_db/src/search.rs
+++ b/crates/ide_db/src/search.rs
@@ -416,10 +416,11 @@ impl<'a> FindUsages<'a> {
416 sink: &mut dyn FnMut(FileId, FileReference) -> bool, 416 sink: &mut dyn FnMut(FileId, FileReference) -> bool,
417 ) -> bool { 417 ) -> bool {
418 match NameClass::classify(self.sema, name) { 418 match NameClass::classify(self.sema, name) {
419 Some(NameClass::PatFieldShorthand { local_def: _, field_ref }) => { 419 Some(NameClass::PatFieldShorthand { local_def: _, field_ref })
420 if !matches!(self.def, Definition::Field(_) if &field_ref == self.def) { 420 if matches!(
421 return false; 421 self.def, Definition::Field(_) if &field_ref == self.def
422 } 422 ) =>
423 {
423 let FileRange { file_id, range } = self.sema.original_range(name.syntax()); 424 let FileRange { file_id, range } = self.sema.original_range(name.syntax());
424 let reference = FileReference { 425 let reference = FileReference {
425 range, 426 range,
@@ -429,6 +430,12 @@ impl<'a> FindUsages<'a> {
429 }; 430 };
430 sink(file_id, reference) 431 sink(file_id, reference)
431 } 432 }
433 Some(NameClass::ConstReference(def)) if *self.def == def => {
434 let FileRange { file_id, range } = self.sema.original_range(name.syntax());
435 let reference =
436 FileReference { range, name: ast::NameLike::Name(name.clone()), access: None };
437 sink(file_id, reference)
438 }
432 _ => false, // not a usage 439 _ => false, // not a usage
433 } 440 }
434 } 441 }