Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 0d2b785

Browse files
authored
Merge pull request rust-lang#18567 from lnicola/sync-from-rust
minor: fix proc macro test
2 parents 8cf30c2 + ad6e993 commit 0d2b785

File tree

76 files changed

+545
-369
lines changed

Some content is hidden

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

76 files changed

+545
-369
lines changed

compiler/rustc_ast_lowering/src/asm.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
8282
let mut clobber_abis = FxIndexMap::default();
8383
if let Some(asm_arch) = asm_arch {
8484
for (abi_name, abi_span) in &asm.clobber_abis {
85-
match asm::InlineAsmClobberAbi::parse(asm_arch, &self.tcx.sess.target, *abi_name) {
85+
match asm::InlineAsmClobberAbi::parse(
86+
asm_arch,
87+
&self.tcx.sess.target,
88+
&self.tcx.sess.unstable_target_features,
89+
*abi_name,
90+
) {
8691
Ok(abi) => {
8792
// If the abi was already in the list, emit an error
8893
match clobber_abis.get(&abi) {

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
118118
}
119119
ExprKind::Repeat(expr, count) => {
120120
let expr = self.lower_expr(expr);
121-
let count = self.lower_array_length(count);
121+
let count = self.lower_array_length_to_const_arg(count);
122122
hir::ExprKind::Repeat(expr, count)
123123
}
124124
ExprKind::Tup(elts) => hir::ExprKind::Tup(self.lower_exprs(elts)),

compiler/rustc_ast_lowering/src/index.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
235235
}
236236

237237
fn visit_anon_const(&mut self, constant: &'hir AnonConst) {
238-
// FIXME: use real span?
239-
self.insert(DUMMY_SP, constant.hir_id, Node::AnonConst(constant));
238+
self.insert(constant.span, constant.hir_id, Node::AnonConst(constant));
240239

241240
self.with_parent(constant.hir_id, |this| {
242241
intravisit::walk_anon_const(this, constant);
@@ -252,8 +251,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
252251
}
253252

254253
fn visit_const_arg(&mut self, const_arg: &'hir ConstArg<'hir>) {
255-
// FIXME: use real span?
256-
self.insert(DUMMY_SP, const_arg.hir_id, Node::ConstArg(const_arg));
254+
self.insert(const_arg.span(), const_arg.hir_id, Node::ConstArg(const_arg));
257255

258256
self.with_parent(const_arg.hir_id, |this| {
259257
intravisit::walk_const_arg(this, const_arg);
@@ -387,13 +385,6 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
387385
});
388386
}
389387

390-
fn visit_array_length(&mut self, len: &'hir ArrayLen<'hir>) {
391-
match len {
392-
ArrayLen::Infer(inf) => self.insert(inf.span, inf.hir_id, Node::ArrayLenInfer(inf)),
393-
ArrayLen::Body(..) => intravisit::walk_array_len(self, len),
394-
}
395-
}
396-
397388
fn visit_pattern_type_pattern(&mut self, p: &'hir hir::Pat<'hir>) {
398389
self.visit_pat(p)
399390
}

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,9 +1277,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12771277
}),
12781278
))
12791279
}
1280-
TyKind::Array(ty, length) => {
1281-
hir::TyKind::Array(self.lower_ty(ty, itctx), self.lower_array_length(length))
1282-
}
1280+
TyKind::Array(ty, length) => hir::TyKind::Array(
1281+
self.lower_ty(ty, itctx),
1282+
self.lower_array_length_to_const_arg(length),
1283+
),
12831284
TyKind::Typeof(expr) => hir::TyKind::Typeof(self.lower_anon_const_to_anon_const(expr)),
12841285
TyKind::TraitObject(bounds, kind) => {
12851286
let mut lifetime_bound = None;
@@ -2029,14 +2030,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20292030
self.expr_block(block)
20302031
}
20312032

2032-
fn lower_array_length(&mut self, c: &AnonConst) -> hir::ArrayLen<'hir> {
2033+
fn lower_array_length_to_const_arg(&mut self, c: &AnonConst) -> &'hir hir::ConstArg<'hir> {
20332034
match c.value.kind {
20342035
ExprKind::Underscore => {
20352036
if self.tcx.features().generic_arg_infer() {
2036-
hir::ArrayLen::Infer(hir::InferArg {
2037-
hir_id: self.lower_node_id(c.id),
2038-
span: self.lower_span(c.value.span),
2039-
})
2037+
let ct_kind = hir::ConstArgKind::Infer(self.lower_span(c.value.span));
2038+
self.arena.alloc(hir::ConstArg { hir_id: self.next_id(), kind: ct_kind })
20402039
} else {
20412040
feature_err(
20422041
&self.tcx.sess,
@@ -2045,10 +2044,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20452044
fluent_generated::ast_lowering_underscore_array_length_unstable,
20462045
)
20472046
.stash(c.value.span, StashKey::UnderscoreForArrayLengths);
2048-
hir::ArrayLen::Body(self.lower_anon_const_to_const_arg(c))
2047+
self.lower_anon_const_to_const_arg(c)
20492048
}
20502049
}
2051-
_ => hir::ArrayLen::Body(self.lower_anon_const_to_const_arg(c)),
2050+
_ => self.lower_anon_const_to_const_arg(c),
20522051
}
20532052
}
20542053

compiler/rustc_codegen_cranelift/src/inline_asm.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,14 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> {
476476
let mut new_slot = |x| new_slot_fn(&mut slot_size, x);
477477

478478
// Allocate stack slots for saving clobbered registers
479-
let abi_clobber = InlineAsmClobberAbi::parse(self.arch, &self.tcx.sess.target, sym::C)
480-
.unwrap()
481-
.clobbered_regs();
479+
let abi_clobber = InlineAsmClobberAbi::parse(
480+
self.arch,
481+
&self.tcx.sess.target,
482+
&self.tcx.sess.unstable_target_features,
483+
sym::C,
484+
)
485+
.unwrap()
486+
.clobbered_regs();
482487
for (i, reg) in self.registers.iter().enumerate().filter_map(|(i, r)| r.map(|r| (i, r))) {
483488
let mut need_save = true;
484489
// If the register overlaps with a register clobbered by function call, then

compiler/rustc_codegen_gcc/src/asm.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,9 @@ fn reg_to_gcc(reg: InlineAsmRegOrRegClass) -> ConstraintOrRegister {
634634
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => "r",
635635
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => "w",
636636
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::reg) => "r",
637+
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::preg) => {
638+
unreachable!("clobber-only")
639+
}
637640
InlineAsmRegClass::LoongArch(LoongArchInlineAsmRegClass::reg) => "r",
638641
InlineAsmRegClass::LoongArch(LoongArchInlineAsmRegClass::freg) => "f",
639642
InlineAsmRegClass::M68k(M68kInlineAsmRegClass::reg) => "r",
@@ -720,6 +723,9 @@ fn dummy_output_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, reg: InlineAsmRegCl
720723
cx.type_vector(cx.type_i64(), 2)
721724
}
722725
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::reg) => cx.type_i32(),
726+
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::preg) => {
727+
unreachable!("clobber-only")
728+
}
723729
InlineAsmRegClass::LoongArch(LoongArchInlineAsmRegClass::reg) => cx.type_i32(),
724730
InlineAsmRegClass::LoongArch(LoongArchInlineAsmRegClass::freg) => cx.type_f32(),
725731
InlineAsmRegClass::Mips(MipsInlineAsmRegClass::reg) => cx.type_i32(),

