Fix fixes for unused raw variables

Example
---
```
fn main() {
    let $0r#type = 2;
}
```

**Before this PR**:

```rust
fn main() {
    let _r#type = 2;
}
```

**After this PR**:

```rust
fn main() {
    let _type = 2;
}
```
This commit is contained in:
A4-Tacks 2025-09-25 19:58:45 +08:00
parent bbb6459dc4
commit 4353624cc0
No known key found for this signature in database
GPG Key ID: DBD861323040663B

View File

@ -6,7 +6,7 @@ use ide_db::{
label::Label,
source_change::SourceChange,
};
use syntax::{AstNode, Edition, TextRange};
use syntax::{AstNode, Edition, TextRange, ToSmolStr};
use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext};
@ -73,7 +73,8 @@ fn fixes(
if is_in_marco {
return None;
}
let name = var_name.display(db, edition);
let name = var_name.display(db, edition).to_smolstr();
let name = name.strip_prefix("r#").unwrap_or(&name);
let new_name = if is_shorthand_field { format!("{name}: _{name}") } else { format!("_{name}") };
Some(vec![Assist {
@ -231,6 +232,19 @@ fn main() {
}
}
}
"#,
);
check_fix(
r#"
fn main() {
let $0r#type = 2;
}
"#,
r#"
fn main() {
let _type = 2;
}
"#,
);
}