7772: Pickup ConstReference patterns in FindUsages r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
bors[bot] 2021-02-23 22:32:47 +00:00 committed by GitHub
commit aa38fa1c72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 4 deletions

View File

@ -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
"#]],
);
}
} }

View File

@ -416,10 +416,11 @@ fn found_name(
sink: &mut dyn FnMut(FileId, FileReference) -> bool, sink: &mut dyn FnMut(FileId, FileReference) -> bool,
) -> bool { ) -> bool {
match NameClass::classify(self.sema, name) { match NameClass::classify(self.sema, name) {
Some(NameClass::PatFieldShorthand { local_def: _, field_ref }) => { Some(NameClass::PatFieldShorthand { local_def: _, field_ref })
if !matches!(self.def, Definition::Field(_) if &field_ref == self.def) { if matches!(
return false; self.def, Definition::Field(_) if &field_ref == self.def
} ) =>
{
let FileRange { file_id, range } = self.sema.original_range(name.syntax()); let FileRange { file_id, range } = self.sema.original_range(name.syntax());
let reference = FileReference { let reference = FileReference {
range, range,
@ -429,6 +430,12 @@ fn found_name(
}; };
sink(file_id, reference) 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 _ => false, // not a usage
} }
} }