diff options
| author | Shoyu Vanilla (Flint) <modulo641@gmail.com> | 2025-07-21 04:30:42 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-21 04:30:42 +0000 |
| commit | 33d62b5fbad2a9075a1ce5f296021896cdc04cad (patch) | |
| tree | c2c79d3b5c18a4731910ea2f746d84eb1b918fcc /src | |
| parent | fa0320d077489e4d40d3225b097dcf37cc0d5ad8 (diff) | |
| parent | a6c7ceaae3a918caf7b2e4443441e781405af926 (diff) | |
| download | rust-33d62b5fbad2a9075a1ce5f296021896cdc04cad.tar.gz rust-33d62b5fbad2a9075a1ce5f296021896cdc04cad.zip | |
Merge pull request #20262 from ChayimFriedman2/goto-ref-raw
fix: Fix search of raw labels and lifetimes
Diffstat (limited to 'src')
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide-db/src/search.rs | 9 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide/src/references.rs | 38 |
2 files changed, 45 insertions, 2 deletions
diff --git a/src/tools/rust-analyzer/crates/ide-db/src/search.rs b/src/tools/rust-analyzer/crates/ide-db/src/search.rs index 4efb83ba323..9cf0bcf9190 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/search.rs +++ b/src/tools/rust-analyzer/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/src/tools/rust-analyzer/crates/ide/src/references.rs b/src/tools/rust-analyzer/crates/ide/src/references.rs index fe874bc99b4..86b88a17c75 100644 --- a/src/tools/rust-analyzer/crates/ide/src/references.rs +++ b/src/tools/rust-analyzer/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 + "#]], + ); + } } |
