Skip to content

Commit 65334c7

Browse files
authored
Unrolled build for #155661
Rollup merge of #155661 - GuillaumeGomez:rm-attributelintkind, r=JonathanBrouwer Remove `AttributeLintKind` variants - part 6 Part of #153099. r? @JonathanBrouwer
2 parents 2eaa5de + b716ebc commit 65334c7

6 files changed

Lines changed: 133 additions & 143 deletions

File tree

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

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::ops::Range;
22

3-
use rustc_errors::E0232;
3+
use rustc_errors::{Diagnostic, E0232};
44
use rustc_hir::AttrPath;
55
use rustc_hir::attrs::diagnostic::{
66
Directive, FilterFormatString, Flag, FormatArg, FormatString, LitOrArg, Name, NameValue,
@@ -18,6 +18,10 @@ use rustc_span::{Ident, InnerSpan, Span, Symbol, kw, sym};
1818
use thin_vec::{ThinVec, thin_vec};
1919

2020
use crate::context::{AcceptContext, Stage};
21+
use crate::errors::{
22+
DisallowedPlaceholder, DisallowedPositionalArgument, IgnoredDiagnosticOption,
23+
InvalidFormatSpecifier, MalFormedDiagnosticAttributeLint, WrappedParserError,
24+
};
2125
use crate::parser::{ArgParser, MetaItemListParser, MetaItemOrLitParser, MetaItemParser};
2226

2327
pub(crate) mod do_not_recommend;
@@ -112,12 +116,12 @@ fn merge<T, S: Stage>(
112116
match (first, later) {
113117
(Some(_) | None, None) => {}
114118
(Some((first_span, _)), Some((later_span, _))) => {
115-
cx.emit_lint(
119+
let first_span = *first_span;
120+
cx.emit_dyn_lint(
116121
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
117-
AttributeLintKind::IgnoredDiagnosticOption {
118-
first_span: *first_span,
119-
later_span,
120-
option_name,
122+
move |dcx, level| {
123+
IgnoredDiagnosticOption { first_span, later_span, option_name }
124+
.into_diag(dcx, level)
121125
},
122126
later_span,
123127
);
@@ -157,12 +161,15 @@ fn parse_list<'p, S: Stage>(
157161
);
158162
}
159163
ArgParser::NameValue(_) => {
160-
cx.emit_lint(
164+
cx.emit_dyn_lint(
161165
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
162-
AttributeLintKind::MalFormedDiagnosticAttribute {
163-
attribute: mode.as_str(),
164-
options: mode.allowed_options(),
165-
span,
166+
move |dcx, level| {
167+
MalFormedDiagnosticAttributeLint {
168+
attribute: mode.as_str(),
169+
options: mode.allowed_options(),
170+
span,
171+
}
172+
.into_diag(dcx, level)
166173
},
167174
span,
168175
);
@@ -188,12 +195,15 @@ fn parse_directive_items<'p, S: Stage>(
188195
let span = item.span();
189196

190197
macro malformed() {{
191-
cx.emit_lint(
198+
cx.emit_dyn_lint(
192199
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
193-
AttributeLintKind::MalFormedDiagnosticAttribute {
194-
attribute: mode.as_str(),
195-
options: mode.allowed_options(),
196-
span,
200+
move |dcx, level| {
201+
MalFormedDiagnosticAttributeLint {
202+
attribute: mode.as_str(),
203+
options: mode.allowed_options(),
204+
span,
205+
}
206+
.into_diag(dcx, level)
197207
},
198208
span,
199209
);
@@ -210,13 +220,14 @@ fn parse_directive_items<'p, S: Stage>(
210220
}}
211221

212222
macro duplicate($name: ident, $($first_span:tt)*) {{
213-
cx.emit_lint(
223+
let first_span = $($first_span)*;
224+
cx.emit_dyn_lint(
214225
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
215-
AttributeLintKind::IgnoredDiagnosticOption {
216-
first_span: $($first_span)*,
226+
move |dcx, level| IgnoredDiagnosticOption {
227+
first_span,
217228
later_span: span,
218229
option_name: $name,
219-
},
230+
}.into_diag(dcx, level),
220231
span,
221232
);
222233
}}
@@ -245,22 +256,35 @@ fn parse_directive_items<'p, S: Stage>(
245256
let (FormatWarning::InvalidSpecifier { span, .. }
246257
| FormatWarning::PositionalArgument { span, .. }
247258
| FormatWarning::DisallowedPlaceholder { span }) = warning;
248-
cx.emit_lint(
259+
cx.emit_dyn_lint(
249260
MALFORMED_DIAGNOSTIC_FORMAT_LITERALS,
250-
AttributeLintKind::MalformedDiagnosticFormat { warning },
261+
move |dcx, level| match warning {
262+
FormatWarning::PositionalArgument { .. } => {
263+
DisallowedPositionalArgument.into_diag(dcx, level)
264+
}
265+
FormatWarning::InvalidSpecifier { .. } => {
266+
InvalidFormatSpecifier.into_diag(dcx, level)
267+
}
268+
FormatWarning::DisallowedPlaceholder { .. } => {
269+
DisallowedPlaceholder.into_diag(dcx, level)
270+
}
271+
},
251272
span,
252273
);
253274
}
254275

255276
f
256277
}
257278
Err(e) => {
258-
cx.emit_lint(
279+
cx.emit_dyn_lint(
259280
MALFORMED_DIAGNOSTIC_FORMAT_LITERALS,
260-
AttributeLintKind::DiagnosticWrappedParserError {
261-
description: e.description,
262-
label: e.label,
263-
span: slice_span(input.span, e.span, is_snippet),
281+
move |dcx, level| {
282+
WrappedParserError {
283+
description: &e.description,
284+
label: &e.label,
285+
span: slice_span(input.span, e.span.clone(), is_snippet),
286+
}
287+
.into_diag(dcx, level)
264288
},
265289
input.span,
266290
);

compiler/rustc_attr_parsing/src/attributes/doc.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use rustc_hir::Target;
55
use rustc_hir::attrs::{
66
AttributeKind, CfgEntry, CfgHideShow, CfgInfo, DocAttribute, DocInline, HideOrShow,
77
};
8-
use rustc_hir::lints::AttributeLintKind;
98
use rustc_session::parse::feature_err;
109
use rustc_span::{Span, Symbol, edition, sym};
1110
use thin_vec::ThinVec;
@@ -17,7 +16,8 @@ use crate::errors::{
1716
AttrCrateLevelOnly, DocAliasDuplicated, DocAutoCfgExpectsHideOrShow,
1817
DocAutoCfgHideShowExpectsList, DocAutoCfgHideShowUnexpectedItem, DocAutoCfgWrongLiteral,
1918
DocTestLiteral, DocTestTakesList, DocTestUnknown, DocUnknownAny, DocUnknownInclude,
20-
DocUnknownPasses, DocUnknownPlugins, DocUnknownSpotlight, IllFormedAttributeInput,
19+
DocUnknownPasses, DocUnknownPlugins, DocUnknownSpotlight, ExpectedNameValue, ExpectedNoArgs,
20+
IllFormedAttributeInput, MalformedDoc,
2121
};
2222
use crate::parser::{ArgParser, MetaItemOrLitParser, MetaItemParser, OwnedPathParser};
2323
use crate::session_diagnostics::{
@@ -84,18 +84,18 @@ fn expected_name_value<S: Stage>(
8484
span: Span,
8585
_name: Option<Symbol>,
8686
) {
87-
cx.emit_lint(
87+
cx.emit_dyn_lint(
8888
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
89-
AttributeLintKind::ExpectedNameValue,
89+
|dcx, level| ExpectedNameValue.into_diag(dcx, level),
9090
span,
9191
);
9292
}
9393

9494
// FIXME: remove this method once merged and use `cx.expected_no_args(span)` instead.
9595
fn expected_no_args<S: Stage>(cx: &mut AcceptContext<'_, '_, S>, span: Span) {
96-
cx.emit_lint(
96+
cx.emit_dyn_lint(
9797
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
98-
AttributeLintKind::ExpectedNoArgs,
98+
|dcx, level| ExpectedNoArgs.into_diag(dcx, level),
9999
span,
100100
);
101101
}
@@ -107,9 +107,9 @@ fn expected_string_literal<S: Stage>(
107107
span: Span,
108108
_actual_literal: Option<&MetaItemLit>,
109109
) {
110-
cx.emit_lint(
110+
cx.emit_dyn_lint(
111111
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
112-
AttributeLintKind::MalformedDoc,
112+
|dcx, level| MalformedDoc.into_diag(dcx, level),
113113
span,
114114
);
115115
}
@@ -203,9 +203,9 @@ impl DocParser {
203203
// FIXME: remove this method once merged and uncomment the line below instead.
204204
// cx.expected_list(cx.attr_span, args);
205205
let span = cx.attr_span;
206-
cx.emit_lint(
206+
cx.emit_dyn_lint(
207207
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
208-
AttributeLintKind::MalformedDoc,
208+
|dcx, level| MalformedDoc.into_diag(dcx, level),
209209
span,
210210
);
211211
return;
@@ -399,9 +399,9 @@ impl DocParser {
399399
// FIXME: remove this method once merged and uncomment the line
400400
// below instead.
401401
// cx.expected_identifier(sub_item.path().span());
402-
cx.emit_lint(
402+
cx.emit_dyn_lint(
403403
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
404-
AttributeLintKind::MalformedDoc,
404+
|dcx, level| MalformedDoc.into_diag(dcx, level),
405405
sub_item.path().span(),
406406
);
407407
continue;
@@ -605,9 +605,9 @@ impl DocParser {
605605
// FIXME: remove this method once merged and uncomment the line
606606
// below instead.
607607
// cx.unexpected_literal(lit.span);
608-
cx.emit_lint(
608+
cx.emit_dyn_lint(
609609
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
610-
AttributeLintKind::MalformedDoc,
610+
|dcx, level| MalformedDoc.into_diag(dcx, level),
611611
lit.span,
612612
);
613613
}

compiler/rustc_attr_parsing/src/errors.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,70 @@ pub(crate) struct IncorrectDoNotRecommendLocation {
325325
#[label("not a trait implementation")]
326326
pub target_span: Span,
327327
}
328+
329+
#[derive(Diagnostic)]
330+
#[diag("malformed `doc` attribute input")]
331+
#[warning(
332+
"this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!"
333+
)]
334+
pub(crate) struct MalformedDoc;
335+
336+
#[derive(Diagnostic)]
337+
#[diag("didn't expect any arguments here")]
338+
#[warning(
339+
"this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!"
340+
)]
341+
pub(crate) struct ExpectedNoArgs;
342+
343+
#[derive(Diagnostic)]
344+
#[diag("expected this to be of the form `... = \"...\"`")]
345+
#[warning(
346+
"this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!"
347+
)]
348+
pub(crate) struct ExpectedNameValue;
349+
350+
#[derive(Diagnostic)]
351+
#[diag("malformed `{$attribute}` attribute")]
352+
#[help("{$options}")]
353+
pub(crate) struct MalFormedDiagnosticAttributeLint {
354+
pub attribute: &'static str,
355+
pub options: &'static str,
356+
#[label("invalid option found here")]
357+
pub span: Span,
358+
}
359+
360+
#[derive(Diagnostic)]
361+
#[diag("positional format arguments are not allowed here")]
362+
#[help(
363+
"only named format arguments with the name of one of the generic types are allowed in this context"
364+
)]
365+
pub(crate) struct DisallowedPositionalArgument;
366+
367+
#[derive(Diagnostic)]
368+
#[diag("format arguments are not allowed here")]
369+
#[help("consider removing this format argument")]
370+
pub(crate) struct DisallowedPlaceholder;
371+
372+
#[derive(Diagnostic)]
373+
#[diag("invalid format specifier")]
374+
#[help("no format specifier are supported in this position")]
375+
pub(crate) struct InvalidFormatSpecifier;
376+
377+
#[derive(Diagnostic)]
378+
#[diag("{$description}")]
379+
pub(crate) struct WrappedParserError<'a> {
380+
pub description: &'a str,
381+
#[label("{$label}")]
382+
pub span: Span,
383+
pub label: &'a str,
384+
}
385+
386+
#[derive(Diagnostic)]
387+
#[diag("`{$option_name}` is ignored due to previous definition of `{$option_name}`")]
388+
pub(crate) struct IgnoredDiagnosticOption {
389+
pub option_name: Symbol,
390+
#[label("`{$option_name}` is first declared here")]
391+
pub first_span: Span,
392+
#[label("`{$option_name}` is later redundantly declared here")]
393+
pub later_span: Span,
394+
}

compiler/rustc_lint/src/early/diagnostics.rs

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::any::Any;
22

33
use rustc_data_structures::sync::DynSend;
44
use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, Level};
5-
use rustc_hir::lints::{AttributeLintKind, FormatWarning};
5+
use rustc_hir::lints::AttributeLintKind;
66
use rustc_middle::ty::TyCtxt;
77
use rustc_session::Session;
88

@@ -43,33 +43,6 @@ impl<'a> Diagnostic<'a, ()> for DecorateAttrLint<'_, '_, '_> {
4343
.into_diag(dcx, level)
4444
}
4545

46-
&AttributeLintKind::MalformedDoc => lints::MalformedDoc.into_diag(dcx, level),
47-
48-
&AttributeLintKind::ExpectedNoArgs => lints::ExpectedNoArgs.into_diag(dcx, level),
49-
50-
&AttributeLintKind::ExpectedNameValue => lints::ExpectedNameValue.into_diag(dcx, level),
51-
&AttributeLintKind::MalFormedDiagnosticAttribute { attribute, options, span } => {
52-
lints::MalFormedDiagnosticAttributeLint { attribute, options, span }
53-
.into_diag(dcx, level)
54-
}
55-
AttributeLintKind::MalformedDiagnosticFormat { warning } => match warning {
56-
FormatWarning::PositionalArgument { .. } => {
57-
lints::DisallowedPositionalArgument.into_diag(dcx, level)
58-
}
59-
FormatWarning::InvalidSpecifier { .. } => {
60-
lints::InvalidFormatSpecifier.into_diag(dcx, level)
61-
}
62-
FormatWarning::DisallowedPlaceholder { .. } => {
63-
lints::DisallowedPlaceholder.into_diag(dcx, level)
64-
}
65-
},
66-
AttributeLintKind::DiagnosticWrappedParserError { description, label, span } => {
67-
lints::WrappedParserError { description, label, span: *span }.into_diag(dcx, level)
68-
}
69-
&AttributeLintKind::IgnoredDiagnosticOption { option_name, first_span, later_span } => {
70-
lints::IgnoredDiagnosticOption { option_name, first_span, later_span }
71-
.into_diag(dcx, level)
72-
}
7346
&AttributeLintKind::MissingOptionsForDiagnosticAttribute { attribute, options } => {
7447
lints::MissingOptionsForDiagnosticAttribute { attribute, options }
7548
.into_diag(dcx, level)

0 commit comments

Comments
 (0)