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

[WIP] Move more early buffered lints to dyn lint diagnostics #145881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
fmease wants to merge 4 commits into rust-lang:master
base: master
Choose a base branch
Loading
from fmease:mv-var-to-dyn-buf-lints
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_ast_passes/messages.ftl
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ ast_passes_match_arm_with_no_body =
.suggestion = add a body after the pattern

ast_passes_missing_unsafe_on_extern = extern blocks must be unsafe
.suggestion = needs `unsafe` before the extern keyword

ast_passes_module_nonascii = trying to load file for module `{$name}` with non-ascii identifier name
.help = consider using the `#[path]` attribute to specify filesystem path
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/src/ast_validation.rs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
MISSING_UNSAFE_ON_EXTERN,
item.id,
item.span,
BuiltinLintDiag::MissingUnsafeOnExtern {
errors::MissingUnsafeOnExternLint {
suggestion: item.span.shrink_to_lo(),
},
);
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_ast_passes/src/errors.rs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,13 @@ pub(crate) struct MissingUnsafeOnExtern {
pub span: Span,
}

#[derive(LintDiagnostic)]
#[diag(ast_passes_missing_unsafe_on_extern)]
pub(crate) struct MissingUnsafeOnExternLint {
#[suggestion(code = "unsafe ", applicability = "machine-applicable")]
pub suggestion: Span,
}

#[derive(Diagnostic)]
#[diag(ast_passes_fieldless_union)]
pub(crate) struct FieldlessUnion {
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_builtin_macros/messages.ftl
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ builtin_macros_autodiff_ty_activity = {$act} can not be used for this type
builtin_macros_autodiff_unknown_activity = did not recognize Activity: `{$act}`

builtin_macros_autodiff_width = autodiff width must fit u32, but is {$width}

builtin_macros_avoid_att_syntax = avoid using `.att_syntax`, prefer using `options(att_syntax)` instead

builtin_macros_avoid_intel_syntax = avoid using `.intel_syntax`, Intel syntax is the default

builtin_macros_bad_derive_target = `derive` may only be applied to `struct`s, `enum`s and `union`s
.label = not applicable here
.label2 = not a `struct`, `enum` or `union`
Expand Down Expand Up @@ -138,6 +143,8 @@ builtin_macros_derive_path_args_list = traits in `#[derive(...)]` don't accept a
builtin_macros_derive_path_args_value = traits in `#[derive(...)]` don't accept values
.suggestion = remove the value

builtin_macros_duplicate_macro_attribute = duplicated attribute

builtin_macros_env_not_defined = environment variable `{$var}` not defined at compile time
.cargo = Cargo sets build script variables at run time. Use `std::env::var({$var_expr})` instead
.custom = use `std::env::var({$var_expr})` to read the variable at run time
Expand Down Expand Up @@ -231,6 +238,8 @@ builtin_macros_derive_from_wrong_field_count = `#[derive(From)]` used on a struc

builtin_macros_derive_from_usage_note = `#[derive(From)]` can only be used on structs with exactly one field

builtin_macros_incomplete_include = include macro expected single expression in source

builtin_macros_multiple_default_attrs = multiple `#[default]` attributes
.note = only one `#[default]` attribute is needed
.label = `#[default]` used here
Expand Down Expand Up @@ -294,3 +303,5 @@ builtin_macros_unexpected_lit = expected path to a trait, found literal
.label = not a trait
.str_lit = try using `#[derive({$sym})]`
.other = for example, write `#[derive(Debug)]` for `Debug`

builtin_macros_unnameable_test_items = cannot test inner items
5 changes: 2 additions & 3 deletions compiler/rustc_builtin_macros/src/asm.rs
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use lint::BuiltinLintDiag;
use rustc_ast::tokenstream::TokenStream;
use rustc_ast::{AsmMacro, token};
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
Expand Down Expand Up @@ -352,15 +351,15 @@ fn expand_preparsed_asm(
lint::builtin::BAD_ASM_STYLE,
find_span(".intel_syntax"),
ecx.current_expansion.lint_node_id,
BuiltinLintDiag::AvoidUsingIntelSyntax,
errors::AvoidIntelSyntax,
);
}
if template_str.contains(".att_syntax") {
ecx.psess().buffer_lint(
lint::builtin::BAD_ASM_STYLE,
find_span(".att_syntax"),
ecx.current_expansion.lint_node_id,
BuiltinLintDiag::AvoidUsingAttSyntax,
errors::AvoidAttSyntax,
);
}
}
Expand Down
22 changes: 21 additions & 1 deletion compiler/rustc_builtin_macros/src/errors.rs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,29 @@ use rustc_errors::{
Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, MultiSpan, SingleLabelManySpans,
Subdiagnostic,
};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_span::{Ident, Span, Symbol};

#[derive(LintDiagnostic)]
#[diag(builtin_macros_avoid_intel_syntax)]
pub(crate) struct AvoidIntelSyntax;

