mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-25 11:17:13 +00:00
Fix search of raw labels and lifetimes
It used to search for `'foo` which won't find `'r#foo`, now we search for `foo` instead.
This commit is contained in:
parent
ed193af369
commit
7723b21c3f
@ -531,7 +531,7 @@ impl<'a> FindUsages<'a> {
|
||||
node.token_at_offset(offset)
|
||||
.find(|it| {
|
||||
// `name` is stripped of raw ident prefix. See the comment on name retrieval below.
|
||||
it.text().trim_start_matches("r#") == name
|
||||
it.text().trim_start_matches('\'').trim_start_matches("r#") == name
|
||||
})
|
||||
.into_iter()
|
||||
.flat_map(move |token| {
|
||||
@ -938,7 +938,12 @@ impl<'a> FindUsages<'a> {
|
||||
})
|
||||
};
|
||||
// We need to search without the `r#`, hence `as_str` access.
|
||||
self.def.name(sema.db).or_else(self_kw_refs).map(|it| it.as_str().to_smolstr())
|
||||
// We strip `'` from lifetimes and labels as otherwise they may not match with raw-escaped ones,
|
||||
// e.g. if we search `'foo` we won't find `'r#foo`.
|
||||
self.def
|
||||
.name(sema.db)
|
||||
.or_else(self_kw_refs)
|
||||
.map(|it| it.as_str().trim_start_matches('\'').to_smolstr())
|
||||
}
|
||||
};
|
||||
let name = match &name {
|
||||
|
@ -3088,4 +3088,42 @@ fn main() {
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn raw_labels_and_lifetimes() {
|
||||
check(
|
||||
r#"
|
||||
fn foo<'r#fn>(s: &'r#fn str) {
|
||||
let _a: &'r#fn str = s;
|
||||
let _b: &'r#fn str;
|
||||
'r#break$0: {
|
||||
break 'r#break;
|
||||
}
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
'r#break Label FileId(0) 87..96 87..95
|
||||
|
||||
FileId(0) 113..121
|
||||
"#]],
|
||||
);
|
||||
check(
|
||||
r#"
|
||||
fn foo<'r#fn$0>(s: &'r#fn str) {
|
||||
let _a: &'r#fn str = s;
|
||||
let _b: &'r#fn str;
|
||||
'r#break: {
|
||||
break 'r#break;
|
||||
}
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
'r#fn LifetimeParam FileId(0) 7..12
|
||||
|
||||
FileId(0) 18..23
|
||||
FileId(0) 44..49
|
||||
FileId(0) 72..77
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user