Skip to content

Commit a89e69e

Browse files
authored
Rollup merge of rust-lang#156002 - GuillaumeGomez:diagnostic-instead-of-closure, r=JonathanBrouwer
Allow to use `Diagnostic` directly in `SharedContext::emit_lint` Part of rust-lang#153099. r? @JonathanBrouwer
2 parents cf60705 + f51cf63 commit a89e69e

16 files changed

Lines changed: 95 additions & 191 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/crate_level.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use rustc_errors::Diagnostic;
21
use rustc_hir::attrs::{CrateType, WindowsSubsystemKind};
32
use rustc_session::lint::builtin::UNKNOWN_CRATE_TYPES;
43
use rustc_span::Symbol;
@@ -61,12 +60,8 @@ impl CombineAttributeParser for CrateTypeParser {
6160
let span = n.value_span;
6261
cx.emit_lint(
6362
UNKNOWN_CRATE_TYPES,
64-
move |dcx, level| {
65-
UnknownCrateTypes {
66-
sugg: candidate
67-
.map(|s| UnknownCrateTypesSuggestion { span, snippet: s }),
68-
}
69-
.into_diag(dcx, level)
63+
UnknownCrateTypes {
64+
sugg: candidate.map(|s| UnknownCrateTypesSuggestion { span, snippet: s }),
7065
},
7166
span,
7267
);

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use rustc_errors::Diagnostic;
21
use rustc_feature::{AttributeTemplate, template};
32
use rustc_hir::Target;
43
use rustc_hir::attrs::AttributeKind;
@@ -26,7 +25,7 @@ impl SingleAttributeParser for DoNotRecommendParser {
2625
if !matches!(args, ArgParser::NoArgs) {
2726
cx.emit_lint(
2827
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
29-
|dcx, level| crate::errors::DoNotRecommendDoesNotExpectArgs.into_diag(dcx, level),
28+
crate::errors::DoNotRecommendDoesNotExpectArgs,
3029
attr_span,
3130
);
3231
}
@@ -35,9 +34,7 @@ impl SingleAttributeParser for DoNotRecommendParser {
3534
let target_span = cx.target_span;
3635
cx.emit_lint(
3736
MISPLACED_DIAGNOSTIC_ATTRIBUTES,
38-
move |dcx, level| {
39-
IncorrectDoNotRecommendLocation { target_span }.into_diag(dcx, level)
40-
},
37+
IncorrectDoNotRecommendLocation { target_span },
4138
attr_span,
4239
);
4340
return None;

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

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

3-
use rustc_errors::{Diagnostic, E0232};
3+
use rustc_errors::E0232;
44
use rustc_hir::AttrPath;
55
use rustc_hir::attrs::diagnostic::{
66
Directive, FilterFormatString, Flag, FormatArg, FormatString, LitOrArg, Name, NameValue,
@@ -142,10 +142,7 @@ fn merge<T>(
142142
let first_span = *first_span;
143143
cx.emit_lint(
144144
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
145-
move |dcx, level| {
146-
IgnoredDiagnosticOption { first_span, later_span, option_name }
147-
.into_diag(dcx, level)
148-
},
145+
IgnoredDiagnosticOption { first_span, later_span, option_name },
149146
later_span,
150147
);
151148
}
@@ -169,33 +166,27 @@ fn parse_list<'p>(
169166
// if the user used non-metaitem syntax. See `ArgParser::from_attr_args`.
170167
cx.emit_lint(
171168
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
172-
move |dcx, level| NonMetaItemDiagnosticAttribute.into_diag(dcx, level),
169+
NonMetaItemDiagnosticAttribute,
173170
list.span,
174171
);
175172
}
176173
ArgParser::NoArgs => {
177174
cx.emit_lint(
178175
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
179-
move |dcx, level| {
180-
MissingOptionsForDiagnosticAttribute {
181-
attribute: mode.as_str(),
182-
options: mode.expected_options(),
183-
}
184-
.into_diag(dcx, level)
176+
MissingOptionsForDiagnosticAttribute {
177+
attribute: mode.as_str(),
178+
options: mode.expected_options(),
185179
},
186180
span,
187181
);
188182
}
189183
ArgParser::NameValue(_) => {
190184
cx.emit_lint(
191185
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
192-
move |dcx, level| {
193-
MalFormedDiagnosticAttributeLint {
194-
attribute: mode.as_str(),
195-
options: mode.allowed_options(),
196-
span,
197-
}
198-
.into_diag(dcx, level)
186+
MalFormedDiagnosticAttributeLint {
187+
attribute: mode.as_str(),
188+
options: mode.allowed_options(),
189+
span,
199190
},
200191
span,
201192
);
@@ -223,13 +214,10 @@ fn parse_directive_items<'p>(
223214
macro malformed() {{
224215
cx.emit_lint(
225216
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
226-
move |dcx, level| {
227-
MalFormedDiagnosticAttributeLint {
228-
attribute: mode.as_str(),
229-
options: mode.allowed_options(),
230-
span,
231-
}
232-
.into_diag(dcx, level)
217+
MalFormedDiagnosticAttributeLint {
218+
attribute: mode.as_str(),
219+
options: mode.allowed_options(),
220+
span,
233221
},
234222
span,
235223
);
@@ -251,11 +239,11 @@ fn parse_directive_items<'p>(
251239
let first_span = $($first_span)*;
252240
cx.emit_lint(
253241
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
254-
move |dcx, level| IgnoredDiagnosticOption {
242+
IgnoredDiagnosticOption {
255243
first_span,
256244
later_span: span,
257245
option_name: $name,
258-
}.into_diag(dcx, level),
246+
},
259247
span,
260248
);
261249
}}
@@ -285,25 +273,18 @@ fn parse_directive_items<'p>(
285273
| FormatWarning::PositionalArgument { span }
286274
| FormatWarning::IndexedArgument { span }
287275
| FormatWarning::DisallowedPlaceholder { span, .. }) = warning;
288-
cx.emit_lint(
289-
MALFORMED_DIAGNOSTIC_FORMAT_LITERALS,
290-
move |dcx, level| warning.into_diag(dcx, level),
291-
span,
292-
);
276+
cx.emit_lint(MALFORMED_DIAGNOSTIC_FORMAT_LITERALS, warning, span);
293277
}
294278

295279
f
296280
}
297281
Err(e) => {
298282
cx.emit_lint(
299283
MALFORMED_DIAGNOSTIC_FORMAT_LITERALS,
300-
move |dcx, level| {
301-
WrappedParserError {
302-
description: &e.description,
303-
label: &e.label,
304-
span: slice_span(input.span, e.span.clone(), is_snippet),
305-
}
306-
.into_diag(dcx, level)
284+
WrappedParserError {
285+
description: e.description,
286+
label: e.label,
287+
span: slice_span(input.span, e.span.clone(), is_snippet),
307288
},
308289
input.span,
309290
);

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use rustc_errors::Diagnostic;
21
use rustc_hir::attrs::diagnostic::Directive;
32
use rustc_session::lint::builtin::MISPLACED_DIAGNOSTIC_ATTRIBUTES;
43

@@ -30,9 +29,7 @@ impl AttributeParser for OnConstParser {
3029
let target_span = cx.target_span;
3130
cx.emit_lint(
3231
MISPLACED_DIAGNOSTIC_ATTRIBUTES,
33-
move |dcx, level| {
34-
DiagnosticOnConstOnlyForTraitImpls { target_span }.into_diag(dcx, level)
35-
},
32+
DiagnosticOnConstOnlyForTraitImpls { target_span },
3633
span,
3734
);
3835
return;

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use rustc_errors::Diagnostic;
21
use rustc_feature::template;
32
use rustc_hir::attrs::AttributeKind;
43
use rustc_session::lint::builtin::MISPLACED_DIAGNOSTIC_ATTRIBUTES;
@@ -28,11 +27,7 @@ impl OnMoveParser {
2827
self.span = Some(span);
2928

3029
if !matches!(cx.target, Target::Enum | Target::Struct | Target::Union) {
31-
cx.emit_lint(
32-
MISPLACED_DIAGNOSTIC_ATTRIBUTES,
33-
move |dcx, level| DiagnosticOnMoveOnlyForAdt.into_diag(dcx, level),
34-
span,
35-
);
30+
cx.emit_lint(MISPLACED_DIAGNOSTIC_ATTRIBUTES, DiagnosticOnMoveOnlyForAdt, span);
3631
return;
3732
}
3833

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use rustc_errors::Diagnostic;
21
use rustc_hir::attrs::diagnostic::Directive;
32
use rustc_session::lint::builtin::MISPLACED_DIAGNOSTIC_ATTRIBUTES;
43

@@ -20,7 +19,7 @@ impl OnUnimplementedParser {
2019
if !matches!(cx.target, Target::Trait) {
2120
cx.emit_lint(
2221
MISPLACED_DIAGNOSTIC_ATTRIBUTES,
23-
move |dcx, level| DiagnosticOnUnimplementedOnlyForTraits.into_diag(dcx, level),
22+
DiagnosticOnUnimplementedOnlyForTraits,
2423
span,
2524
);
2625
return;

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use rustc_errors::Diagnostic;
21
use rustc_hir::attrs::diagnostic::Directive;
32
use rustc_session::lint::builtin::MISPLACED_DIAGNOSTIC_ATTRIBUTES;
43

@@ -32,9 +31,7 @@ impl OnUnknownParser {
3231
let target_span = cx.target_span;
3332
cx.emit_lint(
3433
MISPLACED_DIAGNOSTIC_ATTRIBUTES,
35-
move |dcx, level| {
36-
DiagnosticOnUnknownOnlyForImports { target_span }.into_diag(dcx, level)
37-
},
34+
DiagnosticOnUnknownOnlyForImports { target_span },
3835
span,
3936
);
4037
return;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use rustc_errors::Diagnostic;
21
use rustc_hir::attrs::diagnostic::Directive;
32
use rustc_session::lint::builtin::MISPLACED_DIAGNOSTIC_ATTRIBUTES;
43

@@ -27,7 +26,7 @@ impl AttributeParser for OnUnmatchArgsParser {
2726
if !matches!(cx.target, Target::MacroDef) {
2827
cx.emit_lint(
2928
MISPLACED_DIAGNOSTIC_ATTRIBUTES,
30-
move |dcx, level| DiagnosticOnUnmatchArgsOnlyForMacros.into_diag(dcx, level),
29+
DiagnosticOnUnmatchArgsOnlyForMacros,
3130
span,
3231
);
3332
return;

0 commit comments

Comments
 (0)