Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5e2b622

Browse files
committed
Move more early buffered lints to dyn lint diagnostics
1 parent d327d65 commit 5e2b622

File tree

19 files changed

+146
-183
lines changed

19 files changed

+146
-183
lines changed

‎compiler/rustc_builtin_macros/messages.ftl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ builtin_macros_autodiff_ty_activity = {$act} can not be used for this type
6464
builtin_macros_autodiff_unknown_activity = did not recognize Activity: `{$act}`
6565
6666
builtin_macros_autodiff_width = autodiff width must fit u32, but is {$width}
67+
68+
builtin_macros_avoid_att_syntax = avoid using `.att_syntax`, prefer using `options(att_syntax)` instead
69+
70+
builtin_macros_avoid_intel_syntax = avoid using `.intel_syntax`, Intel syntax is the default
71+
6772
builtin_macros_bad_derive_target = `derive` may only be applied to `struct`s, `enum`s and `union`s
6873
.label = not applicable here
6974
.label2 = not a `struct`, `enum` or `union`
@@ -138,6 +143,8 @@ builtin_macros_derive_path_args_list = traits in `#[derive(...)]` don't accept a
138143
builtin_macros_derive_path_args_value = traits in `#[derive(...)]` don't accept values
139144
.suggestion = remove the value
140145
146+
builtin_macros_duplicate_macro_attribute = duplicated attribute
147+
141148
builtin_macros_env_not_defined = environment variable `{$var}` not defined at compile time
142149
.cargo = Cargo sets build script variables at run time. Use `std::env::var({$var_expr})` instead
143150
.custom = use `std::env::var({$var_expr})` to read the variable at run time
@@ -231,6 +238,8 @@ builtin_macros_derive_from_wrong_field_count = `#[derive(From)]` used on a struc
231238
232239
builtin_macros_derive_from_usage_note = `#[derive(From)]` can only be used on structs with exactly one field
233240
241+
builtin_macros_incomplete_include = include macro expected single expression in source
242+
234243
builtin_macros_multiple_default_attrs = multiple `#[default]` attributes
235244
.note = only one `#[default]` attribute is needed
236245
.label = `#[default]` used here
@@ -294,3 +303,5 @@ builtin_macros_unexpected_lit = expected path to a trait, found literal
294303
.label = not a trait
295304
.str_lit = try using `#[derive({$sym})]`
296305
.other = for example, write `#[derive(Debug)]` for `Debug`
306+
307+
builtin_macros_unnameable_test_items = cannot test inner items

‎compiler/rustc_builtin_macros/src/asm.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use lint::BuiltinLintDiag;
21
use rustc_ast::tokenstream::TokenStream;
32
use rustc_ast::{AsmMacro, token};
43
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
@@ -352,15 +351,15 @@ fn expand_preparsed_asm(
352351
lint::builtin::BAD_ASM_STYLE,
353352
find_span(".intel_syntax"),
354353
ecx.current_expansion.lint_node_id,
355-
BuiltinLintDiag::AvoidUsingIntelSyntax,
354+
errors::AvoidIntelSyntax,
356355
);
357356
}
358357
if template_str.contains(".att_syntax") {
359358
ecx.psess().buffer_lint(
360359
lint::builtin::BAD_ASM_STYLE,
361360
find_span(".att_syntax"),
362361
ecx.current_expansion.lint_node_id,
363-
BuiltinLintDiag::AvoidUsingAttSyntax,
362+
errors::AvoidAttSyntax,
364363
);
365364
}
366365
}

‎compiler/rustc_builtin_macros/src/errors.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,29 @@ use rustc_errors::{
33
Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, MultiSpan, SingleLabelManySpans,
44
Subdiagnostic,
55
};
6-
use rustc_macros::{Diagnostic, Subdiagnostic};
6+
use rustc_macros::{Diagnostic, LintDiagnostic,Subdiagnostic};
77
use rustc_span::{Ident, Span, Symbol};
88

