File tree Expand file tree Collapse file tree 2 files changed +45
-2
lines changed
src/tools/rust-analyzer/crates Expand file tree Collapse file tree 2 files changed +45
-2
lines changed Original file line number Diff line number Diff line change @@ -531,7 +531,7 @@ impl<'a> FindUsages<'a> {
531531 node. token_at_offset ( offset)
532532 . find ( |it| {
533533 // `name` is stripped of raw ident prefix. See the comment on name retrieval below.
534- it. text ( ) . trim_start_matches ( "r#" ) == name
534+ it. text ( ) . trim_start_matches ( '\'' ) . trim_start_matches ( "r#" ) == name
535535 } )
536536 . into_iter ( )
537537 . flat_map ( move |token| {
@@ -938,7 +938,12 @@ impl<'a> FindUsages<'a> {
938938 } )
939939 } ;
940940 // We need to search without the `r#`, hence `as_str` access.
941- self . def . name ( sema. db ) . or_else ( self_kw_refs) . map ( |it| it. as_str ( ) . to_smolstr ( ) )
941+ // We strip `'` from lifetimes and labels as otherwise they may not match with raw-escaped ones,
942+ // e.g. if we search `'foo` we won't find `'r#foo`.
943+ self . def
944+ . name ( sema. db )
945+ . or_else ( self_kw_refs)
946+ . map ( |it| it. as_str ( ) . trim_start_matches ( '\'' ) . to_smolstr ( ) )
942947 }
943948 } ;
944949 let name = match & name {
Original file line number Diff line number Diff line change @@ -3088,4 +3088,42 @@ fn main() {
30883088 "# ] ] ,
30893089 ) ;
30903090 }
3091+
3092+ #[ test]
3093+ fn raw_labels_and_lifetimes ( ) {
3094+ check (
3095+ r#"
3096+ fn foo<'r#fn>(s: &'r#fn str) {
3097+ let _a: &'r#fn str = s;
3098+ let _b: &'r#fn str;
3099+ 'r#break$0: {
3100+ break 'r#break;
3101+ }
3102+ }
3103+ "# ,
3104+ expect ! [ [ r#"
3105+ 'r#break Label FileId(0) 87..96 87..95
3106+
3107+ FileId(0) 113..121
3108+ "# ] ] ,
3109+ ) ;
3110+ check (
3111+ r#"
3112+ fn foo<'r#fn$0>(s: &'r#fn str) {
3113+ let _a: &'r#fn str = s;
3114+ let _b: &'r#fn str;
3115+ 'r#break: {
3116+ break 'r#break;
3117+ }
3118+ }
3119+ "# ,
3120+ expect ! [ [ r#"
3121+ 'r#fn LifetimeParam FileId(0) 7..12
3122+
3123+ FileId(0) 18..23
3124+ FileId(0) 44..49
3125+ FileId(0) 72..77
3126+ "# ] ] ,
3127+ ) ;
3128+ }
30913129}
You can’t perform that action at this time.
0 commit comments