diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index fb2ccefe12a18..a4a80475ba737 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -2109,16 +2109,18 @@ pub struct MacroDef { /// `true` if macro was defined with `macro_rules`. pub macro_rules: bool, - /// If this is a macro used for externally implementable items, - /// it refers to an extern item which is its "target". This requires - /// name resolution so can't just be an attribute, so we store it in this field. - pub eii_extern_target: Option, + /// Corresponds to `#[eii_declaration(...)]`. + /// `#[eii_declaration(...)]` is a built-in attribute macro, not a built-in attribute, + /// because we require some name resolution to occur in the parameters of this attribute. + /// Name resolution isn't possible in attributes otherwise, so we encode it in the AST. + /// During ast lowering, we turn it back into an attribute again + pub eii_declaration: Option, } #[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic, Walkable)] -pub struct EiiExternTarget { +pub struct EiiDecl { /// path to the extern item we're targeting - pub extern_item_path: Path, + pub foreign_item: Path, pub impl_unsafe: bool, } @@ -3824,7 +3826,7 @@ pub struct EiiImpl { /// /// This field is that shortcut: we prefill the extern target to skip a name resolution step, /// making sure it never fails. It'd be awful UX if we fail name resolution in code invisible to the user. - pub known_eii_macro_resolution: Option, + pub known_eii_macro_resolution: Option, pub impl_safety: Safety, pub span: Span, pub inner_span: Span, diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index 83b751fbde902..f7b8b9da32417 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -489,7 +489,7 @@ macro_rules! common_visitor_and_walkers { WhereEqPredicate, WhereRegionPredicate, YieldKind, - EiiExternTarget, + EiiDecl, EiiImpl, ); diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 3a7308ef7c97a..c8ebfb96b5583 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -2,7 +2,7 @@ use rustc_abi::ExternAbi; use rustc_ast::visit::AssocCtxt; use rustc_ast::*; use rustc_errors::{E0570, ErrorGuaranteed, struct_span_code_err}; -use rustc_hir::attrs::{AttributeKind, EiiDecl, EiiImplResolution}; +use rustc_hir::attrs::{AttributeKind, EiiImplResolution}; use rustc_hir::def::{DefKind, PerNS, Res}; use rustc_hir::def_id::{CRATE_DEF_ID, LocalDefId}; use rustc_hir::{ @@ -134,16 +134,16 @@ impl<'hir> LoweringContext<'_, 'hir> { } } - fn lower_eii_extern_target( + fn lower_eii_decl( &mut self, id: NodeId, - eii_name: Ident, - EiiExternTarget { extern_item_path, impl_unsafe }: &EiiExternTarget, - ) -> Option { - self.lower_path_simple_eii(id, extern_item_path).map(|did| EiiDecl { - eii_extern_target: did, + name: Ident, + EiiDecl { foreign_item, impl_unsafe }: &EiiDecl, + ) -> Option { + self.lower_path_simple_eii(id, foreign_item).map(|did| hir::attrs::EiiDecl { + foreign_item: did, impl_unsafe: *impl_unsafe, - name: eii_name, + name, }) } @@ -160,7 +160,7 @@ impl<'hir> LoweringContext<'_, 'hir> { }: &EiiImpl, ) -> hir::attrs::EiiImpl { let resolution = if let Some(target) = known_eii_macro_resolution - && let Some(decl) = self.lower_eii_extern_target( + && let Some(decl) = self.lower_eii_decl( *node_id, // the expect is ok here since we always generate this path in the eii macro. eii_macro_path.segments.last().expect("at least one segment").ident, @@ -196,9 +196,9 @@ impl<'hir> LoweringContext<'_, 'hir> { eii_impls.iter().map(|i| self.lower_eii_impl(i)).collect(), ))] } - ItemKind::MacroDef(name, MacroDef { eii_extern_target: Some(target), .. }) => self - .lower_eii_extern_target(id, *name, target) - .map(|decl| vec![hir::Attribute::Parsed(AttributeKind::EiiExternTarget(decl))]) + ItemKind::MacroDef(name, MacroDef { eii_declaration: Some(target), .. }) => self + .lower_eii_decl(id, *name, target) + .map(|decl| vec![hir::Attribute::Parsed(AttributeKind::EiiDeclaration(decl))]) .unwrap_or_default(), ItemKind::ExternCrate(..) @@ -242,10 +242,7 @@ impl<'hir> LoweringContext<'_, 'hir> { vis_span, span: self.lower_span(i.span), has_delayed_lints: !self.delayed_lints.is_empty(), - eii: find_attr!( - attrs, - AttributeKind::EiiImpls(..) | AttributeKind::EiiExternTarget(..) - ), + eii: find_attr!(attrs, AttributeKind::EiiImpls(..) | AttributeKind::EiiDeclaration(..)), }; self.arena.alloc(item) } @@ -539,7 +536,7 @@ impl<'hir> LoweringContext<'_, 'hir> { ); hir::ItemKind::TraitAlias(constness, ident, generics, bounds) } - ItemKind::MacroDef(ident, MacroDef { body, macro_rules, eii_extern_target: _ }) => { + ItemKind::MacroDef(ident, MacroDef { body, macro_rules, eii_declaration: _ }) => { let ident = self.lower_ident(*ident); let body = Box::new(self.lower_delim_args(body)); let def_id = self.local_def_id(id); @@ -553,7 +550,7 @@ impl<'hir> LoweringContext<'_, 'hir> { let macro_def = self.arena.alloc(ast::MacroDef { body, macro_rules: *macro_rules, - eii_extern_target: None, + eii_declaration: None, }); hir::ItemKind::Macro(ident, macro_def, macro_kinds) } @@ -693,7 +690,7 @@ impl<'hir> LoweringContext<'_, 'hir> { has_delayed_lints: !this.delayed_lints.is_empty(), eii: find_attr!( attrs, - AttributeKind::EiiImpls(..) | AttributeKind::EiiExternTarget(..) + AttributeKind::EiiImpls(..) | AttributeKind::EiiDeclaration(..) ), }; hir::OwnerNode::Item(this.arena.alloc(item)) diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index 0cf0eae821e90..e50e31c226fdb 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -865,10 +865,10 @@ pub trait PrintState<'a>: std::ops::Deref + std::ops::Dere sp: Span, print_visibility: impl FnOnce(&mut Self), ) { - if let Some(eii_extern_target) = ¯o_def.eii_extern_target { - self.word("#[eii_extern_target("); - self.print_path(&eii_extern_target.extern_item_path, false, 0); - if eii_extern_target.impl_unsafe { + if let Some(eii_decl) = ¯o_def.eii_declaration { + self.word("#[eii_declaration("); + self.print_path(&eii_decl.foreign_item, false, 0); + if eii_decl.impl_unsafe { self.word(","); self.space(); self.word("unsafe"); diff --git a/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs b/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs index c68c66b271857..5bbaeda18df3f 100644 --- a/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs +++ b/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs @@ -709,11 +709,11 @@ impl NoArgsAttributeParser for RustcPassIndirectlyInNonRusticAbisPa const CREATE: fn(Span) -> AttributeKind = AttributeKind::RustcPassIndirectlyInNonRusticAbis; } -pub(crate) struct EiiExternItemParser; +pub(crate) struct EiiForeignItemParser; -impl NoArgsAttributeParser for EiiExternItemParser { - const PATH: &[Symbol] = &[sym::rustc_eii_extern_item]; +impl NoArgsAttributeParser for EiiForeignItemParser { + const PATH: &[Symbol] = &[sym::rustc_eii_foreign_item]; const ON_DUPLICATE: OnDuplicate = OnDuplicate::Error; const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::ForeignFn)]); - const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::EiiExternItem; + const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::EiiForeignItem; } diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index 835bf8ae5c9c4..00921cf54cd87 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -21,7 +21,7 @@ use crate::attributes::allow_unstable::{ use crate::attributes::body::CoroutineParser; use crate::attributes::cfi_encoding::CfiEncodingParser; use crate::attributes::codegen_attrs::{ - ColdParser, CoverageParser, EiiExternItemParser, ExportNameParser, ForceTargetFeatureParser, + ColdParser, CoverageParser, EiiForeignItemParser, ExportNameParser, ForceTargetFeatureParser, NakedParser, NoMangleParser, ObjcClassParser, ObjcSelectorParser, OptimizeParser, RustcPassIndirectlyInNonRusticAbisParser, SanitizeParser, TargetFeatureParser, ThreadLocalParser, TrackCallerParser, UsedParser, @@ -243,7 +243,7 @@ attribute_parsers!( Single>, Single>, Single>, - Single>, + Single>, Single>, Single>, Single>, diff --git a/compiler/rustc_builtin_macros/messages.ftl b/compiler/rustc_builtin_macros/messages.ftl index e4fded0cb01e1..1501bd6c73e29 100644 --- a/compiler/rustc_builtin_macros/messages.ftl +++ b/compiler/rustc_builtin_macros/messages.ftl @@ -151,9 +151,9 @@ builtin_macros_derive_path_args_value = traits in `#[derive(...)]` don't accept builtin_macros_duplicate_macro_attribute = duplicated attribute -builtin_macros_eii_extern_target_expected_list = `#[eii_extern_target(...)]` expects a list of one or two elements -builtin_macros_eii_extern_target_expected_macro = `#[eii_extern_target(...)]` is only valid on macros -builtin_macros_eii_extern_target_expected_unsafe = expected this argument to be "unsafe" +builtin_macros_eii_declaration_expected_list = `#[eii_declaration(...)]` expects a list of one or two elements +builtin_macros_eii_declaration_expected_macro = `#[eii_declaration(...)]` is only valid on macros +builtin_macros_eii_declaration_expected_unsafe = expected this argument to be "unsafe" .note = the second argument is optional builtin_macros_eii_only_once = `#[{$name}]` can only be specified once diff --git a/compiler/rustc_builtin_macros/src/eii.rs b/compiler/rustc_builtin_macros/src/eii.rs index a5009b3bfa52f..cec7599d68e9c 100644 --- a/compiler/rustc_builtin_macros/src/eii.rs +++ b/compiler/rustc_builtin_macros/src/eii.rs @@ -1,7 +1,7 @@ use rustc_ast::token::{Delimiter, TokenKind}; use rustc_ast::tokenstream::{DelimSpacing, DelimSpan, Spacing, TokenStream, TokenTree}; use rustc_ast::{ - Attribute, DUMMY_NODE_ID, EiiExternTarget, EiiImpl, ItemKind, MetaItem, Path, Stmt, StmtKind, + Attribute, DUMMY_NODE_ID, EiiDecl, EiiImpl, ItemKind, MetaItem, Path, Stmt, StmtKind, Visibility, ast, }; use rustc_ast_pretty::pprust::path_to_string; @@ -30,7 +30,7 @@ use crate::errors::{ /// } /// /// #[rustc_builtin_macro(eii_shared_macro)] -/// #[eii_extern_target(panic_handler)] +/// #[eii_declaration(panic_handler)] /// macro panic_handler() {} /// ``` pub(crate) fn eii( @@ -210,8 +210,8 @@ fn generate_default_impl( }, span: eii_attr_span, is_default: true, - known_eii_macro_resolution: Some(ast::EiiExternTarget { - extern_item_path: ecx.path( + known_eii_macro_resolution: Some(ast::EiiDecl { + foreign_item: ecx.path( foreign_item_name.span, // prefix super to escape the `dflt` module generated below vec![Ident::from_str_and_span("super", foreign_item_name.span), foreign_item_name], @@ -295,9 +295,9 @@ fn generate_foreign_item( let mut foreign_item_attrs = ThinVec::new(); foreign_item_attrs.extend_from_slice(attrs_from_decl); - // Add the rustc_eii_extern_item on the foreign item. Usually, foreign items are mangled. + // Add the rustc_eii_foreign_item on the foreign item. Usually, foreign items are mangled. // This attribute makes sure that we later know that this foreign item's symbol should not be. - foreign_item_attrs.push(ecx.attr_word(sym::rustc_eii_extern_item, eii_attr_span)); + foreign_item_attrs.push(ecx.attr_word(sym::rustc_eii_foreign_item, eii_attr_span)); let abi = match func.sig.header.ext { // extern "X" fn => extern "X" {} @@ -349,7 +349,7 @@ fn generate_foreign_item( /// // This attribute tells the compiler that /// #[builtin_macro(eii_shared_macro)] /// // the metadata to link this macro to the generated foreign item. -/// #[eii_extern_target()] +/// #[eii_declaration()] /// macro macro_name { () => {} } /// ``` fn generate_attribute_macro_to_implement( @@ -401,9 +401,9 @@ fn generate_attribute_macro_to_implement( ]), }), macro_rules: false, - // #[eii_extern_target(foreign_item_ident)] - eii_extern_target: Some(ast::EiiExternTarget { - extern_item_path: ast::Path::from_ident(foreign_item_name), + // #[eii_declaration(foreign_item_ident)] + eii_declaration: Some(ast::EiiDecl { + foreign_item: ast::Path::from_ident(foreign_item_name), impl_unsafe, }), }, @@ -412,7 +412,7 @@ fn generate_attribute_macro_to_implement( }) } -pub(crate) fn eii_extern_target( +pub(crate) fn eii_declaration( ecx: &mut ExtCtxt<'_>, span: Span, meta_item: &ast::MetaItem, @@ -461,7 +461,7 @@ pub(crate) fn eii_extern_target( false }; - d.eii_extern_target = Some(EiiExternTarget { extern_item_path, impl_unsafe }); + d.eii_declaration = Some(EiiDecl { foreign_item: extern_item_path, impl_unsafe }); // Return the original item and the new methods. vec![item] diff --git a/compiler/rustc_builtin_macros/src/errors.rs b/compiler/rustc_builtin_macros/src/errors.rs index e673ad3f8a647..5d4c4e340fa1f 100644 --- a/compiler/rustc_builtin_macros/src/errors.rs +++ b/compiler/rustc_builtin_macros/src/errors.rs @@ -1010,21 +1010,21 @@ pub(crate) struct CfgSelectUnreachable { } #[derive(Diagnostic)] -#[diag(builtin_macros_eii_extern_target_expected_macro)] +#[diag(builtin_macros_eii_declaration_expected_macro)] pub(crate) struct EiiExternTargetExpectedMacro { #[primary_span] pub span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_eii_extern_target_expected_list)] +#[diag(builtin_macros_eii_declaration_expected_list)] pub(crate) struct EiiExternTargetExpectedList { #[primary_span] pub span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_eii_extern_target_expected_unsafe)] +#[diag(builtin_macros_eii_declaration_expected_unsafe)] pub(crate) struct EiiExternTargetExpectedUnsafe { #[primary_span] #[note] diff --git a/compiler/rustc_builtin_macros/src/lib.rs b/compiler/rustc_builtin_macros/src/lib.rs index 89ac8db760638..e1c5a4f85c1ba 100644 --- a/compiler/rustc_builtin_macros/src/lib.rs +++ b/compiler/rustc_builtin_macros/src/lib.rs @@ -119,7 +119,7 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) { derive: derive::Expander { is_const: false }, derive_const: derive::Expander { is_const: true }, eii: eii::eii, - eii_extern_target: eii::eii_extern_target, + eii_declaration: eii::eii_declaration, eii_shared_macro: eii::eii_shared_macro, global_allocator: global_allocator::expand, test: test::expand_test, diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index 7dda824e2b18a..fa02c5c51f7c1 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -282,16 +282,16 @@ fn process_builtin_attrs( AttributeKind::ObjcSelector { methname, .. } => { codegen_fn_attrs.objc_selector = Some(*methname); } - AttributeKind::EiiExternItem => { + AttributeKind::EiiForeignItem => { codegen_fn_attrs.flags |= CodegenFnAttrFlags::EXTERNALLY_IMPLEMENTABLE_ITEM; } AttributeKind::EiiImpls(impls) => { for i in impls { - let extern_item = match i.resolution { + let foreign_item = match i.resolution { EiiImplResolution::Macro(def_id) => { let Some(extern_item) = find_attr!( tcx.get_all_attrs(def_id), - AttributeKind::EiiExternTarget(target) => target.eii_extern_target + AttributeKind::EiiDeclaration(target) => target.foreign_item ) else { tcx.dcx().span_delayed_bug( i.span, @@ -301,7 +301,7 @@ fn process_builtin_attrs( }; extern_item } - EiiImplResolution::Known(decl) => decl.eii_extern_target, + EiiImplResolution::Known(decl) => decl.foreign_item, EiiImplResolution::Error(_eg) => continue, }; @@ -316,13 +316,13 @@ fn process_builtin_attrs( // iterate over all implementations *in the current crate* // (this is ok since we generate codegen fn attrs in the local crate) // if any of them is *not default* then don't emit the alias. - && tcx.externally_implementable_items(LOCAL_CRATE).get(&extern_item).expect("at least one").1.iter().any(|(_, imp)| !imp.is_default) + && tcx.externally_implementable_items(LOCAL_CRATE).get(&foreign_item).expect("at least one").1.iter().any(|(_, imp)| !imp.is_default) { continue; } codegen_fn_attrs.foreign_item_symbol_aliases.push(( - extern_item, + foreign_item, if i.is_default { Linkage::LinkOnceAny } else { Linkage::External }, Visibility::Default, )); diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index a7e8515e415f0..22753adb4c995 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -962,7 +962,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ EncodeCrossCrate::No, "allow_internal_unsafe side-steps the unsafe_code lint", ), gated!( - rustc_eii_extern_item, Normal, template!(Word), + rustc_eii_foreign_item, Normal, template!(Word), ErrorFollowing, EncodeCrossCrate::Yes, eii_internals, "used internally to mark types with a `transparent` representation when it is guaranteed by the documentation", ), diff --git a/compiler/rustc_hir/src/attrs/data_structures.rs b/compiler/rustc_hir/src/attrs/data_structures.rs index a5ecfa45fb408..15a668bd91994 100644 --- a/compiler/rustc_hir/src/attrs/data_structures.rs +++ b/compiler/rustc_hir/src/attrs/data_structures.rs @@ -43,7 +43,7 @@ pub struct EiiImpl { #[derive(Copy, Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)] pub struct EiiDecl { - pub eii_extern_target: DefId, + pub foreign_item: DefId, /// whether or not it is unsafe to implement this EII pub impl_unsafe: bool, pub name: Ident, @@ -744,10 +744,10 @@ pub enum AttributeKind { Dummy, /// Implementation detail of `#[eii]` - EiiExternItem, + EiiDeclaration(EiiDecl), /// Implementation detail of `#[eii]` - EiiExternTarget(EiiDecl), + EiiForeignItem, /// Implementation detail of `#[eii]` EiiImpls(ThinVec), diff --git a/compiler/rustc_hir/src/attrs/encode_cross_crate.rs b/compiler/rustc_hir/src/attrs/encode_cross_crate.rs index efdb4f2f22b2e..233aee54adbb6 100644 --- a/compiler/rustc_hir/src/attrs/encode_cross_crate.rs +++ b/compiler/rustc_hir/src/attrs/encode_cross_crate.rs @@ -47,8 +47,8 @@ impl AttributeKind { Doc(_) => Yes, DocComment { .. } => Yes, Dummy => No, - EiiExternItem => No, - EiiExternTarget(_) => Yes, + EiiDeclaration(_) => Yes, + EiiForeignItem => No, EiiImpls(..) => No, ExportName { .. } => Yes, ExportStable => No, diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 7ec4110f80b90..cfc7e57cc14e7 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1205,7 +1205,7 @@ fn check_eiis(tcx: TyCtxt<'_>, def_id: LocalDefId) { EiiImplResolution::Macro(def_id) => { // we expect this macro to have the `EiiMacroFor` attribute, that points to a function // signature that we'd like to compare the function we're currently checking with - if let Some(foreign_item) = find_attr!(tcx.get_all_attrs(*def_id), AttributeKind::EiiExternTarget(EiiDecl {eii_extern_target: t, ..}) => *t) + if let Some(foreign_item) = find_attr!(tcx.get_all_attrs(*def_id), AttributeKind::EiiDeclaration(EiiDecl {foreign_item: t, ..}) => *t) { (foreign_item, tcx.item_name(*def_id)) } else { @@ -1213,7 +1213,7 @@ fn check_eiis(tcx: TyCtxt<'_>, def_id: LocalDefId) { continue; } } - EiiImplResolution::Known(decl) => (decl.eii_extern_target, decl.name.name), + EiiImplResolution::Known(decl) => (decl.foreign_item, decl.name.name), EiiImplResolution::Error(_eg) => continue, }; diff --git a/compiler/rustc_metadata/src/eii.rs b/compiler/rustc_metadata/src/eii.rs index b06ac84813975..42497a82ef8c0 100644 --- a/compiler/rustc_metadata/src/eii.rs +++ b/compiler/rustc_metadata/src/eii.rs @@ -31,9 +31,9 @@ pub(crate) fn collect<'tcx>(tcx: TyCtxt<'tcx>, LocalCrate: LocalCrate) -> EiiMap let decl = match i.resolution { EiiImplResolution::Macro(macro_defid) => { // find the decl for this one if it wasn't in yet (maybe it's from the local crate? not very useful but not illegal) - let Some(decl) = find_attr!(tcx.get_all_attrs(macro_defid), AttributeKind::EiiExternTarget(d) => *d) + let Some(decl) = find_attr!(tcx.get_all_attrs(macro_defid), AttributeKind::EiiDeclaration(d) => *d) else { - // skip if it doesn't have eii_extern_target (if we resolved to another macro that's not an EII) + // skip if it doesn't have eii_declaration (if we resolved to another macro that's not an EII) tcx.dcx() .span_delayed_bug(i.span, "resolved to something that's not an EII"); continue; @@ -45,7 +45,7 @@ pub(crate) fn collect<'tcx>(tcx: TyCtxt<'tcx>, LocalCrate: LocalCrate) -> EiiMap }; // FIXME(eii) remove extern target from encoded decl - eiis.entry(decl.eii_extern_target) + eiis.entry(decl.foreign_item) .or_insert_with(|| (decl, Default::default())) .1 .insert(id.into(), *i); @@ -53,9 +53,9 @@ pub(crate) fn collect<'tcx>(tcx: TyCtxt<'tcx>, LocalCrate: LocalCrate) -> EiiMap // if we find a new declaration, add it to the list without a known implementation if let Some(decl) = - find_attr!(tcx.get_all_attrs(id), AttributeKind::EiiExternTarget(d) => *d) + find_attr!(tcx.get_all_attrs(id), AttributeKind::EiiDeclaration(d) => *d) { - eiis.entry(decl.eii_extern_target).or_insert((decl, Default::default())); + eiis.entry(decl.foreign_item).or_insert((decl, Default::default())); } } diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index f8610f0c5b034..c7423386a771d 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -1536,7 +1536,7 @@ impl<'a> CrateMetadataRef<'a> { .get((self, tcx), id) .unwrap() .decode((self, tcx)); - ast::MacroDef { macro_rules, body: Box::new(body), eii_extern_target: None } + ast::MacroDef { macro_rules, body: Box::new(body), eii_declaration: None } } _ => bug!(), } diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 26f60c96aed6b..cdcdaa342a5d0 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -2283,7 +2283,7 @@ impl<'a> Parser<'a> { self.psess.gated_spans.gate(sym::decl_macro, lo.to(self.prev_token.span)); Ok(ItemKind::MacroDef( ident, - ast::MacroDef { body, macro_rules: false, eii_extern_target: None }, + ast::MacroDef { body, macro_rules: false, eii_declaration: None }, )) } @@ -2333,7 +2333,7 @@ impl<'a> Parser<'a> { Ok(ItemKind::MacroDef( ident, - ast::MacroDef { body, macro_rules: true, eii_extern_target: None }, + ast::MacroDef { body, macro_rules: true, eii_declaration: None }, )) } diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 717a0e54d0c6e..1d48785169d74 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -224,8 +224,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> { self.check_rustc_must_implement_one_of(*attr_span, fn_names, hir_id,target) }, Attribute::Parsed( - AttributeKind::EiiExternTarget { .. } - | AttributeKind::EiiExternItem + AttributeKind::EiiDeclaration { .. } + | AttributeKind::EiiForeignItem | AttributeKind::BodyStability { .. } | AttributeKind::ConstStabilityIndirect | AttributeKind::MacroTransparency(_) @@ -553,7 +553,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } if let EiiImplResolution::Macro(eii_macro) = resolution - && find_attr!(self.tcx.get_all_attrs(*eii_macro), AttributeKind::EiiExternTarget(EiiDecl { impl_unsafe, .. }) if *impl_unsafe) + && find_attr!(self.tcx.get_all_attrs(*eii_macro), AttributeKind::EiiDeclaration(EiiDecl { impl_unsafe, .. }) if *impl_unsafe) && !impl_marked_unsafe { self.dcx().emit_err(errors::EiiImplRequiresUnsafe { diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 4d2ba73c9cab3..6d00976317729 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -1079,7 +1079,7 @@ impl<'ast, 'ra, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tc self.smart_resolve_path( *node_id, &None, - &target.extern_item_path, + &target.foreign_item, PathSource::Expr(None), ); } else { @@ -2931,8 +2931,8 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { self.parent_scope.macro_rules = self.r.macro_rules_scopes[&def_id]; } - if let Some(EiiExternTarget { extern_item_path, impl_unsafe: _ }) = - ¯o_def.eii_extern_target + if let Some(EiiDecl { foreign_item: extern_item_path, impl_unsafe: _ }) = + ¯o_def.eii_declaration { self.smart_resolve_path( item.id, diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index b473d36a45fcb..f56c3421ce0f5 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -935,7 +935,7 @@ symbols! { eh_catch_typeinfo, eh_personality, eii, - eii_extern_target, + eii_declaration, eii_impl, eii_internals, eii_shared_macro, @@ -1951,7 +1951,7 @@ symbols! { rustc_dump_user_args, rustc_dump_vtable, rustc_effective_visibility, - rustc_eii_extern_item, + rustc_eii_foreign_item, rustc_evaluate_where_clauses, rustc_expected_cgu_reuse, rustc_force_inline, diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index 338c5688bf100..a437a4795481c 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -1912,7 +1912,7 @@ pub(crate) mod builtin { /// Impl detail of EII #[unstable(feature = "eii_internals", issue = "none")] #[rustc_builtin_macro] - pub macro eii_extern_target($item:item) { + pub macro eii_declaration($item:item) { /* compiler built-in */ } } diff --git a/library/core/src/prelude/v1.rs b/library/core/src/prelude/v1.rs index a5d9a5352dfcf..7e0a84df5118d 100644 --- a/library/core/src/prelude/v1.rs +++ b/library/core/src/prelude/v1.rs @@ -122,4 +122,4 @@ pub use crate::macros::builtin::define_opaque; pub use crate::macros::builtin::{eii, unsafe_eii}; #[unstable(feature = "eii_internals", issue = "none")] -pub use crate::macros::builtin::eii_extern_target; +pub use crate::macros::builtin::eii_declaration; diff --git a/library/std/src/prelude/v1.rs b/library/std/src/prelude/v1.rs index 63f75ea8a8819..0f0841379b297 100644 --- a/library/std/src/prelude/v1.rs +++ b/library/std/src/prelude/v1.rs @@ -114,7 +114,7 @@ pub use core::prelude::v1::define_opaque; pub use core::prelude::v1::{eii, unsafe_eii}; #[unstable(feature = "eii_internals", issue = "none")] -pub use core::prelude::v1::eii_extern_target; +pub use core::prelude::v1::eii_declaration; // The file so far is equivalent to core/src/prelude/v1.rs. It is duplicated // rather than glob imported because we want docs to show these re-exports as diff --git a/tests/ui/eii/errors.rs b/tests/ui/eii/errors.rs index d59850a7d5f5f..5fcf33336b402 100644 --- a/tests/ui/eii/errors.rs +++ b/tests/ui/eii/errors.rs @@ -5,19 +5,19 @@ #![feature(rustc_attrs)] #![feature(eii_internals)] -#[eii_extern_target(bar)] //~ ERROR `#[eii_extern_target(...)]` is only valid on macros +#[eii_declaration(bar)] //~ ERROR `#[eii_declaration(...)]` is only valid on macros fn hello() { - #[eii_extern_target(bar)] //~ ERROR `#[eii_extern_target(...)]` is only valid on macros + #[eii_declaration(bar)] //~ ERROR `#[eii_declaration(...)]` is only valid on macros let x = 3 + 3; } -#[eii_extern_target] //~ ERROR `#[eii_extern_target(...)]` expects a list of one or two elements -#[eii_extern_target()] //~ ERROR `#[eii_extern_target(...)]` expects a list of one or two elements -#[eii_extern_target(bar, hello)] //~ ERROR expected this argument to be "unsafe" -#[eii_extern_target(bar, "unsafe", hello)] //~ ERROR `#[eii_extern_target(...)]` expects a list of one or two elements -#[eii_extern_target(bar, hello, "unsafe")] //~ ERROR `#[eii_extern_target(...)]` expects a list of one or two elements -#[eii_extern_target = "unsafe"] //~ ERROR `#[eii_extern_target(...)]` expects a list of one or two elements -#[eii_extern_target(bar)] +#[eii_declaration] //~ ERROR `#[eii_declaration(...)]` expects a list of one or two elements +#[eii_declaration()] //~ ERROR `#[eii_declaration(...)]` expects a list of one or two elements +#[eii_declaration(bar, hello)] //~ ERROR expected this argument to be "unsafe" +#[eii_declaration(bar, "unsafe", hello)] //~ ERROR `#[eii_declaration(...)]` expects a list of one or two elements +#[eii_declaration(bar, hello, "unsafe")] //~ ERROR `#[eii_declaration(...)]` expects a list of one or two elements +#[eii_declaration = "unsafe"] //~ ERROR `#[eii_declaration(...)]` expects a list of one or two elements +#[eii_declaration(bar)] #[rustc_builtin_macro(eii_shared_macro)] macro foo() {} diff --git a/tests/ui/eii/errors.stderr b/tests/ui/eii/errors.stderr index c3b51421f2957..c7eb96a9c2190 100644 --- a/tests/ui/eii/errors.stderr +++ b/tests/ui/eii/errors.stderr @@ -1,56 +1,56 @@ -error: `#[eii_extern_target(...)]` is only valid on macros +error: `#[eii_declaration(...)]` is only valid on macros --> $DIR/errors.rs:8:1 | -LL | #[eii_extern_target(bar)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[eii_declaration(bar)] + | ^^^^^^^^^^^^^^^^^^^^^^^ -error: `#[eii_extern_target(...)]` is only valid on macros +error: `#[eii_declaration(...)]` is only valid on macros --> $DIR/errors.rs:10:5 | -LL | #[eii_extern_target(bar)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[eii_declaration(bar)] + | ^^^^^^^^^^^^^^^^^^^^^^^ -error: `#[eii_extern_target(...)]` expects a list of one or two elements +error: `#[eii_declaration(...)]` expects a list of one or two elements --> $DIR/errors.rs:14:1 | -LL | #[eii_extern_target] - | ^^^^^^^^^^^^^^^^^^^^ +LL | #[eii_declaration] + | ^^^^^^^^^^^^^^^^^^ -error: `#[eii_extern_target(...)]` expects a list of one or two elements +error: `#[eii_declaration(...)]` expects a list of one or two elements --> $DIR/errors.rs:15:1 | -LL | #[eii_extern_target()] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #[eii_declaration()] + | ^^^^^^^^^^^^^^^^^^^^ error: expected this argument to be "unsafe" - --> $DIR/errors.rs:16:26 + --> $DIR/errors.rs:16:24 | -LL | #[eii_extern_target(bar, hello)] - | ^^^^^ +LL | #[eii_declaration(bar, hello)] + | ^^^^^ | note: the second argument is optional - --> $DIR/errors.rs:16:26 + --> $DIR/errors.rs:16:24 | -LL | #[eii_extern_target(bar, hello)] - | ^^^^^ +LL | #[eii_declaration(bar, hello)] + | ^^^^^ -error: `#[eii_extern_target(...)]` expects a list of one or two elements +error: `#[eii_declaration(...)]` expects a list of one or two elements --> $DIR/errors.rs:17:1 | -LL | #[eii_extern_target(bar, "unsafe", hello)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[eii_declaration(bar, "unsafe", hello)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: `#[eii_extern_target(...)]` expects a list of one or two elements +error: `#[eii_declaration(...)]` expects a list of one or two elements --> $DIR/errors.rs:18:1 | -LL | #[eii_extern_target(bar, hello, "unsafe")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[eii_declaration(bar, hello, "unsafe")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: `#[eii_extern_target(...)]` expects a list of one or two elements +error: `#[eii_declaration(...)]` expects a list of one or two elements --> $DIR/errors.rs:19:1 | -LL | #[eii_extern_target = "unsafe"] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[eii_declaration = "unsafe"] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `#[foo]` is only valid on functions --> $DIR/errors.rs:28:1 diff --git a/tests/ui/eii/type_checking/auxiliary/cross_crate_eii_declaration.rs b/tests/ui/eii/type_checking/auxiliary/cross_crate_eii_declaration.rs index 40d0222082d52..95ae5d923b604 100644 --- a/tests/ui/eii/type_checking/auxiliary/cross_crate_eii_declaration.rs +++ b/tests/ui/eii/type_checking/auxiliary/cross_crate_eii_declaration.rs @@ -5,7 +5,7 @@ #![feature(rustc_attrs)] #![feature(eii_internals)] -#[eii_extern_target(bar)] +#[eii_declaration(bar)] #[rustc_builtin_macro(eii_shared_macro)] pub macro foo() {} diff --git a/tests/ui/eii/type_checking/subtype_1.rs b/tests/ui/eii/type_checking/subtype_1.rs index dfb998aa6f669..d853bc4e7e3d8 100644 --- a/tests/ui/eii/type_checking/subtype_1.rs +++ b/tests/ui/eii/type_checking/subtype_1.rs @@ -6,7 +6,7 @@ #![feature(rustc_attrs)] #![feature(eii_internals)] -#[eii_extern_target(bar)] +#[eii_declaration(bar)] #[rustc_builtin_macro(eii_shared_macro)] macro foo() {} diff --git a/tests/ui/eii/type_checking/subtype_2.rs b/tests/ui/eii/type_checking/subtype_2.rs index 5f0c5553fcccb..d2b2eb073de2c 100644 --- a/tests/ui/eii/type_checking/subtype_2.rs +++ b/tests/ui/eii/type_checking/subtype_2.rs @@ -6,7 +6,7 @@ #![feature(rustc_attrs)] #![feature(eii_internals)] -#[eii_extern_target(bar)] +#[eii_declaration(bar)] #[rustc_builtin_macro(eii_shared_macro)] macro foo() {} diff --git a/tests/ui/eii/type_checking/subtype_3.rs b/tests/ui/eii/type_checking/subtype_3.rs index 269bc84df744a..458bacf4a7729 100644 --- a/tests/ui/eii/type_checking/subtype_3.rs +++ b/tests/ui/eii/type_checking/subtype_3.rs @@ -7,7 +7,7 @@ #![feature(rustc_attrs)] #![feature(eii_internals)] -#[eii_extern_target(bar)] +#[eii_declaration(bar)] #[rustc_builtin_macro(eii_shared_macro)] macro foo() {} diff --git a/tests/ui/eii/type_checking/subtype_4.rs b/tests/ui/eii/type_checking/subtype_4.rs index e9194df7584c7..6f1e4253dd735 100644 --- a/tests/ui/eii/type_checking/subtype_4.rs +++ b/tests/ui/eii/type_checking/subtype_4.rs @@ -7,7 +7,7 @@ #![feature(rustc_attrs)] #![feature(eii_internals)] -#[eii_extern_target(bar)] +#[eii_declaration(bar)] #[rustc_builtin_macro(eii_shared_macro)] macro foo() {} diff --git a/tests/ui/eii/type_checking/wrong_ret_ty.rs b/tests/ui/eii/type_checking/wrong_ret_ty.rs index 5fe7d2f8bb620..8ee81a4f24657 100644 --- a/tests/ui/eii/type_checking/wrong_ret_ty.rs +++ b/tests/ui/eii/type_checking/wrong_ret_ty.rs @@ -5,7 +5,7 @@ #![feature(rustc_attrs)] #![feature(eii_internals)] -#[eii_extern_target(bar)] +#[eii_declaration(bar)] #[rustc_builtin_macro(eii_shared_macro)] macro foo() {} diff --git a/tests/ui/eii/type_checking/wrong_ty.rs b/tests/ui/eii/type_checking/wrong_ty.rs index ebb756f6a3148..625af6e11dbf7 100644 --- a/tests/ui/eii/type_checking/wrong_ty.rs +++ b/tests/ui/eii/type_checking/wrong_ty.rs @@ -5,7 +5,7 @@ #![feature(rustc_attrs)] #![feature(eii_internals)] -#[eii_extern_target(bar)] +#[eii_declaration(bar)] #[rustc_builtin_macro(eii_shared_macro)] macro foo() {} diff --git a/tests/ui/eii/type_checking/wrong_ty_2.rs b/tests/ui/eii/type_checking/wrong_ty_2.rs index d55f405bf1575..2e477b5b6fcce 100644 --- a/tests/ui/eii/type_checking/wrong_ty_2.rs +++ b/tests/ui/eii/type_checking/wrong_ty_2.rs @@ -5,7 +5,7 @@ #![feature(rustc_attrs)] #![feature(eii_internals)] -#[eii_extern_target(bar)] +#[eii_declaration(bar)] #[rustc_builtin_macro(eii_shared_macro)] macro foo() {} diff --git a/tests/ui/eii/unsafe_impl_err.rs b/tests/ui/eii/unsafe_impl_err.rs index 6af7e9724e15b..a6d24c47ae213 100644 --- a/tests/ui/eii/unsafe_impl_err.rs +++ b/tests/ui/eii/unsafe_impl_err.rs @@ -5,7 +5,7 @@ #![feature(rustc_attrs)] #![feature(eii_internals)] -#[eii_extern_target(bar, "unsafe")] +#[eii_declaration(bar, "unsafe")] #[rustc_builtin_macro(eii_shared_macro)] macro foo() {} diff --git a/tests/ui/eii/unsafe_impl_ok.rs b/tests/ui/eii/unsafe_impl_ok.rs index 268c5bc16fd84..1af6d63eb7cff 100644 --- a/tests/ui/eii/unsafe_impl_ok.rs +++ b/tests/ui/eii/unsafe_impl_ok.rs @@ -7,7 +7,7 @@ #![feature(rustc_attrs)] #![feature(eii_internals)] -#[eii_extern_target(bar, "unsafe")] +#[eii_declaration(bar, "unsafe")] #[rustc_builtin_macro(eii_shared_macro)] macro foo() {} diff --git a/tests/ui/feature-gates/feature-gate-eii-internals.rs b/tests/ui/feature-gates/feature-gate-eii-internals.rs index b70e007ed798b..96699f2905b65 100644 --- a/tests/ui/feature-gates/feature-gate-eii-internals.rs +++ b/tests/ui/feature-gates/feature-gate-eii-internals.rs @@ -2,7 +2,7 @@ #![feature(decl_macro)] #![feature(rustc_attrs)] -#[eii_extern_target(bar)] //~ ERROR use of unstable library feature `eii_internals` +#[eii_declaration(bar)] //~ ERROR use of unstable library feature `eii_internals` #[rustc_builtin_macro(eii_macro)] macro foo() {} //~ ERROR: cannot find a built-in macro with name `foo` diff --git a/tests/ui/feature-gates/feature-gate-eii-internals.stderr b/tests/ui/feature-gates/feature-gate-eii-internals.stderr index f08f0a5e65b3b..78aa49ebab1cf 100644 --- a/tests/ui/feature-gates/feature-gate-eii-internals.stderr +++ b/tests/ui/feature-gates/feature-gate-eii-internals.stderr @@ -1,8 +1,8 @@ error[E0658]: use of unstable library feature `eii_internals` --> $DIR/feature-gate-eii-internals.rs:5:3 | -LL | #[eii_extern_target(bar)] - | ^^^^^^^^^^^^^^^^^ +LL | #[eii_declaration(bar)] + | ^^^^^^^^^^^^^^^ | = help: add `#![feature(eii_internals)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date