9+
#[derive(LintDiagnostic)]
10+
#[diag(builtin_macros_avoid_intel_syntax)]
11+
pub(crate) struct AvoidIntelSyntax;
12+
13+
#[derive(LintDiagnostic)]
14+
#[diag(builtin_macros_avoid_att_syntax)]
15+
pub(crate) struct AvoidAttSyntax;
16+
17+
#[derive(LintDiagnostic)]
18+
#[diag(builtin_macros_incomplete_include)]
19+
pub(crate) struct IncompleteInclude;
20+
21+
#[derive(LintDiagnostic)]
22+
#[diag(builtin_macros_unnameable_test_items)]
23+
pub(crate) struct UnnameableTestItems;
24+
25+
#[derive(LintDiagnostic)]
26+
#[diag(builtin_macros_duplicate_macro_attribute)]
27+
pub(crate) struct DuplicateMacroAttribute;
28+
929
#[derive(Diagnostic)]
1030
#[diag(builtin_macros_requires_cfg_pattern)]
1131
pub(crate) struct RequiresCfgPattern {

‎compiler/rustc_builtin_macros/src/source_util.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use rustc_expand::base::{
1010
DummyResult, ExpandResult, ExtCtxt, MacEager, MacResult, MacroExpanderResult, resolve_path,
1111
};
1212
use rustc_expand::module::DirOwnership;
13-
use rustc_lint_defs::BuiltinLintDiag;
1413
use rustc_parse::parser::{ForceCollect, Parser};
1514
use rustc_parse::{new_parser_from_file, unwrap_or_emit_fatal, utf8_error};
1615
use rustc_session::lint::builtin::INCOMPLETE_INCLUDE;
@@ -150,7 +149,7 @@ pub(crate) fn expand_include<'cx>(
150149
INCOMPLETE_INCLUDE,
151150
self.p.token.span,
152151
self.node_id,
153-
BuiltinLintDiag::IncompleteInclude,
152+
errors::IncompleteInclude,
154153
);
155154
}
156155
Some(expr)

‎compiler/rustc_builtin_macros/src/test_harness.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use rustc_errors::DiagCtxtHandle;
1111
use rustc_expand::base::{ExtCtxt, ResolverExpand};
1212
use rustc_expand::expand::{AstFragment, ExpansionConfig};
1313
use rustc_feature::Features;
14-
use rustc_lint_defs::BuiltinLintDiag;
1514
use rustc_session::Session;
1615
use rustc_session::lint::builtin::UNNAMEABLE_TEST_ITEMS;
1716
use rustc_span::hygiene::{AstPass, SyntaxContext, Transparency};
@@ -165,7 +164,7 @@ impl<'a> Visitor<'a> for InnerItemLinter<'_> {
165164
UNNAMEABLE_TEST_ITEMS,
166165
attr.span,
167166
i.id,
168-
BuiltinLintDiag::UnnameableTestItems,
167+
errors::UnnameableTestItems,
169168
);
170169
}
171170
}

‎compiler/rustc_builtin_macros/src/util.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use rustc_errors::{Applicability, Diag, ErrorGuaranteed};
55
use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt};
66
use rustc_expand::expand::AstFragment;
77
use rustc_feature::AttributeTemplate;
8-
use rustc_lint_defs::BuiltinLintDiag;
98
use rustc_lint_defs::builtin::DUPLICATE_MACRO_ATTRIBUTES;
109
use rustc_parse::{exp, parser};
1110
use rustc_session::errors::report_lit_error;
@@ -49,7 +48,7 @@ pub(crate) fn warn_on_duplicate_attribute(ecx: &ExtCtxt<'_>, item: &Annotatable,
4948
DUPLICATE_MACRO_ATTRIBUTES,
5049
attr.span,
5150
ecx.current_expansion.lint_node_id,
52-
BuiltinLintDiag::DuplicateMacroAttribute,
51+
errors::DuplicateMacroAttribute,
5352
);
5453
}
5554
}

‎compiler/rustc_expand/messages.ftl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ expand_attributes_on_expressions_experimental =
33
.help_outer_doc = `///` is used for outer documentation comments; for a plain comment, use `//`
44
.help_inner_doc = `//!` is used for inner documentation comments; for a plain comment, use `//` by removing the `!` or inserting a space in between them: `// !`
55
6+
expand_cfg_attr_no_attributes = `#[cfg_attr]` does not expand to any attributes
7+
68
expand_collapse_debuginfo_illegal =
79
illegal value for attribute #[collapse_debuginfo(no|external|yes)]
810
@@ -89,6 +91,13 @@ expand_malformed_feature_attribute =
8991
malformed `feature` attribute input
9092
.expected = expected just one word
9193
94+
expand_metavariable_still_repeating = variable `{$name}` is still repeating at this depth
95+
.label = expected repetition
96+
97+
expand_metavariable_wrong_operator = meta-variable repeats with different Kleene operator
98+
.binder_label = expected repetition
99+
.occurrence_label = conflicting repetition
100+
92101
expand_meta_var_dif_seq_matchers = {$msg}
93102
94103
expand_missing_fragment_specifier = missing fragment specifier
@@ -176,6 +185,8 @@ expand_resolve_relative_path =
176185
177186
expand_trace_macro = trace_macro
178187
188+
expand_unknown_macro_variable = unknown macro variable `{$name}`
189+
179190
expand_unsupported_key_value =
180191
key-value macro attributes are not supported
181192

