Skip to content

Commit 0eb7b6c

Browse files
committed
Don't show unused_variables fixes if the name comes from a macro definition
1 parent 701068d commit 0eb7b6c

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ pub(crate) fn unused_variables(
3030
.primary_source(ctx.sema.db)
3131
.name()
3232
.map(|v| v.syntax().original_file_range_rooted(ctx.sema.db))
33-
.filter(|it| Some(it.file_id) == ast.file_id.file_id())?;
34-
if !diagnostic_range.range.contains_range(name_range.range) {
35-
return None;
36-
}
33+
.filter(|it| {
34+
Some(it.file_id) == ast.file_id.file_id()
35+
&& diagnostic_range.range.contains_range(it.range)
36+
});
3737
let var_name = d.local.name(ctx.sema.db);
3838
Some(
3939
Diagnostic::new_with_syntax_node_ptr(
@@ -42,13 +42,9 @@ pub(crate) fn unused_variables(
4242
"unused variable",
4343
ast,
4444
)
45-
.with_fixes(fixes(
46-
ctx.sema.db,
47-
var_name,
48-
name_range.range,
49-
diagnostic_range,
50-
ast.file_id.is_macro(),
51-
))
45+
.with_fixes(name_range.and_then(|it| {
46+
fixes(ctx.sema.db, var_name, it.range, diagnostic_range, ast.file_id.is_macro())
47+
}))
5248
.experimental(),
5349
)
5450
}

0 commit comments

Comments
 (0)