Skip to content

Commit a2411f6

Browse files
Remove AttributeLintKind::UnusedDuplicate
1 parent d1fd617 commit a2411f6

7 files changed

Lines changed: 62 additions & 39 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/doc.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_ast::ast::{AttrStyle, LitKind, MetaItemLit};
2-
use rustc_errors::msg;
2+
use rustc_errors::{Diagnostic, msg};
33
use rustc_feature::template;
44
use rustc_hir::Target;
55
use rustc_hir::attrs::{
@@ -171,12 +171,15 @@ impl DocParser {
171171

172172
if let Some(used_span) = self.attribute.no_crate_inject {
173173
let unused_span = path.span();
174-
cx.emit_lint(
174+
cx.emit_dyn_lint(
175175
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
176-
AttributeLintKind::UnusedDuplicate {
177-
this: unused_span,
178-
other: used_span,
179-
warning: true,
176+
move |dcx, level| {
177+
rustc_errors::lints::UnusedDuplicate {
178+
this: unused_span,
179+
other: used_span,
180+
warning: true,
181+
}
182+
.into_diag(dcx, level)
180183
},
181184
unused_span,
182185
);

compiler/rustc_attr_parsing/src/context.rs

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

88
use private::Sealed;
99
use rustc_ast::{AttrStyle, MetaItemLit, NodeId};
10-
use rustc_errors::{Diag, Diagnostic, Level};
10+
use rustc_data_structures::sync::{DynSend, DynSync};
11+
use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, Level};
1112
use rustc_feature::{AttrSuggestionStyle, AttributeTemplate};
1213
use rustc_hir::attrs::AttributeKind;
1314
use rustc_hir::lints::AttributeLintKind;
@@ -456,22 +457,43 @@ impl<'f, 'sess: 'f, S: Stage> SharedContext<'f, 'sess, S> {
456457
/// must be delayed until after HIR is built. This method will take care of the details of
457458
/// that.
458459
pub(crate) fn emit_lint(&mut self, lint: &'static Lint, kind: AttributeLintKind, span: Span) {
460+
self.emit_lint_inner(lint, EmitAttribute::Static(kind), span);
461+
}
462+
463+
/// Emit a lint. This method is somewhat special, since lints emitted during attribute parsing
464+
/// must be delayed until after HIR is built. This method will take care of the details of
465+
/// that.
466+
pub(crate) fn emit_dyn_lint<
467+
F: for<'a> Fn(DiagCtxtHandle<'a>, Level) -> Diag<'a, ()> + DynSend + DynSync + 'static,
468+
>(
469+
&mut self,
470+
lint: &'static Lint,
471+
callback: F,
472+
span: Span,
473+
) {
474+
self.emit_lint_inner(lint, EmitAttribute::Dynamic(Box::new(callback)), span);
475+
}
476+
477+
fn emit_lint_inner(&mut self, lint: &'static Lint, kind: EmitAttribute, span: Span) {
459478
if !matches!(
460479
self.stage.should_emit(),
461480
ShouldEmit::ErrorsAndLints { .. } | ShouldEmit::EarlyFatal { also_emit_lints: true }
462481
) {
463482
return;
464483
}
465-
(self.emit_lint)(LintId::of(lint), span, EmitAttribute::Static(kind));
484+
(self.emit_lint)(LintId::of(lint), span, kind);
466485
}
467486

468487
pub(crate) fn warn_unused_duplicate(&mut self, used_span: Span, unused_span: Span) {
469-
self.emit_lint(
488+
self.emit_dyn_lint(
470489
rustc_session::lint::builtin::UNUSED_ATTRIBUTES,
471-
AttributeLintKind::UnusedDuplicate {
472-
this: unused_span,
473-
other: used_span,
474-
warning: false,
490+
move |dcx, level| {
491+
rustc_errors::lints::UnusedDuplicate {
492+
this: unused_span,
493+
other: used_span,
494+
warning: false,
495+
}
496+
.into_diag(dcx, level)
475497
},
476498
unused_span,
477499
)
@@ -482,12 +504,15 @@ impl<'f, 'sess: 'f, S: Stage> SharedContext<'f, 'sess, S> {
482504
used_span: Span,
483505
unused_span: Span,
484506
) {
485-
self.emit_lint(
507+
self.emit_dyn_lint(
486508
rustc_session::lint::builtin::UNUSED_ATTRIBUTES,
487-
AttributeLintKind::UnusedDuplicate {
488-
this: unused_span,
489-
other: used_span,
490-
warning: true,
509+
move |dcx, level| {
510+
rustc_errors::lints::UnusedDuplicate {
511+
this: unused_span,
512+
other: used_span,
513+
warning: true,
514+
}
515+
.into_diag(dcx, level)
491516
},
492517
unused_span,
493518
)

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_errors/src/lints.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use rustc_macros::Diagnostic;
2+
use rustc_span::Span;
3+
4+
#[derive(Diagnostic)]
5+
#[diag("unused attribute")]
6+
pub struct UnusedDuplicate {
7+
#[suggestion("remove this attribute", code = "", applicability = "machine-applicable")]
8+
pub this: Span,
9+
#[note("attribute also specified here")]
10+
pub other: Span,
11+
#[warning(
12+
"this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!"
13+
)]
14+
pub warning: bool,
15+
}

compiler/rustc_lint/src/early/diagnostics.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ pub struct DecorateAttrLint<'a, 'sess, 'tcx> {
3535
impl<'a> Diagnostic<'a, ()> for DecorateAttrLint<'_, '_, '_> {
3636
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
3737
match self.diagnostic {
38-
&AttributeLintKind::UnusedDuplicate { this, other, warning } => {
39-
lints::UnusedDuplicate { this, other, warning }.into_diag(dcx, level)
40-
}
4138
AttributeLintKind::IllFormedAttributeInput { suggestions, docs, help } => {
4239
lints::IllFormedAttributeInput {
4340
num_suggestions: suggestions.len(),

compiler/rustc_lint/src/lints.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3353,19 +3353,6 @@ pub(crate) struct InvalidAttrStyle {
33533353
pub target: &'static str,
33543354
}
33553355

3356-
#[derive(Diagnostic)]
3357-
#[diag("unused attribute")]
3358-
pub(crate) struct UnusedDuplicate {
3359-
#[suggestion("remove this attribute", code = "", applicability = "machine-applicable")]
3360-
pub this: Span,
3361-
#[note("attribute also specified here")]
3362-
pub other: Span,
3363-
#[warning(
3364-
"this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!"
3365-
)]
3366-
pub warning: bool,
3367-
}
3368-
33693356
#[derive(Diagnostic)]
33703357
#[diag("malformed `doc` attribute input")]
33713358
#[warning(

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -654,11 +654,6 @@ pub enum DeprecatedSinceKind {
654654

655655
#[derive(Debug, HashStable_Generic)]
656656
pub enum AttributeLintKind {
657-
UnusedDuplicate {
658-
this: Span,
659-
other: Span,
660-
warning: bool,
661-
},
662657
IllFormedAttributeInput {
663658
suggestions: Vec<String>,
664659
docs: Option<&'static str>,

0 commit comments

Comments
 (0)