Skip to content

Commit

Permalink
Merge pull request rust-lang#18611 from ChayimFriedman2/proc-macro-warn
Browse files Browse the repository at this point in the history
fix: Do not report warnings from proc macros, ever
  • Loading branch information
Veykril authored Dec 4, 2024
2 parents 39aab98 + d5f3ed8 commit 3640db2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/tools/rust-analyzer/crates/hir-expand/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions src/tools/rust-analyzer/crates/ide-diagnostics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,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.
Expand Down

0 comments on commit 3640db2

Please sign in to comment.