Skip to content

Commit 750d566

Browse files
authored
Merge pull request #20742 from A4-Tacks/unused-raw-var
Fix fixes for unused raw variables
2 parents 84e87d5 + 4353624 commit 750d566

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

crates/ide-diagnostics/src/handlers/unused_variables.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use ide_db::{
66
label::Label,
77
source_change::SourceChange,
88
};
9-
use syntax::{AstNode, Edition, TextRange};
9+
use syntax::{AstNode, Edition, TextRange, ToSmolStr};
1010

1111
use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext};
1212

@@ -73,7 +73,8 @@ fn fixes(
7373
if is_in_marco {
7474
return None;
7575
}
76-
let name = var_name.display(db, edition);
76+
let name = var_name.display(db, edition).to_smolstr();
77+
let name = name.strip_prefix("r#").unwrap_or(&name);
7778
let new_name = if is_shorthand_field { format!("{name}: _{name}") } else { format!("_{name}") };
7879

7980
Some(vec![Assist {
@@ -231,6 +232,19 @@ fn main() {
231232
}
232233
}
233234
}
235+
"#,
236+
);
237+
238+
check_fix(
239+
r#"
240+
fn main() {
241+
let $0r#type = 2;
242+
}
243+
"#,
244+
r#"
245+
fn main() {
246+
let _type = 2;
247+
}
234248
"#,
235249
);
236250
}

0 commit comments

Comments
 (0)