Skip to content

Commit 2b502f5

Browse files
Simplify rustc_lint::EmitDiag by removing Lint from its API
1 parent b352490 commit 2b502f5

File tree

4 files changed

+171
-226
lines changed

4 files changed

+171
-226
lines changed

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,26 +153,27 @@ fn emit_delayed_lint(lint: &DelayedLint, tcx: TyCtxt<'_>) {
153153
hir_id: rustc_hir::HirId,
154154
tcx: TyCtxt<'tcx>,
155155
span: Span,
156+
lint: &'static rustc_lint::Lint,
156157
}
157158

158159
impl rustc_lint::EmitDiag for DiagEmitter<'_> {
159-
fn emit(
160-
&self,
161-
lint: &'static rustc_lint::Lint,
162-
diag: impl for<'a> rustc_errors::Diagnostic<'a, ()>,
163-
) {
164-
self.tcx.emit_node_span_lint(lint, self.hir_id, self.span, diag);
160+
fn emit(&self, diag: impl for<'a> rustc_errors::Diagnostic<'a, ()>) {
161+
self.tcx.emit_node_span_lint(self.lint, self.hir_id, self.span, diag);
165162
}
166163
}
167164

168165
match lint {
169166
DelayedLint::AttributeParsing(attribute_lint) => {
170167
rustc_lint::decorate_attribute_lint(
171-
&DiagEmitter { hir_id: attribute_lint.id, tcx, span: attribute_lint.span },
168+
&DiagEmitter {
169+
hir_id: attribute_lint.id,
170+
tcx,
171+
span: attribute_lint.span,
172+
lint: attribute_lint.lint_id.lint,
173+
},
172174
tcx.sess,
173175
Some(tcx),
174176
&attribute_lint.kind,
175-
attribute_lint.lint_id.lint,
176177
);
177178
}
178179
}

compiler/rustc_lint/src/early.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,18 @@ pub struct EarlyContextAndPass<'ecx, 'tcx, T: EarlyLintPass> {
3434
}
3535

3636
pub trait EmitDiag {
37-
fn emit(&self, lint: &'static Lint, diag: impl for<'a> Diagnostic<'a, ()>);
37+
fn emit(&self, diag: impl for<'a> Diagnostic<'a, ()>);
3838
}
3939

4040
struct DiagEmitter<'a, 'b> {
4141
ctx: &'a EarlyContext<'b>,
4242
span: Option<MultiSpan>,
43+
lint: &'static Lint,
4344
}
4445

4546
impl EmitDiag for DiagEmitter<'_, '_> {
46-
fn emit(&self, lint: &'static Lint, diag: impl for<'a> Diagnostic<'a, ()>) {
47-
self.ctx.opt_span_diag_lint(lint, self.span.clone(), diag);
47+
fn emit(&self, diag: impl for<'a> Diagnostic<'a, ()>) {
48+
self.ctx.opt_span_diag_lint(self.lint, self.span.clone(), diag);
4849
}
4950
}
5051

@@ -55,11 +56,10 @@ impl<'ecx, 'tcx, T: EarlyLintPass> EarlyContextAndPass<'ecx, 'tcx, T> {
5556
match diagnostic {
5657
DecorateDiagCompat::Builtin(b) => {
5758
diagnostics::decorate_builtin_lint(
58-
&DiagEmitter { ctx: &self.context, span },
59+
&DiagEmitter { ctx: &self.context, span, lint: lint_id.lint },
5960
self.context.sess(),
6061
self.tcx,
6162
b,
62-
lint_id.lint,
6363
);
6464
}
6565
DecorateDiagCompat::Dynamic(d) => {

0 commit comments

Comments
 (0)