Auto merge of #145881 - fmease:mv-var-to-dyn-buf-lints, r=joshtriplett

Move more early buffered lints to dyn lint diagnostics

Follow-up to rust-lang/rust#145747.

Presently, it's unclear to me if it's possible to migrate all variants to dyn lint diagnostics without regressing performance because for some early lints `decorate_builtin_lint` performs a bit more work (past PR rust-lang/rust#124417 has shown that eagerly decorating early lints is incredibly heavy and we had to revert back to lazily decorating in rust-lang/rust#125410). Let's see how this fares once I tackle the more 'risky' variants.

cc `@joshtriplett` (you can immediately unsubscribe again, I just want to prevent duplicate efforts).
This commit is contained in:
bors 2025-09-14 10:40:39 +00:00
commit 52618eb338
32 changed files with 305 additions and 434 deletions

View file

@ -216,6 +216,10 @@ 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_missing_unsafe_on_extern_lint = extern blocks should 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

View file

@ -1131,7 +1131,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(),
},
);

View file

@ -523,6 +523,13 @@ pub(crate) struct MissingUnsafeOnExtern {
pub span: Span,
}
#[derive(LintDiagnostic)]
#[diag(ast_passes_missing_unsafe_on_extern_lint)]
pub(crate) struct MissingUnsafeOnExternLint {
#[suggestion(code = "unsafe ", applicability = "machine-applicable")]
pub suggestion: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_fieldless_union)]
pub(crate) struct FieldlessUnion {

View file

@ -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`
@ -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
@ -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
@ -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

View file

@ -1,4 +1,3 @@
use lint::BuiltinLintDiag;
use rustc_ast::tokenstream::TokenStream;
use rustc_ast::{AsmMacro, token};
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
@ -352,7 +351,7 @@ 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") {
@ -360,7 +359,7 @@ fn expand_preparsed_asm(
lint::builtin::BAD_ASM_STYLE,
find_span(".att_syntax"),
ecx.current_expansion.lint_node_id,
BuiltinLintDiag::AvoidUsingAttSyntax,
errors::AvoidAttSyntax,
);
}
}

View file

@ -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 {

View file

@ -12,7 +12,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::lexer::StripTokens;
use rustc_parse::parser::ForceCollect;
use rustc_parse::{new_parser_from_file, unwrap_or_emit_fatal, utf8_error};
@ -159,7 +158,7 @@ pub(crate) fn expand_include<'cx>(
INCOMPLETE_INCLUDE,
p.token.span,
self.node_id,
BuiltinLintDiag::IncompleteInclude,
errors::IncompleteInclude,
);
}
Some(expr)

View file

@ -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};
@ -165,7 +164,7 @@ impl<'a> Visitor<'a> for InnerItemLinter<'_> {
UNNAMEABLE_TEST_ITEMS,
attr.span,
i.id,
BuiltinLintDiag::UnnameableTestItems,
errors::UnnameableTestItems,
);
}
}

View file

@ -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;
@ -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,
);
}
}

View file

@ -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)]
@ -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
@ -89,6 +95,13 @@ expand_malformed_feature_attribute =
malformed `feature` attribute input
.expected = expected just one word
expand_metavar_still_repeating = variable `{$ident}` 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
@ -147,6 +160,9 @@ expand_mve_unrecognized_var =
expand_non_inline_modules_in_proc_macro_input_are_unstable =
non-inline modules in proc macro input are unstable
expand_or_patterns_back_compat = the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro
.suggestion = use pat_param to preserve semantics
expand_proc_macro_back_compat = using an old version of `{$crate_name}`
.note = older versions of the `{$crate_name}` crate no longer compile; please update to `{$crate_name}` v{$fixed_version}, or switch to one of the `{$crate_name}` alternatives
@ -176,11 +192,18 @@ expand_resolve_relative_path =
expand_trace_macro = trace_macro
expand_trailing_semi_macro = trailing semicolon in macro used in expression position
.note1 = macro invocations at the end of a block are treated as expressions
.note2 = to ignore the value produced by the macro, add a semicolon after the invocation of `{$name}`
expand_unknown_macro_variable = unknown macro variable `{$name}`
expand_unused_builtin_attribute = unused attribute `{$attr_name}`
.note = the built-in attribute `{$attr_name}` will be ignored, since it's applied to the macro invocation `{$macro_name}`
.suggestion = remove the attribute
expand_unsupported_key_value =
key-value macro attributes are not supported
expand_var_still_repeating =
variable `{$ident}` is still repeating at this depth
expand_wrong_fragment_kind =
non-{$kind} macro in {$kind} position: {$name}

View file

@ -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};
@ -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,
);
}

View file

@ -3,9 +3,13 @@ use std::borrow::Cow;
use rustc_ast::ast;
use rustc_errors::codes::*;
use rustc_hir::limit::Limit;
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
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 {
@ -28,13 +32,30 @@ pub(crate) struct CountRepetitionMisplaced {
}
#[derive(Diagnostic)]
#[diag(expand_var_still_repeating)]
pub(crate) struct VarStillRepeating {
#[diag(expand_metavar_still_repeating)]
pub(crate) struct MacroVarStillRepeating {
#[primary_span]
pub span: Span,
pub ident: MacroRulesNormalizedIdent,
}
#[derive(LintDiagnostic)]
#[diag(expand_metavar_still_repeating)]
pub(crate) struct MetaVarStillRepeatingLint {
#[label]
pub label: Span,
pub ident: MacroRulesNormalizedIdent,
}
#[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 {
@ -43,6 +64,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 {
@ -345,6 +372,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]
@ -501,3 +537,39 @@ 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,
}
#[derive(LintDiagnostic)]
#[diag(expand_or_patterns_back_compat)]
pub(crate) struct OrPatternsBackCompat {
#[suggestion(code = "{suggestion}", applicability = "machine-applicable")]
pub span: Span,
pub suggestion: String,
}
#[derive(LintDiagnostic)]
#[diag(expand_trailing_semi_macro)]
pub(crate) struct TrailingMacro {
#[note(expand_note1)]
#[note(expand_note2)]
pub is_trailing: bool,
pub name: Ident,
}
#[derive(LintDiagnostic)]
#[diag(expand_unused_builtin_attribute)]
pub(crate) struct UnusedBuiltinAttribute {
#[note]
pub invoc_span: Span,
pub attr_name: Symbol,
pub macro_name: String,
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
pub attr_span: Span,
}

View file

@ -25,7 +25,6 @@ use rustc_parse::parser::{
token_descr,
};
use rustc_session::Session;
use rustc_session::lint::BuiltinLintDiag;
use rustc_session::lint::builtin::{UNUSED_ATTRIBUTES, UNUSED_DOC_COMMENTS};
use rustc_session::parse::feature_err;
use rustc_span::hygiene::SyntaxContext;
@ -2183,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())
@ -2196,7 +2195,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
UNUSED_ATTRIBUTES,
attr.span,
self.cx.current_expansion.lint_node_id,
BuiltinLintDiag::UnusedBuiltinAttribute {
crate::errors::UnusedBuiltinAttribute {
attr_name,
macro_name: pprust::path_to_string(&call.path),
invoc_span: call.path.span,

View file

@ -108,8 +108,7 @@
use rustc_ast::token::{Delimiter, IdentIsRaw, Token, TokenKind};
use rustc_ast::{DUMMY_NODE_ID, NodeId};
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::MultiSpan;
use rustc_lint_defs::BuiltinLintDiag;
use rustc_errors::DecorateDiagCompat;
use rustc_session::lint::builtin::META_VARIABLE_MISUSE;
use rustc_session::parse::ParseSess;
use rustc_span::{ErrorGuaranteed, MacroRulesNormalizedIdent, Span, kw};
@ -245,9 +244,12 @@ fn check_binders(
// There are 3 possibilities:
if let Some(prev_info) = binders.get(&name) {
// 1. The meta-variable is already bound in the current LHS: This is an error.
let mut span = MultiSpan::from_span(span);
span.push_span_label(prev_info.span, "previous declaration");
buffer_lint(psess, span, node_id, BuiltinLintDiag::DuplicateMatcherBinding);
buffer_lint(
psess,
span,
node_id,
errors::DuplicateMatcherBindingLint { span, prev: prev_info.span },
);
} else if get_binder_info(macros, binders, name).is_none() {
// 2. The meta-variable is free: This is a binder.
binders.insert(name, BinderInfo { span, ops: ops.into() });
@ -579,7 +581,7 @@ fn check_ops_is_prefix(
return;
}
}
buffer_lint(psess, span.into(), node_id, BuiltinLintDiag::UnknownMacroVariable(name));
buffer_lint(psess, span, node_id, errors::UnknownMacroVariable { name });
}
/// Returns whether `binder_ops` is a prefix of `occurrence_ops`.
@ -604,29 +606,42 @@ fn ops_is_prefix(
psess: &ParseSess,
node_id: NodeId,
span: Span,
name: MacroRulesNormalizedIdent,
ident: MacroRulesNormalizedIdent,
binder_ops: &[KleeneToken],
occurrence_ops: &[KleeneToken],
) {
for (i, binder) in binder_ops.iter().enumerate() {
if i >= occurrence_ops.len() {
let mut span = MultiSpan::from_span(span);
span.push_span_label(binder.span, "expected repetition");
buffer_lint(psess, span, node_id, BuiltinLintDiag::MetaVariableStillRepeating(name));
buffer_lint(
psess,
span,
node_id,
errors::MetaVarStillRepeatingLint { label: binder.span, ident },
);
return;
}
let occurrence = &occurrence_ops[i];
if occurrence.op != binder.op {
let mut span = MultiSpan::from_span(span);
span.push_span_label(binder.span, "expected repetition");
span.push_span_label(occurrence.span, "conflicting repetition");
buffer_lint(psess, span, node_id, BuiltinLintDiag::MetaVariableWrongOperator);
buffer_lint(
psess,
span,
node_id,
errors::MetaVariableWrongOperator {
binder: binder.span,
occurrence: occurrence.span,
},
);
return;
}
}
}
fn buffer_lint(psess: &ParseSess, span: MultiSpan, node_id: NodeId, diag: BuiltinLintDiag) {
fn buffer_lint(
psess: &ParseSess,
span: Span,
node_id: NodeId,
diag: impl Into<DecorateDiagCompat>,
) {
// Macros loaded from other crates have dummy node ids.
if node_id != DUMMY_NODE_ID {
psess.buffer_lint(META_VARIABLE_MISUSE, span, node_id, diag);

View file

@ -17,7 +17,6 @@ use rustc_hir as hir;
use rustc_hir::attrs::AttributeKind;
use rustc_hir::def::MacroKinds;
use rustc_hir::find_attr;
use rustc_lint_defs::BuiltinLintDiag;
use rustc_lint_defs::builtin::{
RUST_2021_INCOMPATIBLE_OR_PATTERNS, SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
};
@ -90,7 +89,7 @@ impl<'a> ParserAnyMacro<'a> {
SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
parser.token.span,
lint_node_id,
BuiltinLintDiag::TrailingMacro(is_trailing_mac, macro_ident),
errors::TrailingMacro { is_trailing: is_trailing_mac, name: macro_ident },
);
}
parser.bump();
@ -1425,7 +1424,7 @@ fn check_matcher_core<'tt>(
RUST_2021_INCOMPATIBLE_OR_PATTERNS,
span,
ast::CRATE_NODE_ID,
BuiltinLintDiag::OrPatternsBackCompat(span, suggestion),
errors::OrPatternsBackCompat { span, suggestion },
);
}
match is_in_follow(next_token, kind) {

View file

@ -17,8 +17,8 @@ use rustc_span::{
use smallvec::{SmallVec, smallvec};
use crate::errors::{
CountRepetitionMisplaced, MetaVarsDifSeqMatchers, MustRepeatOnce, MveUnrecognizedVar,
NoSyntaxVarsExprRepeat, VarStillRepeating,
CountRepetitionMisplaced, MacroVarStillRepeating, MetaVarsDifSeqMatchers, MustRepeatOnce,
MveUnrecognizedVar, NoSyntaxVarsExprRepeat,
};
use crate::mbe::macro_parser::NamedMatch;
use crate::mbe::macro_parser::NamedMatch::*;
@ -483,7 +483,7 @@ fn transcribe_metavar<'tx>(
}
MatchedSeq(..) => {
// We were unable to descend far enough. This is an error.
return Err(dcx.create_err(VarStillRepeating { span: sp, ident }));
return Err(dcx.create_err(MacroVarStillRepeating { span: sp, ident }));
}
};

View file

@ -30,6 +30,9 @@ interface_ignoring_out_dir = ignoring --out-dir flag due to -o flag
interface_input_file_would_be_overwritten =
the input file "{$path}" would be overwritten by the generated executable
interface_invalid_crate_type_value = invalid `crate_type` value
.suggestion = did you mean
interface_mixed_bin_crate =
cannot mix `bin` crate type with others

View file

@ -1,7 +1,7 @@
use std::io;
use std::path::Path;
use rustc_macros::Diagnostic;
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_span::{Span, Symbol};
#[derive(Diagnostic)]
@ -108,3 +108,18 @@ pub(crate) struct AbiRequiredTargetFeature<'a> {
pub feature: &'a str,
pub enabled: &'a str,
}
#[derive(LintDiagnostic)]
#[diag(interface_invalid_crate_type_value)]
pub(crate) struct UnknownCrateTypes {
#[subdiagnostic]
pub sugg: Option<UnknownCrateTypesSub>,
}
#[derive(Subdiagnostic)]
#[suggestion(interface_suggestion, code = r#""{snippet}""#, applicability = "maybe-incorrect")]
pub(crate) struct UnknownCrateTypesSub {
#[primary_span]
pub span: Span,
pub snippet: Symbol,
}

View file

@ -13,9 +13,8 @@ use rustc_errors::LintBuffer;
use rustc_metadata::{DylibError, load_symbol_from_dylib};
use rustc_middle::ty::CurrentGcx;
use rustc_session::config::{Cfg, OutFileName, OutputFilenames, OutputTypes, Sysroot, host_tuple};
use rustc_session::lint::{self, BuiltinLintDiag};
use rustc_session::output::{CRATE_TYPES, categorize_crate_type};
use rustc_session::{EarlyDiagCtxt, Session, filesearch};
use rustc_session::{EarlyDiagCtxt, Session, filesearch, lint};
use rustc_span::edit_distance::find_best_match_for_name;
use rustc_span::edition::Edition;
use rustc_span::source_map::SourceMapInputs;
@ -468,7 +467,10 @@ pub(crate) fn check_attr_crate_type(
lint::builtin::UNKNOWN_CRATE_TYPES,
ast::CRATE_NODE_ID,
span,
BuiltinLintDiag::UnknownCrateTypes { span, candidate },
errors::UnknownCrateTypes {
sugg: candidate
.map(|cand| errors::UnknownCrateTypesSub { span, snippet: cand }),
},
);
}
} else {

View file

@ -40,12 +40,6 @@ lint_atomic_ordering_load = atomic loads cannot have `Release` or `AcqRel` order
lint_atomic_ordering_store = atomic stores cannot have `Acquire` or `AcqRel` ordering
.help = consider using ordering modes `Release`, `SeqCst` or `Relaxed`
lint_avoid_att_syntax =
avoid using `.att_syntax`, prefer using `options(att_syntax)` instead
lint_avoid_intel_syntax =
avoid using `.intel_syntax`, Intel syntax is the default
lint_bad_attribute_argument = bad attribute argument
lint_bad_opt_access = {$msg}
@ -187,12 +181,6 @@ lint_builtin_unused_doc_comment = unused doc comment
lint_builtin_while_true = denote infinite loops with `loop {"{"} ... {"}"}`
.suggestion = use `loop`
lint_byte_slice_in_packed_struct_with_derive = {$ty} slice in a packed struct that derives a built-in trait
.help = consider implementing the trait by hand, or remove the `packed` attribute
lint_cfg_attr_no_attributes =
`#[cfg_attr]` does not expand to any attributes
lint_check_name_unknown_tool = unknown lint tool: `{$tool_name}`
lint_closure_returning_async_block = closure returning async block can be made into an async closure
@ -249,11 +237,6 @@ lint_dropping_copy_types = calls to `std::mem::drop` with a value that implement
lint_dropping_references = calls to `std::mem::drop` with a reference instead of an owned value does nothing
.label = argument has type `{$arg_ty}`
lint_duplicate_macro_attribute =
duplicated attribute
lint_duplicate_matcher_binding = duplicate matcher binding
lint_enum_intrinsics_mem_discriminant =
the return value of `mem::discriminant` is unspecified when called with a non-enum type
.note = the argument to `discriminant` should be a reference to an enum, but it was passed a reference to a `{$ty_param}`, which is not an enum
@ -409,9 +392,6 @@ lint_improper_ctypes_union_layout_help = consider adding a `#[repr(C)]` or `#[re
lint_improper_ctypes_union_layout_reason = this union has unspecified layout
lint_improper_ctypes_union_non_exhaustive = this union is non-exhaustive
lint_incomplete_include =
include macro expected single expression in source
lint_invalid_asm_label_binary = avoid using labels containing only the digits `0` and `1` in inline assembly
.label = use a different label that doesn't start with `0` or `1`
.help = start numbering with `2` instead
@ -427,9 +407,6 @@ lint_invalid_asm_label_named = avoid using named labels in inline assembly
.note = see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information
lint_invalid_asm_label_no_span = the label may be declared in the expansion of a macro
lint_invalid_crate_type_value = invalid `crate_type` value
.suggestion = did you mean
# FIXME: we should ordinalize $valid_up_to when we add support for doing so
lint_invalid_from_utf8_checked = calls to `{$method}` with an invalid literal always return an error
.label = the literal was valid UTF-8 up to the {$valid_up_to} bytes
@ -470,15 +447,9 @@ lint_int_to_ptr_transmutes = transmuting an integer to a pointer creates a point
.suggestion_with_exposed_provenance = use `std::ptr::with_exposed_provenance{$suffix}` instead to use a previously exposed provenance
.suggestion_without_provenance_mut = if you truly mean to create a pointer without provenance, use `std::ptr::without_provenance_mut`
lint_legacy_derive_helpers = derive helper attribute is used before it is introduced
.label = the attribute is introduced here
lint_lintpass_by_hand = implementing `LintPass` by hand
.help = try using `declare_lint_pass!` or `impl_lint_pass!` instead
lint_macro_expanded_macro_exports_accessed_by_absolute_paths = macro-expanded `macro_export` macros from the current crate cannot be referred to by absolute paths
.note = the macro is defined here
lint_macro_expr_fragment_specifier_2024_migration =
the `expr` fragment specifier will accept more expressions in the 2024 edition
.suggestion = to keep the existing behavior, use the `expr_2021` fragment specifier
@ -486,10 +457,6 @@ lint_macro_is_private = macro `{$ident}` is private
lint_macro_rule_never_used = rule #{$n} of macro `{$name}` is never used
lint_macro_use_deprecated =
applying the `#[macro_use]` attribute to an `extern crate` item is deprecated
.help = remove it and import macros at use sites with a `use` item instead
lint_malformed_attribute = malformed lint attribute input
lint_map_unit_fn = `Iterator::map` call that discard the iterator's values
@ -499,10 +466,6 @@ lint_map_unit_fn = `Iterator::map` call that discard the iterator's values
.map_label = after this call to map, the resulting iterator is `impl Iterator<Item = ()>`, which means the only information carried by the iterator is the number of items
.suggestion = you might have meant to use `Iterator::for_each`
lint_metavariable_still_repeating = variable `{$name}` is still repeating at this depth
lint_metavariable_wrong_operator = meta-variable repeats with different Kleene operator
lint_mismatched_lifetime_syntaxes_eliding_while_named =
eliding a lifetime that's named elsewhere is confusing
@ -548,9 +511,6 @@ lint_mismatched_lifetime_syntaxes_suggestion_mixed =
lint_mismatched_lifetime_syntaxes_suggestion_mixed_only_paths =
use `'_` for type paths
lint_missing_unsafe_on_extern = extern blocks should be unsafe
.suggestion = needs `unsafe` before the extern keyword
lint_mixed_script_confusables =
the usage of Script Group `{$set}` in this crate consists solely of mixed script confusables
.includes_note = the usage includes {$includes}
@ -674,9 +634,6 @@ lint_opaque_hidden_inferred_bound = opaque type `{$ty}` does not satisfy its ass
lint_opaque_hidden_inferred_bound_sugg = add this bound
lint_or_patterns_back_compat = the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro
.suggestion = use pat_param to preserve semantics
lint_out_of_scope_macro_calls = cannot find macro `{$path}` in the current scope when looking from {$location}
.label = not found from {$location}
.help = import `macro_rules` with `use` to make it callable above its definition
@ -719,9 +676,6 @@ lint_pattern_in_foreign = patterns aren't allowed in foreign function declaratio
lint_private_extern_crate_reexport = extern crate `{$ident}` is private and cannot be re-exported
.suggestion = consider making the `extern crate` item publicly accessible
lint_proc_macro_derive_resolution_fallback = cannot find {$ns_descr} `{$ident}` in this scope
.label = names from parent modules are not accessible without an explicit import
lint_query_instability = using `{$query}` can result in unstable query results
.note = if you believe this case to be fine, allow this lint and add a comment explaining your rationale
@ -762,9 +716,6 @@ lint_redundant_semicolons_suggestion = remove {$multiple_semicolons ->
*[false] this semicolon
}
lint_reexport_private_dependency =
{$kind} `{$name}` from private dependency '{$krate}' is re-exported
lint_remove_mut_from_pattern = remove `mut` from the parameter
lint_removed_lint = lint `{$name}` has been removed: {$reason}
@ -826,10 +777,6 @@ lint_symbol_intern_string_literal = using `Symbol::intern` on a string literal
lint_too_large_char_cast = value exceeds maximum `char` value
.note = maximum valid `char` value is `0x10FFFF`
lint_trailing_semi_macro = trailing semicolon in macro used in expression position
.note1 = macro invocations at the end of a block are treated as expressions
.note2 = to ignore the value produced by the macro, add a semicolon after the invocation of `{$name}`
lint_ty_qualified = usage of qualified `ty::{$ty}`
.suggestion = try importing it and using it unqualified
@ -935,13 +882,9 @@ lint_unknown_lint =
*[false] did you mean: `{$replace}`
}
lint_unknown_macro_variable = unknown macro variable `{$name}`
lint_unknown_tool_in_scoped_lint = unknown tool name `{$tool_name}` found in scoped lint: `{$tool_name}::{$lint_name}`
.help = add `#![register_tool({$tool_name})]` to the crate root
lint_unnameable_test_items = cannot test inner items
lint_unnecessary_qualification = unnecessary qualification
.suggestion = remove the unnecessary path segments
@ -964,10 +907,6 @@ lint_untranslatable_diag = diagnostics should be created using translatable mess
lint_unused_allocation = unnecessary allocation, use `&` instead
lint_unused_allocation_mut = unnecessary allocation, use `&mut` instead
lint_unused_builtin_attribute = unused attribute `{$attr_name}`
.note = the built-in attribute `{$attr_name}` will be ignored, since it's applied to the macro invocation `{$macro_name}`
.suggestion = remove the attribute
lint_unused_closure =
unused {$pre}{$count ->
[one] closure
@ -993,14 +932,6 @@ lint_unused_def = unused {$pre}`{$def}`{$post} that must be used
lint_unused_delim = unnecessary {$delim} around {$item}
.suggestion = remove these {$delim}
lint_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
lint_unused_extern_crate = unused extern crate
.label = unused
.suggestion = remove the unused `extern crate`
lint_unused_import_braces = braces around {$node} is unnecessary
lint_unused_imports = {$num_snippets ->
@ -1014,15 +945,11 @@ lint_unused_imports = {$num_snippets ->
}
.help = if this is a test module, consider adding a `#[cfg(test)]` to the containing module
lint_unused_label = unused label
lint_unused_lifetime = lifetime parameter `{$ident}` never used
.suggestion = elide the unused lifetime
lint_unused_macro_definition = unused macro definition: `{$name}`
lint_unused_macro_use = unused `#[macro_use]` import
lint_unused_op = unused {$op} that must be used
.label = the {$op} produces a value
.suggestion = use `let _ = ...` to ignore the resulting value

View file

@ -64,17 +64,6 @@ pub fn decorate_builtin_lint(
}
.decorate_lint(diag);
}
BuiltinLintDiag::ProcMacroDeriveResolutionFallback {
span: macro_span,
ns_descr,
ident,
} => lints::ProcMacroDeriveResolutionFallback { span: macro_span, ns_descr, ident }
.decorate_lint(diag),
BuiltinLintDiag::MacroExpandedMacroExportsAccessedByAbsolutePaths(span_def) => {
lints::MacroExpandedMacroExportsAccessedByAbsolutePaths { definition: span_def }
.decorate_lint(diag)
}
BuiltinLintDiag::ElidedLifetimesInPaths(n, path_span, incl_angl_brckt, insertion_span) => {
lints::ElidedLifetimesInPaths {
subdiag: elided_lifetime_in_path_suggestion(
@ -87,10 +76,6 @@ pub fn decorate_builtin_lint(
}
.decorate_lint(diag);
}
BuiltinLintDiag::UnknownCrateTypes { span, candidate } => {
let sugg = candidate.map(|candidate| lints::UnknownCrateTypesSub { span, candidate });
lints::UnknownCrateTypes { sugg }.decorate_lint(diag);
}
BuiltinLintDiag::UnusedImports {
remove_whole_use,
num_to_remove,
@ -146,9 +131,6 @@ pub fn decorate_builtin_lint(
stability::Deprecated { sub, kind: "macro".to_owned(), path, note, since_kind }
.decorate_lint(diag);
}
BuiltinLintDiag::UnusedDocComment(attr_span) => {
lints::UnusedDocComment { span: attr_span }.decorate_lint(diag);
}
BuiltinLintDiag::PatternsInFnsWithoutBody { span: remove_span, ident, is_foreign } => {
let sub = lints::PatternsInFnsWithoutBodySub { ident, span: remove_span };
if is_foreign {
@ -158,12 +140,6 @@ pub fn decorate_builtin_lint(
}
.decorate_lint(diag);
}
BuiltinLintDiag::LegacyDeriveHelpers(label_span) => {
lints::LegacyDeriveHelpers { span: label_span }.decorate_lint(diag);
}
BuiltinLintDiag::OrPatternsBackCompat(suggestion_span, suggestion) => {
lints::OrPatternsBackCompat { span: suggestion_span, suggestion }.decorate_lint(diag);
}
BuiltinLintDiag::ReservedPrefix(label_span, prefix) => {
lints::ReservedPrefix {
label: label_span,
@ -183,18 +159,6 @@ pub fn decorate_builtin_lint(
lints::ReservedMultihash { suggestion }.decorate_lint(diag);
}
}
BuiltinLintDiag::UnusedBuiltinAttribute {
attr_name,
macro_name,
invoc_span,
attr_span,
} => {
lints::UnusedBuiltinAttribute { invoc_span, attr_name, macro_name, attr_span }
.decorate_lint(diag);
}
BuiltinLintDiag::TrailingMacro(is_trailing, name) => {
lints::TrailingMacro { is_trailing, name }.decorate_lint(diag);
}
BuiltinLintDiag::BreakWithLabelAndLoop(sugg_span) => {
lints::BreakWithLabelAndLoop {
sub: lints::BreakWithLabelAndLoopSub {
@ -221,9 +185,6 @@ pub fn decorate_builtin_lint(
};
lints::DeprecatedWhereClauseLocation { suggestion }.decorate_lint(diag);
}
BuiltinLintDiag::MissingUnsafeOnExtern { suggestion } => {
lints::MissingUnsafeOnExtern { suggestion }.decorate_lint(diag);
}
BuiltinLintDiag::SingleUseLifetime {
param_span,
use_span: Some((use_span, elide)),
@ -253,7 +214,6 @@ pub fn decorate_builtin_lint(
.decorate_lint(diag);
}
BuiltinLintDiag::SingleUseLifetime { use_span: None, deletion_span, ident, .. } => {
debug!(?deletion_span);
lints::UnusedLifetime { deletion_span, ident }.decorate_lint(diag);
}
BuiltinLintDiag::NamedArgumentUsedPositionally {
@ -291,12 +251,6 @@ pub fn decorate_builtin_lint(
}
.decorate_lint(diag);
}
BuiltinLintDiag::ByteSliceInPackedStructWithDerive { ty } => {
lints::ByteSliceInPackedStructWithDerive { ty }.decorate_lint(diag);
}
BuiltinLintDiag::UnusedExternCrate { span, removal_span } => {
lints::UnusedExternCrate { span, removal_span }.decorate_lint(diag);
}
BuiltinLintDiag::ExternCrateNotIdiomatic { vis_span, ident_span } => {
let suggestion_span = vis_span.between(ident_span);
let code = if vis_span.is_empty() { "use " } else { " use " };
@ -335,9 +289,6 @@ pub fn decorate_builtin_lint(
}
.decorate_lint(diag);
}
BuiltinLintDiag::ReexportPrivateDependency { name, kind, krate } => {
lints::ReexportPrivateDependency { name, kind, krate }.decorate_lint(diag);
}
BuiltinLintDiag::UnusedQualifications { removal_span } => {
lints::UnusedQualifications { removal_span }.decorate_lint(diag);
}
@ -377,15 +328,10 @@ pub fn decorate_builtin_lint(
});
lints::UnknownDiagnosticAttribute { typo }.decorate_lint(diag);
}
BuiltinLintDiag::MacroUseDeprecated => {
lints::MacroUseDeprecated.decorate_lint(diag);
}
BuiltinLintDiag::UnusedMacroUse => lints::UnusedMacroUse.decorate_lint(diag),
BuiltinLintDiag::PrivateExternCrateReexport { source: ident, extern_crate_span } => {
lints::PrivateExternCrateReexport { ident, sugg: extern_crate_span.shrink_to_lo() }
.decorate_lint(diag);
}
BuiltinLintDiag::UnusedLabel => lints::UnusedLabel.decorate_lint(diag),
BuiltinLintDiag::MacroIsPrivate(ident) => {
lints::MacroIsPrivate { ident }.decorate_lint(diag);
}
@ -398,36 +344,6 @@ pub fn decorate_builtin_lint(
BuiltinLintDiag::UnstableFeature(msg) => {
lints::UnstableFeature { msg }.decorate_lint(diag);
}
BuiltinLintDiag::AvoidUsingIntelSyntax => {
lints::AvoidIntelSyntax.decorate_lint(diag);
}
BuiltinLintDiag::AvoidUsingAttSyntax => {
lints::AvoidAttSyntax.decorate_lint(diag);
}
BuiltinLintDiag::IncompleteInclude => {
lints::IncompleteInclude.decorate_lint(diag);
}
BuiltinLintDiag::UnnameableTestItems => {
lints::UnnameableTestItems.decorate_lint(diag);
}
BuiltinLintDiag::DuplicateMacroAttribute => {
lints::DuplicateMacroAttribute.decorate_lint(diag);
}
BuiltinLintDiag::CfgAttrNoAttributes => {
lints::CfgAttrNoAttributes.decorate_lint(diag);
}
BuiltinLintDiag::MetaVariableStillRepeating(name) => {
lints::MetaVariableStillRepeating { name }.decorate_lint(diag);
}
BuiltinLintDiag::MetaVariableWrongOperator => {
lints::MetaVariableWrongOperator.decorate_lint(diag);
}
BuiltinLintDiag::DuplicateMatcherBinding => {
lints::DuplicateMatcherBinding.decorate_lint(diag);
}
BuiltinLintDiag::UnknownMacroVariable(name) => {
lints::UnknownMacroVariable { name }.decorate_lint(diag);
}
BuiltinLintDiag::UnusedCrateDependency { extern_crate, local_crate } => {
lints::UnusedCrateDependency { extern_crate, local_crate }.decorate_lint(diag)
}

View file

@ -17,7 +17,7 @@ use rustc_middle::ty::{Clause, PolyExistentialTraitRef, Ty, TyCtxt};
use rustc_session::Session;
use rustc_session::lint::AmbiguityErrorDiag;
use rustc_span::edition::Edition;
use rustc_span::{Ident, MacroRulesNormalizedIdent, Span, Symbol, sym};
use rustc_span::{Ident, Span, Symbol, sym};
use crate::builtin::{InitError, ShorthandAssocTyCollector, TypeAliasBounds};
use crate::errors::{OverruledAttributeSub, RequestedLevel};
@ -2535,15 +2535,6 @@ pub(crate) mod unexpected_cfg_value {
}
}
#[derive(LintDiagnostic)]
#[diag(lint_macro_use_deprecated)]
#[help]
pub(crate) struct MacroUseDeprecated;
#[derive(LintDiagnostic)]
#[diag(lint_unused_macro_use)]
pub(crate) struct UnusedMacroUse;
#[derive(LintDiagnostic)]
#[diag(lint_private_extern_crate_reexport, code = E0365)]
pub(crate) struct PrivateExternCrateReexport {
@ -2552,10 +2543,6 @@ pub(crate) struct PrivateExternCrateReexport {
pub sugg: Span,
}
#[derive(LintDiagnostic)]
#[diag(lint_unused_label)]
pub(crate) struct UnusedLabel;
#[derive(LintDiagnostic)]
#[diag(lint_macro_is_private)]
pub(crate) struct MacroIsPrivate {
@ -2585,50 +2572,6 @@ impl<'a> LintDiagnostic<'a, ()> for UnstableFeature {
}
}
#[derive(LintDiagnostic)]
#[diag(lint_avoid_intel_syntax)]
pub(crate) struct AvoidIntelSyntax;
#[derive(LintDiagnostic)]
#[diag(lint_avoid_att_syntax)]
pub(crate) struct AvoidAttSyntax;
#[derive(LintDiagnostic)]
#[diag(lint_incomplete_include)]
pub(crate) struct IncompleteInclude;
#[derive(LintDiagnostic)]
#[diag(lint_unnameable_test_items)]
pub(crate) struct UnnameableTestItems;
#[derive(LintDiagnostic)]
#[diag(lint_duplicate_macro_attribute)]
pub(crate) struct DuplicateMacroAttribute;
#[derive(LintDiagnostic)]
#[diag(lint_cfg_attr_no_attributes)]
pub(crate) struct CfgAttrNoAttributes;
#[derive(LintDiagnostic)]
#[diag(lint_metavariable_still_repeating)]
pub(crate) struct MetaVariableStillRepeating {
pub name: MacroRulesNormalizedIdent,
}
#[derive(LintDiagnostic)]
#[diag(lint_metavariable_wrong_operator)]
pub(crate) struct MetaVariableWrongOperator;
#[derive(LintDiagnostic)]
#[diag(lint_duplicate_matcher_binding)]
pub(crate) struct DuplicateMatcherBinding;
#[derive(LintDiagnostic)]
#[diag(lint_unknown_macro_variable)]
pub(crate) struct UnknownMacroVariable {
pub name: MacroRulesNormalizedIdent,
}
#[derive(LintDiagnostic)]
#[diag(lint_unused_crate_dependency)]
#[help]
@ -2714,22 +2657,6 @@ pub(crate) struct AbsPathWithModuleSugg {
pub replacement: String,
}
#[derive(LintDiagnostic)]
#[diag(lint_proc_macro_derive_resolution_fallback)]
pub(crate) struct ProcMacroDeriveResolutionFallback {
#[label]
pub span: Span,
pub ns_descr: &'static str,
pub ident: Ident,
}
#[derive(LintDiagnostic)]
#[diag(lint_macro_expanded_macro_exports_accessed_by_absolute_paths)]
pub(crate) struct MacroExpandedMacroExportsAccessedByAbsolutePaths {
#[note]
pub definition: Span,
}
#[derive(LintDiagnostic)]
#[diag(lint_hidden_lifetime_parameters)]
pub(crate) struct ElidedLifetimesInPaths {
@ -2737,21 +2664,6 @@ pub(crate) struct ElidedLifetimesInPaths {
pub subdiag: ElidedLifetimeInPathSubdiag,
}
#[derive(LintDiagnostic)]
#[diag(lint_invalid_crate_type_value)]
pub(crate) struct UnknownCrateTypes {
#[subdiagnostic]
pub sugg: Option<UnknownCrateTypesSub>,
}
#[derive(Subdiagnostic)]
#[suggestion(lint_suggestion, code = r#""{candidate}""#, applicability = "maybe-incorrect")]
pub(crate) struct UnknownCrateTypesSub {
#[primary_span]
pub span: Span,
pub candidate: Symbol,
}
#[derive(LintDiagnostic)]
#[diag(lint_unused_imports)]
pub(crate) struct UnusedImports {
@ -2809,14 +2721,6 @@ pub(crate) enum RedundantImportSub {
DefinedPrelude(#[primary_span] Span),
}
#[derive(LintDiagnostic)]
#[diag(lint_unused_doc_comment)]
#[help]
pub(crate) struct UnusedDocComment {
#[label]
pub span: Span,
}
#[derive(LintDiagnostic)]
pub(crate) enum PatternsInFnsWithoutBody {
#[diag(lint_pattern_in_foreign)]
@ -2840,21 +2744,6 @@ pub(crate) struct PatternsInFnsWithoutBodySub {
pub ident: Ident,
}
#[derive(LintDiagnostic)]
#[diag(lint_legacy_derive_helpers)]
pub(crate) struct LegacyDeriveHelpers {
#[label]
pub span: Span,
}
#[derive(LintDiagnostic)]
#[diag(lint_or_patterns_back_compat)]
pub(crate) struct OrPatternsBackCompat {
#[suggestion(code = "{suggestion}", applicability = "machine-applicable")]
pub span: Span,
pub suggestion: String,
}
#[derive(LintDiagnostic)]
#[diag(lint_reserved_prefix)]
pub(crate) struct ReservedPrefix {
@ -2875,27 +2764,6 @@ pub(crate) struct RawPrefix {
pub suggestion: Span,
}
#[derive(LintDiagnostic)]
#[diag(lint_unused_builtin_attribute)]
pub(crate) struct UnusedBuiltinAttribute {
#[note]
pub invoc_span: Span,
pub attr_name: Symbol,
pub macro_name: String,
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
pub attr_span: Span,
}
#[derive(LintDiagnostic)]
#[diag(lint_trailing_semi_macro)]
pub(crate) struct TrailingMacro {
#[note(lint_note1)]
#[note(lint_note2)]
pub is_trailing: bool,
pub name: Ident,
}
#[derive(LintDiagnostic)]
#[diag(lint_break_with_label_and_loop)]
pub(crate) struct BreakWithLabelAndLoop {
@ -2938,13 +2806,6 @@ pub(crate) enum DeprecatedWhereClauseLocationSugg {
},
}
#[derive(LintDiagnostic)]
#[diag(lint_missing_unsafe_on_extern)]
pub(crate) struct MissingUnsafeOnExtern {
#[suggestion(code = "unsafe ", applicability = "machine-applicable")]
pub suggestion: Span,
}
#[derive(LintDiagnostic)]
#[diag(lint_single_use_lifetime)]
pub(crate) struct SingleUseLifetime {
@ -2992,23 +2853,6 @@ pub(crate) struct NamedArgumentUsedPositionally {
pub named_arg_name: String,
}
#[derive(LintDiagnostic)]
#[diag(lint_byte_slice_in_packed_struct_with_derive)]
#[help]
pub(crate) struct ByteSliceInPackedStructWithDerive {
// FIXME: make this translatable
pub ty: String,
}
#[derive(LintDiagnostic)]
#[diag(lint_unused_extern_crate)]
pub(crate) struct UnusedExternCrate {
#[label]
pub span: Span,
#[suggestion(code = "", applicability = "machine-applicable", style = "verbose")]
pub removal_span: Span,
}
#[derive(LintDiagnostic)]
#[diag(lint_extern_crate_not_idiomatic)]
pub(crate) struct ExternCrateNotIdiomatic {
@ -3056,14 +2900,6 @@ pub(crate) struct HiddenGlobReexports {
pub namespace: String,
}
#[derive(LintDiagnostic)]
#[diag(lint_reexport_private_dependency)]
pub(crate) struct ReexportPrivateDependency {
pub name: String,
pub kind: String,
pub krate: Symbol,
}
#[derive(LintDiagnostic)]
#[diag(lint_unnecessary_qualification)]
pub(crate) struct UnusedQualifications {

View file

@ -11,7 +11,7 @@ use rustc_hir_id::{HashStableContext, HirId, ItemLocalId};
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
use rustc_span::def_id::DefPathHash;
pub use rustc_span::edition::Edition;
use rustc_span::{Ident, MacroRulesNormalizedIdent, Span, Symbol, sym};
use rustc_span::{Ident, Span, Symbol, sym};
use serde::{Deserialize, Serialize};
pub use self::Level::*;
@ -620,17 +620,7 @@ pub enum DeprecatedSinceKind {
#[derive(Debug)]
pub enum BuiltinLintDiag {
AbsPathWithModule(Span),
ProcMacroDeriveResolutionFallback {
span: Span,
ns_descr: &'static str,
ident: Ident,
},
MacroExpandedMacroExportsAccessedByAbsolutePaths(Span),
ElidedLifetimesInPaths(usize, Span, bool, Span),
UnknownCrateTypes {
span: Span,
candidate: Option<Symbol>,
},
UnusedImports {
remove_whole_use: bool,
num_to_remove: usize,
@ -646,20 +636,11 @@ pub enum BuiltinLintDiag {
path: String,
since_kind: DeprecatedSinceKind,
},
UnusedDocComment(Span),
UnusedBuiltinAttribute {
attr_name: Symbol,
macro_name: String,
invoc_span: Span,
attr_span: Span,
},
PatternsInFnsWithoutBody {
span: Span,
ident: Ident,
is_foreign: bool,
},
LegacyDeriveHelpers(Span),
OrPatternsBackCompat(Span, String),
ReservedPrefix(Span, String),
/// `'r#` in edition < 2021.
RawPrefix(Span),
@ -668,15 +649,11 @@ pub enum BuiltinLintDiag {
is_string: bool,
suggestion: Span,
},
TrailingMacro(bool, Ident),
BreakWithLabelAndLoop(Span),
UnicodeTextFlow(Span, String),
UnexpectedCfgName((Symbol, Span), Option<(Symbol, Span)>),
UnexpectedCfgValue((Symbol, Span), Option<(Symbol, Span)>),
DeprecatedWhereclauseLocation(Span, Option<(Span, String)>),
MissingUnsafeOnExtern {
suggestion: Span,
},
SingleUseLifetime {
/// Span of the parameter which declares this lifetime.
param_span: Span,
@ -701,14 +678,6 @@ pub enum BuiltinLintDiag {
/// Indicates if the named argument is used as a width/precision for formatting
is_formatting_arg: bool,
},
ByteSliceInPackedStructWithDerive {
// FIXME: enum of byte/string
ty: String,
},
UnusedExternCrate {
span: Span,
removal_span: Span,
},
ExternCrateNotIdiomatic {
vis_span: Span,
ident_span: Span,
@ -736,11 +705,6 @@ pub enum BuiltinLintDiag {
/// The local binding that shadows the glob reexport.
private_item_span: Span,
},
ReexportPrivateDependency {
name: String,
kind: String,
krate: Symbol,
},
UnusedQualifications {
/// The span of the unnecessarily-qualified path to remove.
removal_span: Span,
@ -763,27 +727,14 @@ pub enum BuiltinLintDiag {
span: Span,
typo_name: Option<Symbol>,
},
MacroUseDeprecated,
UnusedMacroUse,
PrivateExternCrateReexport {
source: Ident,
extern_crate_span: Span,
},
UnusedLabel,
MacroIsPrivate(Ident),
UnusedMacroDefinition(Symbol),
MacroRuleNeverUsed(usize, Symbol),
UnstableFeature(DiagMessage),
AvoidUsingIntelSyntax,
AvoidUsingAttSyntax,
IncompleteInclude,
UnnameableTestItems,
DuplicateMacroAttribute,
CfgAttrNoAttributes,
MetaVariableStillRepeating(MacroRulesNormalizedIdent),
MetaVariableWrongOperator,
DuplicateMatcherBinding,
UnknownMacroVariable(MacroRulesNormalizedIdent),
UnusedCrateDependency {
extern_crate: Symbol,
local_crate: Symbol,

View file

@ -231,6 +231,9 @@ resolve_item_was_cfg_out = the item is gated here
resolve_label_with_similar_name_reachable =
a label with a similar name is reachable
resolve_legacy_derive_helpers = derive helper attribute is used before it is introduced
.label = the attribute is introduced here
resolve_lending_iterator_report_error =
associated type `Iterator::Item` is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
.note = you can't create an `Iterator` that borrows each `Item` from itself, but you can instead create a new type that borrows your existing type and implement `Iterator` for that new type
@ -260,6 +263,9 @@ resolve_macro_defined_later =
resolve_macro_expanded_extern_crate_cannot_shadow_extern_arguments =
macro-expanded `extern crate` items cannot shadow names passed with `--extern`
resolve_macro_expanded_macro_exports_accessed_by_absolute_paths = macro-expanded `macro_export` macros from the current crate cannot be referred to by absolute paths
.note = the macro is defined here
resolve_macro_expected_found =
expected {$expected}, found {$found} `{$macro_path}`
.label = not {$article} {$expected}
@ -268,6 +274,10 @@ resolve_macro_extern_deprecated =
`#[macro_escape]` is a deprecated synonym for `#[macro_use]`
.help = try an outer attribute: `#[macro_use]`
resolve_macro_use_deprecated =
applying the `#[macro_use]` attribute to an `extern crate` item is deprecated
.help = remove it and import macros at use sites with a `use` item instead
resolve_macro_use_extern_crate_self = `#[macro_use]` is not supported on `extern crate self`
resolve_macro_use_name_already_in_use =
@ -339,6 +349,9 @@ resolve_param_in_ty_of_const_param =
resolve_pattern_doesnt_bind_name = pattern doesn't bind `{$name}`
resolve_proc_macro_derive_resolution_fallback = cannot find {$ns_descr} `{$ident}` in this scope
.label = names from parent modules are not accessible without an explicit import
resolve_proc_macro_same_crate = can't use a procedural macro from the same crate that defines it
.help = you can define integration tests in a directory named `tests`
@ -348,6 +361,9 @@ resolve_reexport_of_crate_public =
resolve_reexport_of_private =
re-export of private `{$ident}`
resolve_reexport_private_dependency =
{$kind} `{$name}` from private dependency '{$krate}' is re-exported
resolve_relative_2018 =
relative paths are not supported in visibilities in 2018 edition or later
.suggestion = try
@ -465,6 +481,14 @@ resolve_unreachable_label_suggestion_use_similarly_named =
resolve_unreachable_label_with_similar_name_exists =
a label with a similar name exists but is unreachable
resolve_unused_extern_crate = unused extern crate
.label = unused
.suggestion = remove the unused `extern crate`
resolve_unused_label = unused label
resolve_unused_macro_use = unused `#[macro_use]` import
resolve_variable_bound_with_different_mode =
variable `{$variable_name}` is bound inconsistently across alternatives separated by `|`
.label = bound in different ways

View file

@ -169,7 +169,7 @@ impl<'a, 'ra, 'tcx> UnusedImportCheckVisitor<'a, 'ra, 'tcx> {
UNUSED_EXTERN_CRATES,
extern_crate.id,
span,
BuiltinLintDiag::UnusedExternCrate {
crate::errors::UnusedExternCrate {
span: extern_crate.span,
removal_span: extern_crate.span_with_attributes,
},
@ -406,7 +406,7 @@ impl Resolver<'_, '_> {
MACRO_USE_EXTERN_CRATE,
import.root_id,
import.span,
BuiltinLintDiag::MacroUseDeprecated,
crate::errors::MacroUseDeprecated,
);
}
}
@ -427,7 +427,7 @@ impl Resolver<'_, '_> {
UNUSED_IMPORTS,
import.root_id,
import.span,
BuiltinLintDiag::UnusedMacroUse,
crate::errors::UnusedMacroUse,
);
}
_ => {}

View file

@ -138,7 +138,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
CRATE_NODE_ID,
span_use,
BuiltinLintDiag::MacroExpandedMacroExportsAccessedByAbsolutePaths(span_def),
errors::MacroExpandedMacroExportsAccessedByAbsolutePaths { definition: span_def },
);
}

View file

@ -3,7 +3,7 @@ use rustc_errors::{
Applicability, Diag, ElidedLifetimeInPathSubdiag, EmissionGuarantee, IntoDiagArg, MultiSpan,
Subdiagnostic,
};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_span::{Ident, Span, Symbol};
use crate::late::PatternSource;
@ -566,6 +566,22 @@ pub(crate) struct ProcMacroSameCrate {
pub(crate) is_test: bool,
}
#[derive(LintDiagnostic)]
#[diag(resolve_proc_macro_derive_resolution_fallback)]
pub(crate) struct ProcMacroDeriveResolutionFallback {
#[label]
pub span: Span,
pub ns_descr: &'static str,
pub ident: Ident,
}
#[derive(LintDiagnostic)]
#[diag(resolve_macro_expanded_macro_exports_accessed_by_absolute_paths)]
pub(crate) struct MacroExpandedMacroExportsAccessedByAbsolutePaths {
#[note]
pub definition: Span,
}
#[derive(Diagnostic)]
#[diag(resolve_imported_crate)]
pub(crate) struct CrateImported {
@ -1276,3 +1292,40 @@ pub(crate) struct TraitImplMismatch {
#[label(resolve_trait_impl_mismatch_label_item)]
pub(crate) trait_item_span: Span,
}
#[derive(LintDiagnostic)]
#[diag(resolve_legacy_derive_helpers)]
pub(crate) struct LegacyDeriveHelpers {
#[label]
pub span: Span,
}
#[derive(LintDiagnostic)]
#[diag(resolve_unused_extern_crate)]
pub(crate) struct UnusedExternCrate {
#[label]
pub span: Span,
#[suggestion(code = "", applicability = "machine-applicable", style = "verbose")]
pub removal_span: Span,
}
#[derive(LintDiagnostic)]
#[diag(resolve_reexport_private_dependency)]
pub(crate) struct ReexportPrivateDependency {
pub name: Symbol,
pub kind: &'static str,
pub krate: Symbol,
}
#[derive(LintDiagnostic)]
#[diag(resolve_unused_label)]
pub(crate) struct UnusedLabel;
#[derive(LintDiagnostic)]
#[diag(resolve_unused_macro_use)]
pub(crate) struct UnusedMacroUse;
#[derive(LintDiagnostic)]
#[diag(resolve_macro_use_deprecated)]
#[help]
pub(crate) struct MacroUseDeprecated;

View file

@ -4,7 +4,6 @@ use rustc_ast::{self as ast, NodeId};
use rustc_errors::ErrorGuaranteed;
use rustc_hir::def::{DefKind, MacroKinds, Namespace, NonMacroAttrKind, PartialRes, PerNS};
use rustc_middle::bug;
use rustc_session::lint::BuiltinLintDiag;
use rustc_session::lint::builtin::PROC_MACRO_DERIVE_RESOLUTION_FALLBACK;
use rustc_session::parse::feature_err;
use rustc_span::hygiene::{ExpnId, ExpnKind, LocalExpnId, MacroKind, SyntaxContext};
@ -520,7 +519,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
lint_id,
orig_ident.span,
BuiltinLintDiag::ProcMacroDeriveResolutionFallback {
errors::ProcMacroDeriveResolutionFallback {
span: orig_ident.span,
ns_descr: ns.descr(),
ident,

View file

@ -720,9 +720,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
EXPORTED_PRIVATE_DEPENDENCIES,
binding_id,
binding.span,
BuiltinLintDiag::ReexportPrivateDependency {
kind: binding.res().descr().to_string(),
name: key.ident.name.to_string(),
crate::errors::ReexportPrivateDependency {
name: key.ident.name,
kind: binding.res().descr(),
krate: self.tcx.crate_name(reexported_def_id.krate),
},
);

View file

@ -29,7 +29,7 @@ use rustc_middle::middle::resolve_bound_vars::Set1;
use rustc_middle::ty::{DelegationFnSig, Visibility};
use rustc_middle::{bug, span_bug};
use rustc_session::config::{CrateType, ResolveDocLinks};
use rustc_session::lint::{self, BuiltinLintDiag};
use rustc_session::lint;
use rustc_session::parse::feature_err;
use rustc_span::source_map::{Spanned, respan};
use rustc_span::{BytePos, Ident, Span, Symbol, SyntaxContext, kw, sym};
@ -5225,7 +5225,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
lint::builtin::UNUSED_LABELS,
*id,
*span,
BuiltinLintDiag::UnusedLabel,
errors::UnusedLabel,
);
}
}

View file

@ -979,7 +979,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
LEGACY_DERIVE_HELPERS,
node_id,
ident.span,
BuiltinLintDiag::LegacyDeriveHelpers(binding.span),
errors::LegacyDeriveHelpers { span: binding.span },
);
}
}

View file

@ -2,9 +2,9 @@ error: duplicate matcher binding
--> $DIR/issue-61053-duplicate-binder.rs:7:20
|
LL | ($x:tt $x:tt) => { $x };
| -- ^^
| -- ^^ duplicate binding
| |
| previous declaration
| previous binding
|
note: the lint level is defined here
--> $DIR/issue-61053-duplicate-binder.rs:1:9