Skip to content
16 changes: 7 additions & 9 deletions compiler/rustc_hir_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ use rustc_abi::{CVariadicStatus, ExternAbi};
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::lints::DelayedLint;
use rustc_lint::DecorateAttrLint;
use rustc_middle::mir::interpret::GlobalId;
use rustc_middle::query::Providers;
use rustc_middle::ty::{Const, Ty, TyCtxt};
Expand Down Expand Up @@ -148,20 +149,17 @@ pub fn provide(providers: &mut Providers) {
};
}

fn emit_delayed_lint(lint: &DelayedLint, tcx: TyCtxt<'_>) {
pub fn emit_delayed_lint(lint: &DelayedLint, tcx: TyCtxt<'_>) {
match lint {
DelayedLint::AttributeParsing(attribute_lint) => {
tcx.node_span_lint(
tcx.emit_node_span_lint(
attribute_lint.lint_id.lint,
attribute_lint.id,
attribute_lint.span,
|diag| {
rustc_lint::decorate_attribute_lint(
tcx.sess,
Some(tcx),
&attribute_lint.kind,
diag,
);
DecorateAttrLint {
sess: tcx.sess,
tcx: Some(tcx),
diagnostic: &attribute_lint.kind,
},
);
}
Expand Down
32 changes: 5 additions & 27 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_ast::util::parser::ExprPrecedence;
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::sync;
use rustc_data_structures::unord::UnordMap;
use rustc_errors::{Diag, Diagnostic, LintBuffer, LintDiagnostic, MultiSpan};
use rustc_errors::{Diag, Diagnostic, LintBuffer, MultiSpan};
use rustc_feature::Features;
use rustc_hir::def::Res;
use rustc_hir::def_id::{CrateNum, DefId};
Expand Down Expand Up @@ -535,8 +535,8 @@ pub trait LintContext {
decorate: impl for<'a> Diagnostic<'a, ()>,
);

/// Emit a lint at `span` from a lint struct (some type that implements `LintDiagnostic`,
/// typically generated by `#[derive(LintDiagnostic)]`).
/// Emit a lint at `span` from a lint struct (some type that implements `Diagnostic`,
/// typically generated by `#[derive(Diagnostic)]`).
fn emit_span_lint<S: Into<MultiSpan>>(
&self,
lint: &'static Lint,
Expand All @@ -546,20 +546,6 @@ pub trait LintContext {
self.opt_span_diag_lint(lint, Some(span), decorator);
}

/// Emit a lint at `span` from a lazily-constructed lint struct (some type that implements
/// `LintDiagnostic`, typically generated by `#[derive(LintDiagnostic)]`).
fn emit_span_lint_lazy<S: Into<MultiSpan>, L: for<'a> LintDiagnostic<'a, ()>>(
&self,
lint: &'static Lint,
span: S,
decorator: impl FnOnce() -> L,
) {
self.opt_span_lint(lint, Some(span), |lint| {
let decorator = decorator();
decorator.decorate_lint(lint);
});
}

/// Emit a lint at the appropriate level, with an associated span.
///
/// [`lint_level`]: rustc_middle::lint::lint_level#decorate-signature
Expand All @@ -573,16 +559,8 @@ pub trait LintContext {
self.opt_span_lint(lint, Some(span), decorate);
}

/// Emit a lint from a lint struct (some type that implements `LintDiagnostic`, typically
/// generated by `#[derive(LintDiagnostic)]`).
fn emit_lint(&self, lint: &'static Lint, decorator: impl for<'a> LintDiagnostic<'a, ()>) {
self.opt_span_lint(lint, None as Option<Span>, |lint| {
decorator.decorate_lint(lint);
});
}

/// Emit a lint from a lint struct (some type that implements `LintDiagnostic`, typically
/// generated by `#[derive(LintDiagnostic)]`).
/// Emit a lint from a lint struct (some type that implements `Diagnostic`, typically
/// generated by `#[derive(Diagnostic)]`).
fn emit_diag_lint(&self, lint: &'static Lint, decorator: impl for<'a> Diagnostic<'a, ()>) {
self.opt_span_diag_lint(lint, None as Option<Span>, decorator);
}
Expand Down
20 changes: 16 additions & 4 deletions compiler/rustc_lint/src/early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use rustc_session::lint::LintPass;
use rustc_span::{Ident, Span};
use tracing::debug;

use crate::DecorateBuiltinLint;
use crate::context::{EarlyContext, LintContext, LintStore};
use crate::passes::{EarlyLintPass, EarlyLintPassObject};

Expand All @@ -36,12 +37,23 @@ impl<'ecx, 'tcx, T: EarlyLintPass> EarlyContextAndPass<'ecx, 'tcx, T> {
fn check_id(&mut self, id: ast::NodeId) {
for early_lint in self.context.buffered.take(id) {
let BufferedEarlyLint { span, node_id: _, lint_id, diagnostic } = early_lint;
self.context.opt_span_lint(lint_id.lint, span, |diag| match diagnostic {
match diagnostic {
DecorateDiagCompat::Builtin(b) => {
diagnostics::decorate_builtin_lint(self.context.sess(), self.tcx, b, diag);
self.context.opt_span_diag_lint(
lint_id.lint,
span,
DecorateBuiltinLint {
sess: self.context.sess(),
tcx: self.tcx,
diagnostic: b,
},
);
}
DecorateDiagCompat::Dynamic(d) => d.decorate_lint_box(diag),
});
DecorateDiagCompat::Dynamic(d) => {
self.context
.opt_span_lint(lint_id.lint, span, |diag| d.decorate_lint_box(diag));
}
}
}
}

Expand Down
Loading
Loading