mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-05 05:04:24 +00:00
Merge #7772
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:
commit
aa38fa1c72
@ -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 New Issue
Block a user