Skip to content

Commit 04a7dfe

Browse files
Remove AttributeLintKind::UnusedDuplicate
1 parent b9665ac commit 04a7dfe

File tree

7 files changed

+62
-39
lines changed

7 files changed

+62
-39
lines changed

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;
@@ -460,22 +461,43 @@ impl<'f, 'sess: 'f, S: Stage> SharedContext<'f, 'sess, S> {
460461
/// must be delayed until after HIR is built. This method will take care of the details of
461462
/// that.
462463
pub(crate) fn emit_lint(&mut self, lint: &'static Lint, kind: AttributeLintKind, span: Span) {
464+
self.emit_lint_inner(lint, EmitAttribute::Static(kind), span);
465+
}
466+
467+
/// Emit a lint. This method is somewhat special, since lints emitted during attribute parsing
468+
/// must be delayed until after HIR is built. This method will take care of the details of
469+
/// that.
470+
pub(crate) fn emit_dyn_lint<
471+
F: for<'a> Fn(DiagCtxtHandle<'a>, Level) -> Diag<'a, ()> + DynSend + DynSync + 'static,
472+
>(
473+
&mut self,
474+
lint: &'static Lint,
475+
callback: F,
476+
span: Span,
477+
) {
478+
self.emit_lint_inner(lint, EmitAttribute::Dynamic(Box::new(callback)), span);
479+
}
480+
481+
fn emit_lint_inner(&mut self, lint: &'static Lint, kind: EmitAttribute, span: Span) {
463482
if !matches!(
464483
self.stage.should_emit(),
465484
ShouldEmit::ErrorsAndLints { .. } | ShouldEmit::EarlyFatal { also_emit_lints: true }
466485
) {
467486
return;
468487
}
469-
(self.emit_lint)(LintId::of(lint), span, EmitAttribute::Static(kind));
488+
(self.emit_lint)(LintId::of(lint), span, kind);
470489
}
471490

472491
pub(crate) fn warn_unused_duplicate(&mut self, used_span: Span, unused_span: Span) {
473-
self.emit_lint(
492+
self.emit_dyn_lint(
474493
rustc_session::lint::builtin::UNUSED_ATTRIBUTES,
475-
AttributeLintKind::UnusedDuplicate {
476-
this: unused_span,
477-
other: used_span,
478-
warning: false,
494+
move |dcx, level| {
495+
rustc_errors::lints::UnusedDuplicate {
496+
this: unused_span,
497+
other: used_span,
498+
warning: false,
499+
}
500+
.into_diag(dcx, level)
479501
},
480502
unused_span,
481503
)
@@ -486,12 +508,15 @@ impl<'f, 'sess: 'f, S: Stage> SharedContext<'f, 'sess, S> {
486508
used_span: Span,
487509
unused_span: Span,
488510
) {
489-
self.emit_lint(
511+
self.emit_dyn_lint(
490512
rustc_session::lint::builtin::UNUSED_ATTRIBUTES,
491-
AttributeLintKind::UnusedDuplicate {
492-
this: unused_span,
493-
other: used_span,
494-
warning: true,
513+
move |dcx, level| {
514+
rustc_errors::lints::UnusedDuplicate {
515+
this: unused_span,
516+
other: used_span,
517+
warning: true,
518+
}
519+
.into_diag(dcx, level)
495520
},
496521
unused_span,
497522
)

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)