compiler/rustc_codegen_llvm/src/asm.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
645645
| Arm(ArmInlineAsmRegClass::qreg_low4) => "x",
646646
Arm(ArmInlineAsmRegClass::dreg) | Arm(ArmInlineAsmRegClass::qreg) => "w",
647647
Hexagon(HexagonInlineAsmRegClass::reg) => "r",
648+
Hexagon(HexagonInlineAsmRegClass::preg) => unreachable!("clobber-only"),
648649
LoongArch(LoongArchInlineAsmRegClass::reg) => "r",
649650
LoongArch(LoongArchInlineAsmRegClass::freg) => "f",
650651
Mips(MipsInlineAsmRegClass::reg) => "r",
@@ -813,6 +814,7 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
813814
| Arm(ArmInlineAsmRegClass::qreg_low8)
814815
| Arm(ArmInlineAsmRegClass::qreg_low4) => cx.type_vector(cx.type_i64(), 2),
815816
Hexagon(HexagonInlineAsmRegClass::reg) => cx.type_i32(),
817+
Hexagon(HexagonInlineAsmRegClass::preg) => unreachable!("clobber-only"),
816818
LoongArch(LoongArchInlineAsmRegClass::reg) => cx.type_i32(),
817819
LoongArch(LoongArchInlineAsmRegClass::freg) => cx.type_f32(),
818820
Mips(MipsInlineAsmRegClass::reg) => cx.type_i32(),

compiler/rustc_codegen_ssa/src/traits/backend.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,19 @@ pub trait CodegenBackend {
7171
need_metadata_module: bool,
7272
) -> Box<dyn Any>;
7373

74-
/// This is called on the returned `Box<dyn Any>` from `codegen_backend`
74+
/// This is called on the returned `Box<dyn Any>` from [`codegen_crate`](Self::codegen_crate)
7575
///
7676
/// # Panics
7777
///
78-
/// Panics when the passed `Box<dyn Any>` was not returned by `codegen_backend`.
78+
/// Panics when the passed `Box<dyn Any>` was not returned by [`codegen_crate`](Self::codegen_crate).
7979
fn join_codegen(
8080
&self,
8181
ongoing_codegen: Box<dyn Any>,
8282
sess: &Session,
8383
outputs: &OutputFilenames,
8484
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>);
8585

