Skip to content

Commit 3640db2

Browse files
authored
Merge pull request rust-lang#18611 from ChayimFriedman2/proc-macro-warn
fix: Do not report warnings from proc macros, ever
2 parents 39aab98 + d5f3ed8 commit 3640db2

File tree

2 files changed

+13
-0
lines changed
  • src/tools/rust-analyzer/crates

2 files changed

+13
-0
lines changed

Diff for: src/tools/rust-analyzer/crates/hir-expand/src/lib.rs

+7
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.

Diff for: src/tools/rust-analyzer/crates/ide-diagnostics/src/lib.rs

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

0 commit comments

Comments
 (0)