Skip to content

Commit 33c7e81

Browse files
Do not report warnings from proc macros, ever
1 parent 26bc01d commit 33c7e81

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

crates/hir-expand/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,13 @@ pub enum MacroDefKind {
269269
ProcMacro(AstId<ast::Fn>, CustomProcMacroExpander, ProcMacroKind),
270270
}
271271

272+
impl MacroDefKind {
273+
#[inline]
274+
pub fn is_declarative(&self) -> bool {
275+
matches!(self, MacroDefKind::Declarative(..))
276+
}
277+
}
278+
272279
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
273280
pub struct EagerCallInfo {
274281
/// The expanded argument of the eager macro.

crates/ide-diagnostics/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,13 @@ fn handle_diag_from_macros(
542542
sema.db.lookup_intern_syntax_context(span.ctx).outer_expn.is_some_and(|expansion| {
543543
let macro_call =
544544
sema.db.lookup_intern_macro_call(expansion.as_macro_file().macro_call_id);
545+
// We don't want to show diagnostics for non-local macros at all, but proc macros authors
546+
// seem to rely on being able to emit non-warning-free code, so we don't want to show warnings
547+
// for them even when the proc macro comes from the same workspace (in rustc that's not a
548+
// problem because it doesn't have the concept of workspaces, and proc macros always reside
549+
// in a different crate).
545550
!Crate::from(macro_call.def.krate).origin(sema.db).is_local()
551+
|| !macro_call.def.kind.is_declarative()
546552
})
547553
}) {
548554
// Disable suggestions for external macros, they'll change library code and it's just bad.

0 commit comments

Comments
 (0)