diff options
| author | Chayim Refael Friedman <chayimfr@gmail.com> | 2024-12-04 15:25:01 +0200 |
|---|---|---|
| committer | Chayim Refael Friedman <chayimfr@gmail.com> | 2024-12-04 15:25:01 +0200 |
| commit | d5f3ed89cb0c1fa2164147efff25695be02bc36a (patch) | |
| tree | 84245e7db724b9a04dc7e53a2d4f53a8b2022da0 | |
| parent | 609621db7fc830d4cc81fa9aeb4aca297f9fb158 (diff) | |
| download | rust-d5f3ed89cb0c1fa2164147efff25695be02bc36a.tar.gz rust-d5f3ed89cb0c1fa2164147efff25695be02bc36a.zip | |
Do not report warnings from proc macros, ever
| -rw-r--r-- | src/tools/rust-analyzer/crates/hir-expand/src/lib.rs | 7 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide-diagnostics/src/lib.rs | 6 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/lib.rs b/src/tools/rust-analyzer/crates/hir-expand/src/lib.rs index 7d2f556406d..2ee598dfbfd 100644 --- a/src/tools/rust-analyzer/crates/hir-expand/src/lib.rs +++ b/src/tools/rust-analyzer/crates/hir-expand/src/lib.rs @@ -269,6 +269,13 @@ pub enum MacroDefKind { ProcMacro(AstId<ast::Fn>, CustomProcMacroExpander, ProcMacroKind), } +impl MacroDefKind { + #[inline] + pub fn is_declarative(&self) -> bool { + matches!(self, MacroDefKind::Declarative(..)) + } +} + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct EagerCallInfo { /// The expanded argument of the eager macro. diff --git a/src/tools/rust-analyzer/crates/ide-diagnostics/src/lib.rs b/src/tools/rust-analyzer/crates/ide-diagnostics/src/lib.rs index 1f1b6478d36..9fbed7db35b 100644 --- a/src/tools/rust-analyzer/crates/ide-diagnostics/src/lib.rs +++ b/src/tools/rust-analyzer/crates/ide-diagnostics/src/lib.rs @@ -542,7 +542,13 @@ fn handle_diag_from_macros( sema.db.lookup_intern_syntax_context(span.ctx).outer_expn.is_some_and(|expansion| { let macro_call = sema.db.lookup_intern_macro_call(expansion.as_macro_file().macro_call_id); + // We don't want to show diagnostics for non-local macros at all, but proc macros authors + // seem to rely on being able to emit non-warning-free code, so we don't want to show warnings + // for them even when the proc macro comes from the same workspace (in rustc that's not a + // problem because it doesn't have the concept of workspaces, and proc macros always reside + // in a different crate). !Crate::from(macro_call.def.krate).origin(sema.db).is_local() + || !macro_call.def.kind.is_declarative() }) }) { // Disable suggestions for external macros, they'll change library code and it's just bad. |
