Skip to content

Remove SHOULD_EMIT_LINTS in favor of should_emit #144866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ mod private {
#[allow(private_interfaces)]
pub trait Stage: Sized + 'static + Sealed {
type Id: Copy;
const SHOULD_EMIT_LINTS: bool;

fn parsers() -> &'static GroupType<Self>;

Expand All @@ -233,13 +232,14 @@ pub trait Stage: Sized + 'static + Sealed {
sess: &'sess Session,
diag: impl for<'x> Diagnostic<'x>,
) -> ErrorGuaranteed;

fn should_emit(&self) -> ShouldEmit;
}

// allow because it's a sealed trait
#[allow(private_interfaces)]
impl Stage for Early {
type Id = NodeId;
const SHOULD_EMIT_LINTS: bool = false;

fn parsers() -> &'static GroupType<Self> {
&early::ATTRIBUTE_PARSERS
Expand All @@ -255,13 +255,16 @@ impl Stage for Early {
sess.dcx().create_err(diag).delay_as_bug()
}
}

fn should_emit(&self) -> ShouldEmit {
self.emit_errors
}
}

// allow because it's a sealed trait
#[allow(private_interfaces)]
impl Stage for Late {
type Id = HirId;
const SHOULD_EMIT_LINTS: bool = true;

fn parsers() -> &'static GroupType<Self> {
&late::ATTRIBUTE_PARSERS
Expand All @@ -273,6 +276,10 @@ impl Stage for Late {
) -> ErrorGuaranteed {
tcx.dcx().emit_err(diag)
}

fn should_emit(&self) -> ShouldEmit {
ShouldEmit::ErrorsAndLints
}
}

/// used when parsing attributes for miscellaneous things *before* ast lowering
Expand Down Expand Up @@ -311,7 +318,7 @@ impl<'f, 'sess: 'f, S: Stage> SharedContext<'f, 'sess, S> {
/// must be delayed until after HIR is built. This method will take care of the details of
/// that.
pub(crate) fn emit_lint(&mut self, lint: AttributeLintKind, span: Span) {
if !S::SHOULD_EMIT_LINTS {
if !self.stage.should_emit().should_emit() {
return;
}
let id = self.target_id;
Expand Down
Loading