diff --git a/Cargo.lock b/Cargo.lock index 0b47aae128338..2e9e60dd4af02 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3714,6 +3714,7 @@ dependencies = [ "rustc_ast_pretty", "rustc_data_structures", "rustc_error_messages", + "rustc_lint_defs", "rustc_macros", "rustc_serialize", "rustc_span", diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 72e9f92c6b95a..46c9460d085c8 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -378,6 +378,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { tcx.sess, tcx.features(), tcx.registered_attr_tools(()), + tcx.registered_lint_tools(()), ShouldEmit::ErrorsAndLints { recovery: Recovery::Allowed }, ), } diff --git a/compiler/rustc_attr_ir/Cargo.toml b/compiler/rustc_attr_ir/Cargo.toml index a1afc13cbd1e7..349d241d584c4 100644 --- a/compiler/rustc_attr_ir/Cargo.toml +++ b/compiler/rustc_attr_ir/Cargo.toml @@ -10,6 +10,7 @@ rustc_ast = { path = "../rustc_ast" } rustc_ast_pretty = { path = "../rustc_ast_pretty" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_error_messages = { path = "../rustc_error_messages" } +rustc_lint_defs = { path = "../rustc_lint_defs" } rustc_macros = { path = "../rustc_macros" } rustc_serialize = { path = "../rustc_serialize" } rustc_span = { path = "../rustc_span" } diff --git a/compiler/rustc_attr_ir/src/lint.rs b/compiler/rustc_attr_ir/src/lint.rs index 2dafadf4cb2a9..7ce2c000419e1 100644 --- a/compiler/rustc_attr_ir/src/lint.rs +++ b/compiler/rustc_attr_ir/src/lint.rs @@ -1,6 +1,6 @@ +use rustc_lint_defs::LintName; use rustc_macros::{Decodable, Encodable, PrintAttribute, StableHash}; use rustc_span::{Span, Symbol, sym}; -use rustc_structures::LintName; use crate::{HashIgnoredAttrId, PrintAttribute}; @@ -45,7 +45,12 @@ impl LintCheckKind { /// ``` #[derive(Clone, Debug, StableHash, Encodable, Decodable, PrintAttribute)] pub struct LintCheck { - pub lint_name: LintName, + /// The full normalized lint name of an existing lint, including the tool name. + /// This may not be what the user wrote down, in case of renamed lints the new lint name is here. + /// The above implies that `LintStore::find_lints` is guaranteed to find this lint using this symbol. + /// + /// For example, `single_use_lifetime` is changed to `single_use_lifetimes`. + pub lint_name_normalized: LintName, pub kind: LintCheckKind, pub reason: Option, /// Needed by `LintExpectationId` to track fulfilled expectations @@ -61,5 +66,4 @@ pub struct LintCheck { /// #[deny(foo::bar::baz)] /// ^^^^^^^^^^^^^ pub lint_span: Span, - pub tool_span: Option, } diff --git a/compiler/rustc_attr_ir/src/pretty_printing.rs b/compiler/rustc_attr_ir/src/pretty_printing.rs index 4ffd0f07029a3..06df735f9325f 100644 --- a/compiler/rustc_attr_ir/src/pretty_printing.rs +++ b/compiler/rustc_attr_ir/src/pretty_printing.rs @@ -11,12 +11,11 @@ use rustc_ast::token::{CommentKind, DocFragmentKind}; use rustc_ast::{AttrId, AttrStyle, IntTy, UintTy}; use rustc_ast_pretty::pp::Printer; use rustc_data_structures::fx::FxIndexMap; +use rustc_lint_defs::LintName; use rustc_span::def_id::DefId; use rustc_span::hygiene::Transparency; use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol}; -use rustc_structures::{ - CollapseMacroDebuginfo, CrateType, Limit, LintName, NativeLibKind, SanitizerSet, -}; +use rustc_structures::{CollapseMacroDebuginfo, CrateType, Limit, NativeLibKind, SanitizerSet}; use thin_vec::ThinVec; use crate::HashIgnoredAttrId; diff --git a/compiler/rustc_attr_parsing/src/attributes/lint.rs b/compiler/rustc_attr_parsing/src/attributes/lint.rs index e0607c49124d9..8fc5ae94a6b01 100644 --- a/compiler/rustc_attr_parsing/src/attributes/lint.rs +++ b/compiler/rustc_attr_parsing/src/attributes/lint.rs @@ -1,13 +1,18 @@ +use rustc_ast::join_path_syms; use rustc_attr_ir::AttributeKind; use rustc_attr_ir::lint::{LintCheck, LintCheckKind}; use rustc_attr_ir::target::{AssocCtxt, MethodKind, Target}; -use rustc_lint_defs::builtin::UNUSED_ATTRIBUTES; -use rustc_span::sym; -use rustc_structures::LintName; +use rustc_lint_defs::builtin::{RENAMED_AND_REMOVED_LINTS, UNKNOWN_LINTS, UNUSED_ATTRIBUTES}; +use rustc_lint_defs::{CheckLintNameResult, LintId, LintName}; +use rustc_span::{Span, Symbol, sym}; use thin_vec::ThinVec; use crate::attributes::{AcceptMapping, AttributeParser, AttributeStability}; use crate::context::{AcceptContext, ExpectStringLiteral, FinalizeContext}; +use crate::diagnostics::{ + DeprecatedLintName, RemovedLint, RenamedLint, RenamedLintSuggestion, UnknownLint, + UnknownLintSuggestion, UnknownToolInScopedLint, +}; use crate::parser::{ArgParser, MetaItemOrLitParser}; use crate::target_checking::AllowedTargets; use crate::target_checking::Policy::{Allow, Warn}; @@ -52,21 +57,47 @@ impl LintParser { match item { MetaItemOrLitParser::MetaItemParser(p) => { match p.args() { - ArgParser::NoArgs => self.lints.push(LintCheck { - lint_name: LintName::new( - p.path().0.segments.iter().map(|s| s.ident.name), - ), - kind, - attr_id, - reason, - attr_span, - lint_span: p.span(), - tool_span: if let [tool, _, ..] = &*p.path().0.segments { - Some(tool.span()) + ArgParser::NoArgs => { + let (tool, lint_name) = match &*p.path().0.segments { + [] => unreachable!(), + [lint_name] => (None, lint_name.ident.name), + [tool, lint_name] => (Some(tool.ident), lint_name.ident.name), + // Not reachable for any builtin lints, + // but reachable using `register_tool`. + [tool, multi_segment_lint_name @ ..] => ( + Some(tool.ident), + Symbol::intern(&join_path_syms( + multi_segment_lint_name + .iter() + .map(|seg| seg.ident.name), + )), + ), + }; + let lint_name = + LintName { tool: tool.map(|tool| tool.name), name: lint_name }; + + let lint_name_normalized = if let Some((_lint_ids, new_lint_name)) = + LintParser::check_lint_name( + lint_name, + tool.map(|tool| tool.span), + p.span(), + cx, + ) { + new_lint_name } else { - None - }, - }), + // Discard lint attributes with unknown lints in them + continue; + }; + + self.lints.push(LintCheck { + lint_name_normalized, + lint_span: p.span(), + kind, + attr_id, + reason, + attr_span, + }) + } // We've found a `reason = "reason"` but we're not the last element. ArgParser::NameValue(nv) if p.path().word_is(sym::reason) => { cx.emit_err(diagnostics::MalformedAttribute { @@ -118,6 +149,135 @@ impl LintParser { } } } + + fn check_lint_name<'sess>( + lint_name: LintName, + tool_span: Option, + lint_span: Span, + cx: &mut AcceptContext<'_, 'sess>, + ) -> Option<(&'sess [LintId], LintName)> { + let lint_result = cx + .sess + .lint_store + .as_ref() + .unwrap() + .check_attribute_lint_name(lint_name, cx.lint_tools.unwrap()); + + // FIXME(164898) Lint attributes are parsed twice, once on the AST and once on the HIR + // Both times emit diagnostics, for historic reasons + // We only want to emit these lints once, on the HIR. + // On the AST the parse filter will be `Some` (since we're only parsing lint attributes then) + // #164898 will fix this, after that PR this check can be removed + let should_lint = cx.parse_filter.is_none(); + + let (ids, name) = match lint_result { + CheckLintNameResult::Ok(ids) => (ids, lint_name), + + CheckLintNameResult::Tool(ids, new_lint_name) => { + let name = match new_lint_name { + None => lint_name, + Some(replacement) => { + if should_lint { + cx.emit_lint( + RENAMED_AND_REMOVED_LINTS, + DeprecatedLintName { + lint_name, + suggestion: lint_span, + replacement, + }, + lint_span, + ); + } + replacement + } + }; + (ids, name) + } + + CheckLintNameResult::MissingTool => { + // If `MissingTool` is returned, then either the lint does not + // exist in the tool or the code was not compiled with the tool and + // therefore the lint was never added to the `LintStore`. To detect + // this is the responsibility of the lint tool. + return None; + } + + CheckLintNameResult::NoTool(tool_name) => { + if should_lint { + cx.emit_err(UnknownToolInScopedLint { + span: Some(tool_span.unwrap()), + tool_name, + lint_name, + is_nightly_build: cx.sess.is_nightly_build(), + }); + } + return None; + } + + CheckLintNameResult::Renamed(replacement) => { + if should_lint { + let suggestion = + RenamedLintSuggestion::WithSpan { suggestion: lint_span, replacement }; + cx.emit_lint( + RENAMED_AND_REMOVED_LINTS, + RenamedLint { name: lint_name, replacement, suggestion }, + lint_span, + ); + } + + // If this lint was renamed, apply the new lint instead of ignoring the + // attribute. Ignore any errors or warnings that happen because the new + // name is inaccurate. + // NOTE: `new_name` already includes the tool name, so we don't + // have to add it again. + let replace_check = cx + .sess + .lint_store + .as_ref() + .unwrap() + .check_attribute_lint_name(replacement, cx.lint_tools.unwrap()); + let (CheckLintNameResult::Ok(ids) | CheckLintNameResult::Tool(ids, _)) = + replace_check + else { + panic!( + "renamed lint does not exist: {lint_name} => {replacement}\n{replace_check:?}" + ); + }; + + (ids, replacement) + } + + CheckLintNameResult::Removed(ref reason) => { + if should_lint { + cx.emit_lint( + RENAMED_AND_REMOVED_LINTS, + RemovedLint { name: lint_name, reason: reason.clone() }, + lint_span, + ); + } + return None; + } + + CheckLintNameResult::NoLint(suggestion) => { + if should_lint { + let suggestion = suggestion.map(|(replacement, from_rustc)| { + UnknownLintSuggestion::WithSpan { + suggestion: lint_span, + replacement, + from_rustc, + } + }); + cx.emit_lint( + UNKNOWN_LINTS, + UnknownLint { name: lint_name, suggestion }, + lint_span, + ); + } + return None; + } + }; + Some((ids, name)) + } } impl AttributeParser for LintParser { diff --git a/compiler/rustc_attr_parsing/src/diagnostics.rs b/compiler/rustc_attr_parsing/src/diagnostics.rs index 4059114456431..4d2294667d217 100644 --- a/compiler/rustc_attr_parsing/src/diagnostics.rs +++ b/compiler/rustc_attr_parsing/src/diagnostics.rs @@ -5,6 +5,7 @@ use rustc_errors::codes::*; use rustc_errors::{ Applicability, Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, E0264, Level, MultiSpan, }; +use rustc_lint_defs::LintName; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::{Ident, Span, Symbol}; use rustc_target::spec::TargetTuple; @@ -2225,3 +2226,84 @@ pub(crate) struct DocKeywordAttributeNotAnonConst { pub span: Span, pub attr_name: Symbol, } + +#[derive(Diagnostic)] +#[diag("lint name `{$lint_name}` is deprecated and may not have an effect in the future")] +pub(crate) struct DeprecatedLintName { + pub lint_name: LintName, + #[suggestion("change it to", code = "{replacement}", applicability = "machine-applicable")] + pub suggestion: Span, + pub replacement: LintName, +} + +#[derive(Diagnostic)] +#[diag("unknown tool name `{$tool_name}` found in scoped lint: `{$lint_name}`", code = E0710)] +pub(crate) struct UnknownToolInScopedLint { + #[primary_span] + pub span: Option, + pub tool_name: Symbol, + pub lint_name: LintName, + #[help("add `#![register_tool({$tool_name})]` to the crate root")] + pub is_nightly_build: bool, +} + +#[derive(Diagnostic)] +#[diag("lint `{$name}` has been renamed to `{$replacement}`")] +pub(crate) struct RenamedLint { + pub name: LintName, + pub replacement: LintName, + #[subdiagnostic] + pub suggestion: RenamedLintSuggestion, +} + +#[derive(Subdiagnostic)] +pub enum RenamedLintSuggestion { + #[suggestion("use the new name", code = "{replacement}", applicability = "machine-applicable")] + WithSpan { + #[primary_span] + suggestion: Span, + replacement: LintName, + }, + #[help("use the new name `{$replacement}`")] + WithoutSpan { replacement: LintName }, +} + +#[derive(Diagnostic)] +#[diag("unknown lint: `{$name}`")] +pub(crate) struct UnknownLint { + pub name: LintName, + #[subdiagnostic] + pub suggestion: Option, +} + +#[derive(Subdiagnostic)] +pub enum UnknownLintSuggestion { + #[suggestion( + "{$from_rustc -> + [true] a lint with a similar name exists in `rustc` lints + *[false] did you mean + }", + code = "{replacement}", + applicability = "maybe-incorrect" + )] + WithSpan { + #[primary_span] + suggestion: Span, + replacement: LintName, + from_rustc: bool, + }, + #[help( + "{$from_rustc -> + [true] a lint with a similar name exists in `rustc` lints: `{$replacement}` + *[false] did you mean: `{$replacement}` + }" + )] + WithoutSpan { replacement: LintName, from_rustc: bool }, +} + +#[derive(Diagnostic)] +#[diag("lint `{$name}` has been removed: {$reason}")] +pub(crate) struct RemovedLint { + pub name: LintName, + pub reason: String, +} diff --git a/compiler/rustc_attr_parsing/src/interface.rs b/compiler/rustc_attr_parsing/src/interface.rs index 7d3f6fbc067dc..739526e24f702 100644 --- a/compiler/rustc_attr_parsing/src/interface.rs +++ b/compiler/rustc_attr_parsing/src/interface.rs @@ -39,6 +39,7 @@ pub struct EmitAttribute( /// context, through which all attributes can be lowered. pub struct AttributeParser<'sess> { pub(crate) attr_tools: Option<&'sess RegisteredTools>, + pub(crate) lint_tools: Option<&'sess RegisteredTools>, pub(crate) features: Option<&'sess Features>, pub(crate) sess: &'sess Session, pub(crate) should_emit: ShouldEmit, @@ -46,7 +47,7 @@ pub struct AttributeParser<'sess> { /// *Only* parse attributes that passes this filter. /// /// Used in cases where we want the lowering infrastructure for parse just limited attributes. - parse_filter: Option<&'sess dyn Fn(&ast::Attribute) -> bool>, + pub(crate) parse_filter: Option<&'sess dyn Fn(&ast::Attribute) -> bool>, } impl<'sess> AttributeParser<'sess> { @@ -114,6 +115,7 @@ impl<'sess> AttributeParser<'sess> { features, should_emit, None, + None, ); assert!(parsed.len() <= 1); parsed.pop() @@ -156,8 +158,10 @@ impl<'sess> AttributeParser<'sess> { features: Option<&'sess Features>, should_emit: ShouldEmit, attr_tools: Option<&'sess RegisteredTools>, + lint_tools: Option<&'sess RegisteredTools>, ) -> Vec { - let mut p = AttributeParser { features, attr_tools, parse_filter, sess, should_emit }; + let mut p = + AttributeParser { features, attr_tools, lint_tools, parse_filter, sess, should_emit }; p.parse_attribute_list( attrs, target_span, @@ -239,7 +243,14 @@ impl<'sess> AttributeParser<'sess> { parse_fn: fn(cx: &mut AcceptContext<'_, '_>, item: &I) -> T, template: &AttributeTemplate, ) -> T { - let mut parser = Self { features, attr_tools: None, parse_filter: None, sess, should_emit }; + let mut parser = Self { + features, + attr_tools: None, + lint_tools: None, + parse_filter: None, + sess, + should_emit, + }; let mut emit_lint = |lint_id: LintId, span: MultiSpan, kind: EmitAttribute| { sess.psess.dyn_buffer_lint_sess(lint_id.lint, span, target_node_id, kind.0) }; @@ -282,11 +293,13 @@ impl<'sess> AttributeParser<'sess> { sess: &'sess Session, features: &'sess Features, attr_tools: &'sess RegisteredTools, + lint_tools: &'sess RegisteredTools, should_emit: ShouldEmit, ) -> Self { Self { features: Some(features), attr_tools: Some(attr_tools), + lint_tools: Some(lint_tools), parse_filter: None, sess, should_emit, diff --git a/compiler/rustc_attr_parsing/src/lib.rs b/compiler/rustc_attr_parsing/src/lib.rs index 4e6b8b2d38f3b..813c980411dd5 100644 --- a/compiler/rustc_attr_parsing/src/lib.rs +++ b/compiler/rustc_attr_parsing/src/lib.rs @@ -118,7 +118,7 @@ pub use attributes::cfg::{ pub use attributes::cfg_select::*; pub use attributes::util::{is_builtin_attr, parse_version}; pub use context::ShouldEmit; -pub use diagnostics::ParsedDescription; +pub use diagnostics::{ParsedDescription, RenamedLintSuggestion, UnknownLintSuggestion}; pub use interface::{AttributeParser, EmitAttribute}; pub use rustc_parse::parser::Recovery; pub use template::AttributeTemplate; diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index f1919cab3957e..e2d56fb2c4e43 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -44,7 +44,7 @@ use rustc_interface::passes::collect_crate_types; use rustc_interface::util::{self, get_codegen_backend}; use rustc_interface::{Linker, create_and_enter_global_ctxt, interface, passes}; use rustc_lint::unerased_lint_store; -use rustc_lint_defs::{Lint, LintId}; +use rustc_lint_defs::{Lint, LintId, LintName}; use rustc_metadata::creader::MetadataLoader; use rustc_metadata::locator; use rustc_middle::ty::TyCtxt; @@ -59,7 +59,7 @@ use rustc_session::output::invalid_output_for_target; use rustc_session::{EarlyDiagCtxt, Session, config}; use rustc_span::def_id::LOCAL_CRATE; use rustc_span::{DUMMY_SP, FileName}; -use rustc_structures::{CrateType, LintName}; +use rustc_structures::CrateType; use rustc_target::json::ToJson; use rustc_target::spec::{Target, TargetTuple}; use tracing::trace; diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 3cad1a34cad99..15ed9e6d59c28 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -2246,6 +2246,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { Some(self.cx.ecfg.features), ShouldEmit::ErrorsAndLints { recovery: Recovery::Allowed }, Some(self.cx.resolver.registered_attr_tools()), + Some(self.cx.resolver.registered_lint_tools()), ); let current_span = if let Some(sp) = span { sp.to(attr.span) } else { attr.span }; diff --git a/compiler/rustc_interface/src/limits.rs b/compiler/rustc_interface/src/limits.rs index a97aef1a66058..2595646cd0794 100644 --- a/compiler/rustc_interface/src/limits.rs +++ b/compiler/rustc_interface/src/limits.rs @@ -39,6 +39,7 @@ pub fn get_limits(krate_attrs: &[ast::Attribute], sess: &Session, features: &Fea // So, no lints here to avoid duplicates. ShouldEmit::EarlyFatal { also_emit_lints: false }, None, + None, ); let attrs = &attrs; Limits { diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 9423bec5a8715..e31da0d839e7a 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -19,8 +19,8 @@ use rustc_hir::def_id::{CrateNum, DefId}; use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData}; use rustc_hir::{Pat, PatKind}; use rustc_lint_defs::{ - FutureIncompatibleInfo, Lint, LintExpectationId, LintId, StableLintExpectationId, - UnstableLintExpectationId, + CheckLintNameResult, FutureIncompatibleInfo, Lint, LintExpectationId, LintId, LintName, + StableLintExpectationId, UnstableLintExpectationId, }; use rustc_middle::lint::{LevelSpec, StableLevelSpec, UnstableLevelSpec}; use rustc_middle::middle::privacy::EffectiveVisibilities; @@ -30,7 +30,6 @@ use rustc_middle::ty::{self, RegisteredTools, Ty, TyCtxt, TypingEnv, TypingMode, use rustc_session::{DynLintStore, Session}; use rustc_span::edit_distance::find_best_match_for_names; use rustc_span::{Ident, Span, Symbol, bug, sym}; -use rustc_structures::LintName; use tracing::debug; use self::TargetLint::*; @@ -90,6 +89,14 @@ impl DynLintStore for LintStore { rustc_session::LintGroup { name, lints, is_externally_loaded } })) } + + fn check_attribute_lint_name( + &self, + lint_name: LintName, + lint_tools: &RegisteredTools, + ) -> CheckLintNameResult<'_> { + self.check_lint_name(lint_name, lint_tools) + } } /// The target of the `by_name` map, which accounts for renaming/deprecation. @@ -124,29 +131,6 @@ struct LintGroup { depr: Option, } -#[derive(Debug)] -pub enum CheckLintNameResult<'a> { - Ok(&'a [LintId]), - /// Lint doesn't exist. Potentially contains a suggestion for a correct lint name. - NoLint(Option<(LintName, bool)>), - /// The lint refers to a tool that has not been registered. - NoTool(Symbol), - /// The lint has been renamed to a new name. - Renamed(LintName), - /// The lint has been removed due to the given reason. - Removed(String), - - /// The lint is from a tool. The `LintId` will be returned as if it were a - /// rustc lint. The `Option` indicates if the lint has been - /// renamed. - Tool(&'a [LintId], Option), - - /// The lint is from a tool. Either the lint does not exist in the tool or - /// the code was not compiled with the tool and therefore the lint was - /// never added to the `LintStore`. - MissingTool, -} - impl LintStore { pub fn new() -> LintStore { LintStore { diff --git a/compiler/rustc_lint/src/diagnostics.rs b/compiler/rustc_lint/src/diagnostics.rs index b722cb1354987..3a4ca91ce3ead 100644 --- a/compiler/rustc_lint/src/diagnostics.rs +++ b/compiler/rustc_lint/src/diagnostics.rs @@ -2,6 +2,7 @@ use std::num::NonZero; use rustc_attr_ir::find_attr; +use rustc_attr_parsing::{RenamedLintSuggestion, UnknownLintSuggestion}; use rustc_data_structures::fx::FxIndexMap; use rustc_errors::codes::*; use rustc_errors::formatting::DiagMessageAddArg; @@ -12,13 +13,13 @@ use rustc_errors::{ use rustc_hir as hir; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::intravisit::Visitor; +use rustc_lint_defs::LintName; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_middle::ty::inhabitedness::InhabitedPredicate; use rustc_middle::ty::{Clause, PolyExistentialTraitRef, Ty, TyCtxt}; use rustc_session::Session; use rustc_span::edition::Edition; use rustc_span::{Ident, Span, Symbol, sym}; -use rustc_structures::LintName; use crate::LateContext; use crate::builtin::{InitError, ShorthandAssocTyCollector, TypeAliasBounds}; @@ -66,17 +67,6 @@ impl Subdiagnostic for OverruledAttributeSub { } } -#[derive(Diagnostic)] -#[diag("unknown tool name `{$tool_name}` found in scoped lint: `{$lint_name}`", code = E0710)] -pub(crate) struct UnknownToolInScopedLint { - #[primary_span] - pub span: Option, - pub tool_name: Symbol, - pub lint_name: LintName, - #[help("add `#![register_tool({$tool_name})]` to the crate root")] - pub is_nightly_build: bool, -} - #[derive(Diagnostic)] #[diag("functions generic over types or consts must be mangled")] pub(crate) struct BuiltinNoMangleGeneric { @@ -1412,15 +1402,6 @@ pub(crate) struct OverruledAttributeLint<'a> { pub sub: OverruledAttributeSub, } -#[derive(Diagnostic)] -#[diag("lint name `{$lint_name}` is deprecated and may not have an effect in the future")] -pub(crate) struct DeprecatedLintName { - pub lint_name: LintName, - #[suggestion("change it to", code = "{replacement}", applicability = "machine-applicable")] - pub suggestion: Span, - pub replacement: LintName, -} - #[derive(Diagnostic)] #[diag("lint name `{$lint_name}` is deprecated and may not have an effect in the future")] #[help("change it to {$replacement}")] @@ -1431,27 +1412,6 @@ pub(crate) struct DeprecatedLintNameFromCommandLine { pub requested_level: RequestedLevel, } -#[derive(Diagnostic)] -#[diag("lint `{$name}` has been renamed to `{$replacement}`")] -pub(crate) struct RenamedLint { - pub name: LintName, - pub replacement: LintName, - #[subdiagnostic] - pub suggestion: RenamedLintSuggestion, -} - -#[derive(Subdiagnostic)] -pub(crate) enum RenamedLintSuggestion { - #[suggestion("use the new name", code = "{replacement}", applicability = "machine-applicable")] - WithSpan { - #[primary_span] - suggestion: Span, - replacement: LintName, - }, - #[help("use the new name `{$replacement}`")] - WithoutSpan { replacement: LintName }, -} - #[derive(Diagnostic)] #[diag("lint `{$lint_name}` has been renamed to `{$replacement}`")] pub(crate) struct RenamedLintFromCommandLine { @@ -1463,13 +1423,6 @@ pub(crate) struct RenamedLintFromCommandLine { pub requested_level: RequestedLevel, } -#[derive(Diagnostic)] -#[diag("lint `{$name}` has been removed: {$reason}")] -pub(crate) struct RemovedLint<'a> { - pub name: LintName, - pub reason: &'a str, -} - #[derive(Diagnostic)] #[diag("lint `{$lint_name}` has been removed: {$reason}")] pub(crate) struct RemovedLintFromCommandLine<'a> { @@ -1479,39 +1432,6 @@ pub(crate) struct RemovedLintFromCommandLine<'a> { pub requested_level: RequestedLevel, } -#[derive(Diagnostic)] -#[diag("unknown lint: `{$name}`")] -pub(crate) struct UnknownLint { - pub name: LintName, - #[subdiagnostic] - pub suggestion: Option, -} - -#[derive(Subdiagnostic)] -pub(crate) enum UnknownLintSuggestion { - #[suggestion( - "{$from_rustc -> - [true] a lint with a similar name exists in `rustc` lints - *[false] did you mean - }", - code = "{replacement}", - applicability = "maybe-incorrect" - )] - WithSpan { - #[primary_span] - suggestion: Span, - replacement: LintName, - from_rustc: bool, - }, - #[help( - "{$from_rustc -> - [true] a lint with a similar name exists in `rustc` lints: `{$replacement}` - *[false] did you mean: `{$replacement}` - }" - )] - WithoutSpan { replacement: LintName, from_rustc: bool }, -} - #[derive(Diagnostic)] #[diag("unknown lint: `{$lint_name}`", code = E0602)] pub(crate) struct UnknownLintFromCommandLine { diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index ededeb4196078..dad92c3462b9b 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -5,7 +5,9 @@ use rustc_ast::CRATE_NODE_ID; use rustc_attr_ir::lint::{LintCheck, LintCheckKind}; use rustc_attr_ir::target::Target; use rustc_attr_ir::{Attribute, DocAttribute, find_attr}; -use rustc_attr_parsing::{AttributeParser, Recovery, ShouldEmit}; +use rustc_attr_parsing::{ + AttributeParser, Recovery, RenamedLintSuggestion, ShouldEmit, UnknownLintSuggestion, +}; use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_data_structures::unord::UnordSet; use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, MultiSpan, msg}; @@ -19,7 +21,8 @@ use rustc_lint_defs::builtin::{ UNFULFILLED_LINT_EXPECTATIONS, UNKNOWN_LINTS, UNUSED_ATTRIBUTES, }; use rustc_lint_defs::{ - Level, Lint, LintExpectationId, LintId, StableLintExpectationId, UnstableLintExpectationId, + CheckLintNameResult, Level, Lint, LintExpectationId, LintId, LintName, StableLintExpectationId, + UnstableLintExpectationId, }; use rustc_middle::hir::nested_filter; use rustc_middle::lint::{ @@ -31,17 +34,14 @@ use rustc_middle::ty::{RegisteredTools, TyCtxt}; use rustc_session::Session; use rustc_span::def_id::CRATE_MOD_ID; use rustc_span::{AttrId, DUMMY_SP, Span, Symbol, sym}; -use rustc_structures::LintName; use tracing::{debug, instrument}; use crate::builtin::MISSING_DOCS; -use crate::context::{CheckLintNameResult, LintStore}; +use crate::context::LintStore; use crate::diagnostics::{ - CheckNameUnknownTool, DeprecatedLintName, DeprecatedLintNameFromCommandLine, - IgnoredUnlessCrateSpecified, OverruledAttribute, OverruledAttributeLint, OverruledAttributeSub, - RemovedLint, RemovedLintFromCommandLine, RenamedLint, RenamedLintFromCommandLine, - RenamedLintSuggestion, RequestedLevel, UnknownLint, UnknownLintFromCommandLine, - UnknownLintSuggestion, UnknownToolInScopedLint, UnsupportedGroup, + CheckNameUnknownTool, DeprecatedLintNameFromCommandLine, IgnoredUnlessCrateSpecified, + OverruledAttribute, OverruledAttributeLint, OverruledAttributeSub, RemovedLintFromCommandLine, + RenamedLintFromCommandLine, RequestedLevel, UnknownLintFromCommandLine, UnsupportedGroup, }; use crate::late::unerased_lint_store; @@ -704,6 +704,7 @@ where CRATE_NODE_ID, Some(self.features), ShouldEmit::ErrorsAndLints { recovery: Recovery::Allowed }, + None, Some(self.registered_lint_tools), ); self.add_hir_inner(&parsed, is_crate_node) @@ -728,13 +729,9 @@ where return; }; - let sess = self.sess; - - // FIXME: consider performing these checks in attribute parsing instead for (lint_index, lint_check) in lint_checks.into_iter().enumerate() { - let LintCheck { lint_name, kind, reason, attr_id, attr_span: _, lint_span, tool_span } = + let LintCheck { lint_name_normalized, lint_span, kind, reason, attr_id, attr_span: _ } = lint_check; - let LintName { tool, name: _ } = lint_name; let level = match kind { LintCheckKind::Allow => Level::Allow, @@ -749,105 +746,9 @@ where let lint_id = (level == Level::Expect) .then(|| self.provider.mk_lint_expectation_id(attr_id.attr_id, lint_index as u16)); - let lint_result = self.store.check_lint_name(lint_name, self.registered_lint_tools); - - let (ids, name): (_, LintName) = match lint_result { - CheckLintNameResult::Ok(ids) => (ids, lint_name), - - CheckLintNameResult::Tool(ids, new_lint_name) => { - let name = match new_lint_name { - None => lint_name, - Some(replacement) => { - self.emit_span_lint( - builtin::RENAMED_AND_REMOVED_LINTS, - lint_span.into(), - DeprecatedLintName { - lint_name, - suggestion: lint_span, - replacement, - }, - ); - replacement - } - }; - (ids, name) - } - - CheckLintNameResult::MissingTool => { - // If `MissingTool` is returned, then either the lint does not - // exist in the tool or the code was not compiled with the tool and - // therefore the lint was never added to the `LintStore`. To detect - // this is the responsibility of the lint tool. - continue; - } - - CheckLintNameResult::NoTool(tool_name) => { - sess.dcx().emit_err(UnknownToolInScopedLint { - span: Some(tool_span.unwrap()), - tool_name, - lint_name, - is_nightly_build: sess.is_nightly_build(), - }); - continue; - } - - CheckLintNameResult::Renamed(replacement) => { - if self.lint_added_lints { - let suggestion = - RenamedLintSuggestion::WithSpan { suggestion: lint_span, replacement }; - - self.emit_span_lint( - RENAMED_AND_REMOVED_LINTS, - lint_span.into(), - RenamedLint { name: lint_name, replacement, suggestion }, - ); - } - - // If this lint was renamed, apply the new lint instead of ignoring the - // attribute. Ignore any errors or warnings that happen because the new - // name is inaccurate. - let replace_check = - self.store.check_lint_name(replacement, self.registered_lint_tools); - let (CheckLintNameResult::Ok(ids) | CheckLintNameResult::Tool(ids, _)) = - replace_check - else { - panic!("renamed lint does not exist: {replacement} :{replace_check:?}"); - }; - - (ids, replacement) - } - - CheckLintNameResult::Removed(ref reason) => { - if self.lint_added_lints { - self.emit_span_lint( - RENAMED_AND_REMOVED_LINTS, - lint_span.into(), - RemovedLint { name: lint_name, reason }, - ); - } - continue; - } - - CheckLintNameResult::NoLint(suggestion) => { - if self.lint_added_lints { - let suggestion = suggestion.map(|(replacement, from_rustc)| { - UnknownLintSuggestion::WithSpan { - suggestion: lint_span, - replacement, - from_rustc, - } - }); - self.emit_span_lint( - UNKNOWN_LINTS, - lint_span.into(), - UnknownLint { name: lint_name, suggestion }, - ); - } - continue; - } - }; + let src = LintLevelSource::Node { name: lint_name_normalized, span: lint_span, reason }; + let ids = self.store.find_lints(lint_name_normalized).unwrap(); - let src = LintLevelSource::Node { name, span: lint_span, reason }; for &id in ids { if self.check_gated_lint(id, lint_span, false) { self.insert_spec(id, LevelSpec::new(level, lint_id, src)); @@ -869,7 +770,12 @@ where }; self.provider.push_expectation( expect_id, - LintExpectation::new(reason, lint_span, is_unfulfilled_lint_expectations, tool), + LintExpectation::new( + reason, + lint_span, + is_unfulfilled_lint_expectations, + lint_name_normalized.tool, + ), ); } } diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 97c500ba74cee..1086e9b0dc982 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -139,7 +139,7 @@ use unused::*; #[rustfmt::skip] pub use builtin::MissingDoc; -pub use context::{CheckLintNameResult, EarlyContext, LateContext, LintContext, LintStore}; +pub use context::{EarlyContext, LateContext, LintContext, LintStore}; pub use early::diagnostics::DiagAndSess; pub use early::{EarlyCheckNode, check_ast_node}; pub use late::{check_crate, late_lint_mod, unerased_lint_store}; diff --git a/compiler/rustc_lint/src/tests.rs b/compiler/rustc_lint/src/tests.rs index b4f789564600d..78e94e0352624 100644 --- a/compiler/rustc_lint/src/tests.rs +++ b/compiler/rustc_lint/src/tests.rs @@ -1,7 +1,7 @@ #![allow(rustc::symbol_intern_string_literal)] +use rustc_lint_defs::LintName; use rustc_span::{Symbol, create_default_session_globals_then, sym}; -use rustc_structures::LintName; use crate::builtin::is_hexagon_register_span; diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index 5e7b417ef68a4..faa45d9bf4550 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -5,6 +5,7 @@ use std::borrow::Cow; use std::fmt::Display; +pub use lint_name::LintName; use rustc_ast::attr::version::RustcVersion; use rustc_data_structures::fx::FxIndexSet; use rustc_data_structures::stable_hash::{StableCompare, StableHash, StableHashCtxt, StableHasher}; @@ -18,6 +19,7 @@ use serde::{Deserialize, Serialize}; pub use self::Level::*; pub mod builtin; +mod lint_name; #[macro_export] macro_rules! pluralize { @@ -603,6 +605,29 @@ pub enum DeprecatedSinceKind { pub type RegisteredTools = FxIndexSet; +#[derive(Debug)] +pub enum CheckLintNameResult<'a> { + Ok(&'a [LintId]), + /// Lint doesn't exist. Potentially contains a suggestion for a correct lint name. + NoLint(Option<(LintName, bool)>), + /// The lint refers to a tool that has not been registered. + NoTool(Symbol), + /// The lint has been renamed to a new name. + Renamed(LintName), + /// The lint has been removed due to the given reason. + Removed(String), + + /// The lint is from a tool. The `LintId` will be returned as if it were a + /// rustc lint. The `Option` indicates if the lint has been + /// renamed. + Tool(&'a [LintId], Option), + + /// The lint is from a tool. Either the lint does not exist in the tool or + /// the code was not compiled with the tool and therefore the lint was + /// never added to the `LintStore`. + MissingTool, +} + /// Declares a static item of type `&'static Lint`. /// /// See for diff --git a/compiler/rustc_structures/src/lint.rs b/compiler/rustc_lint_defs/src/lint_name.rs similarity index 95% rename from compiler/rustc_structures/src/lint.rs rename to compiler/rustc_lint_defs/src/lint_name.rs index b76390c47ac4f..329ec6c62a1f4 100644 --- a/compiler/rustc_structures/src/lint.rs +++ b/compiler/rustc_lint_defs/src/lint_name.rs @@ -1,11 +1,10 @@ use std::fmt; -#[cfg(feature = "nightly")] use rustc_macros::{Decodable, Encodable, StableHash}; use rustc_span::{Symbol, sym}; #[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Ord, PartialOrd)] -#[cfg_attr(feature = "nightly", derive(StableHash, Encodable, Decodable))] +#[derive(StableHash, Encodable, Decodable)] pub struct LintName { /// The lint's tool name, if present. pub tool: Option, @@ -82,7 +81,6 @@ impl fmt::Display for LintName { } } -#[cfg(feature = "nightly")] impl rustc_error_messages::IntoDiagArg for LintName { fn into_diag_arg( self, diff --git a/compiler/rustc_middle/src/lint.rs b/compiler/rustc_middle/src/lint.rs index 94acf8e303a03..08ba9b132c89d 100644 --- a/compiler/rustc_middle/src/lint.rs +++ b/compiler/rustc_middle/src/lint.rs @@ -5,13 +5,12 @@ use rustc_data_structures::sorted_map::SortedMap; use rustc_errors::{Diag, Diagnostic, EmissionOverride, MultiSpan}; use rustc_hir::{HirId, ItemLocalId}; use rustc_lint_defs::{ - EditionFcw, FutureIncompatibilityReason, Level, Lint, LintExpectationId, LintId, + EditionFcw, FutureIncompatibilityReason, Level, Lint, LintExpectationId, LintId, LintName, StableLintExpectationId, UnstableLintExpectationId, builtin, }; use rustc_macros::{Decodable, Encodable, StableHash}; use rustc_session::Session; use rustc_span::{DUMMY_SP, ExpnKind, Span, Symbol, kw, sym}; -use rustc_structures::LintName; use tracing::instrument; use crate::ty::TyCtxt; diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index d34aa0e773b1e..9143ffe1c7fb2 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -1344,8 +1344,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } fn check_lint_check(&self, hir_id: HirId, lints: &[LintCheck]) { - for LintCheck { lint_name, lint_span, .. } in lints { - if lint_name.is(sym::dead_code_pub_in_binary) { + for LintCheck { lint_name_normalized, lint_span, .. } in lints { + if lint_name_normalized.is(sym::dead_code_pub_in_binary) { if !self.tcx.crate_types().contains(&CrateType::Executable) { self.tcx.emit_node_span_lint( UNUSED_ATTRIBUTES, @@ -1359,7 +1359,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } } - if lint_name.is(sym::linker_messages) | lint_name.is(sym::linker_info) { + if lint_name_normalized.is(sym::linker_messages) + | lint_name_normalized.is(sym::linker_info) + { if hir_id == CRATE_HIR_ID && self .tcx diff --git a/compiler/rustc_resolve/src/def_collector.rs b/compiler/rustc_resolve/src/def_collector.rs index 474615c9a7672..6277fb69dc212 100644 --- a/compiler/rustc_resolve/src/def_collector.rs +++ b/compiler/rustc_resolve/src/def_collector.rs @@ -177,6 +177,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> { &self.r.tcx.sess, self.r.features, self.r.tcx().registered_attr_tools(()), + self.r.tcx().registered_lint_tools(()), ShouldEmit::Nothing, ); let attrs = parser.parse_attribute_list( diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index b69c26639e7e8..bd3aff546415f 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -20,12 +20,13 @@ use rustc_errors::{ Diag, DiagCtxt, DiagCtxtHandle, DiagMessage, Diagnostic, ErrorGuaranteed, PResult, TerminalUrl, }; use rustc_feature::UnstableFeatures; +use rustc_lint_defs::{CheckLintNameResult, LintName, RegisteredTools}; use rustc_macros::StableHash; pub use rustc_span::def_id::StableCrateId; use rustc_span::edition::Edition; use rustc_span::source_map::{FilePathMapping, SourceMap}; use rustc_span::{RealFileName, Span, Symbol}; -use rustc_structures::{CrateType, Limit, LintName}; +use rustc_structures::{CrateType, Limit}; use rustc_target::asm::InlineAsmArch; use rustc_target::spec::{ Arch, CfgAbi, CodeModel, DebuginfoKind, MergeFunctions, Os, PanicStrategy, RelocModel, @@ -82,6 +83,12 @@ pub struct CompilerIO { pub trait DynLintStore: Any + DynSync + DynSend { /// Provides a way to access lint groups without depending on `rustc_lint` fn lint_groups_iter(&self) -> Box + '_>; + + fn check_attribute_lint_name( + &self, + lint_name: LintName, + lint_tools: &RegisteredTools, + ) -> CheckLintNameResult<'_>; } /// Hardware pointer-signing keys in ARM8.3. diff --git a/compiler/rustc_structures/src/lib.rs b/compiler/rustc_structures/src/lib.rs index caa3cdae45acc..cb5dccdfcd180 100644 --- a/compiler/rustc_structures/src/lib.rs +++ b/compiler/rustc_structures/src/lib.rs @@ -5,14 +5,12 @@ mod collapse_macro_debug_info; mod crate_type; mod limit; -mod lint; mod native_lib_kind; mod sanitizer_set; pub use collapse_macro_debug_info::CollapseMacroDebuginfo; pub use crate_type::CrateType; pub use limit::Limit; -pub use lint::LintName; pub use native_lib_kind::NativeLibKind; pub use sanitizer_set::SanitizerSet; diff --git a/src/tools/clippy/clippy_lints/src/cargo/lint_groups_priority.rs b/src/tools/clippy/clippy_lints/src/cargo/lint_groups_priority.rs index dd87fe61b16ea..6977503bfb52f 100644 --- a/src/tools/clippy/clippy_lints/src/cargo/lint_groups_priority.rs +++ b/src/tools/clippy/clippy_lints/src/cargo/lint_groups_priority.rs @@ -4,7 +4,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_lint::{LateContext, unerased_lint_store}; use rustc_span::{BytePos, Pos as _, SourceFile, Span, SyntaxContext}; -use rustc_structures::LintName; +use rustc_lint_defs::LintName; use std::ops::Range; use std::path::Path; use toml::Spanned; diff --git a/src/tools/clippy/clippy_lints/src/collapsible_if.rs b/src/tools/clippy/clippy_lints/src/collapsible_if.rs index e334eae38c0dc..48fec57d0066e 100644 --- a/src/tools/clippy/clippy_lints/src/collapsible_if.rs +++ b/src/tools/clippy/clippy_lints/src/collapsible_if.rs @@ -11,7 +11,7 @@ use rustc_hir::{Block, Expr, ExprKind, StmtKind}; use rustc_lexer::TokenKind; use rustc_lint::{LateContext, LateLintPass, impl_lint_pass}; use rustc_span::{BytePos, Span, Symbol}; -use rustc_structures::LintName; +use rustc_lint_defs::LintName; declare_clippy_lint! { /// ### What it does @@ -248,7 +248,7 @@ impl CollapsibleIf { matches!( lint, LintCheck { - lint_name: LintName { + lint_name_normalized: LintName { tool: Some(sym::clippy), .. }, @@ -257,7 +257,7 @@ impl CollapsibleIf { } ) }) - .any(|lint| [expected_lint_name, sym::style, sym::all].contains(&lint.lint_name.name)) => + .any(|lint| [expected_lint_name, sym::style, sym::all].contains(&lint.lint_name_normalized.name)) => { let attr_span = lints.first().unwrap().attr_span.to(lints.last().unwrap().attr_span); // There is an `expect` attribute -- check that there is no _other_ significant text diff --git a/src/tools/clippy/clippy_lints/src/lib.rs b/src/tools/clippy/clippy_lints/src/lib.rs index 49d15a5f15dc6..718548a37d9aa 100644 --- a/src/tools/clippy/clippy_lints/src/lib.rs +++ b/src/tools/clippy/clippy_lints/src/lib.rs @@ -37,6 +37,7 @@ extern crate rustc_index; extern crate rustc_infer; extern crate rustc_lexer; extern crate rustc_lint; +extern crate rustc_lint_defs; extern crate rustc_middle; extern crate rustc_parse_format; extern crate rustc_resolve; diff --git a/src/tools/clippy/clippy_lints/src/returns/needless_return.rs b/src/tools/clippy/clippy_lints/src/returns/needless_return.rs index 915211d74fc1b..677b907a1fb2c 100644 --- a/src/tools/clippy/clippy_lints/src/returns/needless_return.rs +++ b/src/tools/clippy/clippy_lints/src/returns/needless_return.rs @@ -14,7 +14,7 @@ use rustc_hir::{Body, Expr, ExprKind, HirId, MatchSource, StmtKind}; use rustc_lint::{LateContext, LintContext as _}; use rustc_middle::ty::{self, Ty}; use rustc_span::{BytePos, Pos as _, Span}; -use rustc_structures::LintName; +use rustc_lint_defs::LintName; use std::borrow::Cow; use std::fmt::Display; @@ -189,7 +189,7 @@ fn check_final_expr<'tcx>( matches!( lint, LintCheck { - lint_name: LintName { + lint_name_normalized: LintName { tool: Some(sym::clippy), name: sym::needless_return | sym::style | sym::all | sym::warnings }, diff --git a/tests/pretty/delegation/generics.pp b/tests/pretty/delegation/generics.pp index f5b42b351633d..dce3886a4f15c 100644 --- a/tests/pretty/delegation/generics.pp +++ b/tests/pretty/delegation/generics.pp @@ -1,4 +1,4 @@ -#![attr = LintCheck([LintCheck {lint_name: LintName { tool: None, name: "incomplete_features" }, +#![attr = LintCheck([LintCheck {lint_name_normalized: LintName { tool: None, name: "incomplete_features" }, kind: Allow}])] #![attr = Feature([fn_delegation#0])] extern crate std; diff --git a/tests/pretty/delegation/inherit-attributes.pp b/tests/pretty/delegation/inherit-attributes.pp index 53f977ebbb7ac..b08a2f37eb4b2 100644 --- a/tests/pretty/delegation/inherit-attributes.pp +++ b/tests/pretty/delegation/inherit-attributes.pp @@ -1,4 +1,4 @@ -#![attr = LintCheck([LintCheck {lint_name: LintName { tool: None, name: "incomplete_features" }, +#![attr = LintCheck([LintCheck {lint_name_normalized: LintName { tool: None, name: "incomplete_features" }, kind: Allow}])] #![attr = Feature([fn_delegation#0])] extern crate std; diff --git a/tests/pretty/delegation/inline-attribute.pp b/tests/pretty/delegation/inline-attribute.pp index 8787a9e167405..faaacfbc6a4b5 100644 --- a/tests/pretty/delegation/inline-attribute.pp +++ b/tests/pretty/delegation/inline-attribute.pp @@ -1,4 +1,4 @@ -#![attr = LintCheck([LintCheck {lint_name: LintName { tool: None, name: "incomplete_features" }, +#![attr = LintCheck([LintCheck {lint_name_normalized: LintName { tool: None, name: "incomplete_features" }, kind: Allow}])] #![attr = Feature([fn_delegation#0])] extern crate std; diff --git a/tests/pretty/hir-delegation.pp b/tests/pretty/hir-delegation.pp index 97364da0e02d8..1b74b8f8ba911 100644 --- a/tests/pretty/hir-delegation.pp +++ b/tests/pretty/hir-delegation.pp @@ -1,4 +1,4 @@ -#![attr = LintCheck([LintCheck {lint_name: LintName { tool: None, name: "incomplete_features" }, +#![attr = LintCheck([LintCheck {lint_name_normalized: LintName { tool: None, name: "incomplete_features" }, kind: Allow}])] #![attr = Feature([fn_delegation#0])] extern crate std; diff --git a/tests/pretty/hir-lifetimes.pp b/tests/pretty/hir-lifetimes.pp index daee41b37889d..85b36fba7ef3c 100644 --- a/tests/pretty/hir-lifetimes.pp +++ b/tests/pretty/hir-lifetimes.pp @@ -1,4 +1,4 @@ -#![attr = LintCheck([LintCheck {lint_name: LintName { tool: None, name: "unused" }, +#![attr = LintCheck([LintCheck {lint_name_normalized: LintName { tool: None, name: "unused" }, kind: Allow}])] extern crate std; #[attr = PreludeImport] diff --git a/tests/pretty/lint-attrs-filtered-out.pp b/tests/pretty/lint-attrs-filtered-out.pp new file mode 100644 index 0000000000000..796fa2fe239b0 --- /dev/null +++ b/tests/pretty/lint-attrs-filtered-out.pp @@ -0,0 +1,11 @@ +extern crate std; +#[attr = PreludeImport] +use ::std::prelude::rust_2015::*; +//@ pretty-compare-only +//@ pretty-mode:hir +//@ pp-exact:lint-attrs-filtered-out.pp + +// `does_not_exist` is filtered out on the hir +#[attr = LintCheck([LintCheck {lint_name_normalized: LintName { tool: None, name: "dead_code" }, +kind: Deny}])] +fn main() { } diff --git a/tests/pretty/lint-attrs-filtered-out.rs b/tests/pretty/lint-attrs-filtered-out.rs new file mode 100644 index 0000000000000..9dc4898f3ff41 --- /dev/null +++ b/tests/pretty/lint-attrs-filtered-out.rs @@ -0,0 +1,7 @@ +//@ pretty-compare-only +//@ pretty-mode:hir +//@ pp-exact:lint-attrs-filtered-out.pp + +// `does_not_exist` is filtered out on the hir +#[deny(dead_code, does_not_exist)] +fn main() {} diff --git a/tests/pretty/pin-ergonomics-hir.pp b/tests/pretty/pin-ergonomics-hir.pp index 624cd37ce5fc4..11b4a87b1c4ce 100644 --- a/tests/pretty/pin-ergonomics-hir.pp +++ b/tests/pretty/pin-ergonomics-hir.pp @@ -1,7 +1,7 @@ #![attr = Feature([pin_ergonomics#0])] -#![attr = LintCheck([LintCheck {lint_name: LintName { tool: None, name: "dead_code" }, +#![attr = LintCheck([LintCheck {lint_name_normalized: LintName { tool: None, name: "dead_code" }, kind: Allow}, -LintCheck {lint_name: LintName { tool: None, name: "incomplete_features" }, +LintCheck {lint_name_normalized: LintName { tool: None, name: "incomplete_features" }, kind: Allow}])] extern crate std; #[attr = PreludeImport] diff --git a/tests/ui/eii/cfg_on_eii.stdout b/tests/ui/eii/cfg_on_eii.stdout index 226ad1849fa43..0dddbad4f9165 100644 --- a/tests/ui/eii/cfg_on_eii.stdout +++ b/tests/ui/eii/cfg_on_eii.stdout @@ -1,5 +1,5 @@ #![attr = Feature([extern_item_impls#0])] -#![attr = LintCheck([LintCheck {lint_name: LintName { tool: None, name: "deprecated" }, +#![attr = LintCheck([LintCheck {lint_name_normalized: LintName { tool: None, name: "deprecated" }, kind: Deny}])] extern crate std; #[attr = PreludeImport] diff --git a/tests/ui/feature-gates/feature-gate-strict_provenance_lints.stderr b/tests/ui/feature-gates/feature-gate-strict_provenance_lints.stderr index 4e7c835b57912..d14e7328c308c 100644 --- a/tests/ui/feature-gates/feature-gate-strict_provenance_lints.stderr +++ b/tests/ui/feature-gates/feature-gate-strict_provenance_lints.stderr @@ -10,14 +10,6 @@ LL | #![deny(implicit_provenance_casts)] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date = note: `#[warn(unknown_lints)]` on by default -warning: lint `fuzzy_provenance_casts` has been renamed to `implicit_provenance_casts` - --> $DIR/feature-gate-strict_provenance_lints.rs:7:9 - | -LL | #![deny(fuzzy_provenance_casts)] - | ^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `implicit_provenance_casts` - | - = note: `#[warn(renamed_and_removed_lints)]` on by default - warning: unknown lint: `implicit_provenance_casts` --> $DIR/feature-gate-strict_provenance_lints.rs:7:9 | @@ -29,12 +21,6 @@ LL | #![deny(fuzzy_provenance_casts)] = help: add `#![feature(strict_provenance_lints)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -warning: lint `lossy_provenance_casts` has been renamed to `implicit_provenance_casts` - --> $DIR/feature-gate-strict_provenance_lints.rs:10:9 - | -LL | #![deny(lossy_provenance_casts)] - | ^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `implicit_provenance_casts` - warning: unknown lint: `implicit_provenance_casts` --> $DIR/feature-gate-strict_provenance_lints.rs:10:9 | @@ -46,5 +32,19 @@ LL | #![deny(lossy_provenance_casts)] = help: add `#![feature(strict_provenance_lints)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date +warning: lint `fuzzy_provenance_casts` has been renamed to `implicit_provenance_casts` + --> $DIR/feature-gate-strict_provenance_lints.rs:7:9 + | +LL | #![deny(fuzzy_provenance_casts)] + | ^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `implicit_provenance_casts` + | + = note: `#[warn(renamed_and_removed_lints)]` on by default + +warning: lint `lossy_provenance_casts` has been renamed to `implicit_provenance_casts` + --> $DIR/feature-gate-strict_provenance_lints.rs:10:9 + | +LL | #![deny(lossy_provenance_casts)] + | ^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `implicit_provenance_casts` + warning: 5 warnings emitted diff --git a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.stderr b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.stderr index f685a989c0aa6..9b091ff4fbf91 100644 --- a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.stderr +++ b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.stderr @@ -12,6 +12,27 @@ warning: `#[macro_escape]` is a deprecated synonym for `#[macro_use]` LL | #[macro_escape] | ^^^^^^^^^^^^^^^ +warning: the feature `rust1` has been stable since 1.0.0 and no longer requires an attribute to enable + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:101:12 + | +LL | #![feature(rust1)] + | ^^^^^ + | + = note: `#[warn(stable_features)]` on by default + +warning: unused attribute + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:257:9 + | +LL | #![path="3800"] + | ^^^^^^^^^^^^^^^ help: remove this attribute + | + = note: `#[path]` is unused on this inline module +note: the lint level is defined here + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:35:9 + | +LL | #![warn(unused_attributes, unknown_lints)] + | ^^^^^^^^^^^^^^^^^ + warning: unknown lint: `x5400` --> $DIR/issue-43106-gating-of-builtin-attrs.rs:41:9 | @@ -42,6 +63,87 @@ warning: unknown lint: `x5100` LL | #![deny(x5100)] | ^^^^^ +warning: the `macro_use` attribute cannot be used on crates + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:45:4 + | +LL | #![macro_use] + | ^^^^^^^^^ + | + = help: the `macro_use` attribute can be applied to extern crates and modules + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + +warning: the `should_panic` attribute cannot be used on crates + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:51:4 + | +LL | #![should_panic] + | ^^^^^^^^^^^^ + | + = help: the `should_panic` attribute can only be applied to functions + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + +warning: the `ignore` attribute cannot be used on crates + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:55:4 + | +LL | #![ignore] + | ^^^^^^ + | + = help: the `ignore` attribute can only be applied to functions + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + +warning: the `proc_macro_derive` attribute cannot be used on crates + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:63:4 + | +LL | #![proc_macro_derive(Test)] + | ^^^^^^^^^^^^^^^^^ + | + = help: the `proc_macro_derive` attribute can only be applied to functions + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + +warning: the `cold` attribute cannot be used on crates + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:68:4 + | +LL | #![cold] + | ^^^^ + | + = help: the `cold` attribute can only be applied to functions + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + +warning: the `link` attribute cannot be used on crates + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:72:4 + | +LL | #![link(name = "x")] + | ^^^^ + | + = help: the `link` attribute can only be applied to foreign modules + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + +warning: the `link_name` attribute cannot be used on crates + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:76:4 + | +LL | #![link_name = "1900"] + | ^^^^^^^^^ + | + = help: the `link_name` attribute can be applied to foreign functions and foreign statics + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + +warning: the `link_section` attribute cannot be used on crates + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:81:4 + | +LL | #![link_section = ",1800"] + | ^^^^^^^^^^^^ + | + = help: the `link_section` attribute can be applied to functions and statics + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + +warning: the `must_use` attribute cannot be used on crates + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:86:4 + | +LL | #![must_use] + | ^^^^^^^^ + | + = help: the `must_use` attribute can be applied to data types, functions, and traits + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + warning: unknown lint: `x5400` --> $DIR/issue-43106-gating-of-builtin-attrs.rs:112:8 | @@ -186,108 +288,6 @@ warning: unknown lint: `x5100` LL | #[deny(x5100)] impl S { } | ^^^^^ -warning: the feature `rust1` has been stable since 1.0.0 and no longer requires an attribute to enable - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:101:12 - | -LL | #![feature(rust1)] - | ^^^^^ - | - = note: `#[warn(stable_features)]` on by default - -warning: unused attribute - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:257:9 - | -LL | #![path="3800"] - | ^^^^^^^^^^^^^^^ help: remove this attribute - | - = note: `#[path]` is unused on this inline module -note: the lint level is defined here - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:35:9 - | -LL | #![warn(unused_attributes, unknown_lints)] - | ^^^^^^^^^^^^^^^^^ - -warning: the `macro_use` attribute cannot be used on crates - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:45:4 - | -LL | #![macro_use] - | ^^^^^^^^^ - | - = help: the `macro_use` attribute can be applied to extern crates and modules - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - -warning: the `should_panic` attribute cannot be used on crates - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:51:4 - | -LL | #![should_panic] - | ^^^^^^^^^^^^ - | - = help: the `should_panic` attribute can only be applied to functions - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - -warning: the `ignore` attribute cannot be used on crates - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:55:4 - | -LL | #![ignore] - | ^^^^^^ - | - = help: the `ignore` attribute can only be applied to functions - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - -warning: the `proc_macro_derive` attribute cannot be used on crates - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:63:4 - | -LL | #![proc_macro_derive(Test)] - | ^^^^^^^^^^^^^^^^^ - | - = help: the `proc_macro_derive` attribute can only be applied to functions - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - -warning: the `cold` attribute cannot be used on crates - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:68:4 - | -LL | #![cold] - | ^^^^ - | - = help: the `cold` attribute can only be applied to functions - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - -warning: the `link` attribute cannot be used on crates - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:72:4 - | -LL | #![link(name = "x")] - | ^^^^ - | - = help: the `link` attribute can only be applied to foreign modules - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - -warning: the `link_name` attribute cannot be used on crates - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:76:4 - | -LL | #![link_name = "1900"] - | ^^^^^^^^^ - | - = help: the `link_name` attribute can be applied to foreign functions and foreign statics - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - -warning: the `link_section` attribute cannot be used on crates - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:81:4 - | -LL | #![link_section = ",1800"] - | ^^^^^^^^^^^^ - | - = help: the `link_section` attribute can be applied to functions and statics - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - -warning: the `must_use` attribute cannot be used on crates - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:86:4 - | -LL | #![must_use] - | ^^^^^^^^ - | - = help: the `must_use` attribute can be applied to data types, functions, and traits - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - warning: the `macro_use` attribute cannot be used on functions --> $DIR/issue-43106-gating-of-builtin-attrs.rs:192:7 | diff --git a/tests/ui/lint/lint-check-on-macro.rs b/tests/ui/lint/lint-check-on-macro.rs new file mode 100644 index 0000000000000..ae409c926e7bf --- /dev/null +++ b/tests/ui/lint/lint-check-on-macro.rs @@ -0,0 +1,17 @@ +macro_rules! identity { ($( $tt:tt )*) => { $( $tt )* } } + +fn main() { + #[expect(wat::doesnt_exist)] + //~^ WARN cannot be used on + //~| WARN previously accepted + //~| ERROR unknown tool name + println!(); + + identity!{ + #[expect(wat::doesnt_exist)] + //~^ WARN cannot be used on + //~| WARN previously accepted + //~| ERROR unknown tool name + println!(); + } +} diff --git a/tests/ui/lint/lint-check-on-macro.stderr b/tests/ui/lint/lint-check-on-macro.stderr new file mode 100644 index 0000000000000..0a51b51181f54 --- /dev/null +++ b/tests/ui/lint/lint-check-on-macro.stderr @@ -0,0 +1,44 @@ +error[E0710]: unknown tool name `wat` found in scoped lint: `wat::doesnt_exist` + --> $DIR/lint-check-on-macro.rs:4:14 + | +LL | #[expect(wat::doesnt_exist)] + | ^^^ + | + = help: add `#![register_tool(wat)]` to the crate root + +error[E0710]: unknown tool name `wat` found in scoped lint: `wat::doesnt_exist` + --> $DIR/lint-check-on-macro.rs:11:18 + | +LL | #[expect(wat::doesnt_exist)] + | ^^^ + | + = help: add `#![register_tool(wat)]` to the crate root + +warning: the `expect` attribute cannot be used on macro calls + --> $DIR/lint-check-on-macro.rs:4:7 + | +LL | #[expect(wat::doesnt_exist)] + | ^^^^^^ +... +LL | println!(); + | + = help: the `expect` attribute can be applied to associated consts, associated types, break expressions, const parameters, constants, crates, data types, enum variants, extern crates, for loops, foreign modules, foreign statics, function params, functions, global asms, impl blocks, lifetime parameters, loops, macro defs, match arms, modules, pattern fields, statics, struct fields, trait aliases, traits, type aliases, type parameters, use statements, and while loops + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute + = note: requested on the command line with `-W unused-attributes` + +warning: the `expect` attribute cannot be used on macro calls + --> $DIR/lint-check-on-macro.rs:11:11 + | +LL | #[expect(wat::doesnt_exist)] + | ^^^^^^ +... +LL | println!(); + | + = help: the `expect` attribute can be applied to associated consts, associated types, break expressions, const parameters, constants, crates, data types, enum variants, extern crates, for loops, foreign modules, foreign statics, function params, functions, global asms, impl blocks, lifetime parameters, loops, macro defs, match arms, modules, pattern fields, statics, struct fields, trait aliases, traits, type aliases, type parameters, use statements, and while loops + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute + +error: aborting due to 2 previous errors; 2 warnings emitted + +For more information about this error, try `rustc --explain E0710`. diff --git a/tests/ui/lint/register-tool-lint.rs b/tests/ui/lint/register-tool-lint.rs index 17d3afbf6e26e..f56d9a0a8c362 100644 --- a/tests/ui/lint/register-tool-lint.rs +++ b/tests/ui/lint/register-tool-lint.rs @@ -5,5 +5,3 @@ #![warn(abc::my_lint)] //~^ ERROR unknown tool name `abc` found in scoped lint //~| HELP add `#![register_tool(abc)]` -//~| ERROR unknown tool name `abc` -//~| HELP add `#![register_tool(abc)]` diff --git a/tests/ui/lint/register-tool-lint.stderr b/tests/ui/lint/register-tool-lint.stderr index 7ebdbdec92972..98b4af935d340 100644 --- a/tests/ui/lint/register-tool-lint.stderr +++ b/tests/ui/lint/register-tool-lint.stderr @@ -6,15 +6,6 @@ LL | #![warn(abc::my_lint)] | = help: add `#![register_tool(abc)]` to the crate root -error[E0710]: unknown tool name `abc` found in scoped lint: `abc::my_lint` - --> $DIR/register-tool-lint.rs:5:9 - | -LL | #![warn(abc::my_lint)] - | ^^^ - | - = help: add `#![register_tool(abc)]` to the crate root - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0710`. diff --git a/tests/ui/lint/renamed-lints-still-apply.stderr b/tests/ui/lint/renamed-lints-still-apply.stderr index 9eaf711293388..5e4dae1e21be7 100644 --- a/tests/ui/lint/renamed-lints-still-apply.stderr +++ b/tests/ui/lint/renamed-lints-still-apply.stderr @@ -1,11 +1,3 @@ -warning: lint `single_use_lifetime` has been renamed to `single_use_lifetimes` - --> $DIR/renamed-lints-still-apply.rs:2:9 - | -LL | #![deny(single_use_lifetime)] - | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `single_use_lifetimes` - | - = note: `#[warn(renamed_and_removed_lints)]` on by default - error: lifetime parameter `'a` only used once --> $DIR/renamed-lints-still-apply.rs:6:9 | @@ -25,5 +17,13 @@ LL - fn _foo<'a>(_x: &'a u32) {} LL + fn _foo(_x: &u32) {} | +warning: lint `single_use_lifetime` has been renamed to `single_use_lifetimes` + --> $DIR/renamed-lints-still-apply.rs:2:9 + | +LL | #![deny(single_use_lifetime)] + | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `single_use_lifetimes` + | + = note: `#[warn(renamed_and_removed_lints)]` on by default + error: aborting due to 1 previous error; 1 warning emitted diff --git a/tests/ui/tool-attributes/cross-crate.rs b/tests/ui/tool-attributes/cross-crate.rs index 1992174aca3e1..11c594de02aa3 100644 --- a/tests/ui/tool-attributes/cross-crate.rs +++ b/tests/ui/tool-attributes/cross-crate.rs @@ -5,6 +5,4 @@ extern crate use_tool; #[foo::bar] //~ ERROR cannot find module or crate `foo` in this scope #[allow(foo::baz)] //~ ERROR unknown tool name `foo` - //~| ERROR unknown tool name `foo` - //~| ERROR unknown tool name `foo` fn main() {} diff --git a/tests/ui/tool-attributes/cross-crate.stderr b/tests/ui/tool-attributes/cross-crate.stderr index 051a1b05405e9..6b669601f24f2 100644 --- a/tests/ui/tool-attributes/cross-crate.stderr +++ b/tests/ui/tool-attributes/cross-crate.stderr @@ -1,11 +1,3 @@ -error[E0710]: unknown tool name `foo` found in scoped lint: `foo::baz` - --> $DIR/cross-crate.rs:7:9 - | -LL | #[allow(foo::baz)] - | ^^^ - | - = help: add `#![register_tool(foo)]` to the crate root - error[E0433]: cannot find module or crate `foo` in this scope --> $DIR/cross-crate.rs:6:3 | @@ -19,18 +11,8 @@ LL | #[allow(foo::baz)] | ^^^ | = help: add `#![register_tool(foo)]` to the crate root - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error[E0710]: unknown tool name `foo` found in scoped lint: `foo::baz` - --> $DIR/cross-crate.rs:7:9 - | -LL | #[allow(foo::baz)] - | ^^^ - | - = help: add `#![register_tool(foo)]` to the crate root - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: aborting due to 4 previous errors +error: aborting due to 2 previous errors Some errors have detailed explanations: E0433, E0710. For more information about an error, try `rustc --explain E0433`. diff --git a/tests/ui/tool-attributes/tool_lints.rs b/tests/ui/tool-attributes/tool_lints.rs index 9e4aa7a939acb..0a9be75681ca5 100644 --- a/tests/ui/tool-attributes/tool_lints.rs +++ b/tests/ui/tool-attributes/tool_lints.rs @@ -1,5 +1,3 @@ #[warn(foo::bar)] //~^ ERROR unknown tool name `foo` found in scoped lint: `foo::bar` -//~| ERROR unknown tool name `foo` found in scoped lint: `foo::bar` -//~| ERROR unknown tool name `foo` found in scoped lint: `foo::bar` fn main() {} diff --git a/tests/ui/tool-attributes/tool_lints.stderr b/tests/ui/tool-attributes/tool_lints.stderr index eee0a9784ece8..a0c5316d95b07 100644 --- a/tests/ui/tool-attributes/tool_lints.stderr +++ b/tests/ui/tool-attributes/tool_lints.stderr @@ -6,24 +6,6 @@ LL | #[warn(foo::bar)] | = help: add `#![register_tool(foo)]` to the crate root -error[E0710]: unknown tool name `foo` found in scoped lint: `foo::bar` - --> $DIR/tool_lints.rs:1:8 - | -LL | #[warn(foo::bar)] - | ^^^ - | - = help: add `#![register_tool(foo)]` to the crate root - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error[E0710]: unknown tool name `foo` found in scoped lint: `foo::bar` - --> $DIR/tool_lints.rs:1:8 - | -LL | #[warn(foo::bar)] - | ^^^ - | - = help: add `#![register_tool(foo)]` to the crate root - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: aborting due to 3 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0710`. diff --git a/tests/ui/tool-attributes/unknown-lint-tool-name.rs b/tests/ui/tool-attributes/unknown-lint-tool-name.rs index 84ab7c1944ab2..cf26341d8b588 100644 --- a/tests/ui/tool-attributes/unknown-lint-tool-name.rs +++ b/tests/ui/tool-attributes/unknown-lint-tool-name.rs @@ -1,8 +1,4 @@ #![deny(foo::bar)] //~ ERROR unknown tool name `foo` found in scoped lint: `foo::bar` - //~| ERROR unknown tool name `foo` found in scoped lint: `foo::bar` - //~| ERROR unknown tool name `foo` found in scoped lint: `foo::bar` #[allow(foo::bar)] //~ ERROR unknown tool name `foo` found in scoped lint: `foo::bar` - //~| ERROR unknown tool name `foo` found in scoped lint: `foo::bar` - //~| ERROR unknown tool name `foo` found in scoped lint: `foo::bar` fn main() {} diff --git a/tests/ui/tool-attributes/unknown-lint-tool-name.stderr b/tests/ui/tool-attributes/unknown-lint-tool-name.stderr index 91baf88273756..8ef80efdbcf51 100644 --- a/tests/ui/tool-attributes/unknown-lint-tool-name.stderr +++ b/tests/ui/tool-attributes/unknown-lint-tool-name.stderr @@ -7,49 +7,13 @@ LL | #![deny(foo::bar)] = help: add `#![register_tool(foo)]` to the crate root error[E0710]: unknown tool name `foo` found in scoped lint: `foo::bar` - --> $DIR/unknown-lint-tool-name.rs:5:9 + --> $DIR/unknown-lint-tool-name.rs:3:9 | LL | #[allow(foo::bar)] | ^^^ | = help: add `#![register_tool(foo)]` to the crate root -error[E0710]: unknown tool name `foo` found in scoped lint: `foo::bar` - --> $DIR/unknown-lint-tool-name.rs:1:9 - | -LL | #![deny(foo::bar)] - | ^^^ - | - = help: add `#![register_tool(foo)]` to the crate root - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error[E0710]: unknown tool name `foo` found in scoped lint: `foo::bar` - --> $DIR/unknown-lint-tool-name.rs:5:9 - | -LL | #[allow(foo::bar)] - | ^^^ - | - = help: add `#![register_tool(foo)]` to the crate root - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error[E0710]: unknown tool name `foo` found in scoped lint: `foo::bar` - --> $DIR/unknown-lint-tool-name.rs:1:9 - | -LL | #![deny(foo::bar)] - | ^^^ - | - = help: add `#![register_tool(foo)]` to the crate root - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error[E0710]: unknown tool name `foo` found in scoped lint: `foo::bar` - --> $DIR/unknown-lint-tool-name.rs:5:9 - | -LL | #[allow(foo::bar)] - | ^^^ - | - = help: add `#![register_tool(foo)]` to the crate root - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: aborting due to 6 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0710`. diff --git a/tests/ui/unpretty/exhaustive.hir.stdout b/tests/ui/unpretty/exhaustive.hir.stdout index b1c956c2fe9f1..74f7079357f3a 100644 --- a/tests/ui/unpretty/exhaustive.hir.stdout +++ b/tests/ui/unpretty/exhaustive.hir.stdout @@ -3,9 +3,9 @@ coroutines#0, decl_macro#0, deref_patterns#0, explicit_tail_calls#0, gen_blocks#0, more_qualified_paths#0, never_patterns#0, pattern_types#0, pattern_type_macro#0, prelude_import#0, specialization#0, trace_macros#0, trait_alias#0, try_blocks#0, try_blocks_heterogeneous#0, yeet_expr#0])] -#![attr = LintCheck([LintCheck {lint_name: LintName { tool: None, name: "incomplete_features" }, +#![attr = LintCheck([LintCheck {lint_name_normalized: LintName { tool: None, name: "incomplete_features" }, kind: Allow}, -LintCheck {lint_name: LintName { tool: None, name: "unused_attributes" }, +LintCheck {lint_name_normalized: LintName { tool: None, name: "unused_attributes" }, kind: Allow}])] extern crate std; #[attr = PreludeImport] @@ -41,9 +41,9 @@ use self::prelude::*; * inner multi-line doc comment */ #[doc = "inner doc attribute"] -#[attr = LintCheck([LintCheck {lint_name: LintName { tool: None, name: "dead_code" }, +#[attr = LintCheck([LintCheck {lint_name_normalized: LintName { tool: None, name: "dead_code" }, kind: Allow}, -LintCheck {lint_name: LintName { tool: None, name: "unused_variables" }, +LintCheck {lint_name_normalized: LintName { tool: None, name: "unused_variables" }, kind: Allow}])] #[attr = NoStd] mod attributes { diff --git a/tests/ui/unpretty/struct-exprs-tuple-call-pretty-printing.stdout b/tests/ui/unpretty/struct-exprs-tuple-call-pretty-printing.stdout index d94a76fb882e1..aa1567fdb0d1c 100644 --- a/tests/ui/unpretty/struct-exprs-tuple-call-pretty-printing.stdout +++ b/tests/ui/unpretty/struct-exprs-tuple-call-pretty-printing.stdout @@ -1,6 +1,6 @@ #![attr = Feature([adt_const_params#0, gca_adts#0, gca_min_const_items#0, gca_macroless_args#0])] -#![attr = LintCheck([LintCheck {lint_name: LintName { tool: None, name: "dead_code" }, +#![attr = LintCheck([LintCheck {lint_name_normalized: LintName { tool: None, name: "dead_code" }, kind: Allow}])] extern crate std; #[attr = PreludeImport] diff --git a/tests/ui/unpretty/unpretty-expr-fn-arg.stdout b/tests/ui/unpretty/unpretty-expr-fn-arg.stdout index d80b073e52b73..93938fed46d47 100644 --- a/tests/ui/unpretty/unpretty-expr-fn-arg.stdout +++ b/tests/ui/unpretty/unpretty-expr-fn-arg.stdout @@ -1,4 +1,4 @@ -#![attr = LintCheck([LintCheck {lint_name: LintName { tool: None, name: "dead_code" }, +#![attr = LintCheck([LintCheck {lint_name_normalized: LintName { tool: None, name: "dead_code" }, kind: Allow}])] extern crate std; #[attr = PreludeImport]