Remove SHOULD_EMIT_LINTS in favor of should_emit

This commit is contained in:
Jonathan Brouwer
2025-08-03 21:48:23 +02:00
parent 7cd950546b
commit f92934f43a

View File

@@ -224,7 +224,6 @@ mod private {
#[allow(private_interfaces)] #[allow(private_interfaces)]
pub trait Stage: Sized + 'static + Sealed { pub trait Stage: Sized + 'static + Sealed {
type Id: Copy; type Id: Copy;
const SHOULD_EMIT_LINTS: bool;
fn parsers() -> &'static GroupType<Self>; fn parsers() -> &'static GroupType<Self>;
@@ -233,13 +232,14 @@ pub trait Stage: Sized + 'static + Sealed {
sess: &'sess Session, sess: &'sess Session,
diag: impl for<'x> Diagnostic<'x>, diag: impl for<'x> Diagnostic<'x>,
) -> ErrorGuaranteed; ) -> ErrorGuaranteed;
fn should_emit(&self) -> ShouldEmit;
} }
// allow because it's a sealed trait // allow because it's a sealed trait
#[allow(private_interfaces)] #[allow(private_interfaces)]
impl Stage for Early { impl Stage for Early {
type Id = NodeId; type Id = NodeId;
const SHOULD_EMIT_LINTS: bool = false;
fn parsers() -> &'static GroupType<Self> { fn parsers() -> &'static GroupType<Self> {
&early::ATTRIBUTE_PARSERS &early::ATTRIBUTE_PARSERS
@@ -255,13 +255,16 @@ impl Stage for Early {
sess.dcx().create_err(diag).delay_as_bug() sess.dcx().create_err(diag).delay_as_bug()
} }
} }
fn should_emit(&self) -> ShouldEmit {
self.emit_errors
}
} }
// allow because it's a sealed trait // allow because it's a sealed trait
#[allow(private_interfaces)] #[allow(private_interfaces)]
impl Stage for Late { impl Stage for Late {
type Id = HirId; type Id = HirId;
const SHOULD_EMIT_LINTS: bool = true;
fn parsers() -> &'static GroupType<Self> { fn parsers() -> &'static GroupType<Self> {
&late::ATTRIBUTE_PARSERS &late::ATTRIBUTE_PARSERS
@@ -273,6 +276,10 @@ impl Stage for Late {
) -> ErrorGuaranteed { ) -> ErrorGuaranteed {
tcx.dcx().emit_err(diag) tcx.dcx().emit_err(diag)
} }
fn should_emit(&self) -> ShouldEmit {
ShouldEmit::ErrorsAndLints
}
} }
/// used when parsing attributes for miscellaneous things *before* ast lowering /// used when parsing attributes for miscellaneous things *before* ast lowering
@@ -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 /// must be delayed until after HIR is built. This method will take care of the details of
/// that. /// that.
pub(crate) fn emit_lint(&mut self, lint: AttributeLintKind, span: Span) { pub(crate) fn emit_lint(&mut self, lint: AttributeLintKind, span: Span) {
if !S::SHOULD_EMIT_LINTS { if !self.stage.should_emit().should_emit() {
return; return;
} }
let id = self.target_id; let id = self.target_id;