Skip to content

Commit 6fbbfae

Browse files
GuillaumeGomezJonathanBrouwer
authored andcommitted
Remove AttributeLintKind::UnusedDuplicate
1 parent 5a70bb0 commit 6fbbfae

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;
@@ -458,28 +459,54 @@ impl<'f, 'sess: 'f, S: Stage> SharedContext<'f, 'sess, S> {
458459
/// Emit a lint. This method is somewhat special, since lints emitted during attribute parsing
459460
/// must be delayed until after HIR is built. This method will take care of the details of
460461
/// that.
461-
pub(crate) fn emit_lint<M: Into<MultiSpan>>(
462+
pub(crate) fn emit_lint(
462463
&mut self,
463464
lint: &'static Lint,
464465
kind: AttributeLintKind,
465-
span: M,
466+
span: impl Into<MultiSpan>,
467+
) {
468+
self.emit_lint_inner(lint, EmitAttribute::Static(kind), span);
469+
}
470+
471+
/// Emit a lint. This method is somewhat special, since lints emitted during attribute parsing
472+
/// must be delayed until after HIR is built. This method will take care of the details of
473+
/// that.
474+
pub(crate) fn emit_dyn_lint<
475+
F: for<'a> Fn(DiagCtxtHandle<'a>, Level) -> Diag<'a, ()> + DynSend + DynSync + 'static,
476+
>(
477+
&mut self,
478+
lint: &'static Lint,
479+
callback: F,
480+
span: impl Into<MultiSpan>,
481+
) {
482+
self.emit_lint_inner(lint, EmitAttribute::Dynamic(Box::new(callback)), span);
483+
}
484+
485+
fn emit_lint_inner(
486+
&mut self,
487+
lint: &'static Lint,
488+
kind: EmitAttribute,
489+
span: impl Into<MultiSpan>,
466490
) {
467491
if !matches!(
468492
self.stage.should_emit(),
469493
ShouldEmit::ErrorsAndLints { .. } | ShouldEmit::EarlyFatal { also_emit_lints: true }
470494
) {
471495
return;
472496
}
473-
(self.emit_lint)(LintId::of(lint), span.into(), EmitAttribute::Static(kind));
497+
(self.emit_lint)(LintId::of(lint), span.into(), kind);
474498
}
475499

476500
pub(crate) fn warn_unused_duplicate(&mut self, used_span: Span, unused_span: Span) {
477-
self.emit_lint(
501+
self.emit_dyn_lint(
478502
rustc_session::lint::builtin::UNUSED_ATTRIBUTES,
479-
AttributeLintKind::UnusedDuplicate {
480-
this: unused_span,
481-
other: used_span,
482-
warning: false,
503+
move |dcx, level| {
504+
rustc_errors::lints::UnusedDuplicate {
505+
this: unused_span,
506+
other: used_span,
507+
warning: false,
508+
}
509+
.into_diag(dcx, level)
483510
},
484511
unused_span,
485512
)
@@ -490,12 +517,15 @@ impl<'f, 'sess: 'f, S: Stage> SharedContext<'f, 'sess, S> {
490517
used_span: Span,
491518
unused_span: Span,
492519
) {
493-
self.emit_lint(
520+
self.emit_dyn_lint(
494521
rustc_session::lint::builtin::UNUSED_ATTRIBUTES,
495-
AttributeLintKind::UnusedDuplicate {
496-
this: unused_span,
497-
other: used_span,
498-
warning: true,
522+
move |dcx, level| {
523+
rustc_errors::lints::UnusedDuplicate {
524+
this: unused_span,
525+
other: used_span,
526+
warning: true,
527+
}
528+
.into_diag(dcx, level)
499529
},
500530
unused_span,
501531
)

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, 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)