86-
/// This is called on the returned `CodegenResults` from `join_codegen`
86+
/// This is called on the returned [`CodegenResults`] from [`join_codegen`](Self::join_codegen).
8787
fn link(
8888
&self,
8989
sess: &Session,

compiler/rustc_hir/src/hir.rs

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ impl<'hir> ConstArg<'hir> {
275275
match self.kind {
276276
ConstArgKind::Path(path) => path.span(),
277277
ConstArgKind::Anon(anon) => anon.span,
278+
ConstArgKind::Infer(span) => span,
278279
}
279280
}
280281
}
@@ -289,6 +290,11 @@ pub enum ConstArgKind<'hir> {
289290
/// However, in the future, we'll be using it for all of those.
290291
Path(QPath<'hir>),
291292
Anon(&'hir AnonConst),
293+
/// **Note:** Not all inferred consts are represented as
294+
/// `ConstArgKind::Infer`. In cases where it is ambiguous whether
295+
/// a generic arg is a type or a const, inference variables are
296+
/// represented as `GenericArg::Infer` instead.
297+
Infer(Span),
292298
}
293299

294300
#[derive(Clone, Copy, Debug, HashStable_Generic)]
@@ -308,6 +314,10 @@ pub enum GenericArg<'hir> {
308314
Lifetime(&'hir Lifetime),
309315
Type(&'hir Ty<'hir>),
310316
Const(&'hir ConstArg<'hir>),
317+
/// **Note:** Inference variables are only represented as
318+
/// `GenericArg::Infer` in cases where it is ambiguous whether
319+
/// a generic arg is a type or a const. Otherwise, inference variables
320+
/// are represented as `TyKind::Infer` or `ConstArgKind::Infer`.
311321
Infer(InferArg),
312322
}
313323

@@ -1645,29 +1655,6 @@ impl fmt::Display for ConstContext {
16451655
/// A literal.
16461656
pub type Lit = Spanned<LitKind>;
16471657

1648-
#[derive(Copy, Clone, Debug, HashStable_Generic)]
1649-
pub enum ArrayLen<'hir> {
1650-
Infer(InferArg),
1651-
Body(&'hir ConstArg<'hir>),
1652-
}
1653-
1654-
impl ArrayLen<'_> {
1655-
pub fn span(self) -> Span {
1656-
match self {
1657-
ArrayLen::Infer(arg) => arg.span,
1658-
ArrayLen::Body(body) => body.span(),
1659-
}
1660-
}
1661-
1662-
pub fn hir_id(self) -> HirId {
1663-
match self {
1664-
ArrayLen::Infer(InferArg { hir_id, .. }) | ArrayLen::Body(&ConstArg { hir_id, .. }) => {
1665-
hir_id
1666-
}
1667-
}
1668-
}
1669-
}
1670-
16711658
/// A constant (expression) that's not an item or associated item,
16721659
/// but needs its own `DefId` for type-checking, const-eval, etc.
16731660
/// These are usually found nested inside types (e.g., array lengths)
@@ -2115,7 +2102,7 @@ pub enum ExprKind<'hir> {
21152102
///
21162103
/// E.g., `[1; 5]`. The first expression is the element
21172104
/// to be repeated; the second is the number of times to repeat it.
2118-
Repeat(&'hir Expr<'hir>, ArrayLen<'hir>),
2105+
Repeat(&'hir Expr<'hir>, &'hir ConstArg<'hir>),
21192106

21202107
/// A suspension point for coroutines (i.e., `yield <expr>`).
21212108
Yield(&'hir Expr<'hir>, YieldSource),
@@ -2625,7 +2612,7 @@ impl<'hir> Ty<'hir> {
26252612
TyKind::Infer => true,
26262613
TyKind::Slice(ty) => ty.is_suggestable_infer_ty(),
26272614
TyKind::Array(ty, length) => {
2628-
ty.is_suggestable_infer_ty() || matches!(length, ArrayLen::Infer(..))
2615+
ty.is_suggestable_infer_ty() || matches!(length.kind, ConstArgKind::Infer(..))
26292616
}
26302617
TyKind::Tup(tys) => tys.iter().any(Self::is_suggestable_infer_ty),
26312618
TyKind::Ptr(mut_ty) | TyKind::Ref(_, mut_ty) => mut_ty.ty.is_suggestable_infer_ty(),
@@ -2834,7 +2821,7 @@ pub enum TyKind<'hir> {
28342821
/// A variable length slice (i.e., `[T]`).
28352822
Slice(&'hir Ty<'hir>),
28362823
/// A fixed length array (i.e., `[T; n]`).
2837-
Array(&'hir Ty<'hir>, ArrayLen<'hir>),
2824+
Array(&'hir Ty<'hir>, &'hir ConstArg<'hir>),
28382825
/// A raw pointer (i.e., `*const T` or `*mut T`).
28392826
Ptr(MutTy<'hir>),
28402827
/// A reference (i.e., `&'a T` or `&'a mut T`).
@@ -2861,6 +2848,11 @@ pub enum TyKind<'hir> {
28612848
Typeof(&'hir AnonConst),
28622849
/// `TyKind::Infer` means the type should be inferred instead of it having been
28632850
/// specified. This can appear anywhere in a type.
2851+
///
2852+
/// **Note:** Not all inferred types are represented as
2853+
/// `TyKind::Infer`. In cases where it is ambiguous whether
2854+
/// a generic arg is a type or a const, inference variables are
2855+
/// represented as `GenericArg::Infer` instead.
28642856
Infer,
28652857
/// Placeholder for a type that has failed to be defined.
28662858
Err(rustc_span::ErrorGuaranteed),
@@ -3801,8 +3793,6 @@ pub enum Node<'hir> {
38013793
Crate(&'hir Mod<'hir>),
38023794
Infer(&'hir InferArg),
38033795
WherePredicate(&'hir WherePredicate<'hir>),
3804-
// FIXME: Merge into `Node::Infer`.
3805-
ArrayLenInfer(&'hir InferArg),
38063796
PreciseCapturingNonLifetimeArg(&'hir PreciseCapturingNonLifetimeArg),
38073797
// Created by query feeding
38083798
Synthetic,
@@ -3856,7 +3846,6 @@ impl<'hir> Node<'hir> {
38563846
| Node::OpaqueTy(..)
38573847
| Node::Infer(..)
38583848
| Node::WherePredicate(..)
3859-
| Node::ArrayLenInfer(..)
38603849
| Node::Synthetic
38613850
| Node::Err(..) => None,
38623851
}

compiler/rustc_hir/src/intravisit.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,6 @@ pub trait Visitor<'v>: Sized {
343343
fn visit_pat_field(&mut self, f: &'v PatField<'v>) -> Self::Result {
344344
walk_pat_field(self, f)
345345
}
346-
fn visit_array_length(&mut self, len: &'v ArrayLen<'v>) -> Self::Result {
347-
walk_array_len(self, len)
348-
}
349346
fn visit_anon_const(&mut self, c: &'v AnonConst) -> Self::Result {
350347
walk_anon_const(self, c)
351348
}
@@ -710,14 +707,6 @@ pub fn walk_pat_field<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v PatField<'
710707
visitor.visit_pat(field.pat)
711708
}
712709

713-
pub fn walk_array_len<'v, V: Visitor<'v>>(visitor: &mut V, len: &'v ArrayLen<'v>) -> V::Result {
714-
match len {
715-
// FIXME: Use `visit_infer` here.
716-
ArrayLen::Infer(InferArg { hir_id, span: _ }) => visitor.visit_id(*hir_id),
717-
ArrayLen::Body(c) => visitor.visit_const_arg(c),
718-
}
719-
}
720-
721710
pub fn walk_anon_const<'v, V: Visitor<'v>>(visitor: &mut V, constant: &'v AnonConst) -> V::Result {
722711
try_visit!(visitor.visit_id(constant.hir_id));
723712
visitor.visit_nested_body(constant.body)
@@ -739,6 +728,7 @@ pub fn walk_const_arg<'v, V: Visitor<'v>>(
739728
match &const_arg.kind {
740729
ConstArgKind::Path(qpath) => visitor.visit_qpath(qpath, const_arg.hir_id, qpath.span()),
741730
ConstArgKind::Anon(anon) => visitor.visit_anon_const(*anon),
731+
ConstArgKind::Infer(..) => V::Result::output(),
742732
}
743733
}
744734

@@ -753,7 +743,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
753743
}
754744
ExprKind::Repeat(ref element, ref count) => {
755745
try_visit!(visitor.visit_expr(element));
756-
try_visit!(visitor.visit_array_length(count));
746+
try_visit!(visitor.visit_const_arg(count));
757747
}
758748
ExprKind::Struct(ref qpath, fields, ref optional_base) => {
759749
try_visit!(visitor.visit_qpath(qpath, expression.hir_id, expression.span));
@@ -901,7 +891,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) -> V::Resul
901891
}
902892
TyKind::Array(ref ty, ref length) => {
903893
try_visit!(visitor.visit_ty(ty));
904-
try_visit!(visitor.visit_array_length(length));
894+
try_visit!(visitor.visit_const_arg(length));
905895
}
906896
TyKind::TraitObject(bounds, ref lifetime, _syntax) => {
907897
for bound in bounds {

0 commit comments

Comments
 (0)