Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-diagnostics/src/handlers/mutability_errors.rs')
-rw-r--r--crates/ide-diagnostics/src/handlers/mutability_errors.rs50
1 files changed, 31 insertions, 19 deletions
diff --git a/crates/ide-diagnostics/src/handlers/mutability_errors.rs b/crates/ide-diagnostics/src/handlers/mutability_errors.rs
index 34a0038295..00352266dd 100644
--- a/crates/ide-diagnostics/src/handlers/mutability_errors.rs
+++ b/crates/ide-diagnostics/src/handlers/mutability_errors.rs
@@ -7,7 +7,11 @@ use crate::{fix, Diagnostic, DiagnosticCode, DiagnosticsContext};
// Diagnostic: need-mut
//
// This diagnostic is triggered on mutating an immutable variable.
-pub(crate) fn need_mut(ctx: &DiagnosticsContext<'_>, d: &hir::NeedMut) -> Diagnostic {
+pub(crate) fn need_mut(ctx: &DiagnosticsContext<'_>, d: &hir::NeedMut) -> Option<Diagnostic> {
+ if d.span.file_id.macro_file().is_some() {
+ // FIXME: Our infra can't handle allow from within macro expansions rn
+ return None;
+ }
let fixes = (|| {
if d.local.is_ref(ctx.sema.db) {
// There is no simple way to add `mut` to `ref x` and `ref mut x`
@@ -29,24 +33,30 @@ pub(crate) fn need_mut(ctx: &DiagnosticsContext<'_>, d: &hir::NeedMut) -> Diagno
use_range,
)])
})();
- Diagnostic::new_with_syntax_node_ptr(
- ctx,
- // FIXME: `E0384` is not the only error that this diagnostic handles
- DiagnosticCode::RustcHardError("E0384"),
- format!(
- "cannot mutate immutable variable `{}`",
- d.local.name(ctx.sema.db).display(ctx.sema.db)
- ),
- d.span,
+ Some(
+ Diagnostic::new_with_syntax_node_ptr(
+ ctx,
+ // FIXME: `E0384` is not the only error that this diagnostic handles
+ DiagnosticCode::RustcHardError("E0384"),
+ format!(
+ "cannot mutate immutable variable `{}`",
+ d.local.name(ctx.sema.db).display(ctx.sema.db)
+ ),
+ d.span,
+ )
+ .with_fixes(fixes),
)
- .with_fixes(fixes)
}
// Diagnostic: unused-mut
//
// This diagnostic is triggered when a mutable variable isn't actually mutated.
-pub(crate) fn unused_mut(ctx: &DiagnosticsContext<'_>, d: &hir::UnusedMut) -> Diagnostic {
+pub(crate) fn unused_mut(ctx: &DiagnosticsContext<'_>, d: &hir::UnusedMut) -> Option<Diagnostic> {
let ast = d.local.primary_source(ctx.sema.db).syntax_ptr();
+ if ast.file_id.macro_file().is_some() {
+ // FIXME: Our infra can't handle allow from within macro expansions rn
+ return None;
+ }
let fixes = (|| {
let file_id = ast.file_id.file_id()?;
let mut edit_builder = TextEdit::builder();
@@ -70,14 +80,16 @@ pub(crate) fn unused_mut(ctx: &DiagnosticsContext<'_>, d: &hir::UnusedMut) -> Di
)])
})();
let ast = d.local.primary_source(ctx.sema.db).syntax_ptr();
- Diagnostic::new_with_syntax_node_ptr(
- ctx,
- DiagnosticCode::RustcLint("unused_mut"),
- "variable does not need to be mutable",
- ast,
+ Some(
+ Diagnostic::new_with_syntax_node_ptr(
+ ctx,
+ DiagnosticCode::RustcLint("unused_mut"),
+ "variable does not need to be mutable",
+ ast,
+ )
+ .experimental() // Not supporting `#[allow(unused_mut)]` in proc macros leads to false positive.
+ .with_fixes(fixes),
)
- .experimental() // Not supporting `#[allow(unused_mut)]` in proc macros leads to false positive.
- .with_fixes(fixes)
}
pub(super) fn token(parent: &SyntaxNode, kind: SyntaxKind) -> Option<SyntaxToken> {