mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 17:28:09 +00:00
Pickup ConstReference patterns in FindUsages
This commit is contained in:
parent
a307e4f31f
commit
9e8f4d31a4
2 changed files with 36 additions and 4 deletions
|
@ -1224,4 +1224,29 @@ fn test() {}
|
|||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_const_in_pattern() {
|
||||
check(
|
||||
r#"
|
||||
const A$0: i32 = 42;
|
||||
|
||||
fn main() {
|
||||
match A {
|
||||
A => (),
|
||||
_ => (),
|
||||
}
|
||||
if let A = A {}
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
A Const FileId(0) 0..18 6..7
|
||||
|
||||
FileId(0) 42..43
|
||||
FileId(0) 54..55
|
||||
FileId(0) 97..98
|
||||
FileId(0) 101..102
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -416,10 +416,11 @@ impl<'a> FindUsages<'a> {
|
|||
sink: &mut dyn FnMut(FileId, FileReference) -> bool,
|
||||
) -> bool {
|
||||
match NameClass::classify(self.sema, name) {
|
||||
Some(NameClass::PatFieldShorthand { local_def: _, field_ref }) => {
|
||||
if !matches!(self.def, Definition::Field(_) if &field_ref == self.def) {
|
||||
return false;
|
||||
}
|
||||
Some(NameClass::PatFieldShorthand { local_def: _, field_ref })
|
||||
if matches!(
|
||||
self.def, Definition::Field(_) if &field_ref == self.def
|
||||
) =>
|
||||
{
|
||||
let FileRange { file_id, range } = self.sema.original_range(name.syntax());
|
||||
let reference = FileReference {
|
||||
range,
|
||||
|
@ -429,6 +430,12 @@ impl<'a> FindUsages<'a> {
|
|||
};
|
||||
sink(file_id, reference)
|
||||
}
|
||||
Some(NameClass::ConstReference(def)) if *self.def == def => {
|
||||
let FileRange { file_id, range } = self.sema.original_range(name.syntax());
|
||||
let reference =
|
||||
FileReference { range, name: ast::NameLike::Name(name.clone()), access: None };
|
||||
sink(file_id, reference)
|
||||
}
|
||||
_ => false, // not a usage
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue