File tree 2 files changed +15
-4
lines changed
2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -90,11 +90,20 @@ impl Name {
90
90
91
91
/// Resolve a name from the text of token.
92
92
fn resolve ( raw_text : & str ) -> Name {
93
- // When `raw_text` starts with "r#" but the name does not coincide with any
94
- // keyword, we never need the prefix so we strip it.
95
93
match raw_text. strip_prefix ( "r#" ) {
94
+ // When `raw_text` starts with "r#" but the name does not coincide with any
95
+ // keyword, we never need the prefix so we strip it.
96
96
Some ( text) if !is_raw_identifier ( text) => Name :: new_text ( SmolStr :: new ( text) ) ,
97
- _ => Name :: new_text ( raw_text. into ( ) ) ,
97
+ _ => {
98
+ // Keywords (in the current edition) *can* be used as a name in earlier editions of
99
+ // Rust, e.g. "try" in Rust 2015. Even in such cases, we keep track of them in
100
+ // their escaped form.
101
+ if is_raw_identifier ( raw_text) {
102
+ Name :: new_text ( [ "r#" , raw_text] . into_iter ( ) . collect ( ) )
103
+ } else {
104
+ Name :: new_text ( raw_text. into ( ) )
105
+ }
106
+ }
98
107
}
99
108
}
100
109
Original file line number Diff line number Diff line change @@ -402,7 +402,9 @@ impl<'a> FindUsages<'a> {
402
402
. or_else ( || ty. as_builtin ( ) . map ( |builtin| builtin. name ( ) ) )
403
403
} )
404
404
} ;
405
- self . def . name ( sema. db ) . or_else ( self_kw_refs) . map ( |it| it. to_smol_str ( ) )
405
+ // We need to unescape the name in case it is written without "r#" in earlier
406
+ // editions of Rust where it isn't a keyword.
407
+ self . def . name ( sema. db ) . or_else ( self_kw_refs) . map ( |it| it. unescaped ( ) . to_smol_str ( ) )
406
408
}
407
409
} ;
408
410
let name = match & name {
You can’t perform that action at this time.
0 commit comments