diff --git a/compiler/rustc_attr_data_structures/src/attributes.rs b/compiler/rustc_attr_data_structures/src/attributes.rs index 995ac514d8d6c..981d9b6678f2f 100644 --- a/compiler/rustc_attr_data_structures/src/attributes.rs +++ b/compiler/rustc_attr_data_structures/src/attributes.rs @@ -141,6 +141,13 @@ pub enum UsedBy { Linker, } +#[derive(Encodable, Decodable, Clone, Debug, PartialEq, Eq, Hash)] +#[derive(HashStable_Generic, PrintAttribute)] +pub enum MacroUseArgs { + UseAll, + UseSpecific(ThinVec), +} + #[derive(Debug, Clone, Encodable, Decodable, HashStable_Generic)] pub struct StrippedCfgItem { pub parent_module: ModId, @@ -331,9 +338,15 @@ pub enum AttributeKind { /// Represents `#[loop_match]`. LoopMatch(Span), + /// Represents `#[macro_escape]`. + MacroEscape(Span), + /// Represents `#[rustc_macro_transparency]`. MacroTransparency(Transparency), + /// Represents `#[macro_use]`. + MacroUse { span: Span, arguments: MacroUseArgs }, + /// Represents `#[marker]`. Marker(Span), diff --git a/compiler/rustc_attr_data_structures/src/encode_cross_crate.rs b/compiler/rustc_attr_data_structures/src/encode_cross_crate.rs index 494b570c86c73..f3b73b0e88a31 100644 --- a/compiler/rustc_attr_data_structures/src/encode_cross_crate.rs +++ b/compiler/rustc_attr_data_structures/src/encode_cross_crate.rs @@ -44,7 +44,9 @@ impl AttributeKind { LinkOrdinal { .. } => No, LinkSection { .. } => No, LoopMatch(..) => No, + MacroEscape(..) => No, MacroTransparency(..) => Yes, + MacroUse { .. } => No, Marker(..) => No, MayDangle(..) => No, MustUse { .. } => Yes, diff --git a/compiler/rustc_attr_data_structures/src/lib.rs b/compiler/rustc_attr_data_structures/src/lib.rs index 8f8ce575a1830..f2b303dda1730 100644 --- a/compiler/rustc_attr_data_structures/src/lib.rs +++ b/compiler/rustc_attr_data_structures/src/lib.rs @@ -24,7 +24,7 @@ use rustc_ast::token::CommentKind; use rustc_ast::{AttrStyle, IntTy, UintTy}; use rustc_ast_pretty::pp::Printer; use rustc_span::hygiene::Transparency; -use rustc_span::{Span, Symbol}; +use rustc_span::{Ident, Span, Symbol}; pub use stability::*; use thin_vec::ThinVec; pub use version::*; @@ -172,7 +172,7 @@ macro_rules! print_tup { print_tup!(A B C D E F G H); print_skip!(Span, ()); print_disp!(u16, bool, NonZero); -print_debug!(Symbol, UintTy, IntTy, Align, AttrStyle, CommentKind, Transparency); +print_debug!(Symbol, Ident, UintTy, IntTy, Align, AttrStyle, CommentKind, Transparency); /// Finds attributes in sequences of attributes by pattern matching. /// diff --git a/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs b/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs index 34d9b04834825..3bd29dd039177 100644 --- a/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs +++ b/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs @@ -100,7 +100,7 @@ impl AttributeParser for NakedParser { } })]; - fn finalize(self, cx: &FinalizeContext<'_, '_, S>) -> Option { + fn finalize(self, cx: &mut FinalizeContext<'_, '_, S>) -> Option { // FIXME(jdonszelmann): upgrade this list to *parsed* attributes // once all of these have parsed forms. That'd make the check much nicer... // @@ -271,7 +271,7 @@ impl AttributeParser for UsedParser { }, )]; - fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option { + fn finalize(self, _cx: &mut FinalizeContext<'_, '_, S>) -> Option { // Ratcheting behaviour, if both `linker` and `compiler` are specified, use `linker` Some(match (self.first_compiler, self.first_linker) { (_, Some(span)) => AttributeKind::Used { used_by: UsedBy::Linker, span }, diff --git a/compiler/rustc_attr_parsing/src/attributes/confusables.rs b/compiler/rustc_attr_parsing/src/attributes/confusables.rs index c911908dfb381..2a15f7166696e 100644 --- a/compiler/rustc_attr_parsing/src/attributes/confusables.rs +++ b/compiler/rustc_attr_parsing/src/attributes/confusables.rs @@ -42,7 +42,7 @@ impl AttributeParser for ConfusablesParser { }, )]; - fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option { + fn finalize(self, _cx: &mut FinalizeContext<'_, '_, S>) -> Option { if self.confusables.is_empty() { return None; } diff --git a/compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs b/compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs new file mode 100644 index 0000000000000..41e56d498c2cc --- /dev/null +++ b/compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs @@ -0,0 +1,105 @@ +use rustc_attr_data_structures::{AttributeKind, MacroUseArgs}; +use rustc_errors::DiagArgValue; +use rustc_feature::{AttributeTemplate, template}; +use rustc_span::{Ident, Span, Symbol, sym}; +use thin_vec::ThinVec; + +use crate::attributes::{AcceptMapping, AttributeParser, NoArgsAttributeParser, OnDuplicate}; +use crate::context::{AcceptContext, FinalizeContext, Stage}; +use crate::parser::ArgParser; +use crate::session_diagnostics; + +pub(crate) struct MacroEscapeParser; +impl NoArgsAttributeParser for MacroEscapeParser { + const PATH: &[Symbol] = &[sym::macro_escape]; + const ON_DUPLICATE: OnDuplicate = OnDuplicate::Warn; + const CREATE: fn(Span) -> AttributeKind = AttributeKind::MacroEscape; +} + +/// `#[macro_use]` attributes can either: +/// - Use all macros from a crate, if provided without arguments +/// - Use specific macros from a crate, if provided with arguments `#[macro_use(macro1, macro2)]` +/// A warning should be provided if an use all is combined with specific uses, or if multiple use-alls are used. +#[derive(Default)] +pub(crate) struct MacroUseParser { + /// All specific imports found so far + uses: ThinVec, + /// Span of the first `#[macro_use]` arguments without arguments, used for linting + use_all: Option, + /// Spans of all `#[macro_use]` arguments with arguments, used for linting + uses_attr_spans: ThinVec, + /// Span of the first `#[macro_use]` argument, used as the span for this attribute + first_span: Option, +} + +const MACRO_USE_TEMPLATE: AttributeTemplate = template!(Word, List: "name1, name2, ..."); + +impl AttributeParser for MacroUseParser { + const ATTRIBUTES: AcceptMapping = &[( + &[sym::macro_use], + MACRO_USE_TEMPLATE, + |group: &mut Self, cx: &mut AcceptContext<'_, '_, S>, args| { + let span = cx.attr_span; + group.first_span.get_or_insert(span); + match args { + ArgParser::NoArgs => { + // If there is a `#[macro_use]` import already, give a warning + if let Some(old_attr) = group.use_all.replace(span) { + cx.warn_unused_duplicate(old_attr, span); + } + } + ArgParser::List(list) => { + let mut arguments = ThinVec::new(); + + if list.is_empty() { + cx.warn_empty_attribute(list.span); + return; + } + group.uses_attr_spans.push(cx.attr_span); + + for item in list.mixed() { + let Some(item) = item.meta_item() else { + cx.expected_identifier(item.span()); + continue; + }; + if let Err(err_span) = item.args().no_args() { + cx.expected_no_args(err_span); + continue; + } + let Some(item) = item.path().word() else { + cx.expected_identifier(item.span()); + continue; + }; + arguments.push(item); + } + + group.uses.extend(arguments); + } + ArgParser::NameValue(_) => { + let suggestions = MACRO_USE_TEMPLATE.suggestions(false, sym::macro_use); + cx.emit_err(session_diagnostics::IllFormedAttributeInputLint { + num_suggestions: suggestions.len(), + suggestions: DiagArgValue::StrListSepByAnd( + suggestions.into_iter().map(|s| format!("`{s}`").into()).collect(), + ), + span, + }); + return; + } + }; + }, + )]; + + fn finalize(self, cx: &mut FinalizeContext<'_, '_, S>) -> Option { + let arguments = if let Some(use_all) = self.use_all { + // If there is a `#[macro_use]` attribute, warn on all `#[macro_use(...)]` attributes since everything is already imported + for specific_use in self.uses_attr_spans { + cx.warn_unused_duplicate(use_all, specific_use); + } + MacroUseArgs::UseAll + } else { + MacroUseArgs::UseSpecific(self.uses) + }; + Some(AttributeKind::MacroUse { span: self.first_span?, arguments }) + } +} diff --git a/compiler/rustc_attr_parsing/src/attributes/mod.rs b/compiler/rustc_attr_parsing/src/attributes/mod.rs index 200f138196029..acf610eb31d6e 100644 --- a/compiler/rustc_attr_parsing/src/attributes/mod.rs +++ b/compiler/rustc_attr_parsing/src/attributes/mod.rs @@ -36,6 +36,7 @@ pub(crate) mod inline; pub(crate) mod link_attrs; pub(crate) mod lint_helpers; pub(crate) mod loop_match; +pub(crate) mod macro_attrs; pub(crate) mod must_use; pub(crate) mod no_implicit_prelude; pub(crate) mod non_exhaustive; @@ -85,7 +86,7 @@ pub(crate) trait AttributeParser: Default + 'static { /// that'd be equivalent to unconditionally applying an attribute to /// every single syntax item that could have attributes applied to it. /// Your accept mappings should determine whether this returns something. - fn finalize(self, cx: &FinalizeContext<'_, '_, S>) -> Option; + fn finalize(self, cx: &mut FinalizeContext<'_, '_, S>) -> Option; } /// Alternative to [`AttributeParser`] that automatically handles state management. @@ -161,7 +162,7 @@ impl, S: Stage> AttributeParser for Single }, )]; - fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option { + fn finalize(self, _cx: &mut FinalizeContext<'_, '_, S>) -> Option { Some(self.1?.0) } } @@ -331,7 +332,7 @@ impl, S: Stage> AttributeParser for Combine) -> Option { + fn finalize(self, _cx: &mut FinalizeContext<'_, '_, S>) -> Option { if let Some(first_span) = self.first_span { Some(T::CONVERT(self.items, first_span)) } else { diff --git a/compiler/rustc_attr_parsing/src/attributes/must_use.rs b/compiler/rustc_attr_parsing/src/attributes/must_use.rs index e0a3e6755099b..42af3ed0bfab2 100644 --- a/compiler/rustc_attr_parsing/src/attributes/must_use.rs +++ b/compiler/rustc_attr_parsing/src/attributes/must_use.rs @@ -34,7 +34,7 @@ impl SingleAttributeParser for MustUseParser { ArgParser::List(_) => { let suggestions = >::TEMPLATE.suggestions(false, "must_use"); - cx.emit_err(session_diagnostics::MustUseIllFormedAttributeInput { + cx.emit_err(session_diagnostics::IllFormedAttributeInputLint { num_suggestions: suggestions.len(), suggestions: DiagArgValue::StrListSepByAnd( suggestions.into_iter().map(|s| format!("`{s}`").into()).collect(), diff --git a/compiler/rustc_attr_parsing/src/attributes/repr.rs b/compiler/rustc_attr_parsing/src/attributes/repr.rs index 6a45832ed7fda..6f7c9d0abd3c2 100644 --- a/compiler/rustc_attr_parsing/src/attributes/repr.rs +++ b/compiler/rustc_attr_parsing/src/attributes/repr.rs @@ -317,7 +317,7 @@ impl AlignParser { impl AttributeParser for AlignParser { const ATTRIBUTES: AcceptMapping = &[(Self::PATH, Self::TEMPLATE, Self::parse)]; - fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option { + fn finalize(self, _cx: &mut FinalizeContext<'_, '_, S>) -> Option { let (align, span) = self.0?; Some(AttributeKind::Align { align, span }) } diff --git a/compiler/rustc_attr_parsing/src/attributes/stability.rs b/compiler/rustc_attr_parsing/src/attributes/stability.rs index 6bccd0042a80d..e66e233ec257b 100644 --- a/compiler/rustc_attr_parsing/src/attributes/stability.rs +++ b/compiler/rustc_attr_parsing/src/attributes/stability.rs @@ -80,7 +80,7 @@ impl AttributeParser for StabilityParser { ), ]; - fn finalize(mut self, cx: &FinalizeContext<'_, '_, S>) -> Option { + fn finalize(mut self, cx: &mut FinalizeContext<'_, '_, S>) -> Option { if let Some(atum) = self.allowed_through_unstable_modules { if let Some(( Stability { @@ -125,7 +125,7 @@ impl AttributeParser for BodyStabilityParser { }, )]; - fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option { + fn finalize(self, _cx: &mut FinalizeContext<'_, '_, S>) -> Option { let (stability, span) = self.stability?; Some(AttributeKind::BodyStability { stability, span }) @@ -188,7 +188,7 @@ impl AttributeParser for ConstStabilityParser { }), ]; - fn finalize(mut self, cx: &FinalizeContext<'_, '_, S>) -> Option { + fn finalize(mut self, cx: &mut FinalizeContext<'_, '_, S>) -> Option { if self.promotable { if let Some((ref mut stab, _)) = self.stability { stab.promotable = true; diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index 1f6675b4c5a8a..d031c3df51787 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -30,6 +30,7 @@ use crate::attributes::lint_helpers::{ AsPtrParser, AutomaticallyDerivedParser, PassByValueParser, PubTransparentParser, }; use crate::attributes::loop_match::{ConstContinueParser, LoopMatchParser}; +use crate::attributes::macro_attrs::{MacroEscapeParser, MacroUseParser}; use crate::attributes::must_use::MustUseParser; use crate::attributes::no_implicit_prelude::NoImplicitPreludeParser; use crate::attributes::non_exhaustive::NonExhaustiveParser; @@ -123,6 +124,7 @@ attribute_parsers!( BodyStabilityParser, ConfusablesParser, ConstStabilityParser, + MacroUseParser, NakedParser, StabilityParser, UsedParser, @@ -169,6 +171,7 @@ attribute_parsers!( Single>, Single>, Single>, + Single>, Single>, Single>, Single>, @@ -380,6 +383,17 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> { }) } + /// emit an error that a `name` was expected here + pub(crate) fn expected_identifier(&self, span: Span) -> ErrorGuaranteed { + self.emit_err(AttributeParseError { + span, + attr_span: self.attr_span, + template: self.template.clone(), + attribute: self.attr_path.clone(), + reason: AttributeParseErrorReason::ExpectedIdentifier, + }) + } + /// emit an error that a `name = value` pair was expected at this span. The symbol can be given for /// a nicer error message talking about the specific name that was found lacking a value. pub(crate) fn expected_name_value(&self, span: Span, name: Option) -> ErrorGuaranteed { diff --git a/compiler/rustc_attr_parsing/src/session_diagnostics.rs b/compiler/rustc_attr_parsing/src/session_diagnostics.rs index 97bf3d1c54955..1b9afc0b71271 100644 --- a/compiler/rustc_attr_parsing/src/session_diagnostics.rs +++ b/compiler/rustc_attr_parsing/src/session_diagnostics.rs @@ -438,7 +438,7 @@ pub(crate) struct IllFormedAttributeInput { #[derive(Diagnostic)] #[diag(attr_parsing_ill_formed_attribute_input)] -pub(crate) struct MustUseIllFormedAttributeInput { +pub(crate) struct IllFormedAttributeInputLint { #[primary_span] pub span: Span, pub num_suggestions: usize, @@ -534,6 +534,7 @@ pub(crate) enum AttributeParseErrorReason { ExpectedNameValue(Option), DuplicateKey(Symbol), ExpectedSpecificArgument { possibilities: Vec<&'static str>, strings: bool }, + ExpectedIdentifier, } pub(crate) struct AttributeParseError { @@ -585,11 +586,11 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AttributeParseError { diag.code(E0538); } AttributeParseErrorReason::UnexpectedLiteral => { - diag.span_label(self.span, format!("didn't expect a literal here")); + diag.span_label(self.span, "didn't expect a literal here"); diag.code(E0565); } AttributeParseErrorReason::ExpectedNoArgs => { - diag.span_label(self.span, format!("didn't expect any arguments here")); + diag.span_label(self.span, "didn't expect any arguments here"); diag.code(E0565); } AttributeParseErrorReason::ExpectedNameValue(None) => { @@ -633,6 +634,9 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AttributeParseError { } } } + AttributeParseErrorReason::ExpectedIdentifier => { + diag.span_label(self.span, "expected a valid identifier here"); + } } let suggestions = self.template.suggestions(false, &name); diff --git a/compiler/rustc_error_codes/src/error_codes/E0466.md b/compiler/rustc_error_codes/src/error_codes/E0466.md index 7aefedbc0875d..28016eb395e97 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0466.md +++ b/compiler/rustc_error_codes/src/error_codes/E0466.md @@ -1,8 +1,10 @@ +#### Note: this error code is no longer emitted by the compiler. + Macro import declaration was malformed. Erroneous code examples: -```compile_fail,E0466 +```compile_fail #[macro_use(a_macro(another_macro))] // error: invalid import declaration extern crate core as some_crate; diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 159518a8d8716..1ef567d4b01a7 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -1302,6 +1302,7 @@ impl AttributeExt for Attribute { // FIXME: should not be needed anymore when all attrs are parsed Attribute::Parsed(AttributeKind::Deprecation { span, .. }) => *span, Attribute::Parsed(AttributeKind::DocComment { span, .. }) => *span, + Attribute::Parsed(AttributeKind::MacroUse { span, .. }) => *span, Attribute::Parsed(AttributeKind::MayDangle(span)) => *span, Attribute::Parsed(AttributeKind::Ignore { span, .. }) => *span, Attribute::Parsed(AttributeKind::AutomaticallyDerived(span)) => *span, diff --git a/compiler/rustc_parse/src/validate_attr.rs b/compiler/rustc_parse/src/validate_attr.rs index e000d61083ddb..e2bcd578b454e 100644 --- a/compiler/rustc_parse/src/validate_attr.rs +++ b/compiler/rustc_parse/src/validate_attr.rs @@ -300,6 +300,8 @@ pub fn check_builtin_meta_item( | sym::cold | sym::target_feature | sym::rustc_allow_const_fn_unstable + | sym::macro_use + | sym::macro_escape | sym::naked | sym::no_mangle | sym::non_exhaustive diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 820255afe274d..3598b4b415b0d 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -214,6 +214,12 @@ impl<'tcx> CheckAttrVisitor<'tcx> { Attribute::Parsed(AttributeKind::LinkSection { span: attr_span, .. }) => { self.check_link_section(hir_id, *attr_span, span, target) } + Attribute::Parsed(AttributeKind::MacroUse { span, .. }) => { + self.check_macro_use(hir_id, sym::macro_use, *span, target) + } + Attribute::Parsed(AttributeKind::MacroEscape(span)) => { + self.check_macro_use(hir_id, sym::macro_escape, *span, target) + } Attribute::Parsed(AttributeKind::Naked(attr_span)) => { self.check_naked(hir_id, *attr_span, span, target) } @@ -343,9 +349,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> { [sym::ffi_pure, ..] => self.check_ffi_pure(attr.span(), attrs, target), [sym::ffi_const, ..] => self.check_ffi_const(attr.span(), target), [sym::link, ..] => self.check_link(hir_id, attr, span, target), - [sym::macro_use, ..] | [sym::macro_escape, ..] => { - self.check_macro_use(hir_id, attr, target) - } [sym::path, ..] => self.check_generic_attr_unparsed(hir_id, attr, target, Target::Mod), [sym::macro_export, ..] => self.check_macro_export(hir_id, attr, target), [sym::should_panic, ..] => { @@ -2314,17 +2317,14 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } } - fn check_macro_use(&self, hir_id: HirId, attr: &Attribute, target: Target) { - let Some(name) = attr.name() else { - return; - }; + fn check_macro_use(&self, hir_id: HirId, name: Symbol, attr_span: Span, target: Target) { match target { Target::ExternCrate | Target::Mod => {} _ => { self.tcx.emit_node_span_lint( UNUSED_ATTRIBUTES, hir_id, - attr.span(), + attr_span, errors::MacroUse { name }, ); } @@ -2377,7 +2377,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> { // Warn on useless empty attributes. // FIXME(jdonszelmann): this lint should be moved to attribute parsing, see `AcceptContext::warn_empty_attribute` let note = if attr.has_any_name(&[ - sym::macro_use, sym::allow, sym::expect, sym::warn, diff --git a/compiler/rustc_resolve/messages.ftl b/compiler/rustc_resolve/messages.ftl index aa818cc9c4649..39e9a9cc58afd 100644 --- a/compiler/rustc_resolve/messages.ftl +++ b/compiler/rustc_resolve/messages.ftl @@ -41,8 +41,6 @@ resolve_attempt_to_use_non_constant_value_in_constant_without_suggestion = resolve_attributes_starting_with_rustc_are_reserved = attributes starting with `rustc` are reserved for use by the `rustc` compiler -resolve_bad_macro_import = bad macro import - resolve_binding_in_never_pattern = never patterns cannot contain variable bindings .suggestion = use a wildcard `_` instead diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 6979d89a8e7bb..fcea738a4866d 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -11,11 +11,14 @@ use std::sync::Arc; use rustc_ast::visit::{self, AssocCtxt, Visitor, WalkItemKind}; use rustc_ast::{ self as ast, AssocItem, AssocItemKind, Block, ConstItem, Delegation, Fn, ForeignItem, - ForeignItemKind, Impl, Item, ItemKind, MetaItemKind, NodeId, StaticItem, StmtKind, TyAlias, + ForeignItemKind, Impl, Item, ItemKind, NodeId, StaticItem, StmtKind, TyAlias, }; +use rustc_attr_data_structures::{AttributeKind, MacroUseArgs}; use rustc_attr_parsing as attr; +use rustc_attr_parsing::AttributeParser; use rustc_expand::base::ResolverExpand; use rustc_expand::expand::AstFragment; +use rustc_hir::Attribute; use rustc_hir::def::{self, *}; use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LocalDefId}; use rustc_index::bit_set::DenseBitSet; @@ -25,6 +28,7 @@ use rustc_middle::ty::Feed; use rustc_middle::{bug, ty}; use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind}; use rustc_span::{Ident, Span, Symbol, kw, sym}; +use thin_vec::ThinVec; use tracing::debug; use crate::Namespace::{MacroNS, TypeNS, ValueNS}; @@ -1030,42 +1034,31 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> { /// Returns `true` if we should consider the underlying `extern crate` to be used. fn process_macro_use_imports(&mut self, item: &Item, module: Module<'ra>) -> bool { let mut import_all = None; - let mut single_imports = Vec::new(); - for attr in &item.attrs { - if attr.has_name(sym::macro_use) { - if self.parent_scope.module.parent.is_some() { - self.r.dcx().emit_err(errors::ExternCrateLoadingMacroNotAtCrateRoot { - span: item.span, - }); - } - if let ItemKind::ExternCrate(Some(orig_name), _) = item.kind - && orig_name == kw::SelfLower - { - self.r.dcx().emit_err(errors::MacroUseExternCrateSelf { span: attr.span }); - } - let ill_formed = |span| { - self.r.dcx().emit_err(errors::BadMacroImport { span }); - }; - match attr.meta() { - Some(meta) => match meta.kind { - MetaItemKind::Word => { - import_all = Some(meta.span); - break; - } - MetaItemKind::List(meta_item_inners) => { - for meta_item_inner in meta_item_inners { - match meta_item_inner.ident() { - Some(ident) if meta_item_inner.is_word() => { - single_imports.push(ident) - } - _ => ill_formed(meta_item_inner.span()), - } - } - } - MetaItemKind::NameValue(..) => ill_formed(meta.span), - }, - None => ill_formed(attr.span), - } + let mut single_imports = ThinVec::new(); + if let Some(Attribute::Parsed(AttributeKind::MacroUse { span, arguments })) = + AttributeParser::parse_limited( + self.r.tcx.sess, + &item.attrs, + sym::macro_use, + item.span, + item.id, + None, + ) + { + if self.parent_scope.module.parent.is_some() { + self.r + .dcx() + .emit_err(errors::ExternCrateLoadingMacroNotAtCrateRoot { span: item.span }); + } + if let ItemKind::ExternCrate(Some(orig_name), _) = item.kind + && orig_name == kw::SelfLower + { + self.r.dcx().emit_err(errors::MacroUseExternCrateSelf { span }); + } + + match arguments { + MacroUseArgs::UseAll => import_all = Some(span), + MacroUseArgs::UseSpecific(imports) => single_imports = imports, } } diff --git a/compiler/rustc_resolve/src/errors.rs b/compiler/rustc_resolve/src/errors.rs index b34bcb38f844c..d6b1e4de6ea1a 100644 --- a/compiler/rustc_resolve/src/errors.rs +++ b/compiler/rustc_resolve/src/errors.rs @@ -815,13 +815,6 @@ pub(crate) struct ExternCrateLoadingMacroNotAtCrateRoot { pub(crate) span: Span, } -#[derive(Diagnostic)] -#[diag(resolve_bad_macro_import, code = E0466)] -pub(crate) struct BadMacroImport { - #[primary_span] - pub(crate) span: Span, -} - #[derive(Diagnostic)] #[diag(resolve_extern_crate_self_requires_renaming)] pub(crate) struct ExternCrateSelfRequiresRenaming { diff --git a/src/tools/clippy/clippy_lints/src/macro_use.rs b/src/tools/clippy/clippy_lints/src/macro_use.rs index c1a26c5a9c73d..d1a54df988f52 100644 --- a/src/tools/clippy/clippy_lints/src/macro_use.rs +++ b/src/tools/clippy/clippy_lints/src/macro_use.rs @@ -7,8 +7,9 @@ use rustc_hir::{self as hir, AmbigArg}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_session::impl_lint_pass; use rustc_span::edition::Edition; -use rustc_span::{Span, sym}; +use rustc_span::{Span}; use std::collections::BTreeMap; +use rustc_attr_data_structures::{AttributeKind, find_attr}; declare_clippy_lint! { /// ### What it does @@ -99,15 +100,14 @@ impl LateLintPass<'_> for MacroUseImports { && let hir::ItemKind::Use(path, _kind) = &item.kind && let hir_id = item.hir_id() && let attrs = cx.tcx.hir_attrs(hir_id) - && let Some(mac_attr) = attrs.iter().find(|attr| attr.has_name(sym::macro_use)) + && let Some(mac_attr_span) = find_attr!(attrs, AttributeKind::MacroUse {span, ..} => *span) && let Some(Res::Def(DefKind::Mod, id)) = path.res.type_ns && !id.is_local() { for kid in cx.tcx.module_children(id) { if let Res::Def(DefKind::Macro(_mac_type), mac_id) = kid.res { - let span = mac_attr.span(); let def_path = cx.tcx.def_path_str(mac_id); - self.imports.push((def_path, span, hir_id)); + self.imports.push((def_path, mac_attr_span, hir_id)); } } } else if item.span.from_expansion() { diff --git a/tests/pretty/hir-delegation.pp b/tests/pretty/hir-delegation.pp index e452cee636597..c0d724cccb51e 100644 --- a/tests/pretty/hir-delegation.pp +++ b/tests/pretty/hir-delegation.pp @@ -6,7 +6,7 @@ #![feature(fn_delegation)] #[prelude_import] use ::std::prelude::rust_2015::*; -#[macro_use] +#[attr = MacroUse {arguments: UseAll}] extern crate std; fn b(e: C) { } diff --git a/tests/pretty/hir-fn-params.pp b/tests/pretty/hir-fn-params.pp index 3799c8a3c3b7c..cfb33cc93ebad 100644 --- a/tests/pretty/hir-fn-params.pp +++ b/tests/pretty/hir-fn-params.pp @@ -1,6 +1,6 @@ #[prelude_import] use ::std::prelude::rust_2015::*; -#[macro_use] +#[attr = MacroUse {arguments: UseAll}] extern crate std; //@ pretty-compare-only //@ pretty-mode:hir diff --git a/tests/pretty/hir-fn-variadic.pp b/tests/pretty/hir-fn-variadic.pp index b6bc8e95127f7..99919e7fc6b2d 100644 --- a/tests/pretty/hir-fn-variadic.pp +++ b/tests/pretty/hir-fn-variadic.pp @@ -5,7 +5,7 @@ #![feature(c_variadic)] #[prelude_import] use ::std::prelude::rust_2015::*; -#[macro_use] +#[attr = MacroUse {arguments: UseAll}] extern crate std; extern "C" { diff --git a/tests/pretty/hir-if-else.pp b/tests/pretty/hir-if-else.pp index 200e34ac4f5a4..4bccde663eb53 100644 --- a/tests/pretty/hir-if-else.pp +++ b/tests/pretty/hir-if-else.pp @@ -1,6 +1,6 @@ #[prelude_import] use ::std::prelude::rust_2015::*; -#[macro_use] +#[attr = MacroUse {arguments: UseAll}] extern crate std; //@ pretty-compare-only //@ pretty-mode:hir diff --git a/tests/pretty/hir-lifetimes.pp b/tests/pretty/hir-lifetimes.pp index 58de6d8191583..1bb2f17cdfb4a 100644 --- a/tests/pretty/hir-lifetimes.pp +++ b/tests/pretty/hir-lifetimes.pp @@ -7,7 +7,7 @@ #![allow(unused)] #[prelude_import] use ::std::prelude::rust_2015::*; -#[macro_use] +#[attr = MacroUse {arguments: UseAll}] extern crate std; struct Foo<'a> { diff --git a/tests/pretty/hir-pretty-attr.pp b/tests/pretty/hir-pretty-attr.pp index db7489c12641e..c780f8e3639fe 100644 --- a/tests/pretty/hir-pretty-attr.pp +++ b/tests/pretty/hir-pretty-attr.pp @@ -1,6 +1,6 @@ #[prelude_import] use ::std::prelude::rust_2015::*; -#[macro_use] +#[attr = MacroUse {arguments: UseAll}] extern crate std; //@ pretty-compare-only //@ pretty-mode:hir diff --git a/tests/pretty/hir-pretty-loop.pp b/tests/pretty/hir-pretty-loop.pp index 15f1677885aee..c07120273c909 100644 --- a/tests/pretty/hir-pretty-loop.pp +++ b/tests/pretty/hir-pretty-loop.pp @@ -1,6 +1,6 @@ #[prelude_import] use ::std::prelude::rust_2015::*; -#[macro_use] +#[attr = MacroUse {arguments: UseAll}] extern crate std; //@ pretty-compare-only //@ pretty-mode:hir diff --git a/tests/pretty/hir-struct-expr.pp b/tests/pretty/hir-struct-expr.pp index f85d17542dffb..177eb5e8631fa 100644 --- a/tests/pretty/hir-struct-expr.pp +++ b/tests/pretty/hir-struct-expr.pp @@ -1,6 +1,6 @@ #[prelude_import] use ::std::prelude::rust_2015::*; -#[macro_use] +#[attr = MacroUse {arguments: UseAll}] extern crate std; //@ pretty-compare-only //@ pretty-mode:hir diff --git a/tests/pretty/issue-4264.pp b/tests/pretty/issue-4264.pp index eb808f7122a9d..f4b641335d1db 100644 --- a/tests/pretty/issue-4264.pp +++ b/tests/pretty/issue-4264.pp @@ -1,6 +1,6 @@ #[prelude_import] use ::std::prelude::rust_2015::*; -#[macro_use] +#[attr = MacroUse {arguments: UseAll}] extern crate std; //@ pretty-compare-only //@ pretty-mode:hir,typed diff --git a/tests/pretty/issue-85089.pp b/tests/pretty/issue-85089.pp index f4e0eb3dd5ff1..31c0f90bf27ee 100644 --- a/tests/pretty/issue-85089.pp +++ b/tests/pretty/issue-85089.pp @@ -1,6 +1,6 @@ #[prelude_import] use ::std::prelude::rust_2015::*; -#[macro_use] +#[attr = MacroUse {arguments: UseAll}] extern crate std; // Test to print lifetimes on HIR pretty-printing. diff --git a/tests/pretty/pin-ergonomics-hir.pp b/tests/pretty/pin-ergonomics-hir.pp index 212e0e174daeb..58a1c62f712c3 100644 --- a/tests/pretty/pin-ergonomics-hir.pp +++ b/tests/pretty/pin-ergonomics-hir.pp @@ -6,7 +6,7 @@ #![allow(dead_code, incomplete_features)] #[prelude_import] use ::std::prelude::rust_2015::*; -#[macro_use] +#[attr = MacroUse {arguments: UseAll}] extern crate std; use std::pin::Pin; diff --git a/tests/ui/attributes/invalid-macro-use.rs b/tests/ui/attributes/invalid-macro-use.rs new file mode 100644 index 0000000000000..cfb13fd183c76 --- /dev/null +++ b/tests/ui/attributes/invalid-macro-use.rs @@ -0,0 +1,53 @@ +#![deny(unused_attributes)] +//~^ NOTE the lint level is defined here + +#[macro_use = 5] +//~^ ERROR valid forms for the attribute are `#[macro_use(name1, name2, ...)]` and `#[macro_use]` +extern crate std as s1; + +#[macro_use(5)] +//~^ ERROR malformed `macro_use` attribute input +//~| NOTE expected a valid identifier here +extern crate std as s2; + +#[macro_use(a = "b")] +//~^ ERROR malformed `macro_use` attribute input +//~| NOTE didn't expect any arguments here +extern crate std as s3; + +#[macro_use(a(b))] +//~^ ERROR malformed `macro_use` attribute input +//~| NOTE didn't expect any arguments here +extern crate std as s4; + +#[macro_use(a::b)] +//~^ ERROR malformed `macro_use` attribute input +//~| NOTE expected a valid identifier here +extern crate std as s5; + +#[macro_use(a)] +//~^ ERROR unused attribute +#[macro_use] +//~^ NOTE attribute also specified here +extern crate std as s6; + +#[macro_use] +//~^ NOTE attribute also specified here +#[macro_use(a)] +//~^ ERROR unused attribute +extern crate std as s7; + +#[macro_use] +//~^ NOTE attribute also specified here +#[macro_use] +//~^ ERROR unused attribute +extern crate std as s8; + +// This is fine, both are importing different names +#[macro_use(a)] +//~^ ERROR imported macro not found +#[macro_use(b)] +//~^ ERROR imported macro not found +extern crate std as s9; + +fn main() {} diff --git a/tests/ui/attributes/invalid-macro-use.stderr b/tests/ui/attributes/invalid-macro-use.stderr new file mode 100644 index 0000000000000..4f5db5c558a5c --- /dev/null +++ b/tests/ui/attributes/invalid-macro-use.stderr @@ -0,0 +1,131 @@ +error[E0469]: imported macro not found + --> $DIR/invalid-macro-use.rs:47:13 + | +LL | #[macro_use(a)] + | ^ + +error[E0469]: imported macro not found + --> $DIR/invalid-macro-use.rs:49:13 + | +LL | #[macro_use(b)] + | ^ + +error: valid forms for the attribute are `#[macro_use(name1, name2, ...)]` and `#[macro_use]` + --> $DIR/invalid-macro-use.rs:4:1 + | +LL | #[macro_use = 5] + | ^^^^^^^^^^^^^^^^ + +error[E0539]: malformed `macro_use` attribute input + --> $DIR/invalid-macro-use.rs:8:1 + | +LL | #[macro_use(5)] + | ^^^^^^^^^^^^-^^ + | | + | expected a valid identifier here + | +help: try changing it to one of the following valid forms of the attribute + | +LL - #[macro_use(5)] +LL + #[macro_use(name1, name2, ...)] + | +LL - #[macro_use(5)] +LL + #[macro_use] + | + +error[E0565]: malformed `macro_use` attribute input + --> $DIR/invalid-macro-use.rs:13:1 + | +LL | #[macro_use(a = "b")] + | ^^^^^^^^^^^^^^-----^^ + | | + | didn't expect any arguments here + | +help: try changing it to one of the following valid forms of the attribute + | +LL - #[macro_use(a = "b")] +LL + #[macro_use(name1, name2, ...)] + | +LL - #[macro_use(a = "b")] +LL + #[macro_use] + | + +error[E0565]: malformed `macro_use` attribute input + --> $DIR/invalid-macro-use.rs:18:1 + | +LL | #[macro_use(a(b))] + | ^^^^^^^^^^^^^---^^ + | | + | didn't expect any arguments here + | +help: try changing it to one of the following valid forms of the attribute + | +LL - #[macro_use(a(b))] +LL + #[macro_use(name1, name2, ...)] + | +LL - #[macro_use(a(b))] +LL + #[macro_use] + | + +error[E0539]: malformed `macro_use` attribute input + --> $DIR/invalid-macro-use.rs:23:1 + | +LL | #[macro_use(a::b)] + | ^^^^^^^^^^^^----^^ + | | + | expected a valid identifier here + | +help: try changing it to one of the following valid forms of the attribute + | +LL - #[macro_use(a::b)] +LL + #[macro_use(name1, name2, ...)] + | +LL - #[macro_use(a::b)] +LL + #[macro_use] + | + +error: unused attribute + --> $DIR/invalid-macro-use.rs:28:1 + | +LL | #[macro_use(a)] + | ^^^^^^^^^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $DIR/invalid-macro-use.rs:30:1 + | +LL | #[macro_use] + | ^^^^^^^^^^^^ +note: the lint level is defined here + --> $DIR/invalid-macro-use.rs:1:9 + | +LL | #![deny(unused_attributes)] + | ^^^^^^^^^^^^^^^^^ + +error: unused attribute + --> $DIR/invalid-macro-use.rs:36:1 + | +LL | #[macro_use(a)] + | ^^^^^^^^^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $DIR/invalid-macro-use.rs:34:1 + | +LL | #[macro_use] + | ^^^^^^^^^^^^ + +error: unused attribute + --> $DIR/invalid-macro-use.rs:42:1 + | +LL | #[macro_use] + | ^^^^^^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $DIR/invalid-macro-use.rs:40:1 + | +LL | #[macro_use] + | ^^^^^^^^^^^^ + +error: aborting due to 10 previous errors + +Some errors have detailed explanations: E0469, E0539, E0565. +For more information about an error, try `rustc --explain E0469`. diff --git a/tests/ui/attributes/malformed-attrs.rs b/tests/ui/attributes/malformed-attrs.rs index 5026687b97b05..b3979a1c12dba 100644 --- a/tests/ui/attributes/malformed-attrs.rs +++ b/tests/ui/attributes/malformed-attrs.rs @@ -207,7 +207,7 @@ static mut TLS: u8 = 42; #[no_link()] //~^ ERROR malformed #[macro_use = 1] -//~^ ERROR malformed +//~^ ERROR valid forms for the attribute are `#[macro_use(name1, name2, ...)]` and `#[macro_use]` extern crate wloop; //~^ ERROR can't find crate for `wloop` [E0463] diff --git a/tests/ui/attributes/malformed-attrs.stderr b/tests/ui/attributes/malformed-attrs.stderr index 56f2be353e768..566914830442c 100644 --- a/tests/ui/attributes/malformed-attrs.stderr +++ b/tests/ui/attributes/malformed-attrs.stderr @@ -167,21 +167,6 @@ error: malformed `no_link` attribute input LL | #[no_link()] | ^^^^^^^^^^^^ help: must be of the form: `#[no_link]` -error: malformed `macro_use` attribute input - --> $DIR/malformed-attrs.rs:209:1 - | -LL | #[macro_use = 1] - | ^^^^^^^^^^^^^^^^ - | -help: the following are the possible correct uses - | -LL - #[macro_use = 1] -LL + #[macro_use(name1, name2, ...)] - | -LL - #[macro_use = 1] -LL + #[macro_use] - | - error: malformed `macro_export` attribute input --> $DIR/malformed-attrs.rs:214:1 | @@ -567,6 +552,12 @@ LL | #[non_exhaustive = 1] | | didn't expect any arguments here | help: must be of the form: `#[non_exhaustive]` +error: valid forms for the attribute are `#[macro_use(name1, name2, ...)]` and `#[macro_use]` + --> $DIR/malformed-attrs.rs:209:1 + | +LL | #[macro_use = 1] + | ^^^^^^^^^^^^^^^^ + error[E0565]: malformed `type_const` attribute input --> $DIR/malformed-attrs.rs:143:5 | diff --git a/tests/ui/feature-gates/issue-43106-gating-of-macro_use.rs b/tests/ui/feature-gates/issue-43106-gating-of-macro_use.rs index 6a7ef793924a4..0438152ff35f4 100644 --- a/tests/ui/feature-gates/issue-43106-gating-of-macro_use.rs +++ b/tests/ui/feature-gates/issue-43106-gating-of-macro_use.rs @@ -13,7 +13,7 @@ mod macro_escape { //~^ ERROR arguments to `macro_use` are not allowed here #[macro_use = "2700"] struct S; - //~^ ERROR malformed `macro_use` attribute + //~^ ERROR valid forms for the attribute are `#[macro_use(name1, name2, ...)]` and `#[macro_use]` #[macro_use] fn f() { } diff --git a/tests/ui/feature-gates/issue-43106-gating-of-macro_use.stderr b/tests/ui/feature-gates/issue-43106-gating-of-macro_use.stderr index 8987b87f84e9e..4da7176683795 100644 --- a/tests/ui/feature-gates/issue-43106-gating-of-macro_use.stderr +++ b/tests/ui/feature-gates/issue-43106-gating-of-macro_use.stderr @@ -16,20 +16,11 @@ error: arguments to `macro_use` are not allowed here LL | #![macro_use(my_macro)] | ^^^^^^^^^^^^^^^^^^^^^^^ -error: malformed `macro_use` attribute input +error: valid forms for the attribute are `#[macro_use(name1, name2, ...)]` and `#[macro_use]` --> $DIR/issue-43106-gating-of-macro_use.rs:15:5 | LL | #[macro_use = "2700"] struct S; | ^^^^^^^^^^^^^^^^^^^^^ - | -help: the following are the possible correct uses - | -LL - #[macro_use = "2700"] struct S; -LL + #[macro_use(name1, name2, ...)] struct S; - | -LL - #[macro_use = "2700"] struct S; -LL + #[macro_use] struct S; - | error: aborting due to 4 previous errors diff --git a/tests/ui/lint/unused/unused-attr-duplicate.stderr b/tests/ui/lint/unused/unused-attr-duplicate.stderr index 6db6af823f41e..4396f3f6b5856 100644 --- a/tests/ui/lint/unused/unused-attr-duplicate.stderr +++ b/tests/ui/lint/unused/unused-attr-duplicate.stderr @@ -15,18 +15,6 @@ note: the lint level is defined here LL | #![deny(unused_attributes)] | ^^^^^^^^^^^^^^^^^ -error: unused attribute - --> $DIR/unused-attr-duplicate.rs:37:1 - | -LL | #[macro_use] - | ^^^^^^^^^^^^ help: remove this attribute - | -note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:36:1 - | -LL | #[macro_use] - | ^^^^^^^^^^^^ - error: unused attribute --> $DIR/unused-attr-duplicate.rs:55:1 | @@ -128,6 +116,18 @@ note: attribute also specified here LL | #[macro_export] | ^^^^^^^^^^^^^^^ +error: unused attribute + --> $DIR/unused-attr-duplicate.rs:37:1 + | +LL | #[macro_use] + | ^^^^^^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $DIR/unused-attr-duplicate.rs:36:1 + | +LL | #[macro_use] + | ^^^^^^^^^^^^ + error: unused attribute --> $DIR/unused-attr-duplicate.rs:47:1 | diff --git a/tests/ui/lint/unused/unused-attr-macro-rules.stderr b/tests/ui/lint/unused/unused-attr-macro-rules.stderr index 4698e38142588..1e1211af5e296 100644 --- a/tests/ui/lint/unused/unused-attr-macro-rules.stderr +++ b/tests/ui/lint/unused/unused-attr-macro-rules.stderr @@ -1,8 +1,8 @@ -error: `#[macro_use]` only has an effect on `extern crate` and modules - --> $DIR/unused-attr-macro-rules.rs:7:1 +error: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]` + --> $DIR/unused-attr-macro-rules.rs:9:1 | -LL | #[macro_use] - | ^^^^^^^^^^^^ +LL | #[recursion_limit="1"] + | ^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here --> $DIR/unused-attr-macro-rules.rs:1:9 @@ -10,11 +10,11 @@ note: the lint level is defined here LL | #![deny(unused_attributes)] | ^^^^^^^^^^^^^^^^^ -error: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]` - --> $DIR/unused-attr-macro-rules.rs:9:1 +error: `#[macro_use]` only has an effect on `extern crate` and modules + --> $DIR/unused-attr-macro-rules.rs:7:1 | -LL | #[recursion_limit="1"] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #[macro_use] + | ^^^^^^^^^^^^ error: `#[path]` only has an effect on modules --> $DIR/unused-attr-macro-rules.rs:8:1 diff --git a/tests/ui/macros/genercs-in-path-with-prettry-hir.stdout b/tests/ui/macros/genercs-in-path-with-prettry-hir.stdout index 7c41225f95e67..6b0300132b5f6 100644 --- a/tests/ui/macros/genercs-in-path-with-prettry-hir.stdout +++ b/tests/ui/macros/genercs-in-path-with-prettry-hir.stdout @@ -1,6 +1,6 @@ #[prelude_import] use ::std::prelude::rust_2015::*; -#[macro_use] +#[attr = MacroUse {arguments: UseAll}] extern crate std; //@ compile-flags: -Zunpretty=hir //@ edition: 2015 diff --git a/tests/ui/macros/macro-use-all-and-none.stderr b/tests/ui/macros/macro-use-all-and-none.stderr index 00b10dccd0013..a5efb065a21b1 100644 --- a/tests/ui/macros/macro-use-all-and-none.stderr +++ b/tests/ui/macros/macro-use-all-and-none.stderr @@ -1,10 +1,9 @@ warning: unused attribute - --> $DIR/macro-use-all-and-none.rs:7:1 + --> $DIR/macro-use-all-and-none.rs:7:12 | LL | #[macro_use()] - | ^^^^^^^^^^^^^^ help: remove this attribute + | ^^ help: remove this attribute | - = note: attribute `macro_use` with an empty list has no effect note: the lint level is defined here --> $DIR/macro-use-all-and-none.rs:4:9 | diff --git a/tests/ui/macros/macro-use-bad-args-1.rs b/tests/ui/macros/macro-use-bad-args-1.rs index ec0b64a10953f..bfc19981804d0 100644 --- a/tests/ui/macros/macro-use-bad-args-1.rs +++ b/tests/ui/macros/macro-use-bad-args-1.rs @@ -1,6 +1,6 @@ #![no_std] -#[macro_use(foo(bar))] //~ ERROR bad macro import +#[macro_use(foo(bar))] //~ ERROR malformed `macro_use` attribute input extern crate std; fn main() {} diff --git a/tests/ui/macros/macro-use-bad-args-1.stderr b/tests/ui/macros/macro-use-bad-args-1.stderr index 6d2f159a57406..2f43d0997df52 100644 --- a/tests/ui/macros/macro-use-bad-args-1.stderr +++ b/tests/ui/macros/macro-use-bad-args-1.stderr @@ -1,9 +1,20 @@ -error[E0466]: bad macro import - --> $DIR/macro-use-bad-args-1.rs:3:13 +error[E0565]: malformed `macro_use` attribute input + --> $DIR/macro-use-bad-args-1.rs:3:1 | LL | #[macro_use(foo(bar))] - | ^^^^^^^^ + | ^^^^^^^^^^^^^^^-----^^ + | | + | didn't expect any arguments here + | +help: try changing it to one of the following valid forms of the attribute + | +LL - #[macro_use(foo(bar))] +LL + #[macro_use(name1, name2, ...)] + | +LL - #[macro_use(foo(bar))] +LL + #[macro_use] + | error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0466`. +For more information about this error, try `rustc --explain E0565`. diff --git a/tests/ui/macros/macro-use-bad-args-2.rs b/tests/ui/macros/macro-use-bad-args-2.rs index c5f8f62c18686..e328b6285d91e 100644 --- a/tests/ui/macros/macro-use-bad-args-2.rs +++ b/tests/ui/macros/macro-use-bad-args-2.rs @@ -1,6 +1,6 @@ #![no_std] -#[macro_use(foo="bar")] //~ ERROR bad macro import +#[macro_use(foo="bar")] //~ ERROR malformed `macro_use` attribute input extern crate std; fn main() {} diff --git a/tests/ui/macros/macro-use-bad-args-2.stderr b/tests/ui/macros/macro-use-bad-args-2.stderr index 364f3da6e15ab..d7b03c9358863 100644 --- a/tests/ui/macros/macro-use-bad-args-2.stderr +++ b/tests/ui/macros/macro-use-bad-args-2.stderr @@ -1,9 +1,20 @@ -error[E0466]: bad macro import - --> $DIR/macro-use-bad-args-2.rs:3:13 +error[E0565]: malformed `macro_use` attribute input + --> $DIR/macro-use-bad-args-2.rs:3:1 | LL | #[macro_use(foo="bar")] - | ^^^^^^^^^ + | ^^^^^^^^^^^^^^^------^^ + | | + | didn't expect any arguments here + | +help: try changing it to one of the following valid forms of the attribute + | +LL - #[macro_use(foo="bar")] +LL + #[macro_use(name1, name2, ...)] + | +LL - #[macro_use(foo="bar")] +LL + #[macro_use] + | error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0466`. +For more information about this error, try `rustc --explain E0565`. diff --git a/tests/ui/match/issue-82392.stdout b/tests/ui/match/issue-82392.stdout index a0d83d962e73e..3efc964e053bc 100644 --- a/tests/ui/match/issue-82392.stdout +++ b/tests/ui/match/issue-82392.stdout @@ -1,6 +1,6 @@ #[prelude_import] use ::std::prelude::rust_2015::*; -#[macro_use] +#[attr = MacroUse {arguments: UseAll}] extern crate std; // https://github.com/rust-lang/rust/issues/82329 //@ compile-flags: -Zunpretty=hir,typed diff --git a/tests/ui/type-alias-impl-trait/issue-60662.stdout b/tests/ui/type-alias-impl-trait/issue-60662.stdout index 56fef852e37bf..52152a73affe8 100644 --- a/tests/ui/type-alias-impl-trait/issue-60662.stdout +++ b/tests/ui/type-alias-impl-trait/issue-60662.stdout @@ -5,7 +5,7 @@ #![feature(type_alias_impl_trait)] #[prelude_import] use ::std::prelude::rust_2015::*; -#[macro_use] +#[attr = MacroUse {arguments: UseAll}] extern crate std; trait Animal { } diff --git a/tests/ui/unpretty/bad-literal.stdout b/tests/ui/unpretty/bad-literal.stdout index 06116a4ab5534..ba8467359cd6d 100644 --- a/tests/ui/unpretty/bad-literal.stdout +++ b/tests/ui/unpretty/bad-literal.stdout @@ -1,6 +1,6 @@ #[prelude_import] use ::std::prelude::rust_2015::*; -#[macro_use] +#[attr = MacroUse {arguments: UseAll}] extern crate std; //@ compile-flags: -Zunpretty=hir //@ check-fail diff --git a/tests/ui/unpretty/debug-fmt-hir.stdout b/tests/ui/unpretty/debug-fmt-hir.stdout index dc18675ea8031..1d224c9e91ffe 100644 --- a/tests/ui/unpretty/debug-fmt-hir.stdout +++ b/tests/ui/unpretty/debug-fmt-hir.stdout @@ -1,6 +1,6 @@ #[prelude_import] use ::std::prelude::rust_2015::*; -#[macro_use] +#[attr = MacroUse {arguments: UseAll}] extern crate std; //@ compile-flags: -Zunpretty=hir //@ check-pass diff --git a/tests/ui/unpretty/deprecated-attr.stdout b/tests/ui/unpretty/deprecated-attr.stdout index 042c2f61bd4cc..0abeef6f61e00 100644 --- a/tests/ui/unpretty/deprecated-attr.stdout +++ b/tests/ui/unpretty/deprecated-attr.stdout @@ -1,6 +1,6 @@ #[prelude_import] use ::std::prelude::rust_2015::*; -#[macro_use] +#[attr = MacroUse {arguments: UseAll}] extern crate std; //@ compile-flags: -Zunpretty=hir //@ check-pass diff --git a/tests/ui/unpretty/diagnostic-attr.stdout b/tests/ui/unpretty/diagnostic-attr.stdout index 3b15a845d68fa..a1325c61ca730 100644 --- a/tests/ui/unpretty/diagnostic-attr.stdout +++ b/tests/ui/unpretty/diagnostic-attr.stdout @@ -1,6 +1,6 @@ #[prelude_import] use ::std::prelude::rust_2015::*; -#[macro_use] +#[attr = MacroUse {arguments: UseAll}] extern crate std; //@ compile-flags: -Zunpretty=hir //@ check-pass diff --git a/tests/ui/unpretty/exhaustive-asm.hir.stdout b/tests/ui/unpretty/exhaustive-asm.hir.stdout index ec9bda573312c..bbd846a884549 100644 --- a/tests/ui/unpretty/exhaustive-asm.hir.stdout +++ b/tests/ui/unpretty/exhaustive-asm.hir.stdout @@ -1,6 +1,6 @@ #[prelude_import] use std::prelude::rust_2024::*; -#[macro_use] +#[attr = MacroUse {arguments: UseAll}] extern crate std; //@ revisions: expanded hir //@[expanded]compile-flags: -Zunpretty=expanded diff --git a/tests/ui/unpretty/exhaustive.hir.stdout b/tests/ui/unpretty/exhaustive.hir.stdout index a559d51ed5d65..77807728c9d3e 100644 --- a/tests/ui/unpretty/exhaustive.hir.stdout +++ b/tests/ui/unpretty/exhaustive.hir.stdout @@ -30,7 +30,7 @@ #![allow(incomplete_features)] #[prelude_import] use std::prelude::rust_2024::*; -#[macro_use] +#[attr = MacroUse {arguments: UseAll}] extern crate std; #[prelude_import] diff --git a/tests/ui/unpretty/flattened-format-args.stdout b/tests/ui/unpretty/flattened-format-args.stdout index 4af82924c7b4a..3cd0273466551 100644 --- a/tests/ui/unpretty/flattened-format-args.stdout +++ b/tests/ui/unpretty/flattened-format-args.stdout @@ -1,6 +1,6 @@ #[prelude_import] use ::std::prelude::rust_2015::*; -#[macro_use] +#[attr = MacroUse {arguments: UseAll}] extern crate std; //@ compile-flags: -Zunpretty=hir -Zflatten-format-args=yes //@ check-pass diff --git a/tests/ui/unpretty/let-else-hir.stdout b/tests/ui/unpretty/let-else-hir.stdout index a6dd943ec1b7e..a83790d8bee59 100644 --- a/tests/ui/unpretty/let-else-hir.stdout +++ b/tests/ui/unpretty/let-else-hir.stdout @@ -1,6 +1,6 @@ #[prelude_import] use ::std::prelude::rust_2015::*; -#[macro_use] +#[attr = MacroUse {arguments: UseAll}] extern crate std; //@ compile-flags: -Zunpretty=hir //@ check-pass diff --git a/tests/ui/unpretty/self-hir.stdout b/tests/ui/unpretty/self-hir.stdout index a9e80b1f59201..1eafc3c8b46b6 100644 --- a/tests/ui/unpretty/self-hir.stdout +++ b/tests/ui/unpretty/self-hir.stdout @@ -1,6 +1,6 @@ #[prelude_import] use ::std::prelude::rust_2015::*; -#[macro_use] +#[attr = MacroUse {arguments: UseAll}] extern crate std; //@ compile-flags: -Zunpretty=hir //@ check-pass diff --git a/tests/ui/unpretty/unpretty-expr-fn-arg.stdout b/tests/ui/unpretty/unpretty-expr-fn-arg.stdout index fd2e794fcac89..e9fd2222a8d26 100644 --- a/tests/ui/unpretty/unpretty-expr-fn-arg.stdout +++ b/tests/ui/unpretty/unpretty-expr-fn-arg.stdout @@ -10,7 +10,7 @@ #![allow(dead_code)] #[prelude_import] use ::std::prelude::rust_2015::*; -#[macro_use] +#[attr = MacroUse {arguments: UseAll}] extern crate std; fn main() ({ } as ())