Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/ide-db/src/search.rs9
-rw-r--r--crates/ide/src/references.rs38
2 files changed, 45 insertions, 2 deletions
diff --git a/crates/ide-db/src/search.rs b/crates/ide-db/src/search.rs
index 4efb83ba32..9cf0bcf919 100644
--- a/crates/ide-db/src/search.rs
+++ b/crates/ide-db/src/search.rs
@@ -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 {
diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs
index fe874bc99b..86b88a17c7 100644
--- a/crates/ide/src/references.rs
+++ b/crates/ide/src/references.rs
@@ -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
+ "#]],
+ );
+ }
}