#[derive(LintDiagnostic)]
#[diag(builtin_macros_avoid_att_syntax)]
pub(crate) struct AvoidAttSyntax;

#[derive(LintDiagnostic)]
#[diag(builtin_macros_incomplete_include)]
pub(crate) struct IncompleteInclude;

#[derive(LintDiagnostic)]
#[diag(builtin_macros_unnameable_test_items)]
pub(crate) struct UnnameableTestItems;

#[derive(LintDiagnostic)]
#[diag(builtin_macros_duplicate_macro_attribute)]
pub(crate) struct DuplicateMacroAttribute;

#[derive(Diagnostic)]
#[diag(builtin_macros_requires_cfg_pattern)]
pub(crate) struct RequiresCfgPattern {
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_builtin_macros/src/source_util.rs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use rustc_expand::base::{
DummyResult, ExpandResult, ExtCtxt, MacEager, MacResult, MacroExpanderResult, resolve_path,
};
use rustc_expand::module::DirOwnership;
use rustc_lint_defs::BuiltinLintDiag;
use rustc_parse::parser::{ForceCollect, Parser};
use rustc_parse::{new_parser_from_file, unwrap_or_emit_fatal, utf8_error};
use rustc_session::lint::builtin::INCOMPLETE_INCLUDE;
Expand Down Expand Up @@ -150,7 +149,7 @@ pub(crate) fn expand_include<'cx>(
INCOMPLETE_INCLUDE,
self.p.token.span,
self.node_id,
BuiltinLintDiag::IncompleteInclude,
errors::IncompleteInclude,
);
}
Some(expr)
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_builtin_macros/src/test_harness.rs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use rustc_errors::DiagCtxtHandle;
use rustc_expand::base::{ExtCtxt, ResolverExpand};
use rustc_expand::expand::{AstFragment, ExpansionConfig};
use rustc_feature::Features;
use rustc_lint_defs::BuiltinLintDiag;
use rustc_session::Session;
use rustc_session::lint::builtin::UNNAMEABLE_TEST_ITEMS;
use rustc_span::hygiene::{AstPass, SyntaxContext, Transparency};
Expand Down Expand Up @@ -165,7 +164,7 @@ impl<'a> Visitor<'a> for InnerItemLinter<'_> {
UNNAMEABLE_TEST_ITEMS,
attr.span,
i.id,
BuiltinLintDiag::UnnameableTestItems,
errors::UnnameableTestItems,
);
}
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_builtin_macros/src/util.rs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use rustc_errors::{Applicability, Diag, ErrorGuaranteed};
use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt};
use rustc_expand::expand::AstFragment;
use rustc_feature::AttributeTemplate;
use rustc_lint_defs::BuiltinLintDiag;
use rustc_lint_defs::builtin::DUPLICATE_MACRO_ATTRIBUTES;
use rustc_parse::{exp, parser};
use rustc_session::errors::report_lit_error;
Expand Down Expand Up @@ -49,7 +48,7 @@ pub(crate) fn warn_on_duplicate_attribute(ecx: &ExtCtxt<'_>, item: &Annotatable,
DUPLICATE_MACRO_ATTRIBUTES,
attr.span,
ecx.current_expansion.lint_node_id,
BuiltinLintDiag::DuplicateMacroAttribute,
errors::DuplicateMacroAttribute,
);
}
}
Expand Down
15 changes: 15 additions & 0 deletions compiler/rustc_expand/messages.ftl
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ expand_attributes_on_expressions_experimental =
.help_outer_doc = `///` is used for outer documentation comments; for a plain comment, use `//`
.help_inner_doc = `//!` is used for inner documentation comments; for a plain comment, use `//` by removing the `!` or inserting a space in between them: `// !`

expand_cfg_attr_no_attributes = `#[cfg_attr]` does not expand to any attributes

expand_collapse_debuginfo_illegal =
illegal value for attribute #[collapse_debuginfo(no|external|yes)]

Expand Down Expand Up @@ -78,6 +80,10 @@ expand_macro_body_stability =
.label = invalid body stability attribute
.label2 = body stability attribute affects this macro

expand_macro_call_unused_doc_comment = unused doc comment
.label = rustdoc does not generate documentation for macro invocations
.help = to document an item produced by a macro, the macro must produce the documentation as part of its expansion

expand_macro_const_stability =
macros cannot have const stability attributes
.label = invalid const stability attribute
Expand All @@ -89,6 +95,13 @@ expand_malformed_feature_attribute =
malformed `feature` attribute input
.expected = expected just one word

expand_metavariable_still_repeating = variable `{$name}` is still repeating at this depth
.label = expected repetition

expand_metavariable_wrong_operator = meta-variable repeats with different Kleene operator
.binder_label = expected repetition
.occurrence_label = conflicting repetition

expand_meta_var_dif_seq_matchers = {$msg}

