mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-29 06:23:25 +00:00
Disallow invalid raw ident names
This commit is contained in:
parent
9b0daf20c9
commit
57f0e9c100
2 changed files with 17 additions and 1 deletions
|
@ -537,7 +537,14 @@ impl IdentifierKind {
|
|||
pub fn classify(new_name: &str) -> Result<IdentifierKind> {
|
||||
match parser::LexedStr::single_token(new_name) {
|
||||
Some(res) => match res {
|
||||
(SyntaxKind::IDENT, _) => Ok(IdentifierKind::Ident),
|
||||
(SyntaxKind::IDENT, _) => {
|
||||
if let Some(inner) = new_name.strip_prefix("r#") {
|
||||
if matches!(inner, "self" | "crate" | "super" | "Self") {
|
||||
bail!("Invalid name: `{}` cannot be a raw identifier", inner);
|
||||
}
|
||||
}
|
||||
Ok(IdentifierKind::Ident)
|
||||
}
|
||||
(T![_], _) => Ok(IdentifierKind::Underscore),
|
||||
(SyntaxKind::LIFETIME_IDENT, _) if new_name != "'static" && new_name != "'_" => {
|
||||
Ok(IdentifierKind::Lifetime)
|
||||
|
|
|
@ -562,6 +562,15 @@ impl Foo {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rename_mod_invalid_raw_ident() {
|
||||
check(
|
||||
"r#self",
|
||||
r#"mod foo$0 {}"#,
|
||||
"error: Invalid name: `self` cannot be a raw identifier",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rename_for_local() {
|
||||
check(
|
||||
|
|
Loading…
Reference in a new issue