Skip to content

Commit 79e2ff7

Browse files
Rollup merge of #155590 - GuillaumeGomez:rm-attributelintkind, r=JonathanBrouwer
Remove AttributeLintKind variants - part 5 Part of #153099. r? @JonathanBrouwer
2 parents aa33354 + 80777dd commit 79e2ff7

8 files changed

Lines changed: 69 additions & 91 deletions

File tree

.mailmap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,11 @@ Greg V <greg@unrelenting.technology>
258258
Gregor Peach <gregorpeach@gmail.com>
259259
Grzegorz Bartoszek <grzegorz.bartoszek@thaumatec.com>
260260
Guanqun Lu <guanqun.lu@gmail.com>
261-
Guillaume Gomez <guillaume1.gomez@gmail.com>
262-
Guillaume Gomez <guillaume1.gomez@gmail.com> ggomez <ggomez@ggo.ifr.lan>
263-
Guillaume Gomez <guillaume1.gomez@gmail.com> Guillaume Gomez <ggomez@ggo.ifr.lan>
264-
Guillaume Gomez <guillaume1.gomez@gmail.com> Guillaume Gomez <guillaume.gomez@huawei.com>
265-
Guillaume Gomez <guillaume1.gomez@gmail.com> Guillaume Gomez <contact@guillaume-gomez.fr>
261+
Guillaume Gomez <contact@guillaume-gomez.fr>
262+
Guillaume Gomez <contact@guillaume-gomez.fr> Guillaume Gomez <guillaume1.gomez@gmail.com>
263+
Guillaume Gomez <contact@guillaume-gomez.fr> ggomez <ggomez@ggo.ifr.lan>
264+
Guillaume Gomez <contact@guillaume-gomez.fr> Guillaume Gomez <ggomez@ggo.ifr.lan>
265+
Guillaume Gomez <contact@guillaume-gomez.fr> Guillaume Gomez <guillaume.gomez@huawei.com>
266266
gnzlbg <gonzalobg88@gmail.com> <gnzlbg@users.noreply.github.com>
267267
hamidreza kalbasi <hamidrezakalbasi@protonmail.com>
268268
Hanna Kruppe <hanna.kruppe@gmail.com> <robin.kruppe@gmail.com>

compiler/rustc_attr_parsing/src/attributes/crate_level.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
use rustc_errors::Diagnostic;
12
use rustc_hir::attrs::{CrateType, WindowsSubsystemKind};
2-
use rustc_hir::lints::AttributeLintKind;
33
use rustc_session::lint::builtin::UNKNOWN_CRATE_TYPES;
44
use rustc_span::Symbol;
55
use rustc_span::edit_distance::find_best_match_for_name;
66

77
use super::prelude::*;
8+
use crate::errors::{UnknownCrateTypes, UnknownCrateTypesSuggestion};
89

910
pub(crate) struct CrateNameParser;
1011

