Skip to content

Commit 305d63f

Browse files
authored
Unrolled build for #153152
Rollup merge of #153152 - GuillaumeGomez:migrate-diag, r=JonathanBrouwer Migration of LintDiagnostic - part 5 Part of #153099. With this, `rust_lint` is finally done, although the change of API of `decorate_builtin_lint` impacted a few other crates, although minimal, still needed to be mentioned. r? @JonathanBrouwer
2 parents d3877ec + 8a824ee commit 305d63f

File tree

12 files changed

+528
-511
lines changed

12 files changed

+528
-511
lines changed

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ use rustc_abi::{CVariadicStatus, ExternAbi};
8888
use rustc_hir as hir;
8989
use rustc_hir::def::DefKind;
9090
use rustc_hir::lints::DelayedLint;
91+
use rustc_lint::DecorateAttrLint;
9192
use rustc_middle::mir::interpret::GlobalId;
9293
use rustc_middle::query::Providers;
9394
use rustc_middle::ty::{Const, Ty, TyCtxt};
@@ -148,20 +149,17 @@ pub fn provide(providers: &mut Providers) {
148149
};
149150
}
150151

151-
fn emit_delayed_lint(lint: &DelayedLint, tcx: TyCtxt<'_>) {
152+
pub fn emit_delayed_lint(lint: &DelayedLint, tcx: TyCtxt<'_>) {
152153
match lint {
153154
DelayedLint::AttributeParsing(attribute_lint) => {
154-
tcx.node_span_lint(
155+
tcx.emit_node_span_lint(
155156
attribute_lint.lint_id.lint,
156157
attribute_lint.id,
157158
attribute_lint.span,
158-
|diag| {
159-
rustc_lint::decorate_attribute_lint(
160-
tcx.sess,
161-
Some(tcx),
162-
&attribute_lint.kind,
163-
diag,
164-
);
159+
DecorateAttrLint {
160+
sess: tcx.sess,
161+
tcx: Some(tcx),
162+
diagnostic: &attribute_lint.kind,
165163
},
166164
);
167165
}

compiler/rustc_lint/src/context.rs

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_ast::util::parser::ExprPrecedence;
1111
use rustc_data_structures::fx::FxIndexMap;
1212
use rustc_data_structures::sync;
1313
use rustc_data_structures::unord::UnordMap;
14-
use rustc_errors::{Diag, Diagnostic, LintBuffer, LintDiagnostic, MultiSpan};
14+
use rustc_errors::{Diag, Diagnostic, LintBuffer, MultiSpan};
1515
use rustc_feature::Features;
1616
use rustc_hir::def::Res;
1717
use rustc_hir::def_id::{CrateNum, DefId};
@@ -535,8 +535,8 @@ pub trait LintContext {
535535
decorate: impl for<'a> Diagnostic<'a, ()>,
536536
);
537537

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

549-
/// Emit a lint at `span` from a lazily-constructed lint struct (some type that implements
550-
/// `LintDiagnostic`, typically generated by `#[derive(LintDiagnostic)]`).
551-
fn emit_span_lint_lazy<S: Into<MultiSpan>, L: for<'a> LintDiagnostic<'a, ()>>(
552-
&self,
553-
lint: &'static Lint,
554-
span: S,
555-
decorator: impl FnOnce() -> L,
556-
) {
557-
self.opt_span_lint(lint, Some(span), |lint| {
558-
let decorator = decorator();
559-
decorator.decorate_lint(lint);
560-
});
561-
}
562-
563549
/// Emit a lint at the appropriate level, with an associated span.
564550
///
565551
/// [`lint_level`]: rustc_middle::lint::lint_level#decorate-signature
@@ -573,16 +559,8 @@ pub trait LintContext {
573559
self.opt_span_lint(lint, Some(span), decorate);
574560
}
575561

576-
/// Emit a lint from a lint struct (some type that implements `LintDiagnostic`, typically
577-
/// generated by `#[derive(LintDiagnostic)]`).
578-
fn emit_lint(&self, lint: &'static Lint, decorator: impl for<'a> LintDiagnostic<'a, ()>) {
579-
self.opt_span_lint(lint, None as Option<Span>, |lint| {
580-
decorator.decorate_lint(lint);
581-
});
582-
}
583-
584-
/// Emit a lint from a lint struct (some type that implements `LintDiagnostic`, typically
585-
/// generated by `#[derive(LintDiagnostic)]`).
562+
/// Emit a lint from a lint struct (some type that implements `Diagnostic`, typically
563+
/// generated by `#[derive(Diagnostic)]`).
586564
fn emit_diag_lint(&self, lint: &'static Lint, decorator: impl for<'a> Diagnostic<'a, ()>) {
587565
self.opt_span_diag_lint(lint, None as Option<Span>, decorator);
588566
}

compiler/rustc_lint/src/early.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_session::lint::LintPass;
1515
use rustc_span::{Ident, Span};
1616
use tracing::debug;
1717

18+
use crate::DecorateBuiltinLint;
1819
use crate::context::{EarlyContext, LintContext, LintStore};
1920
use crate::passes::{EarlyLintPass, EarlyLintPassObject};
2021

@@ -36,12 +37,23 @@ impl<'ecx, 'tcx, T: EarlyLintPass> EarlyContextAndPass<'ecx, 'tcx, T> {
3637
fn check_id(&mut self, id: ast::NodeId) {
3738
for early_lint in self.context.buffered.take(id) {
3839
let BufferedEarlyLint { span, node_id: _, lint_id, diagnostic } = early_lint;
39-
self.context.opt_span_lint(lint_id.lint, span, |diag| match diagnostic {
40+
match diagnostic {
4041
DecorateDiagCompat::Builtin(b) => {
41-
diagnostics::decorate_builtin_lint(self.context.sess(), self.tcx, b, diag);
42+
self.context.opt_span_diag_lint(
43+
lint_id.lint,
44+
span,
45+
DecorateBuiltinLint {
46+
sess: self.context.sess(),
47+
tcx: self.tcx,
48+
diagnostic: b,
49+
},
50+
);
4251
}
43-
DecorateDiagCompat::Dynamic(d) => d.decorate_lint_box(diag),
44-
});
52+
DecorateDiagCompat::Dynamic(d) => {
53+
self.context
54+
.opt_span_lint(lint_id.lint, span, |diag| d.decorate_lint_box(diag));
55+
}
56+
}
4557
}
4658
}
4759

0 commit comments

Comments
 (0)