File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -90,10 +90,16 @@ impl Name {
9090
9191 /// Resolve a name from the text of token.
9292 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.
9593 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.
9696 Some ( text) if !is_raw_identifier ( text) => Name :: new_text ( SmolStr :: new ( text) ) ,
97+ // Keywords (in the current edition) *can* be used as a name in earlier editions of
98+ // Rust, e.g. "try" in Rust 2015. Even in such cases, we keep track of them in their
99+ // escaped form.
100+ None if is_raw_identifier ( raw_text) => {
101+ Name :: new_text ( SmolStr :: from_iter ( [ "r#" , raw_text] ) )
102+ }
97103 _ => Name :: new_text ( raw_text. into ( ) ) ,
98104 }
99105 }
Original file line number Diff line number Diff line change @@ -402,7 +402,9 @@ impl<'a> FindUsages<'a> {
402402 . or_else ( || ty. as_builtin ( ) . map ( |builtin| builtin. name ( ) ) )
403403 } )
404404 } ;
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 ( ) )
406408 }
407409 } ;
408410 let name = match & name {
You can’t perform that action at this time.
0 commit comments