@@ -65,13 +66,17 @@ impl<S: Stage> CombineAttributeParser<S> for CrateTypeParser {
6566
crate_type,
6667
None,
6768
);
68-
cx.emit_lint(
69+
let span = n.value_span;
70+
cx.emit_dyn_lint(
6971
UNKNOWN_CRATE_TYPES,
70-
AttributeLintKind::CrateTypeUnknown {
71-
span: n.value_span,
72-
suggested: candidate,
72+
move |dcx, level| {
73+
UnknownCrateTypes {
74+
sugg: candidate
75+
.map(|s| UnknownCrateTypesSuggestion { span, snippet: s }),
76+
}
77+
.into_diag(dcx, level)
7378
},
74-
n.value_span,
79+
span,
7580
);
7681
}
7782
return None;

compiler/rustc_attr_parsing/src/attributes/diagnostic/do_not_recommend.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use rustc_errors::Diagnostic;
22
use rustc_feature::{AttributeTemplate, template};
33
use rustc_hir::Target;
44
use rustc_hir::attrs::AttributeKind;
5-
use rustc_hir::lints::AttributeLintKind;
65
use rustc_session::lint::builtin::{
76
MALFORMED_DIAGNOSTIC_ATTRIBUTES, MISPLACED_DIAGNOSTIC_ATTRIBUTES,
87
};
@@ -25,9 +24,9 @@ impl<S: Stage> SingleAttributeParser<S> for DoNotRecommendParser {
2524
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
2625
let attr_span = cx.attr_span;
2726
if !matches!(args, ArgParser::NoArgs) {
28-
cx.emit_lint(
27+
cx.emit_dyn_lint(
2928
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
30-
AttributeLintKind::DoNotRecommendDoesNotExpectArgs,
29+
|dcx, level| crate::errors::DoNotRecommendDoesNotExpectArgs.into_diag(dcx, level),
3130
attr_span,
3231
);
3332
}

compiler/rustc_attr_parsing/src/attributes/doc.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ use super::prelude::{ALL_TARGETS, AllowedTargets};
1414
use super::{AcceptMapping, AttributeParser};
1515
use crate::context::{AcceptContext, FinalizeContext, Stage};
1616
use crate::errors::{
17-
DocAliasDuplicated, DocAutoCfgExpectsHideOrShow, DocAutoCfgHideShowExpectsList,
18-
DocAutoCfgHideShowUnexpectedItem, DocAutoCfgWrongLiteral, DocUnknownAny, DocUnknownInclude,
17+
AttrCrateLevelOnly, DocAliasDuplicated, DocAutoCfgExpectsHideOrShow,
18+
DocAutoCfgHideShowExpectsList, DocAutoCfgHideShowUnexpectedItem, DocAutoCfgWrongLiteral,
19+
DocTestLiteral, DocTestTakesList, DocTestUnknown, DocUnknownAny, DocUnknownInclude,
1920
DocUnknownPasses, DocUnknownPlugins, DocUnknownSpotlight, IllFormedAttributeInput,
2021
};
2122
use crate::parser::{ArgParser, MetaItemOrLitParser, MetaItemParser, OwnedPathParser};
@@ -67,9 +68,9 @@ fn check_attr_not_crate_level<S: Stage>(
6768
/// Checks that an attribute is used at the crate level. Returns `true` if valid.
6869
fn check_attr_crate_level<S: Stage>(cx: &mut AcceptContext<'_, '_, S>, span: Span) -> bool {
6970
if cx.shared.target != Target::Crate {
70-
cx.emit_lint(
71+
cx.emit_dyn_lint(
7172
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
72-
AttributeLintKind::AttrCrateLevelOnly,
73+
|dcx, level| AttrCrateLevelOnly.into_diag(dcx, level),
7374
span,
7475
);
7576
return false;
@@ -216,16 +217,16 @@ impl DocParser {
216217
}
217218
}
218219
Some(name) => {
219-
cx.emit_lint(
220+
cx.emit_dyn_lint(
220221
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
221-
AttributeLintKind::DocTestUnknown { name },
222+
move |dcx, level| DocTestUnknown { name }.into_diag(dcx, level),
222223
path.span(),
223224
);
224225
}
225226
None => {
226-
cx.emit_lint(
227+
cx.emit_dyn_lint(
227228
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
228-
AttributeLintKind::DocTestLiteral,
229+
|dcx, level| DocTestLiteral.into_diag(dcx, level),
229230
path.span(),
230231
);
231232
}
@@ -587,9 +588,9 @@ impl DocParser {
587588
Some(sym::auto_cfg) => self.parse_auto_cfg(cx, path, args),
588589
Some(sym::test) => {
589590
let Some(list) = args.list() else {
590-
cx.emit_lint(
591+
cx.emit_dyn_lint(
591592
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
592-
AttributeLintKind::DocTestTakesList,
593+
|dcx, level| DocTestTakesList.into_diag(dcx, level),
593594
args.span().unwrap_or(path.span()),
594595
);
595596
return;

compiler/rustc_attr_parsing/src/errors.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,46 @@ pub(crate) struct DocUnknownAny {
253253
#[diag("expected boolean for `#[doc(auto_cfg = ...)]`")]
254254
pub(crate) struct DocAutoCfgWrongLiteral;
255255

256+
#[derive(Diagnostic)]
257+
#[diag("`#[doc(test(...)]` takes a list of attributes")]
258+
pub(crate) struct DocTestTakesList;
259+
260+
#[derive(Diagnostic)]
261+
#[diag("unknown `doc(test)` attribute `{$name}`")]
262+
pub(crate) struct DocTestUnknown {
263+
pub name: Symbol,
264+
}
265+
266+
#[derive(Diagnostic)]
267+
#[diag("`#![doc(test(...)]` does not take a literal")]
268+
pub(crate) struct DocTestLiteral;
269+
270+
#[derive(Diagnostic)]
271+
#[diag("this attribute can only be applied at the crate level")]
272+
#[note(
273+
"read <https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#at-the-crate-level> for more information"
274+
)]
275+
pub(crate) struct AttrCrateLevelOnly;
276+
277+
#[derive(Diagnostic)]
278+
#[diag("`#[diagnostic::do_not_recommend]` does not expect any arguments")]
279+
pub(crate) struct DoNotRecommendDoesNotExpectArgs;
280+
281+
#[derive(Diagnostic)]
282+
#[diag("invalid `crate_type` value")]
283+
pub(crate) struct UnknownCrateTypes {
284+
#[subdiagnostic]
285+
pub sugg: Option<UnknownCrateTypesSuggestion>,
286+
}
287+
288+
#[derive(Subdiagnostic)]
289+
#[suggestion("did you mean", code = r#""{snippet}""#, applicability = "maybe-incorrect")]
290+
pub(crate) struct UnknownCrateTypesSuggestion {
291+
#[primary_span]
292+
pub span: Span,
293+
pub snippet: Symbol,
294+
}
295+
256296
#[derive(Diagnostic)]
257297
#[diag("`#[diagnostic::on_const]` can only be applied to non-const trait implementations")]
258298
pub(crate) struct DiagnosticOnConstOnlyForTraitImpls {

compiler/rustc_lint/src/early/diagnostics.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,6 @@ impl<'a> Diagnostic<'a, ()> for DecorateAttrLint<'_, '_, '_> {
4343
.into_diag(dcx, level)
4444
}
4545

46-
&AttributeLintKind::DocTestTakesList => lints::DocTestTakesList.into_diag(dcx, level),
47-
48-
&AttributeLintKind::DocTestUnknown { name } => {
49-
lints::DocTestUnknown { name }.into_diag(dcx, level)
50-
}
51-
52-
&AttributeLintKind::DocTestLiteral => lints::DocTestLiteral.into_diag(dcx, level),
53-
54-
&AttributeLintKind::AttrCrateLevelOnly => {
55-
lints::AttrCrateLevelOnly.into_diag(dcx, level)
56-
}
57-
58-
&AttributeLintKind::DoNotRecommendDoesNotExpectArgs => {
59-
lints::DoNotRecommendDoesNotExpectArgs.into_diag(dcx, level)
60-
}
61-
62-
&AttributeLintKind::CrateTypeUnknown { span, suggested } => lints::UnknownCrateTypes {
63-
sugg: suggested.map(|s| lints::UnknownCrateTypesSuggestion { span, snippet: s }),
64-
}
65-
.into_diag(dcx, level),
66-
6746
&AttributeLintKind::MalformedDoc => lints::MalformedDoc.into_diag(dcx, level),
6847

6948
&AttributeLintKind::ExpectedNoArgs => lints::ExpectedNoArgs.into_diag(dcx, level),

compiler/rustc_lint/src/lints.rs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3303,46 +3303,6 @@ pub(crate) struct ExpectedNoArgs;
33033303
)]
33043304
pub(crate) struct ExpectedNameValue;
33053305

3306-
#[derive(Diagnostic)]
3307-
#[diag("`#[doc(test(...)]` takes a list of attributes")]
3308-
pub(crate) struct DocTestTakesList;
3309-
3310-
#[derive(Diagnostic)]
3311-
#[diag("unknown `doc(test)` attribute `{$name}`")]
3312-
pub(crate) struct DocTestUnknown {
3313-
pub name: Symbol,
3314-
}
3315-
3316-
#[derive(Diagnostic)]
3317-
#[diag("`#![doc(test(...)]` does not take a literal")]
3318-
pub(crate) struct DocTestLiteral;
3319-
3320-
#[derive(Diagnostic)]
3321-
#[diag("this attribute can only be applied at the crate level")]
3322-
#[note(
3323-
"read <https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#at-the-crate-level> for more information"
3324-
)]
3325-
pub(crate) struct AttrCrateLevelOnly;
3326-
3327-
#[derive(Diagnostic)]
3328-
#[diag("`#[diagnostic::do_not_recommend]` does not expect any arguments")]
3329-
pub(crate) struct DoNotRecommendDoesNotExpectArgs;
3330-
3331-
#[derive(Diagnostic)]
3332-
#[diag("invalid `crate_type` value")]
3333-
pub(crate) struct UnknownCrateTypes {
3334-
#[subdiagnostic]
3335-
pub sugg: Option<UnknownCrateTypesSuggestion>,
3336-
}
3337-
3338-
#[derive(Subdiagnostic)]
3339-
#[suggestion("did you mean", code = r#""{snippet}""#, applicability = "maybe-incorrect")]
3340-
pub(crate) struct UnknownCrateTypesSuggestion {
3341-
#[primary_span]
3342-
pub span: Span,
3343-
pub snippet: Symbol,
3344-
}
3345-
33463306
#[derive(Diagnostic)]
33473307
#[diag("positional format arguments are not allowed here")]
33483308
#[help(

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -656,12 +656,6 @@ pub enum DeprecatedSinceKind {
656656
pub enum AttributeLintKind {
657657
UnexpectedCfgName((Symbol, Span), Option<(Symbol, Span)>),
658658
UnexpectedCfgValue((Symbol, Span), Option<(Symbol, Span)>),
659-
DocTestTakesList,
660-
DocTestUnknown { name: Symbol },
661-
DocTestLiteral,
662-
AttrCrateLevelOnly,
663-
DoNotRecommendDoesNotExpectArgs,
664-
CrateTypeUnknown { span: Span, suggested: Option<Symbol> },
665659
MalformedDoc,
666660
ExpectedNoArgs,
667661
ExpectedNameValue,

0 commit comments

Comments
 (0)