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 @@ 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user