‎compiler/rustc_expand/src/config.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use rustc_feature::{
2121
ACCEPTED_LANG_FEATURES, AttributeSafety, EnabledLangFeature, EnabledLibFeature, Features,
2222
REMOVED_LANG_FEATURES, UNSTABLE_LANG_FEATURES,
2323
};
24-
use rustc_lint_defs::BuiltinLintDiag;
2524
use rustc_session::Session;
2625
use rustc_session::parse::feature_err;
2726
use rustc_span::{STDLIB_STABLE_CRATES, Span, Symbol, sym};
@@ -315,7 +314,7 @@ impl<'a> StripUnconfigured<'a> {
315314
rustc_lint_defs::builtin::UNUSED_ATTRIBUTES,
316315
cfg_attr.span,
317316
ast::CRATE_NODE_ID,
318-
BuiltinLintDiag::CfgAttrNoAttributes,
317+
crate::errors::CfgAttrNoAttributes,
319318
);
320319
}
321320

‎compiler/rustc_expand/src/errors.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ use std::borrow::Cow;
22

33
use rustc_ast::ast;
44
use rustc_errors::codes::*;
5-
use rustc_macros::{Diagnostic, Subdiagnostic};
5+
use rustc_macros::{Diagnostic, LintDiagnostic,Subdiagnostic};
66
use rustc_session::Limit;
77
use rustc_span::{Ident, MacroRulesNormalizedIdent, Span, Symbol};
88

