Skip to content

Commit 38ca4a3

Browse files
Remove AttributeLintKind::UnusedDuplicate
1 parent ca884be commit 38ca4a3

File tree

6 files changed

+47
-38
lines changed

6 files changed

+47
-38
lines changed

compiler/rustc_attr_parsing/src/attributes/doc.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc_ast::ast::{AttrStyle, LitKind, MetaItemLit};
2+
use rustc_errors::Diagnostic;
23
use rustc_feature::template;
34
use rustc_hir::Target;
45
use rustc_hir::attrs::{
@@ -169,12 +170,15 @@ impl DocParser {
169170

170171
if let Some(used_span) = self.attribute.no_crate_inject {
171172
let unused_span = path.span();
172-
cx.emit_lint(
173+
cx.emit_dyn_lint(
173174
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
174-
AttributeLintKind::UnusedDuplicate {
175-
this: unused_span,
176-
other: used_span,
177-
warning: true,
175+
move |dcx, level| {
176+
rustc_errors::lints::UnusedDuplicate {
177+
this: unused_span,
178+
other: used_span,
179+
warning: true,
180+
}
181+
.into_diag(dcx, level)
178182
},
179183
unused_span,
180184
);

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use std::sync::LazyLock;
66

77
use private::Sealed;
88
use rustc_ast::{AttrStyle, MetaItemLit, NodeId};
9-
use rustc_errors::{Diag, Diagnostic, Level};
9+
use rustc_data_structures::sync::{DynSend, DynSync};
10+
use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, Level};
1011
use rustc_feature::{AttrSuggestionStyle, AttributeTemplate};
1112
use rustc_hir::attrs::AttributeKind;
1213
use rustc_hir::lints::AttributeLintKind;
@@ -448,22 +449,43 @@ impl<'f, 'sess: 'f, S: Stage> SharedContext<'f, 'sess, S> {
448449
/// must be delayed until after HIR is built. This method will take care of the details of
449450
/// that.
450451
pub(crate) fn emit_lint(&mut self, lint: &'static Lint, kind: AttributeLintKind, span: Span) {
452+
self.emit_lint_inner(lint, EmitAttribute::Static(kind), span);
453+
}
454+
455+
/// Emit a lint. This method is somewhat special, since lints emitted during attribute parsing
456+
/// must be delayed until after HIR is built. This method will take care of the details of
457+
/// that.
458+
pub(crate) fn emit_dyn_lint<
459+
F: for<'a> Fn(DiagCtxtHandle<'a>, Level) -> Diag<'a, ()> + DynSend + DynSync + 'static,
460+
>(
461+
&mut self,
462+
lint: &'static Lint,
463+
callback: F,
464+
span: Span,
465+
) {
466+
self.emit_lint_inner(lint, EmitAttribute::Dynamic(Box::new(callback)), span);
467+
}
468+
469+
fn emit_lint_inner(&mut self, lint: &'static Lint, kind: EmitAttribute, span: Span) {
451470
if !matches!(
452471
self.stage.should_emit(),
453472
ShouldEmit::ErrorsAndLints { .. } | ShouldEmit::EarlyFatal { also_emit_lints: true }
454473
) {
455474
return;
456475
}
457-
(self.emit_lint)(LintId::of(lint), span, EmitAttribute::Static(kind));
476+
(self.emit_lint)(LintId::of(lint), span, kind);
458477
}
459478

460479
pub(crate) fn warn_unused_duplicate(&mut self, used_span: Span, unused_span: Span) {
461-
self.emit_lint(
480+
self.emit_dyn_lint(
462481
rustc_session::lint::builtin::UNUSED_ATTRIBUTES,
463-
AttributeLintKind::UnusedDuplicate {
464-
this: unused_span,
465-
other: used_span,
466-
warning: false,
482+
move |dcx, level| {
483+
rustc_errors::lints::UnusedDuplicate {
484+
this: unused_span,
485+
other: used_span,
486+
warning: false,
487+
}
488+
.into_diag(dcx, level)
467489
},
468490
unused_span,
469491
)
@@ -474,12 +496,15 @@ impl<'f, 'sess: 'f, S: Stage> SharedContext<'f, 'sess, S> {
474496
used_span: Span,
475497
unused_span: Span,
476498
) {
477-
self.emit_lint(
499+
self.emit_dyn_lint(
478500
rustc_session::lint::builtin::UNUSED_ATTRIBUTES,
479-
AttributeLintKind::UnusedDuplicate {
480-
this: unused_span,
481-
other: used_span,
482-
warning: true,
501+
move |dcx, level| {
502+
rustc_errors::lints::UnusedDuplicate {
503+
this: unused_span,
504+
other: used_span,
505+
warning: true,
506+
}
507+
.into_diag(dcx, level)
483508
},
484509
unused_span,
485510
)

compiler/rustc_errors/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ mod diagnostic_impls;
7777
pub mod emitter;
7878
pub mod formatting;
7979
pub mod json;
80+
pub mod lints;
8081
mod lock;
8182
pub mod markdown;
8283
pub mod timings;

compiler/rustc_lint/src/early/diagnostics.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,6 @@ pub struct DecorateAttrLint<'a, 'sess, 'tcx> {
172172
impl<'a> Diagnostic<'a, ()> for DecorateAttrLint<'_, '_, '_> {
173173
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
174174
match self.diagnostic {
175-
&AttributeLintKind::UnusedDuplicate { this, other, warning } => {
176-
lints::UnusedDuplicate { this, other, warning }.into_diag(dcx, level)
177-
}
178175
AttributeLintKind::IllFormedAttributeInput { suggestions, docs } => {
179176
lints::IllFormedAttributeInput {
180177
num_suggestions: suggestions.len(),

compiler/rustc_lint/src/lints.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3422,19 +3422,6 @@ pub(crate) struct InvalidAttrStyle {
34223422
pub target: &'static str,
34233423
}
34243424

3425-
#[derive(Diagnostic)]
3426-
#[diag("unused attribute")]
3427-
pub(crate) struct UnusedDuplicate {
3428-
#[suggestion("remove this attribute", code = "", applicability = "machine-applicable")]
3429-
pub this: Span,
3430-
#[note("attribute also specified here")]
3431-
pub other: Span,
3432-
#[warning(
3433-
"this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!"
3434-
)]
3435-
pub warning: bool,
3436-
}
3437-
34383425
#[derive(Diagnostic)]
34393426
#[diag("malformed `doc` attribute input")]
34403427
#[warning(

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -695,11 +695,6 @@ pub enum BuiltinLintDiag {
695695

696696
#[derive(Debug, HashStable_Generic)]
697697
pub enum AttributeLintKind {
698-
UnusedDuplicate {
699-
this: Span,
700-
other: Span,
701-
warning: bool,
702-
},
703698
IllFormedAttributeInput {
704699
suggestions: Vec<String>,
705700
docs: Option<&'static str>,

0 commit comments

Comments
 (0)