mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-28 10:39:45 +00:00
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:
parent
bbb6459dc4
commit
4353624cc0
1 changed files with 16 additions and 2 deletions
|
|
@ -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;
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue