Skip to content

Commit aefa104

Browse files
committed
Auto merge of #151003 - matthiaskrgr:rollup-wvnF9sN, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #150861 (Folding/`ReErased` cleanups) - #150869 (Emit error instead of delayed bug when meeting mismatch type for const tuple) - #150920 (Use a hook to decouple `rustc_mir_transform` from `rustc_mir_build`) - #150941 (rustc_parse_format: improve diagnostics for unsupported python numeric grouping) - #150972 (Rename EII attributes slightly (being consistent in naming things foreign items, not extern items)) - #150980 (Use updated indexes to build reverse map for delegation generics) - #150986 (std: Fix size returned by UEFI tcp4 read operations) - #150996 (Remove `S-waiting-on-bors` after a PR is merged) r? @ghost
2 parents 1377169 + db4c095 commit aefa104

File tree

71 files changed

+286
-235
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+286
-235
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4360,7 +4360,6 @@ dependencies = [
43604360
"rustc_infer",
43614361
"rustc_macros",
43624362
"rustc_middle",
4363-
"rustc_mir_build",
43644363
"rustc_mir_dataflow",
43654364
"rustc_session",
43664365
"rustc_span",

compiler/rustc_ast/src/ast.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,16 +2109,18 @@ pub struct MacroDef {
21092109
/// `true` if macro was defined with `macro_rules`.
21102110
pub macro_rules: bool,
21112111

2112-
/// If this is a macro used for externally implementable items,
2113-
/// it refers to an extern item which is its "target". This requires
2114-
/// name resolution so can't just be an attribute, so we store it in this field.
2115-
pub eii_extern_target: Option<EiiExternTarget>,
2112+
/// Corresponds to `#[eii_declaration(...)]`.
2113+
/// `#[eii_declaration(...)]` is a built-in attribute macro, not a built-in attribute,
2114+
/// because we require some name resolution to occur in the parameters of this attribute.
2115+
/// Name resolution isn't possible in attributes otherwise, so we encode it in the AST.
2116+
/// During ast lowering, we turn it back into an attribute again
2117+
pub eii_declaration: Option<EiiDecl>,
21162118
}
21172119

21182120
#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic, Walkable)]
2119-
pub struct EiiExternTarget {
2121+
pub struct EiiDecl {
21202122
/// path to the extern item we're targeting
2121-
pub extern_item_path: Path,
2123+
pub foreign_item: Path,
21222124
pub impl_unsafe: bool,
21232125
}
21242126

@@ -3824,7 +3826,7 @@ pub struct EiiImpl {
38243826
///
38253827
/// This field is that shortcut: we prefill the extern target to skip a name resolution step,
38263828
/// making sure it never fails. It'd be awful UX if we fail name resolution in code invisible to the user.
3827-
pub known_eii_macro_resolution: Option<EiiExternTarget>,
3829+
pub known_eii_macro_resolution: Option<EiiDecl>,
38283830
pub impl_safety: Safety,
38293831
pub span: Span,
38303832
pub inner_span: Span,

compiler/rustc_ast/src/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ macro_rules! common_visitor_and_walkers {
489489
WhereEqPredicate,
490490
WhereRegionPredicate,
491491
YieldKind,
492-
EiiExternTarget,
492+
EiiDecl,
493493
EiiImpl,
494494
);
495495

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_abi::ExternAbi;
22
use rustc_ast::visit::AssocCtxt;
33
use rustc_ast::*;
44
use rustc_errors::{E0570, ErrorGuaranteed, struct_span_code_err};
5-
use rustc_hir::attrs::{AttributeKind, EiiDecl, EiiImplResolution};
5+
use rustc_hir::attrs::{AttributeKind, EiiImplResolution};
66
use rustc_hir::def::{DefKind, PerNS, Res};
77
use rustc_hir::def_id::{CRATE_DEF_ID, LocalDefId};
88
use rustc_hir::{
@@ -134,16 +134,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
134134
}
135135
}
136136

137-
fn lower_eii_extern_target(
137+
fn lower_eii_decl(
138138
&mut self,
139139
id: NodeId,
140-
eii_name: Ident,
141-
EiiExternTarget { extern_item_path, impl_unsafe }: &EiiExternTarget,
142-
) -> Option<EiiDecl> {
143-
self.lower_path_simple_eii(id, extern_item_path).map(|did| EiiDecl {
144-
eii_extern_target: did,
140+
name: Ident,
141+
EiiDecl { foreign_item, impl_unsafe }: &EiiDecl,
142+
) -> Option<hir::attrs::EiiDecl> {
143+
self.lower_path_simple_eii(id, foreign_item).map(|did| hir::attrs::EiiDecl {
144+
foreign_item: did,
145145
impl_unsafe: *impl_unsafe,
146-
name: eii_name,
146+
name,
147147
})
148148
}
149149

@@ -160,7 +160,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
160160
}: &EiiImpl,
161161
) -> hir::attrs::EiiImpl {
162162
let resolution = if let Some(target) = known_eii_macro_resolution
163-
&& let Some(decl) = self.lower_eii_extern_target(
163+
&& let Some(decl) = self.lower_eii_decl(
164164
*node_id,
165165
// the expect is ok here since we always generate this path in the eii macro.
166166
eii_macro_path.segments.last().expect("at least one segment").ident,
@@ -196,9 +196,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
196196
eii_impls.iter().map(|i| self.lower_eii_impl(i)).collect(),
197197
))]
198198
}
199-
ItemKind::MacroDef(name, MacroDef { eii_extern_target: Some(target), .. }) => self
200-
.lower_eii_extern_target(id, *name, target)
201-
.map(|decl| vec![hir::Attribute::Parsed(AttributeKind::EiiExternTarget(decl))])
199+
ItemKind::MacroDef(name, MacroDef { eii_declaration: Some(target), .. }) => self
200+
.lower_eii_decl(id, *name, target)
201+
.map(|decl| vec![hir::Attribute::Parsed(AttributeKind::EiiDeclaration(decl))])
202202
.unwrap_or_default(),
203203

204204
ItemKind::ExternCrate(..)
@@ -242,10 +242,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
242242
vis_span,
243243
span: self.lower_span(i.span),
244244
has_delayed_lints: !self.delayed_lints.is_empty(),
245-
eii: find_attr!(
246-
attrs,
247-
AttributeKind::EiiImpls(..) | AttributeKind::EiiExternTarget(..)
248-
),
245+
eii: find_attr!(attrs, AttributeKind::EiiImpls(..) | AttributeKind::EiiDeclaration(..)),
249246
};
250247
self.arena.alloc(item)
251248
}
@@ -539,7 +536,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
539536
);
540537
hir::ItemKind::TraitAlias(constness, ident, generics, bounds)
541538
}
542-
ItemKind::MacroDef(ident, MacroDef { body, macro_rules, eii_extern_target: _ }) => {
539+
ItemKind::MacroDef(ident, MacroDef { body, macro_rules, eii_declaration: _ }) => {
543540
let ident = self.lower_ident(*ident);
544541
let body = Box::new(self.lower_delim_args(body));
545542
let def_id = self.local_def_id(id);
@@ -553,7 +550,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
553550
let macro_def = self.arena.alloc(ast::MacroDef {
554551
body,
555552
macro_rules: *macro_rules,
556-
eii_extern_target: None,
553+
eii_declaration: None,
557554
});
558555
hir::ItemKind::Macro(ident, macro_def, macro_kinds)
559556
}
@@ -693,7 +690,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
693690
has_delayed_lints: !this.delayed_lints.is_empty(),
694691
eii: find_attr!(
695692
attrs,
696-
AttributeKind::EiiImpls(..) | AttributeKind::EiiExternTarget(..)
693+
AttributeKind::EiiImpls(..) | AttributeKind::EiiDeclaration(..)
697694
),
698695
};
699696
hir::OwnerNode::Item(this.arena.alloc(item))

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -865,10 +865,10 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
865865
sp: Span,
866866
print_visibility: impl FnOnce(&mut Self),
867867
) {
868-
if let Some(eii_extern_target) = &macro_def.eii_extern_target {
869-
self.word("#[eii_extern_target(");
870-
self.print_path(&eii_extern_target.extern_item_path, false, 0);
871-
if eii_extern_target.impl_unsafe {
868+
if let Some(eii_decl) = &macro_def.eii_declaration {
869+
self.word("#[eii_declaration(");
870+
self.print_path(&eii_decl.foreign_item, false, 0);
871+
if eii_decl.impl_unsafe {
872872
self.word(",");
873873
self.space();
874874
self.word("unsafe");

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -709,11 +709,11 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcPassIndirectlyInNonRusticAbisPa
709709
const CREATE: fn(Span) -> AttributeKind = AttributeKind::RustcPassIndirectlyInNonRusticAbis;
710710
}
711711

712-
pub(crate) struct EiiExternItemParser;
712+
pub(crate) struct EiiForeignItemParser;
713713

714-
impl<S: Stage> NoArgsAttributeParser<S> for EiiExternItemParser {
715-
const PATH: &[Symbol] = &[sym::rustc_eii_extern_item];
714+
impl<S: Stage> NoArgsAttributeParser<S> for EiiForeignItemParser {
715+
const PATH: &[Symbol] = &[sym::rustc_eii_foreign_item];
716716
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
717717
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::ForeignFn)]);
718-
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::EiiExternItem;
718+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::EiiForeignItem;
719719
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::attributes::allow_unstable::{
2121
use crate::attributes::body::CoroutineParser;
2222
use crate::attributes::cfi_encoding::CfiEncodingParser;
2323
use crate::attributes::codegen_attrs::{
24-
ColdParser, CoverageParser, EiiExternItemParser, ExportNameParser, ForceTargetFeatureParser,
24+
ColdParser, CoverageParser, EiiForeignItemParser, ExportNameParser, ForceTargetFeatureParser,
2525
NakedParser, NoMangleParser, ObjcClassParser, ObjcSelectorParser, OptimizeParser,
2626
RustcPassIndirectlyInNonRusticAbisParser, SanitizeParser, TargetFeatureParser,
2727
ThreadLocalParser, TrackCallerParser, UsedParser,
@@ -243,7 +243,7 @@ attribute_parsers!(
243243
Single<WithoutArgs<CoroutineParser>>,
244244
Single<WithoutArgs<DenyExplicitImplParser>>,
245245
Single<WithoutArgs<DoNotImplementViaObjectParser>>,
246-
Single<WithoutArgs<EiiExternItemParser>>,
246+
Single<WithoutArgs<EiiForeignItemParser>>,
247247
Single<WithoutArgs<ExportStableParser>>,
248248
Single<WithoutArgs<FfiConstParser>>,
249249
Single<WithoutArgs<FfiPureParser>>,

compiler/rustc_builtin_macros/messages.ftl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ builtin_macros_derive_path_args_value = traits in `#[derive(...)]` don't accept
151151
152152
builtin_macros_duplicate_macro_attribute = duplicated attribute
153153
154-
builtin_macros_eii_extern_target_expected_list = `#[eii_extern_target(...)]` expects a list of one or two elements
155-
builtin_macros_eii_extern_target_expected_macro = `#[eii_extern_target(...)]` is only valid on macros
156-
builtin_macros_eii_extern_target_expected_unsafe = expected this argument to be "unsafe"
154+
builtin_macros_eii_declaration_expected_list = `#[eii_declaration(...)]` expects a list of one or two elements
155+
builtin_macros_eii_declaration_expected_macro = `#[eii_declaration(...)]` is only valid on macros
156+
builtin_macros_eii_declaration_expected_unsafe = expected this argument to be "unsafe"
157157
.note = the second argument is optional
158158
159159
builtin_macros_eii_only_once = `#[{$name}]` can only be specified once

compiler/rustc_builtin_macros/src/eii.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_ast::token::{Delimiter, TokenKind};
22
use rustc_ast::tokenstream::{DelimSpacing, DelimSpan, Spacing, TokenStream, TokenTree};
33
use rustc_ast::{
4-
Attribute, DUMMY_NODE_ID, EiiExternTarget, EiiImpl, ItemKind, MetaItem, Path, Stmt, StmtKind,
4+
Attribute, DUMMY_NODE_ID, EiiDecl, EiiImpl, ItemKind, MetaItem, Path, Stmt, StmtKind,
55
Visibility, ast,
66
};
77
use rustc_ast_pretty::pprust::path_to_string;
@@ -30,7 +30,7 @@ use crate::errors::{
3030
/// }
3131
///
3232
/// #[rustc_builtin_macro(eii_shared_macro)]
33-
/// #[eii_extern_target(panic_handler)]
33+
/// #[eii_declaration(panic_handler)]
3434
/// macro panic_handler() {}
3535
/// ```
3636
pub(crate) fn eii(
@@ -210,8 +210,8 @@ fn generate_default_impl(
210210
},
211211
span: eii_attr_span,
212212
is_default: true,
213-
known_eii_macro_resolution: Some(ast::EiiExternTarget {
214-
extern_item_path: ecx.path(
213+
known_eii_macro_resolution: Some(ast::EiiDecl {
214+
foreign_item: ecx.path(
215215
foreign_item_name.span,
216216
// prefix super to escape the `dflt` module generated below
217217
vec![Ident::from_str_and_span("super", foreign_item_name.span), foreign_item_name],
@@ -295,9 +295,9 @@ fn generate_foreign_item(
295295
let mut foreign_item_attrs = ThinVec::new();
296296
foreign_item_attrs.extend_from_slice(attrs_from_decl);
297297

298-
// Add the rustc_eii_extern_item on the foreign item. Usually, foreign items are mangled.
298+
// Add the rustc_eii_foreign_item on the foreign item. Usually, foreign items are mangled.
299299
// This attribute makes sure that we later know that this foreign item's symbol should not be.
300-
foreign_item_attrs.push(ecx.attr_word(sym::rustc_eii_extern_item, eii_attr_span));
300+
foreign_item_attrs.push(ecx.attr_word(sym::rustc_eii_foreign_item, eii_attr_span));
301301

302302
let abi = match func.sig.header.ext {
303303
// extern "X" fn => extern "X" {}
@@ -349,7 +349,7 @@ fn generate_foreign_item(
349349
/// // This attribute tells the compiler that
350350
/// #[builtin_macro(eii_shared_macro)]
351351
/// // the metadata to link this macro to the generated foreign item.
352-
/// #[eii_extern_target(<related_reign_item>)]
352+
/// #[eii_declaration(<related_foreign_item>)]
353353
/// macro macro_name { () => {} }
354354
/// ```
355355
fn generate_attribute_macro_to_implement(
@@ -401,9 +401,9 @@ fn generate_attribute_macro_to_implement(
401401
]),
402402
}),
403403
macro_rules: false,
404-
// #[eii_extern_target(foreign_item_ident)]
405-
eii_extern_target: Some(ast::EiiExternTarget {
406-
extern_item_path: ast::Path::from_ident(foreign_item_name),
404+
// #[eii_declaration(foreign_item_ident)]
405+
eii_declaration: Some(ast::EiiDecl {
406+
foreign_item: ast::Path::from_ident(foreign_item_name),
407407
impl_unsafe,
408408
}),
409409
},
@@ -412,7 +412,7 @@ fn generate_attribute_macro_to_implement(
412412
})
413413
}
414414

415-
pub(crate) fn eii_extern_target(
415+
pub(crate) fn eii_declaration(
416416
ecx: &mut ExtCtxt<'_>,
417417
span: Span,
418418
meta_item: &ast::MetaItem,
@@ -461,7 +461,7 @@ pub(crate) fn eii_extern_target(
461461
false
462462
};
463463

464-
d.eii_extern_target = Some(EiiExternTarget { extern_item_path, impl_unsafe });
464+
d.eii_declaration = Some(EiiDecl { foreign_item: extern_item_path, impl_unsafe });
465465

466466
// Return the original item and the new methods.
467467
vec![item]

compiler/rustc_builtin_macros/src/errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,21 +1010,21 @@ pub(crate) struct CfgSelectUnreachable {
10101010
}
10111011

10121012
#[derive(Diagnostic)]
1013-
#[diag(builtin_macros_eii_extern_target_expected_macro)]
1013+
#[diag(builtin_macros_eii_declaration_expected_macro)]
10141014
pub(crate) struct EiiExternTargetExpectedMacro {
10151015
#[primary_span]
10161016
pub span: Span,
10171017
}
10181018

10191019
#[derive(Diagnostic)]
1020-
#[diag(builtin_macros_eii_extern_target_expected_list)]
1020+
#[diag(builtin_macros_eii_declaration_expected_list)]
10211021
pub(crate) struct EiiExternTargetExpectedList {
10221022
#[primary_span]
10231023
pub span: Span,
10241024
}
10251025

10261026
#[derive(Diagnostic)]
1027-
#[diag(builtin_macros_eii_extern_target_expected_unsafe)]
1027+
#[diag(builtin_macros_eii_declaration_expected_unsafe)]
10281028
pub(crate) struct EiiExternTargetExpectedUnsafe {
10291029
#[primary_span]
10301030
#[note]

0 commit comments

Comments
 (0)