Skip to content

Commit 57f0e9c

Browse files
committed
Disallow invalid raw ident names
1 parent 9b0daf2 commit 57f0e9c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

crates/ide-db/src/rename.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,14 @@ impl IdentifierKind {
537537
pub fn classify(new_name: &str) -> Result<IdentifierKind> {
538538
match parser::LexedStr::single_token(new_name) {
539539
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+
}
541548
(T![_], _) => Ok(IdentifierKind::Underscore),
542549
(SyntaxKind::LIFETIME_IDENT, _) if new_name != "'static" && new_name != "'_" => {
543550
Ok(IdentifierKind::Lifetime)

crates/ide/src/rename.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,15 @@ impl Foo {
562562
);
563563
}
564564

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+
565574
#[test]
566575
fn test_rename_for_local() {
567576
check(

0 commit comments

Comments
 (0)