expand_missing_fragment_specifier = missing fragment specifier
Expand Down Expand Up @@ -176,6 +189,8 @@ expand_resolve_relative_path =

expand_trace_macro = trace_macro

expand_unknown_macro_variable = unknown macro variable `{$name}`

expand_unsupported_key_value =
key-value macro attributes are not supported

Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_expand/src/config.rs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use rustc_feature::{
ACCEPTED_LANG_FEATURES, AttributeSafety, EnabledLangFeature, EnabledLibFeature, Features,
REMOVED_LANG_FEATURES, UNSTABLE_LANG_FEATURES,
};
use rustc_lint_defs::BuiltinLintDiag;
use rustc_session::Session;
use rustc_session::parse::feature_err;
use rustc_span::{STDLIB_STABLE_CRATES, Span, Symbol, sym};
Expand Down Expand Up @@ -315,7 +314,7 @@ impl<'a> StripUnconfigured<'a> {
rustc_lint_defs::builtin::UNUSED_ATTRIBUTES,
cfg_attr.span,
ast::CRATE_NODE_ID,
BuiltinLintDiag::CfgAttrNoAttributes,
crate::errors::CfgAttrNoAttributes,
);
}

Expand Down
48 changes: 47 additions & 1 deletion compiler/rustc_expand/src/errors.rs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ use std::borrow::Cow;

use rustc_ast::ast;
use rustc_errors::codes::*;
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_session::Limit;
use rustc_span::{Ident, MacroRulesNormalizedIdent, Span, Symbol};

#[derive(LintDiagnostic)]
#[diag(expand_cfg_attr_no_attributes)]
pub(crate) struct CfgAttrNoAttributes;

#[derive(Diagnostic)]
#[diag(expand_expr_repeat_no_syntax_vars)]
pub(crate) struct NoSyntaxVarsExprRepeat {
Expand All @@ -27,6 +31,8 @@ pub(crate) struct CountRepetitionMisplaced {
pub span: Span,
}

// FIXME(fmease): "Combine"/assimilate VarStillRepeating and MetaVariableStillRepeating

#[derive(Diagnostic)]
#[diag(expand_var_still_repeating)]
pub(crate) struct VarStillRepeating {
Expand All @@ -35,6 +41,23 @@ pub(crate) struct VarStillRepeating {
pub ident: MacroRulesNormalizedIdent,
}

#[derive(LintDiagnostic)]
#[diag(expand_metavariable_still_repeating)]
pub(crate) struct MetaVariableStillRepeating {
pub name: MacroRulesNormalizedIdent,
#[label]
pub label: Span,
}

#[derive(LintDiagnostic)]
#[diag(expand_metavariable_wrong_operator)]
pub(crate) struct MetaVariableWrongOperator {
#[label(expand_binder_label)]
pub binder: Span,
#[label(expand_occurrence_label)]
pub occurrence: Span,
}

#[derive(Diagnostic)]
#[diag(expand_meta_var_dif_seq_matchers)]
pub(crate) struct MetaVarsDifSeqMatchers {
Expand All @@ -43,6 +66,12 @@ pub(crate) struct MetaVarsDifSeqMatchers {
pub msg: String,
}

#[derive(LintDiagnostic)]
#[diag(expand_unknown_macro_variable)]
pub(crate) struct UnknownMacroVariable {
pub name: MacroRulesNormalizedIdent,
}

#[derive(Diagnostic)]
#[diag(expand_resolve_relative_path)]
pub(crate) struct ResolveRelativePath {
Expand Down Expand Up @@ -345,6 +374,15 @@ pub(crate) struct DuplicateMatcherBinding {
pub prev: Span,
}

#[derive(LintDiagnostic)]
#[diag(expand_duplicate_matcher_binding)]
pub(crate) struct DuplicateMatcherBindingLint {
#[label]
pub span: Span,
#[label(expand_label2)]
pub prev: Span,
}

#[derive(Diagnostic)]
#[diag(expand_missing_fragment_specifier)]
#[note]
Expand Down Expand Up @@ -501,3 +539,11 @@ pub(crate) struct MacroArgsBadDelimSugg {
#[suggestion_part(code = ")")]
pub close: Span,
}

#[derive(LintDiagnostic)]
#[diag(expand_macro_call_unused_doc_comment)]
#[help]
pub(crate) struct MacroCallUnusedDocComment {
#[label]
pub span: Span,
}
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/expand.rs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2182,7 +2182,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
UNUSED_DOC_COMMENTS,
current_span,
self.cx.current_expansion.lint_node_id,
BuiltinLintDiag::UnusedDocComment(attr.span),
crate::errors::MacroCallUnusedDocComment { span: attr.span },
);
} else if rustc_attr_parsing::is_builtin_attr(attr)
&& !AttributeParser::<Early>::is_parsed_attribute(&attr.path())
Expand Down
Loading
Loading

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