From 97da8195dea600fbaba876914dfae2ee09ce83ce Mon Sep 17 00:00:00 2001 From: Georg Semmler Date: Wed, 8 Apr 2026 08:36:39 +0200 Subject: [PATCH] Rename the attribute to `on_unknown` --- .../src/attributes/diagnostic/mod.rs | 14 +-- .../{on_unknown_item.rs => on_unknown.rs} | 18 +-- compiler/rustc_attr_parsing/src/context.rs | 4 +- compiler/rustc_feature/src/builtin_attrs.rs | 2 +- compiler/rustc_feature/src/unstable.rs | 2 +- .../rustc_hir/src/attrs/data_structures.rs | 4 +- .../rustc_hir/src/attrs/encode_cross_crate.rs | 2 +- compiler/rustc_lint/src/early/diagnostics.rs | 8 +- compiler/rustc_lint/src/lints.rs | 8 +- compiler/rustc_lint_defs/src/lib.rs | 4 +- compiler/rustc_passes/src/check_attr.rs | 12 +- .../rustc_resolve/src/build_reduced_graph.rs | 10 +- compiler/rustc_resolve/src/imports.rs | 30 ++--- compiler/rustc_resolve/src/macros.rs | 2 +- compiler/rustc_span/src/symbol.rs | 4 +- .../on_unknown/incorrect-locations.rs | 52 +++++++++ .../on_unknown/incorrect-locations.stderr | 103 ++++++++++++++++++ .../incorrect_format_string.rs | 14 +-- .../incorrect_format_string.stderr | 36 +++--- .../on_unknown/malformed_attribute.rs | 19 ++++ .../on_unknown/malformed_attribute.stderr | 44 ++++++++ .../multiple_errors.rs | 10 +- .../multiple_errors.stderr | 0 .../unknown_import.rs | 4 +- .../unknown_import.stderr | 0 .../on_unknown_item/incorrect-locations.rs | 52 --------- .../incorrect-locations.stderr | 103 ------------------ .../on_unknown_item/malformed_attribute.rs | 19 ---- .../malformed_attribute.stderr | 44 -------- ... => feature-gate-diagnostic-on-unknown.rs} | 2 +- ...feature-gate-diagnostic-on-unknown.stderr} | 10 +- 31 files changed, 318 insertions(+), 318 deletions(-) rename compiler/rustc_attr_parsing/src/attributes/diagnostic/{on_unknown_item.rs => on_unknown.rs} (82%) create mode 100644 tests/ui/diagnostic_namespace/on_unknown/incorrect-locations.rs create mode 100644 tests/ui/diagnostic_namespace/on_unknown/incorrect-locations.stderr rename tests/ui/diagnostic_namespace/{on_unknown_item => on_unknown}/incorrect_format_string.rs (67%) rename tests/ui/diagnostic_namespace/{on_unknown_item => on_unknown}/incorrect_format_string.stderr (70%) create mode 100644 tests/ui/diagnostic_namespace/on_unknown/malformed_attribute.rs create mode 100644 tests/ui/diagnostic_namespace/on_unknown/malformed_attribute.stderr rename tests/ui/diagnostic_namespace/{on_unknown_item => on_unknown}/multiple_errors.rs (83%) rename tests/ui/diagnostic_namespace/{on_unknown_item => on_unknown}/multiple_errors.stderr (100%) rename tests/ui/diagnostic_namespace/{on_unknown_item => on_unknown}/unknown_import.rs (75%) rename tests/ui/diagnostic_namespace/{on_unknown_item => on_unknown}/unknown_import.stderr (100%) delete mode 100644 tests/ui/diagnostic_namespace/on_unknown_item/incorrect-locations.rs delete mode 100644 tests/ui/diagnostic_namespace/on_unknown_item/incorrect-locations.stderr delete mode 100644 tests/ui/diagnostic_namespace/on_unknown_item/malformed_attribute.rs delete mode 100644 tests/ui/diagnostic_namespace/on_unknown_item/malformed_attribute.stderr rename tests/ui/feature-gates/{feature-gate-diagnostic-on-unknown-item.rs => feature-gate-diagnostic-on-unknown.rs} (76%) rename tests/ui/feature-gates/{feature-gate-diagnostic-on-unknown-item.stderr => feature-gate-diagnostic-on-unknown.stderr} (64%) diff --git a/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs b/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs index 61fd3f096248..f68bed620f1b 100644 --- a/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs +++ b/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs @@ -24,7 +24,7 @@ pub(crate) mod on_const; pub(crate) mod on_move; pub(crate) mod on_unimplemented; -pub(crate) mod on_unknown_item; +pub(crate) mod on_unknown; #[derive(Copy, Clone)] pub(crate) enum Mode { @@ -36,8 +36,8 @@ pub(crate) enum Mode { DiagnosticOnConst, /// `#[diagnostic::on_move]` DiagnosticOnMove, - /// `#[diagnostic::on_unknown_item]` - DiagnosticOnUnknownItem, + /// `#[diagnostic::on_unknown]` + DiagnosticOnUnknown, } fn merge_directives( @@ -125,10 +125,10 @@ fn parse_directive_items<'p, S: Stage>( span, ); } - Mode::DiagnosticOnUnknownItem => { + Mode::DiagnosticOnUnknown => { cx.emit_lint( MALFORMED_DIAGNOSTIC_ATTRIBUTES, - AttributeLintKind::MalformedOnUnknownItemdAttr { span }, + AttributeLintKind::MalformedOnUnknownAttr { span }, span, ); } @@ -150,7 +150,7 @@ fn parse_directive_items<'p, S: Stage>( Mode::RustcOnUnimplemented => { cx.emit_err(NoValueInOnUnimplemented { span: item.span() }); } - Mode::DiagnosticOnUnimplemented |Mode::DiagnosticOnConst | Mode::DiagnosticOnMove | Mode::DiagnosticOnUnknownItem => { + Mode::DiagnosticOnUnimplemented |Mode::DiagnosticOnConst | Mode::DiagnosticOnMove | Mode::DiagnosticOnUnknown => { cx.emit_lint( MALFORMED_DIAGNOSTIC_ATTRIBUTES, AttributeLintKind::IgnoredDiagnosticOption { @@ -337,7 +337,7 @@ fn parse_arg( is_source_literal: bool, ) -> FormatArg { let span = slice_span(input_span, arg.position_span.clone(), is_source_literal); - if matches!(mode, Mode::DiagnosticOnUnknownItem) { + if matches!(mode, Mode::DiagnosticOnUnknown) { warnings.push(FormatWarning::DisallowedPlaceholder { span }); return FormatArg::AsIs(sym::empty_braces); } diff --git a/compiler/rustc_attr_parsing/src/attributes/diagnostic/on_unknown_item.rs b/compiler/rustc_attr_parsing/src/attributes/diagnostic/on_unknown.rs similarity index 82% rename from compiler/rustc_attr_parsing/src/attributes/diagnostic/on_unknown_item.rs rename to compiler/rustc_attr_parsing/src/attributes/diagnostic/on_unknown.rs index f2a243a8e0bb..bd5eb4cbf82c 100644 --- a/compiler/rustc_attr_parsing/src/attributes/diagnostic/on_unknown_item.rs +++ b/compiler/rustc_attr_parsing/src/attributes/diagnostic/on_unknown.rs @@ -5,19 +5,19 @@ use crate::attributes::prelude::*; #[derive(Default)] -pub(crate) struct OnUnknownItemParser { +pub(crate) struct OnUnknownParser { span: Option, directive: Option<(Span, Directive)>, } -impl OnUnknownItemParser { +impl OnUnknownParser { fn parse<'sess, S: Stage>( &mut self, cx: &mut AcceptContext<'_, 'sess, S>, args: &ArgParser, mode: Mode, ) { - if !cx.features().diagnostic_on_unknown_item() { + if !cx.features().diagnostic_on_unknown() { return; } let span = cx.attr_span; @@ -28,7 +28,7 @@ fn parse<'sess, S: Stage>( ArgParser::NoArgs | ArgParser::List(_) => { cx.emit_lint( MALFORMED_DIAGNOSTIC_ATTRIBUTES, - AttributeLintKind::MissingOptionsForOnUnknownItem, + AttributeLintKind::MissingOptionsForOnUnknown, span, ); return; @@ -36,7 +36,7 @@ fn parse<'sess, S: Stage>( ArgParser::NameValue(_) => { cx.emit_lint( MALFORMED_DIAGNOSTIC_ATTRIBUTES, - AttributeLintKind::MalformedOnUnknownItemdAttr { span }, + AttributeLintKind::MalformedOnUnknownAttr { span }, span, ); return; @@ -49,12 +49,12 @@ fn parse<'sess, S: Stage>( } } -impl AttributeParser for OnUnknownItemParser { +impl AttributeParser for OnUnknownParser { const ATTRIBUTES: AcceptMapping = &[( - &[sym::diagnostic, sym::on_unknown_item], + &[sym::diagnostic, sym::on_unknown], template!(List: &[r#"/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...""#]), |this, cx, args| { - this.parse(cx, args, Mode::DiagnosticOnUnknownItem); + this.parse(cx, args, Mode::DiagnosticOnUnknown); }, )]; //FIXME attribute is not parsed for non-use statements but diagnostics are issued in `check_attr.rs` @@ -62,7 +62,7 @@ impl AttributeParser for OnUnknownItemParser { fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option { if let Some(span) = self.span { - Some(AttributeKind::OnUnknownItem { + Some(AttributeKind::OnUnknown { span, directive: self.directive.map(|d| Box::new(d.1)), }) diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index c10877ce72e6..3fde8d79f514 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -32,7 +32,7 @@ use crate::attributes::diagnostic::on_const::*; use crate::attributes::diagnostic::on_move::*; use crate::attributes::diagnostic::on_unimplemented::*; -use crate::attributes::diagnostic::on_unknown_item::*; +use crate::attributes::diagnostic::on_unknown::*; use crate::attributes::doc::*; use crate::attributes::dummy::*; use crate::attributes::inline::*; @@ -155,7 +155,7 @@ mod late { OnConstParser, OnMoveParser, OnUnimplementedParser, - OnUnknownItemParser, + OnUnknownParser, RustcAlignParser, RustcAlignStaticParser, RustcCguTestAttributeParser, diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index 5d5018ce448e..3edc19e4314c 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -1588,7 +1588,7 @@ pub fn is_stable_diagnostic_attribute(sym: Symbol, features: &Features) -> bool sym::on_unimplemented | sym::do_not_recommend => true, sym::on_const => features.diagnostic_on_const(), sym::on_move => features.diagnostic_on_move(), - sym::on_unknown_item => features.diagnostic_on_unknown_item(), + sym::on_unknown => features.diagnostic_on_unknown(), _ => false, } } diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 7886a4fcac0d..c2fe6e136020 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -475,7 +475,7 @@ pub fn internal(&self, feature: Symbol) -> bool { /// Allows giving on-move borrowck custom diagnostic messages for a type (unstable, diagnostic_on_move, "CURRENT_RUSTC_VERSION", Some(154181)), /// Allows giving unresolved imports a custom diagnostic message - (unstable, diagnostic_on_unknown_item, "CURRENT_RUSTC_VERSION", Some(152900)), + (unstable, diagnostic_on_unknown, "CURRENT_RUSTC_VERSION", Some(152900)), /// Allows `#[doc(cfg(...))]`. (unstable, doc_cfg, "1.21.0", Some(43781)), /// Allows `#[doc(masked)]`. diff --git a/compiler/rustc_hir/src/attrs/data_structures.rs b/compiler/rustc_hir/src/attrs/data_structures.rs index 6fa3df2dfa7d..c94444893f1e 100644 --- a/compiler/rustc_hir/src/attrs/data_structures.rs +++ b/compiler/rustc_hir/src/attrs/data_structures.rs @@ -1193,8 +1193,8 @@ pub enum AttributeKind { directive: Option>, }, - /// Represents `#[diagnostic::on_unknown_item]` - OnUnknownItem { + /// Represents `#[diagnostic::on_unknown]` + OnUnknown { span: Span, /// None if the directive was malformed in some way. directive: Option>, diff --git a/compiler/rustc_hir/src/attrs/encode_cross_crate.rs b/compiler/rustc_hir/src/attrs/encode_cross_crate.rs index 699caa203ae4..861d74766ccb 100644 --- a/compiler/rustc_hir/src/attrs/encode_cross_crate.rs +++ b/compiler/rustc_hir/src/attrs/encode_cross_crate.rs @@ -79,7 +79,7 @@ pub fn encode_cross_crate(&self) -> EncodeCrossCrate { OnConst { .. } => Yes, OnMove { .. } => Yes, OnUnimplemented { .. } => Yes, - OnUnknownItem { .. } => Yes, + OnUnknown { .. } => Yes, Optimize(..) => No, PanicRuntime => No, PatchableFunctionEntry { .. } => Yes, diff --git a/compiler/rustc_lint/src/early/diagnostics.rs b/compiler/rustc_lint/src/early/diagnostics.rs index 0171cf9ebd72..1b31639c4078 100644 --- a/compiler/rustc_lint/src/early/diagnostics.rs +++ b/compiler/rustc_lint/src/early/diagnostics.rs @@ -179,8 +179,8 @@ fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> { &AttributeLintKind::MalformedOnUnimplementedAttr { span } => { lints::MalformedOnUnimplementedAttrLint { span }.into_diag(dcx, level) } - &AttributeLintKind::MalformedOnUnknownItemdAttr { span } => { - lints::MalformedOnUnknownItemAttrLint { span }.into_diag(dcx, level) + &AttributeLintKind::MalformedOnUnknownAttr { span } => { + lints::MalformedOnUnknownAttrLint { span }.into_diag(dcx, level) } &AttributeLintKind::MalformedOnConstAttr { span } => { lints::MalformedOnConstAttrLint { span }.into_diag(dcx, level) @@ -221,8 +221,8 @@ fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> { &AttributeLintKind::MissingOptionsForOnMove => { lints::MissingOptionsForOnMoveAttr.into_diag(dcx, level) } - &AttributeLintKind::MissingOptionsForOnUnknownItem => { - lints::MissingOptionsForOnUnknownItemAttr.into_diag(dcx, level) + &AttributeLintKind::MissingOptionsForOnUnknown => { + lints::MissingOptionsForOnUnknownAttr.into_diag(dcx, level) } } } diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 9f7dbae70ec5..19ec3f4ca45d 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -3577,9 +3577,9 @@ pub(crate) struct IgnoredDiagnosticOption { pub(crate) struct MissingOptionsForOnUnimplementedAttr; #[derive(Diagnostic)] -#[diag("missing options for `on_unknown_item` attribute")] +#[diag("missing options for `on_unknown` attribute")] #[help("at least one of the `message`, `note` and `label` options are expected")] -pub(crate) struct MissingOptionsForOnUnknownItemAttr; +pub(crate) struct MissingOptionsForOnUnknownAttr; #[derive(Diagnostic)] #[diag("missing options for `on_const` attribute")] @@ -3600,9 +3600,9 @@ pub(crate) struct MalformedOnUnimplementedAttrLint { } #[derive(Diagnostic)] -#[diag("malformed `on_unknown_item` attribute")] +#[diag("malformed `on_unknown` attribute")] #[help("only `message`, `note` and `label` are allowed as options")] -pub(crate) struct MalformedOnUnknownItemAttrLint { +pub(crate) struct MalformedOnUnknownAttrLint { #[label("invalid option found here")] pub span: Span, } diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index 5497e2509eaa..a77b7bc7d948 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -736,7 +736,7 @@ pub enum AttributeLintKind { MalformedOnUnimplementedAttr { span: Span, }, - MalformedOnUnknownItemdAttr { + MalformedOnUnknownAttr { span: Span, }, MalformedOnConstAttr { @@ -760,7 +760,7 @@ pub enum AttributeLintKind { }, MissingOptionsForOnUnimplemented, MissingOptionsForOnConst, - MissingOptionsForOnUnknownItem, + MissingOptionsForOnUnknown, MissingOptionsForOnMove, OnMoveMalformedFormatLiterals { name: Symbol, diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index f0495fb820c9..c49872802878 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -75,8 +75,8 @@ struct DiagnosticOnConstOnlyForNonConstTraitImpls { struct DiagnosticOnMoveOnlyForAdt; #[derive(Diagnostic)] -#[diag("`#[diagnostic::on_unknown_item]` can only be applied to `use` statements")] -struct DiagnosticOnUnknownItemOnlyForImports { +#[diag("`#[diagnostic::on_unknown]` can only be applied to `use` statements")] +struct DiagnosticOnUnknownOnlyForImports { #[label("not an import")] item_span: Span, } @@ -226,7 +226,7 @@ fn check_attributes( }, Attribute::Parsed(AttributeKind::DoNotRecommend{attr_span}) => {self.check_do_not_recommend(*attr_span, hir_id, target, item)}, Attribute::Parsed(AttributeKind::OnUnimplemented{span, directive}) => {self.check_diagnostic_on_unimplemented(*span, hir_id, target,directive.as_deref())}, - Attribute::Parsed(AttributeKind::OnUnknownItem { span, .. }) => { self.check_diagnostic_on_unknown_item(*span, hir_id, target) }, + Attribute::Parsed(AttributeKind::OnUnknown { span, .. }) => { self.check_diagnostic_on_unknown(*span, hir_id, target) }, Attribute::Parsed(AttributeKind::OnConst{span, ..}) => {self.check_diagnostic_on_const(*span, hir_id, target, item)} Attribute::Parsed(AttributeKind::OnMove { span, directive }) => { self.check_diagnostic_on_move(*span, hir_id, target, directive.as_deref()) @@ -735,15 +735,15 @@ fn check_diagnostic_on_move( } } - /// Checks if `#[diagnostic::on_unknown_item]` is applied to a trait impl - fn check_diagnostic_on_unknown_item(&self, attr_span: Span, hir_id: HirId, target: Target) { + /// Checks if `#[diagnostic::on_unknown]` is applied to a trait impl + fn check_diagnostic_on_unknown(&self, attr_span: Span, hir_id: HirId, target: Target) { if !matches!(target, Target::Use) { let item_span = self.tcx.hir_span(hir_id); self.tcx.emit_node_span_lint( MISPLACED_DIAGNOSTIC_ATTRIBUTES, hir_id, attr_span, - DiagnosticOnUnknownItemOnlyForImports { item_span }, + DiagnosticOnUnknownOnlyForImports { item_span }, ); } } diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 7eba016d4474..983a7a201b10 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -32,7 +32,7 @@ use crate::Namespace::{MacroNS, TypeNS, ValueNS}; use crate::def_collector::collect_definitions; -use crate::imports::{ImportData, ImportKind, OnUnknownItemData}; +use crate::imports::{ImportData, ImportKind, OnUnknownData}; use crate::macros::{MacroRulesDecl, MacroRulesScope, MacroRulesScopeRef}; use crate::ref_mut::CmCell; use crate::{ @@ -545,7 +545,7 @@ fn add_import( root_id, vis, vis_span: item.vis.span, - on_unknown_item_attr: OnUnknownItemData::from_attrs(self.r.tcx, item), + on_unknown_attr: OnUnknownData::from_attrs(self.r.tcx, item), }); self.r.indeterminate_imports.push(import); @@ -1027,7 +1027,7 @@ fn build_reduced_graph_for_extern_crate( module_path: Vec::new(), vis, vis_span: item.vis.span, - on_unknown_item_attr: OnUnknownItemData::from_attrs(self.r.tcx, item), + on_unknown_attr: OnUnknownData::from_attrs(self.r.tcx, item), }); if used { self.r.import_use_map.insert(import, Used::Other); @@ -1160,7 +1160,7 @@ fn process_macro_use_imports(&mut self, item: &Item, module: Module<'ra>) -> boo module_path: Vec::new(), vis: Visibility::Restricted(CRATE_DEF_ID), vis_span: item.vis.span, - on_unknown_item_attr: OnUnknownItemData::from_attrs(this.r.tcx, item), + on_unknown_attr: OnUnknownData::from_attrs(this.r.tcx, item), }) }; @@ -1332,7 +1332,7 @@ fn define_macro(&mut self, item: &ast::Item) -> MacroRulesScopeRef<'ra> { module_path: Vec::new(), vis, vis_span: item.vis.span, - on_unknown_item_attr: OnUnknownItemData::from_attrs(self.r.tcx, item), + on_unknown_attr: OnUnknownData::from_attrs(self.r.tcx, item), }); self.r.import_use_map.insert(import, Used::Other); let import_decl = self.r.new_import_decl(decl, import); diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 846efdf22b97..18db60167c27 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -145,17 +145,17 @@ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { } #[derive(Debug, Clone, Default)] -pub(crate) struct OnUnknownItemData { +pub(crate) struct OnUnknownData { directive: Directive, } -impl OnUnknownItemData { - pub(crate) fn from_attrs<'tcx>(tcx: TyCtxt<'tcx>, item: &Item) -> Option { - if let Some(Attribute::Parsed(AttributeKind::OnUnknownItem { directive, .. })) = +impl OnUnknownData { + pub(crate) fn from_attrs<'tcx>(tcx: TyCtxt<'tcx>, item: &Item) -> Option { + if let Some(Attribute::Parsed(AttributeKind::OnUnknown { directive, .. })) = AttributeParser::parse_limited( tcx.sess, &item.attrs, - &[sym::diagnostic, sym::on_unknown_item], + &[sym::diagnostic, sym::on_unknown], item.span, item.id, Some(tcx.features()), @@ -215,10 +215,10 @@ pub(crate) struct ImportData<'ra> { /// Span of the visibility. pub vis_span: Span, - /// A `#[diagnostic::on_unknown_item]` attribute applied + /// A `#[diagnostic::on_unknown]` attribute applied /// to the given import. This allows crates to specify /// custom error messages for a specific import - pub on_unknown_item_attr: Option, + pub on_unknown_attr: Option, } /// All imports are unique and allocated on a same arena, @@ -317,7 +317,7 @@ struct UnresolvedImportError { segment: Option, /// comes from `PathRes::Failed { module }` module: Option, - on_unknown_item_attr: Option, + on_unknown_attr: Option, } // Reexports of the form `pub use foo as bar;` where `foo` is `extern crate foo;` @@ -734,7 +734,7 @@ pub(crate) fn finalize_imports(&mut self) { candidates: None, segment: None, module: None, - on_unknown_item_attr: import.on_unknown_item_attr.clone(), + on_unknown_attr: import.on_unknown_attr.clone(), }; errors.push((*import, err)) } @@ -859,8 +859,8 @@ fn throw_unresolved_import_error( .collect::>(); let default_message = format!("unresolved import{} {}", pluralize!(paths.len()), paths.join(", "),); - let (message, label, notes) = if self.tcx.features().diagnostic_on_unknown_item() - && let Some(directive) = errors[0].1.on_unknown_item_attr.as_ref().map(|a| &a.directive) + let (message, label, notes) = if self.tcx.features().diagnostic_on_unknown() + && let Some(directive) = errors[0].1.on_unknown_attr.as_ref().map(|a| &a.directive) { let args = FormatArgs { this: paths.join(", "), @@ -1168,7 +1168,7 @@ fn finalize_import(&mut self, import: Import<'ra>) -> Option UnresolvedImportError { span, @@ -1178,7 +1178,7 @@ fn finalize_import(&mut self, import: Import<'ra>) -> Option) -> Option) -> Option", ops, diff --git a/tests/ui/diagnostic_namespace/on_unknown/incorrect-locations.rs b/tests/ui/diagnostic_namespace/on_unknown/incorrect-locations.rs new file mode 100644 index 000000000000..b8852e7dd216 --- /dev/null +++ b/tests/ui/diagnostic_namespace/on_unknown/incorrect-locations.rs @@ -0,0 +1,52 @@ +//@ run-pass +#![allow(dead_code, unused_imports)] +#![feature(diagnostic_on_unknown)] + +#[diagnostic::on_unknown(message = "foo")] +//~^WARN `#[diagnostic::on_unknown]` can only be applied to `use` statements +extern crate std as other_std; + +#[diagnostic::on_unknown(message = "foo")] +//~^WARN `#[diagnostic::on_unknown]` can only be applied to `use` statements +const CONST: () = (); + +#[diagnostic::on_unknown(message = "foo")] +//~^WARN `#[diagnostic::on_unknown]` can only be applied to `use` statements +static STATIC: () = (); + +#[diagnostic::on_unknown(message = "foo")] +//~^WARN `#[diagnostic::on_unknown]` can only be applied to `use` statements +type Type = (); + +#[diagnostic::on_unknown(message = "foo")] +//~^WARN `#[diagnostic::on_unknown]` can only be applied to `use` statements +enum Enum {} + +#[diagnostic::on_unknown(message = "foo")] +//~^WARN `#[diagnostic::on_unknown]` can only be applied to `use` statements +impl Enum {} + +#[diagnostic::on_unknown(message = "foo")] +//~^WARN `#[diagnostic::on_unknown]` can only be applied to `use` statements +extern "C" {} + +#[diagnostic::on_unknown(message = "foo")] +//~^WARN `#[diagnostic::on_unknown]` can only be applied to `use` statements +fn fun() {} + +#[diagnostic::on_unknown(message = "foo")] +//~^WARN `#[diagnostic::on_unknown]` can only be applied to `use` statements +struct Struct {} + +#[diagnostic::on_unknown(message = "foo")] +//~^WARN `#[diagnostic::on_unknown]` can only be applied to `use` statements +trait Trait {} + +#[diagnostic::on_unknown(message = "foo")] +//~^WARN `#[diagnostic::on_unknown]` can only be applied to `use` statements +impl Trait for i32 {} + +#[diagnostic::on_unknown(message = "foo")] +use std::str::FromStr; + +fn main() {} diff --git a/tests/ui/diagnostic_namespace/on_unknown/incorrect-locations.stderr b/tests/ui/diagnostic_namespace/on_unknown/incorrect-locations.stderr new file mode 100644 index 000000000000..33636e1fcfc3 --- /dev/null +++ b/tests/ui/diagnostic_namespace/on_unknown/incorrect-locations.stderr @@ -0,0 +1,103 @@ +warning: `#[diagnostic::on_unknown]` can only be applied to `use` statements + --> $DIR/incorrect-locations.rs:5:1 + | +LL | #[diagnostic::on_unknown(message = "foo")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | extern crate std as other_std; + | ----------------------------- not an import + | + = note: `#[warn(misplaced_diagnostic_attributes)]` (part of `#[warn(unknown_or_malformed_diagnostic_attributes)]`) on by default + +warning: `#[diagnostic::on_unknown]` can only be applied to `use` statements + --> $DIR/incorrect-locations.rs:9:1 + | +LL | #[diagnostic::on_unknown(message = "foo")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | const CONST: () = (); + | --------------- not an import + +warning: `#[diagnostic::on_unknown]` can only be applied to `use` statements + --> $DIR/incorrect-locations.rs:13:1 + | +LL | #[diagnostic::on_unknown(message = "foo")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | static STATIC: () = (); + | ----------------- not an import + +warning: `#[diagnostic::on_unknown]` can only be applied to `use` statements + --> $DIR/incorrect-locations.rs:17:1 + | +LL | #[diagnostic::on_unknown(message = "foo")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | type Type = (); + | --------- not an import + +warning: `#[diagnostic::on_unknown]` can only be applied to `use` statements + --> $DIR/incorrect-locations.rs:21:1 + | +LL | #[diagnostic::on_unknown(message = "foo")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | enum Enum {} + | --------- not an import + +warning: `#[diagnostic::on_unknown]` can only be applied to `use` statements + --> $DIR/incorrect-locations.rs:25:1 + | +LL | #[diagnostic::on_unknown(message = "foo")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | impl Enum {} + | --------- not an import + +warning: `#[diagnostic::on_unknown]` can only be applied to `use` statements + --> $DIR/incorrect-locations.rs:29:1 + | +LL | #[diagnostic::on_unknown(message = "foo")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | extern "C" {} + | ------------- not an import + +warning: `#[diagnostic::on_unknown]` can only be applied to `use` statements + --> $DIR/incorrect-locations.rs:33:1 + | +LL | #[diagnostic::on_unknown(message = "foo")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | fn fun() {} + | -------- not an import + +warning: `#[diagnostic::on_unknown]` can only be applied to `use` statements + --> $DIR/incorrect-locations.rs:37:1 + | +LL | #[diagnostic::on_unknown(message = "foo")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | struct Struct {} + | ------------- not an import + +warning: `#[diagnostic::on_unknown]` can only be applied to `use` statements + --> $DIR/incorrect-locations.rs:41:1 + | +LL | #[diagnostic::on_unknown(message = "foo")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | trait Trait {} + | ----------- not an import + +warning: `#[diagnostic::on_unknown]` can only be applied to `use` statements + --> $DIR/incorrect-locations.rs:45:1 + | +LL | #[diagnostic::on_unknown(message = "foo")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | impl Trait for i32 {} + | ------------------ not an import + +warning: 11 warnings emitted + diff --git a/tests/ui/diagnostic_namespace/on_unknown_item/incorrect_format_string.rs b/tests/ui/diagnostic_namespace/on_unknown/incorrect_format_string.rs similarity index 67% rename from tests/ui/diagnostic_namespace/on_unknown_item/incorrect_format_string.rs rename to tests/ui/diagnostic_namespace/on_unknown/incorrect_format_string.rs index d7d6f1845060..cdf0f1e89efc 100644 --- a/tests/ui/diagnostic_namespace/on_unknown_item/incorrect_format_string.rs +++ b/tests/ui/diagnostic_namespace/on_unknown/incorrect_format_string.rs @@ -1,31 +1,31 @@ -#![feature(diagnostic_on_unknown_item)] +#![feature(diagnostic_on_unknown)] -#[diagnostic::on_unknown_item(message = "foo {}")] +#[diagnostic::on_unknown(message = "foo {}")] //~^ WARN: format arguments are not allowed here use std::does_not_exist; //~^ ERROR: foo {} -#[diagnostic::on_unknown_item(message = "foo {A}")] +#[diagnostic::on_unknown(message = "foo {A}")] //~^ WARN: format arguments are not allowed here use std::does_not_exist2; //~^ ERROR: foo {} -#[diagnostic::on_unknown_item(label = "foo {}")] +#[diagnostic::on_unknown(label = "foo {}")] //~^ WARN: format arguments are not allowed here use std::does_not_exist3; //~^ ERROR: unresolved import `std::does_not_exist3` -#[diagnostic::on_unknown_item(label = "foo {A}")] +#[diagnostic::on_unknown(label = "foo {A}")] //~^ WARN: format arguments are not allowed here use std::does_not_exist4; //~^ ERROR: unresolved import `std::does_not_exist4` -#[diagnostic::on_unknown_item(note = "foo {}")] +#[diagnostic::on_unknown(note = "foo {}")] //~^ WARN: format arguments are not allowed here use std::does_not_exist5; //~^ ERROR: unresolved import `std::does_not_exist5` -#[diagnostic::on_unknown_item(note = "foo {A}")] +#[diagnostic::on_unknown(note = "foo {A}")] //~^ WARN: format arguments are not allowed here use std::does_not_exist6; //~^ ERROR: unresolved import `std::does_not_exist6` diff --git a/tests/ui/diagnostic_namespace/on_unknown_item/incorrect_format_string.stderr b/tests/ui/diagnostic_namespace/on_unknown/incorrect_format_string.stderr similarity index 70% rename from tests/ui/diagnostic_namespace/on_unknown_item/incorrect_format_string.stderr rename to tests/ui/diagnostic_namespace/on_unknown/incorrect_format_string.stderr index e8551479287e..2b942338ffb4 100644 --- a/tests/ui/diagnostic_namespace/on_unknown_item/incorrect_format_string.stderr +++ b/tests/ui/diagnostic_namespace/on_unknown/incorrect_format_string.stderr @@ -43,51 +43,51 @@ LL | use std::does_not_exist6; = note: foo {} warning: format arguments are not allowed here - --> $DIR/incorrect_format_string.rs:3:47 + --> $DIR/incorrect_format_string.rs:3:42 | -LL | #[diagnostic::on_unknown_item(message = "foo {}")] - | ^ +LL | #[diagnostic::on_unknown(message = "foo {}")] + | ^ | = help: consider removing this format argument = note: `#[warn(malformed_diagnostic_format_literals)]` (part of `#[warn(unknown_or_malformed_diagnostic_attributes)]`) on by default warning: format arguments are not allowed here - --> $DIR/incorrect_format_string.rs:8:47 + --> $DIR/incorrect_format_string.rs:8:42 | -LL | #[diagnostic::on_unknown_item(message = "foo {A}")] - | ^ +LL | #[diagnostic::on_unknown(message = "foo {A}")] + | ^ | = help: consider removing this format argument warning: format arguments are not allowed here - --> $DIR/incorrect_format_string.rs:13:45 + --> $DIR/incorrect_format_string.rs:13:40 | -LL | #[diagnostic::on_unknown_item(label = "foo {}")] - | ^ +LL | #[diagnostic::on_unknown(label = "foo {}")] + | ^ | = help: consider removing this format argument warning: format arguments are not allowed here - --> $DIR/incorrect_format_string.rs:18:45 + --> $DIR/incorrect_format_string.rs:18:40 | -LL | #[diagnostic::on_unknown_item(label = "foo {A}")] - | ^ +LL | #[diagnostic::on_unknown(label = "foo {A}")] + | ^ | = help: consider removing this format argument warning: format arguments are not allowed here - --> $DIR/incorrect_format_string.rs:23:44 + --> $DIR/incorrect_format_string.rs:23:39 | -LL | #[diagnostic::on_unknown_item(note = "foo {}")] - | ^ +LL | #[diagnostic::on_unknown(note = "foo {}")] + | ^ | = help: consider removing this format argument warning: format arguments are not allowed here - --> $DIR/incorrect_format_string.rs:28:44 + --> $DIR/incorrect_format_string.rs:28:39 | -LL | #[diagnostic::on_unknown_item(note = "foo {A}")] - | ^ +LL | #[diagnostic::on_unknown(note = "foo {A}")] + | ^ | = help: consider removing this format argument diff --git a/tests/ui/diagnostic_namespace/on_unknown/malformed_attribute.rs b/tests/ui/diagnostic_namespace/on_unknown/malformed_attribute.rs new file mode 100644 index 000000000000..d8fcd1336bce --- /dev/null +++ b/tests/ui/diagnostic_namespace/on_unknown/malformed_attribute.rs @@ -0,0 +1,19 @@ +#![feature(diagnostic_on_unknown)] +#[diagnostic::on_unknown] +//~^WARN missing options for `on_unknown` attribute +use std::str::FromStr; + +#[diagnostic::on_unknown(foo = "bar", message = "foo")] +//~^WARN malformed `on_unknown` attribute +use std::str::Bytes; + +#[diagnostic::on_unknown(label = "foo", label = "bar")] +//~^WARN `label` is ignored due to previous definition of `label` +use std::str::Chars; + +#[diagnostic::on_unknown(message = "Foo", message = "Bar")] +//~^WARN `message` is ignored due to previous definition of `message` +use std::str::NotExisting; +//~^ERROR Foo + +fn main() {} diff --git a/tests/ui/diagnostic_namespace/on_unknown/malformed_attribute.stderr b/tests/ui/diagnostic_namespace/on_unknown/malformed_attribute.stderr new file mode 100644 index 000000000000..319d45c88c42 --- /dev/null +++ b/tests/ui/diagnostic_namespace/on_unknown/malformed_attribute.stderr @@ -0,0 +1,44 @@ +error[E0432]: Foo + --> $DIR/malformed_attribute.rs:16:5 + | +LL | use std::str::NotExisting; + | ^^^^^^^^^^^^^^^^^^^^^ no `NotExisting` in `str` + | + = note: unresolved import `std::str::NotExisting` + +warning: missing options for `on_unknown` attribute + --> $DIR/malformed_attribute.rs:2:1 + | +LL | #[diagnostic::on_unknown] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: at least one of the `message`, `note` and `label` options are expected + = note: `#[warn(malformed_diagnostic_attributes)]` (part of `#[warn(unknown_or_malformed_diagnostic_attributes)]`) on by default + +warning: malformed `on_unknown` attribute + --> $DIR/malformed_attribute.rs:6:26 + | +LL | #[diagnostic::on_unknown(foo = "bar", message = "foo")] + | ^^^^^^^^^^^ invalid option found here + | + = help: only `message`, `note` and `label` are allowed as options + +warning: `label` is ignored due to previous definition of `label` + --> $DIR/malformed_attribute.rs:10:41 + | +LL | #[diagnostic::on_unknown(label = "foo", label = "bar")] + | ------------- ^^^^^^^^^^^^^ `label` is later redundantly declared here + | | + | `label` is first declared here + +warning: `message` is ignored due to previous definition of `message` + --> $DIR/malformed_attribute.rs:14:43 + | +LL | #[diagnostic::on_unknown(message = "Foo", message = "Bar")] + | --------------- ^^^^^^^^^^^^^^^ `message` is later redundantly declared here + | | + | `message` is first declared here + +error: aborting due to 1 previous error; 4 warnings emitted + +For more information about this error, try `rustc --explain E0432`. diff --git a/tests/ui/diagnostic_namespace/on_unknown_item/multiple_errors.rs b/tests/ui/diagnostic_namespace/on_unknown/multiple_errors.rs similarity index 83% rename from tests/ui/diagnostic_namespace/on_unknown_item/multiple_errors.rs rename to tests/ui/diagnostic_namespace/on_unknown/multiple_errors.rs index 431ab6cdd831..3ccf2fc5f6ca 100644 --- a/tests/ui/diagnostic_namespace/on_unknown_item/multiple_errors.rs +++ b/tests/ui/diagnostic_namespace/on_unknown/multiple_errors.rs @@ -1,7 +1,7 @@ -#![feature(diagnostic_on_unknown_item)] +#![feature(diagnostic_on_unknown)] mod test1 { - #[diagnostic::on_unknown_item( + #[diagnostic::on_unknown( message = "custom message", label = "custom label", note = "custom note" @@ -11,7 +11,7 @@ mod test1 { } mod test2 { - #[diagnostic::on_unknown_item( + #[diagnostic::on_unknown( message = "custom message", label = "custom label", note = "custom note" @@ -21,7 +21,7 @@ mod test2 { } mod test3 { - #[diagnostic::on_unknown_item( + #[diagnostic::on_unknown( message = "custom message", label = "custom label", note = "custom note" @@ -34,7 +34,7 @@ mod test3 { } mod test4 { - #[diagnostic::on_unknown_item( + #[diagnostic::on_unknown( message = "custom message", label = "custom label", note = "custom note" diff --git a/tests/ui/diagnostic_namespace/on_unknown_item/multiple_errors.stderr b/tests/ui/diagnostic_namespace/on_unknown/multiple_errors.stderr similarity index 100% rename from tests/ui/diagnostic_namespace/on_unknown_item/multiple_errors.stderr rename to tests/ui/diagnostic_namespace/on_unknown/multiple_errors.stderr diff --git a/tests/ui/diagnostic_namespace/on_unknown_item/unknown_import.rs b/tests/ui/diagnostic_namespace/on_unknown/unknown_import.rs similarity index 75% rename from tests/ui/diagnostic_namespace/on_unknown_item/unknown_import.rs rename to tests/ui/diagnostic_namespace/on_unknown/unknown_import.rs index 5af79af23c2c..f2b0f059bb0a 100644 --- a/tests/ui/diagnostic_namespace/on_unknown_item/unknown_import.rs +++ b/tests/ui/diagnostic_namespace/on_unknown/unknown_import.rs @@ -1,9 +1,9 @@ -#![feature(diagnostic_on_unknown_item)] +#![feature(diagnostic_on_unknown)] pub mod foo { pub struct Bar; } -#[diagnostic::on_unknown_item( +#[diagnostic::on_unknown( message = "first message", label = "first label", note = "custom note", diff --git a/tests/ui/diagnostic_namespace/on_unknown_item/unknown_import.stderr b/tests/ui/diagnostic_namespace/on_unknown/unknown_import.stderr similarity index 100% rename from tests/ui/diagnostic_namespace/on_unknown_item/unknown_import.stderr rename to tests/ui/diagnostic_namespace/on_unknown/unknown_import.stderr diff --git a/tests/ui/diagnostic_namespace/on_unknown_item/incorrect-locations.rs b/tests/ui/diagnostic_namespace/on_unknown_item/incorrect-locations.rs deleted file mode 100644 index 7b450f2fd4fa..000000000000 --- a/tests/ui/diagnostic_namespace/on_unknown_item/incorrect-locations.rs +++ /dev/null @@ -1,52 +0,0 @@ -//@ run-pass -#![allow(dead_code, unused_imports)] -#![feature(diagnostic_on_unknown_item)] - -#[diagnostic::on_unknown_item(message = "foo")] -//~^WARN `#[diagnostic::on_unknown_item]` can only be applied to `use` statements -extern crate std as other_std; - -#[diagnostic::on_unknown_item(message = "foo")] -//~^WARN `#[diagnostic::on_unknown_item]` can only be applied to `use` statements -const CONST: () = (); - -#[diagnostic::on_unknown_item(message = "foo")] -//~^WARN `#[diagnostic::on_unknown_item]` can only be applied to `use` statements -static STATIC: () = (); - -#[diagnostic::on_unknown_item(message = "foo")] -//~^WARN `#[diagnostic::on_unknown_item]` can only be applied to `use` statements -type Type = (); - -#[diagnostic::on_unknown_item(message = "foo")] -//~^WARN `#[diagnostic::on_unknown_item]` can only be applied to `use` statements -enum Enum {} - -#[diagnostic::on_unknown_item(message = "foo")] -//~^WARN `#[diagnostic::on_unknown_item]` can only be applied to `use` statements -impl Enum {} - -#[diagnostic::on_unknown_item(message = "foo")] -//~^WARN `#[diagnostic::on_unknown_item]` can only be applied to `use` statements -extern "C" {} - -#[diagnostic::on_unknown_item(message = "foo")] -//~^WARN `#[diagnostic::on_unknown_item]` can only be applied to `use` statements -fn fun() {} - -#[diagnostic::on_unknown_item(message = "foo")] -//~^WARN `#[diagnostic::on_unknown_item]` can only be applied to `use` statements -struct Struct {} - -#[diagnostic::on_unknown_item(message = "foo")] -//~^WARN `#[diagnostic::on_unknown_item]` can only be applied to `use` statements -trait Trait {} - -#[diagnostic::on_unknown_item(message = "foo")] -//~^WARN `#[diagnostic::on_unknown_item]` can only be applied to `use` statements -impl Trait for i32 {} - -#[diagnostic::on_unknown_item(message = "foo")] -use std::str::FromStr; - -fn main() {} diff --git a/tests/ui/diagnostic_namespace/on_unknown_item/incorrect-locations.stderr b/tests/ui/diagnostic_namespace/on_unknown_item/incorrect-locations.stderr deleted file mode 100644 index b09b6c90fd0e..000000000000 --- a/tests/ui/diagnostic_namespace/on_unknown_item/incorrect-locations.stderr +++ /dev/null @@ -1,103 +0,0 @@ -warning: `#[diagnostic::on_unknown_item]` can only be applied to `use` statements - --> $DIR/incorrect-locations.rs:5:1 - | -LL | #[diagnostic::on_unknown_item(message = "foo")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | -LL | extern crate std as other_std; - | ----------------------------- not an import - | - = note: `#[warn(misplaced_diagnostic_attributes)]` (part of `#[warn(unknown_or_malformed_diagnostic_attributes)]`) on by default - -warning: `#[diagnostic::on_unknown_item]` can only be applied to `use` statements - --> $DIR/incorrect-locations.rs:9:1 - | -LL | #[diagnostic::on_unknown_item(message = "foo")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | -LL | const CONST: () = (); - | --------------- not an import - -warning: `#[diagnostic::on_unknown_item]` can only be applied to `use` statements - --> $DIR/incorrect-locations.rs:13:1 - | -LL | #[diagnostic::on_unknown_item(message = "foo")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | -LL | static STATIC: () = (); - | ----------------- not an import - -warning: `#[diagnostic::on_unknown_item]` can only be applied to `use` statements - --> $DIR/incorrect-locations.rs:17:1 - | -LL | #[diagnostic::on_unknown_item(message = "foo")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | -LL | type Type = (); - | --------- not an import - -warning: `#[diagnostic::on_unknown_item]` can only be applied to `use` statements - --> $DIR/incorrect-locations.rs:21:1 - | -LL | #[diagnostic::on_unknown_item(message = "foo")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | -LL | enum Enum {} - | --------- not an import - -warning: `#[diagnostic::on_unknown_item]` can only be applied to `use` statements - --> $DIR/incorrect-locations.rs:25:1 - | -LL | #[diagnostic::on_unknown_item(message = "foo")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | -LL | impl Enum {} - | --------- not an import - -warning: `#[diagnostic::on_unknown_item]` can only be applied to `use` statements - --> $DIR/incorrect-locations.rs:29:1 - | -LL | #[diagnostic::on_unknown_item(message = "foo")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | -LL | extern "C" {} - | ------------- not an import - -warning: `#[diagnostic::on_unknown_item]` can only be applied to `use` statements - --> $DIR/incorrect-locations.rs:33:1 - | -LL | #[diagnostic::on_unknown_item(message = "foo")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | -LL | fn fun() {} - | -------- not an import - -warning: `#[diagnostic::on_unknown_item]` can only be applied to `use` statements - --> $DIR/incorrect-locations.rs:37:1 - | -LL | #[diagnostic::on_unknown_item(message = "foo")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | -LL | struct Struct {} - | ------------- not an import - -warning: `#[diagnostic::on_unknown_item]` can only be applied to `use` statements - --> $DIR/incorrect-locations.rs:41:1 - | -LL | #[diagnostic::on_unknown_item(message = "foo")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | -LL | trait Trait {} - | ----------- not an import - -warning: `#[diagnostic::on_unknown_item]` can only be applied to `use` statements - --> $DIR/incorrect-locations.rs:45:1 - | -LL | #[diagnostic::on_unknown_item(message = "foo")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | -LL | impl Trait for i32 {} - | ------------------ not an import - -warning: 11 warnings emitted - diff --git a/tests/ui/diagnostic_namespace/on_unknown_item/malformed_attribute.rs b/tests/ui/diagnostic_namespace/on_unknown_item/malformed_attribute.rs deleted file mode 100644 index 4ffa9ffe37b5..000000000000 --- a/tests/ui/diagnostic_namespace/on_unknown_item/malformed_attribute.rs +++ /dev/null @@ -1,19 +0,0 @@ -#![feature(diagnostic_on_unknown_item)] -#[diagnostic::on_unknown_item] -//~^WARN missing options for `on_unknown_item` attribute -use std::str::FromStr; - -#[diagnostic::on_unknown_item(foo = "bar", message = "foo")] -//~^WARN malformed `on_unknown_item` attribute -use std::str::Bytes; - -#[diagnostic::on_unknown_item(label = "foo", label = "bar")] -//~^WARN `label` is ignored due to previous definition of `label` -use std::str::Chars; - -#[diagnostic::on_unknown_item(message = "Foo", message = "Bar")] -//~^WARN `message` is ignored due to previous definition of `message` -use std::str::NotExisting; -//~^ERROR Foo - -fn main() {} diff --git a/tests/ui/diagnostic_namespace/on_unknown_item/malformed_attribute.stderr b/tests/ui/diagnostic_namespace/on_unknown_item/malformed_attribute.stderr deleted file mode 100644 index 42caaa9354af..000000000000 --- a/tests/ui/diagnostic_namespace/on_unknown_item/malformed_attribute.stderr +++ /dev/null @@ -1,44 +0,0 @@ -error[E0432]: Foo - --> $DIR/malformed_attribute.rs:16:5 - | -LL | use std::str::NotExisting; - | ^^^^^^^^^^^^^^^^^^^^^ no `NotExisting` in `str` - | - = note: unresolved import `std::str::NotExisting` - -warning: missing options for `on_unknown_item` attribute - --> $DIR/malformed_attribute.rs:2:1 - | -LL | #[diagnostic::on_unknown_item] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: at least one of the `message`, `note` and `label` options are expected - = note: `#[warn(malformed_diagnostic_attributes)]` (part of `#[warn(unknown_or_malformed_diagnostic_attributes)]`) on by default - -warning: malformed `on_unknown_item` attribute - --> $DIR/malformed_attribute.rs:6:31 - | -LL | #[diagnostic::on_unknown_item(foo = "bar", message = "foo")] - | ^^^^^^^^^^^ invalid option found here - | - = help: only `message`, `note` and `label` are allowed as options - -warning: `label` is ignored due to previous definition of `label` - --> $DIR/malformed_attribute.rs:10:46 - | -LL | #[diagnostic::on_unknown_item(label = "foo", label = "bar")] - | ------------- ^^^^^^^^^^^^^ `label` is later redundantly declared here - | | - | `label` is first declared here - -warning: `message` is ignored due to previous definition of `message` - --> $DIR/malformed_attribute.rs:14:48 - | -LL | #[diagnostic::on_unknown_item(message = "Foo", message = "Bar")] - | --------------- ^^^^^^^^^^^^^^^ `message` is later redundantly declared here - | | - | `message` is first declared here - -error: aborting due to 1 previous error; 4 warnings emitted - -For more information about this error, try `rustc --explain E0432`. diff --git a/tests/ui/feature-gates/feature-gate-diagnostic-on-unknown-item.rs b/tests/ui/feature-gates/feature-gate-diagnostic-on-unknown.rs similarity index 76% rename from tests/ui/feature-gates/feature-gate-diagnostic-on-unknown-item.rs rename to tests/ui/feature-gates/feature-gate-diagnostic-on-unknown.rs index fffb54636cfb..11cc0d50e0c9 100644 --- a/tests/ui/feature-gates/feature-gate-diagnostic-on-unknown-item.rs +++ b/tests/ui/feature-gates/feature-gate-diagnostic-on-unknown.rs @@ -1,6 +1,6 @@ #![deny(warnings)] -#[diagnostic::on_unknown_item(message = "Tada")] +#[diagnostic::on_unknown(message = "Tada")] //~^ ERROR: unknown diagnostic attribute use std::vec::NotExisting; //~^ ERROR: unresolved import `std::vec::NotExisting` diff --git a/tests/ui/feature-gates/feature-gate-diagnostic-on-unknown-item.stderr b/tests/ui/feature-gates/feature-gate-diagnostic-on-unknown.stderr similarity index 64% rename from tests/ui/feature-gates/feature-gate-diagnostic-on-unknown-item.stderr rename to tests/ui/feature-gates/feature-gate-diagnostic-on-unknown.stderr index 10662eb83b4a..f6d7ffadacea 100644 --- a/tests/ui/feature-gates/feature-gate-diagnostic-on-unknown-item.stderr +++ b/tests/ui/feature-gates/feature-gate-diagnostic-on-unknown.stderr @@ -1,17 +1,17 @@ error[E0432]: unresolved import `std::vec::NotExisting` - --> $DIR/feature-gate-diagnostic-on-unknown-item.rs:5:5 + --> $DIR/feature-gate-diagnostic-on-unknown.rs:5:5 | LL | use std::vec::NotExisting; | ^^^^^^^^^^^^^^^^^^^^^ no `NotExisting` in `vec` error: unknown diagnostic attribute - --> $DIR/feature-gate-diagnostic-on-unknown-item.rs:3:15 + --> $DIR/feature-gate-diagnostic-on-unknown.rs:3:15 | -LL | #[diagnostic::on_unknown_item(message = "Tada")] - | ^^^^^^^^^^^^^^^ +LL | #[diagnostic::on_unknown(message = "Tada")] + | ^^^^^^^^^^ | note: the lint level is defined here - --> $DIR/feature-gate-diagnostic-on-unknown-item.rs:1:9 + --> $DIR/feature-gate-diagnostic-on-unknown.rs:1:9 | LL | #![deny(warnings)] | ^^^^^^^^