Skip to content

Commit ded2eea

Browse files
Remove AttributeLintKind::UnusedDuplicate
1 parent c5b9918 commit ded2eea

7 files changed

Lines changed: 69 additions & 41 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: 44 additions & 14 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, MultiSpan};
10+
use rustc_data_structures::sync::{DynSend, DynSync};
11+
use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, Level, MultiSpan};
1112
use rustc_feature::{AttrSuggestionStyle, AttributeTemplate};
1213
use rustc_hir::attrs::AttributeKind;
1314
use rustc_hir::lints::AttributeLintKind;
@@ -461,28 +462,54 @@ impl<'f, 'sess: 'f, S: Stage> SharedContext<'f, 'sess, S> {
461462
/// Emit a lint. This method is somewhat special, since lints emitted during attribute parsing
462463
/// must be delayed until after HIR is built. This method will take care of the details of
463464
/// that.
464-
pub(crate) fn emit_lint<M: Into<MultiSpan>>(
465+
pub(crate) fn emit_lint(
465466
&mut self,
466467
lint: &'static Lint,
467468
kind: AttributeLintKind,
468-
span: M,
469+
span: impl Into<MultiSpan>,
470+
) {
471+
self.emit_lint_inner(lint, EmitAttribute::Static(kind), span);
472+
}
473+
474+
/// Emit a lint. This method is somewhat special, since lints emitted during attribute parsing
475+
/// must be delayed until after HIR is built. This method will take care of the details of
476+
/// that.
477+
pub(crate) fn emit_dyn_lint<
478+
F: for<'a> Fn(DiagCtxtHandle<'a>, Level) -> Diag<'a, ()> + DynSend + DynSync + 'static,
479+
>(
480+
&mut self,
481+
lint: &'static Lint,
482+
callback: F,
483+
span: impl Into<MultiSpan>,
484+
) {
485+
self.emit_lint_inner(lint, EmitAttribute::Dynamic(Box::new(callback)), span);
486+
}
487+
488+
fn emit_lint_inner(
489+
&mut self,
490+
lint: &'static Lint,
491+
kind: EmitAttribute,
492+
span: impl Into<MultiSpan>,
469493
) {
470494
if !matches!(
471495
self.stage.should_emit(),
472496
ShouldEmit::ErrorsAndLints { .. } | ShouldEmit::EarlyFatal { also_emit_lints: true }
473497
) {
474498
return;
475499
}
476-
(self.emit_lint)(LintId::of(lint), span.into(), EmitAttribute::Static(kind));
500+
(self.emit_lint)(LintId::of(lint), span.into(), kind);
477501
}
478502

479503
pub(crate) fn warn_unused_duplicate(&mut self, used_span: Span, unused_span: Span) {
480-
self.emit_lint(
504+
self.emit_dyn_lint(
481505
rustc_session::lint::builtin::UNUSED_ATTRIBUTES,
482-
AttributeLintKind::UnusedDuplicate {
483-
this: unused_span,
484-
other: used_span,
485-
warning: false,
506+
move |dcx, level| {
507+
rustc_errors::lints::UnusedDuplicate {
508+
this: unused_span,
509+
other: used_span,
510+
warning: false,
511+
}
512+
.into_diag(dcx, level)
486513
},
487514
unused_span,
488515
)
@@ -493,12 +520,15 @@ impl<'f, 'sess: 'f, S: Stage> SharedContext<'f, 'sess, S> {
493520
used_span: Span,
494521
unused_span: Span,
495522
) {
496-
self.emit_lint(
523+
self.emit_dyn_lint(
497524
rustc_session::lint::builtin::UNUSED_ATTRIBUTES,
498-
AttributeLintKind::UnusedDuplicate {
499-
this: unused_span,
500-
other: used_span,
501-
warning: true,
525+
move |dcx, level| {
526+
rustc_errors::lints::UnusedDuplicate {
527+
this: unused_span,
528+
other: used_span,
529+
warning: true,
530+
}
531+
.into_diag(dcx, level)
502532
},
503533
unused_span,
504534
)

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
@@ -3365,19 +3365,6 @@ pub(crate) struct InvalidAttrStyle {
33653365
pub target: &'static str,
33663366
}
33673367

3368-
#[derive(Diagnostic)]
3369-
#[diag("unused attribute")]
3370-
pub(crate) struct UnusedDuplicate {
3371-
#[suggestion("remove this attribute", code = "", applicability = "machine-applicable")]
3372-
pub this: Span,
3373-
#[note("attribute also specified here")]
3374-
pub other: Span,
3375-
#[warning(
3376-
"this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!"
3377-
)]
3378-
pub warning: bool,
3379-
}
3380-
33813368
#[derive(Diagnostic)]
33823369
#[diag("malformed `doc` attribute input")]
33833370
#[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)]
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)