9+
#[derive(LintDiagnostic)]
10+
#[diag(expand_cfg_attr_no_attributes)]
11+
pub(crate) struct CfgAttrNoAttributes;
12+
913
#[derive(Diagnostic)]
1014
#[diag(expand_expr_repeat_no_syntax_vars)]
1115
pub(crate) struct NoSyntaxVarsExprRepeat {
@@ -27,6 +31,8 @@ pub(crate) struct CountRepetitionMisplaced {
2731
pub span: Span,
2832
}
2933

34+
// FIXME(fmease): "Combine"/assimilate VarStillRepeating and MetaVariableStillRepeating
35+
3036
#[derive(Diagnostic)]
3137
#[diag(expand_var_still_repeating)]
3238
pub(crate) struct VarStillRepeating {
@@ -35,6 +41,23 @@ pub(crate) struct VarStillRepeating {
3541
pub ident: MacroRulesNormalizedIdent,
3642
}
3743

44+
#[derive(LintDiagnostic)]
45+
#[diag(expand_metavariable_still_repeating)]
46+
pub(crate) struct MetaVariableStillRepeating {
47+
pub name: MacroRulesNormalizedIdent,
48+
#[label]
49+
pub label: Span,
50+
}
51+
52+
#[derive(LintDiagnostic)]
53+
#[diag(expand_metavariable_wrong_operator)]
54+
pub(crate) struct MetaVariableWrongOperator {
55+
#[label(expand_binder_label)]
56+
pub binder: Span,
57+
#[label(expand_occurrence_label)]
58+
pub occurrence: Span,
59+
}
60+
3861
#[derive(Diagnostic)]
3962
#[diag(expand_meta_var_dif_seq_matchers)]
4063
pub(crate) struct MetaVarsDifSeqMatchers {
@@ -43,6 +66,12 @@ pub(crate) struct MetaVarsDifSeqMatchers {
4366
pub msg: String,
4467
}
4568

69+
#[derive(LintDiagnostic)]
70+
#[diag(expand_unknown_macro_variable)]
71+
pub(crate) struct UnknownMacroVariable {
72+
pub name: MacroRulesNormalizedIdent,
73+
}
74+
4675
#[derive(Diagnostic)]
4776
#[diag(expand_resolve_relative_path)]
4877
pub(crate) struct ResolveRelativePath {
@@ -345,6 +374,15 @@ pub(crate) struct DuplicateMatcherBinding {
345374
pub prev: Span,
346375
}
347376

377+
#[derive(LintDiagnostic)]
378+
#[diag(expand_duplicate_matcher_binding)]
379+
pub(crate) struct DuplicateMatcherBindingLint {
380+
#[label]
381+
pub span: Span,
382+
#[label(expand_label2)]
383+
pub prev: Span,
384+
}
385+
348386
#[derive(Diagnostic)]
349387
#[diag(expand_missing_fragment_specifier)]
350388
#[note]

‎compiler/rustc_expand/src/mbe/macro_check.rs

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@
108108
use rustc_ast::token::{Delimiter, IdentIsRaw, Token, TokenKind};
109109
use rustc_ast::{DUMMY_NODE_ID, NodeId};
110110
use rustc_data_structures::fx::FxHashMap;
111-
use rustc_errors::MultiSpan;
112-
use rustc_lint_defs::BuiltinLintDiag;
111+
use rustc_errors::DecorateDiagCompat;
113112
use rustc_session::lint::builtin::META_VARIABLE_MISUSE;
114113
use rustc_session::parse::ParseSess;
115114
use rustc_span::{ErrorGuaranteed, MacroRulesNormalizedIdent, Span, kw};
@@ -245,9 +244,12 @@ fn check_binders(
245244
// There are 3 possibilities:
246245
if let Some(prev_info) = binders.get(&name) {
247246
// 1. The meta-variable is already bound in the current LHS: This is an error.
248-
let mut span = MultiSpan::from_span(span);
249-
span.push_span_label(prev_info.span, "previous declaration");
250-
buffer_lint(psess, span, node_id, BuiltinLintDiag::DuplicateMatcherBinding);
247+
buffer_lint(
248+
psess,
249+
span,
250+
node_id,
251+
errors::DuplicateMatcherBindingLint { span, prev: prev_info.span },
252+
);
251253
} else if get_binder_info(macros, binders, name).is_none() {
252254
// 2. The meta-variable is free: This is a binder.
253255
binders.insert(name, BinderInfo { span, ops: ops.into() });
@@ -579,7 +581,7 @@ fn check_ops_is_prefix(
579581
return;
580582
}
581583
}
582-
buffer_lint(psess, span.into(), node_id, BuiltinLintDiag::UnknownMacroVariable(name));
584+
buffer_lint(psess, span, node_id, errors::UnknownMacroVariable{name});
583585
}
584586

585587
/// Returns whether `binder_ops` is a prefix of `occurrence_ops`.
@@ -610,23 +612,36 @@ fn ops_is_prefix(
610612
) {
611613
for (i, binder) in binder_ops.iter().enumerate() {
612614
if i >= occurrence_ops.len() {
613-
let mut span = MultiSpan::from_span(span);
614-
span.push_span_label(binder.span, "expected repetition");
615-
buffer_lint(psess, span, node_id, BuiltinLintDiag::MetaVariableStillRepeating(name));
615+
buffer_lint(
616+
psess,
617+
span,
618+
node_id,
619+
errors::MetaVariableStillRepeating { name, label: binder.span },
620+
);
616621
return;
617622
}
618623
let occurrence = &occurrence_ops[i];
619624
if occurrence.op != binder.op {
620-
let mut span = MultiSpan::from_span(span);
621-
span.push_span_label(binder.span, "expected repetition");
622-
span.push_span_label(occurrence.span, "conflicting repetition");
623-
buffer_lint(psess, span, node_id, BuiltinLintDiag::MetaVariableWrongOperator);
625+
buffer_lint(
626+
psess,
627+
span,
628+
node_id,
629+
errors::MetaVariableWrongOperator {
630+
binder: binder.span,
631+
occurrence: occurrence.span,
632+
},
633+
);
624634
return;
625635
}
626636
}
627637
}
628638

629-
fn buffer_lint(psess: &ParseSess, span: MultiSpan, node_id: NodeId, diag: BuiltinLintDiag) {
639+
fn buffer_lint(
640+
psess: &ParseSess,
641+
span: Span,
642+
node_id: NodeId,
643+
diag: impl Into<DecorateDiagCompat>,
644+
) {
630645
// Macros loaded from other crates have dummy node ids.
631646
if node_id != DUMMY_NODE_ID {
632647
psess.buffer_lint(META_VARIABLE_MISUSE, span, node_id, diag);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /