File tree 2 files changed +17
-1
lines changed
2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -537,7 +537,14 @@ impl IdentifierKind {
537
537
pub fn classify ( new_name : & str ) -> Result < IdentifierKind > {
538
538
match parser:: LexedStr :: single_token ( new_name) {
539
539
Some ( res) => match res {
540
- ( SyntaxKind :: IDENT , _) => Ok ( IdentifierKind :: Ident ) ,
540
+ ( SyntaxKind :: IDENT , _) => {
541
+ if let Some ( inner) = new_name. strip_prefix ( "r#" ) {
542
+ if matches ! ( inner, "self" | "crate" | "super" | "Self" ) {
543
+ bail ! ( "Invalid name: `{}` cannot be a raw identifier" , inner) ;
544
+ }
545
+ }
546
+ Ok ( IdentifierKind :: Ident )
547
+ }
541
548
( T ! [ _] , _) => Ok ( IdentifierKind :: Underscore ) ,
542
549
( SyntaxKind :: LIFETIME_IDENT , _) if new_name != "'static" && new_name != "'_" => {
543
550
Ok ( IdentifierKind :: Lifetime )
Original file line number Diff line number Diff line change @@ -562,6 +562,15 @@ impl Foo {
562
562
) ;
563
563
}
564
564
565
+ #[ test]
566
+ fn test_rename_mod_invalid_raw_ident ( ) {
567
+ check (
568
+ "r#self" ,
569
+ r#"mod foo$0 {}"# ,
570
+ "error: Invalid name: `self` cannot be a raw identifier" ,
571
+ ) ;
572
+ }
573
+
565
574
#[ test]
566
575
fn test_rename_for_local ( ) {
567
576
check (
You can’t perform that action at this time.
0 commit comments