Skip to content

Commit 82cf196

Browse files
committed
Merge remote-tracking branch 'origin' into mingw-split
2 parents 30a9fdc + 0c4f3a4 commit 82cf196

File tree

606 files changed

+3597
-4034
lines changed

Some content is hidden

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

606 files changed

+3597
-4034
lines changed

Diff for: Cargo.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -3820,7 +3820,6 @@ dependencies = [
38203820
name = "rustc_index"
38213821
version = "0.0.0"
38223822
dependencies = [
3823-
"arrayvec",
38243823
"rustc_index_macros",
38253824
"rustc_macros",
38263825
"rustc_serialize",
@@ -4137,6 +4136,7 @@ name = "rustc_monomorphize"
41374136
version = "0.0.0"
41384137
dependencies = [
41394138
"rustc_abi",
4139+
"rustc_attr",
41404140
"rustc_data_structures",
41414141
"rustc_errors",
41424142
"rustc_fluent_macro",

Diff for: compiler/rustc_ast/src/ast.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1184,14 +1184,15 @@ pub struct Expr {
11841184
}
11851185

11861186
impl Expr {
1187-
/// Is this expr either `N`, or `{ N }`.
1187+
/// Could this expr be either `N`, or `{ N }`, where `N` is a const parameter.
11881188
///
11891189
/// If this is not the case, name resolution does not resolve `N` when using
11901190
/// `min_const_generics` as more complex expressions are not supported.
11911191
///
11921192
/// Does not ensure that the path resolves to a const param, the caller should check this.
1193-
pub fn is_potential_trivial_const_arg(&self, strip_identity_block: bool) -> bool {
1194-
let this = if strip_identity_block { self.maybe_unwrap_block() } else { self };
1193+
/// This also does not consider macros, so it's only correct after macro-expansion.
1194+
pub fn is_potential_trivial_const_arg(&self) -> bool {
1195+
let this = self.maybe_unwrap_block();
11951196

11961197
if let ExprKind::Path(None, path) = &this.kind
11971198
&& path.is_potential_trivial_const_arg()

Diff for: compiler/rustc_ast_lowering/src/asm.rs

+14-12
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) {
@@ -222,18 +227,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
222227
};
223228

224229
// Wrap the expression in an AnonConst.
225-
let parent_def_id = self.current_def_id_parent;
230+
let parent_def_id = self.current_hir_id_owner.def_id;
226231
let node_id = self.next_node_id();
227-
// HACK(min_generic_const_args): see lower_anon_const
228-
if !expr.is_potential_trivial_const_arg(true) {
229-
self.create_def(
230-
parent_def_id,
231-
node_id,
232-
kw::Empty,
233-
DefKind::AnonConst,
234-
*op_sp,
235-
);
236-
}
232+
self.create_def(
233+
parent_def_id,
234+
node_id,
235+
kw::Empty,
236+
DefKind::AnonConst,
237+
*op_sp,
238+
);
237239
let anon_const = AnonConst { id: node_id, value: P(expr) };
238240
hir::InlineAsmOperand::SymFn {
239241
anon_const: self.lower_anon_const_to_anon_const(&anon_const),

Diff for: compiler/rustc_ast_lowering/src/expr.rs

+48-62
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
109109
hir::ConstBlock {
110110
def_id,
111111
hir_id: this.lower_node_id(c.id),
112-
body: this.with_def_id_parent(def_id, |this| {
113-
this.lower_const_body(c.value.span, Some(&c.value))
114-
}),
112+
body: this.lower_const_body(c.value.span, Some(&c.value)),
115113
}
116114
});
117115
hir::ExprKind::ConstBlock(c)
@@ -452,15 +450,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
452450
let mut generic_args = ThinVec::new();
453451
for (idx, arg) in args.iter().cloned().enumerate() {
454452
if legacy_args_idx.contains(&idx) {
455-
let parent_def_id = self.current_def_id_parent;
453+
let parent_def_id = self.current_hir_id_owner.def_id;
456454
let node_id = self.next_node_id();
457-
458-
// HACK(min_generic_const_args): see lower_anon_const
459-
if !arg.is_potential_trivial_const_arg(true) {
460-
// Add a definition for the in-band const def.
461-
self.create_def(parent_def_id, node_id, kw::Empty, DefKind::AnonConst, f.span);
462-
}
463-
455+
self.create_def(parent_def_id, node_id, kw::Empty, DefKind::AnonConst, f.span);
464456
let mut visitor = WillCreateDefIdsVisitor {};
465457
let const_value = if let ControlFlow::Break(span) = visitor.visit_expr(&arg) {
466458
AstP(Expr {
@@ -759,19 +751,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
759751
lifetime_elision_allowed: false,
760752
});
761753

762-
let body = self.with_def_id_parent(closure_def_id, move |this| {
763-
this.lower_body(move |this| {
764-
this.coroutine_kind = Some(coroutine_kind);
754+
let body = self.lower_body(move |this| {
755+
this.coroutine_kind = Some(coroutine_kind);
765756

766-
let old_ctx = this.task_context;
767-
if task_context.is_some() {
768-
this.task_context = task_context;
769-
}
770-
let res = body(this);
771-
this.task_context = old_ctx;
757+
let old_ctx = this.task_context;
758+
if task_context.is_some() {
759+
this.task_context = task_context;
760+
}
761+
let res = body(this);
762+
this.task_context = old_ctx;
772763

773-
(params, res)
774-
})
764+
(params, res)
775765
});
776766

777767
// `static |<_task_context?>| -> <return_ty> { <body> }`:
@@ -1056,26 +1046,24 @@ impl<'hir> LoweringContext<'_, 'hir> {
10561046
let (binder_clause, generic_params) = self.lower_closure_binder(binder);
10571047

10581048
let (body_id, closure_kind) = self.with_new_scopes(fn_decl_span, move |this| {
1059-
this.with_def_id_parent(closure_def_id, move |this| {
1060-
let mut coroutine_kind = if this
1061-
.attrs
1062-
.get(&closure_hir_id.local_id)
1063-
.is_some_and(|attrs| attrs.iter().any(|attr| attr.has_name(sym::coroutine)))
1064-
{
1065-
Some(hir::CoroutineKind::Coroutine(Movability::Movable))
1066-
} else {
1067-
None
1068-
};
1069-
let body_id = this.lower_fn_body(decl, |this| {
1070-
this.coroutine_kind = coroutine_kind;
1071-
let e = this.lower_expr_mut(body);
1072-
coroutine_kind = this.coroutine_kind;
1073-
e
1074-
});
1075-
let coroutine_option =
1076-
this.closure_movability_for_fn(decl, fn_decl_span, coroutine_kind, movability);
1077-
(body_id, coroutine_option)
1078-
})
1049+
let mut coroutine_kind = if this
1050+
.attrs
1051+
.get(&closure_hir_id.local_id)
1052+
.is_some_and(|attrs| attrs.iter().any(|attr| attr.has_name(sym::coroutine)))
1053+
{
1054+
Some(hir::CoroutineKind::Coroutine(Movability::Movable))
1055+
} else {
1056+
None
1057+
};
1058+
let body_id = this.lower_fn_body(decl, |this| {
1059+
this.coroutine_kind = coroutine_kind;
1060+
let e = this.lower_expr_mut(body);
1061+
coroutine_kind = this.coroutine_kind;
1062+
e
1063+
});
1064+
let coroutine_option =
1065+
this.closure_movability_for_fn(decl, fn_decl_span, coroutine_kind, movability);
1066+
(body_id, coroutine_option)
10791067
});
10801068

10811069
let bound_generic_params = self.lower_lifetime_binder(closure_id, generic_params);
@@ -1165,28 +1153,26 @@ impl<'hir> LoweringContext<'_, 'hir> {
11651153
);
11661154

11671155
let body = self.with_new_scopes(fn_decl_span, |this| {
1168-
this.with_def_id_parent(closure_def_id, |this| {
1169-
let inner_decl =
1170-
FnDecl { inputs: decl.inputs.clone(), output: FnRetTy::Default(fn_decl_span) };
1171-
1172-
// Transform `async |x: u8| -> X { ... }` into
1173-
// `|x: u8| || -> X { ... }`.
1174-
let body_id = this.lower_body(|this| {
1175-
let (parameters, expr) = this.lower_coroutine_body_with_moved_arguments(
1176-
&inner_decl,
1177-
|this| this.with_new_scopes(fn_decl_span, |this| this.lower_expr_mut(body)),
1178-
fn_decl_span,
1179-
body.span,
1180-
coroutine_kind,
1181-
hir::CoroutineSource::Closure,
1182-
);
1156+
let inner_decl =
1157+
FnDecl { inputs: decl.inputs.clone(), output: FnRetTy::Default(fn_decl_span) };
1158+
1159+
// Transform `async |x: u8| -> X { ... }` into
1160+
// `|x: u8| || -> X { ... }`.
1161+
let body_id = this.lower_body(|this| {
1162+
let (parameters, expr) = this.lower_coroutine_body_with_moved_arguments(
1163+
&inner_decl,
1164+
|this| this.with_new_scopes(fn_decl_span, |this| this.lower_expr_mut(body)),
1165+
fn_decl_span,
1166+
body.span,
1167+
coroutine_kind,
1168+
hir::CoroutineSource::Closure,
1169+
);
11831170

1184-
this.maybe_forward_track_caller(body.span, closure_hir_id, expr.hir_id);
1171+
this.maybe_forward_track_caller(body.span, closure_hir_id, expr.hir_id);
11851172

1186-
(parameters, expr)
1187-
});
1188-
body_id
1189-
})
1173+
(parameters, expr)
1174+
});
1175+
body_id
11901176
});
11911177

11921178
let bound_generic_params = self.lower_lifetime_binder(closure_id, generic_params);

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+18-55
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,6 @@ struct LoweringContext<'a, 'hir> {
117117
is_in_dyn_type: bool,
118118

119119
current_hir_id_owner: hir::OwnerId,
120-
/// Why do we need this in addition to [`Self::current_hir_id_owner`]?
121-
///
122-
/// Currently (as of June 2024), anonymous constants are not HIR owners; however,
123-
/// they do get their own DefIds. Some of these DefIds have to be created during
124-
/// AST lowering, rather than def collection, because we can't tell until after
125-
/// name resolution whether an anonymous constant will end up instead being a
126-
/// [`hir::ConstArgKind::Path`]. However, to compute which generics are
127-
/// available to an anonymous constant nested inside another, we need to make
128-
/// sure that the parent is recorded as the parent anon const, not the enclosing
129-
/// item. So we need to track parent defs differently from HIR owners, since they
130-
/// will be finer-grained in the case of anon consts.
131-
current_def_id_parent: LocalDefId,
132120
item_local_id_counter: hir::ItemLocalId,
133121
trait_map: ItemLocalMap<Box<[TraitCandidate]>>,
134122

@@ -161,7 +149,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
161149
attrs: SortedMap::default(),
162150
children: Vec::default(),
163151
current_hir_id_owner: hir::CRATE_OWNER_ID,
164-
current_def_id_parent: CRATE_DEF_ID,
165152
item_local_id_counter: hir::ItemLocalId::ZERO,
166153
ident_and_label_to_local_id: Default::default(),
167154
#[cfg(debug_assertions)]
@@ -565,7 +552,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
565552
debug_assert_eq!(_old, None);
566553
}
567554

568-
let item = self.with_def_id_parent(def_id, f);
555+
let item = f(self);
569556
debug_assert_eq!(def_id, item.def_id().def_id);
570557
// `f` should have consumed all the elements in these vectors when constructing `item`.
571558
debug_assert!(self.impl_trait_defs.is_empty());
@@ -590,13 +577,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
590577
self.children.push((def_id, hir::MaybeOwner::Owner(info)));
591578
}
592579

593-
fn with_def_id_parent<T>(&mut self, parent: LocalDefId, f: impl FnOnce(&mut Self) -> T) -> T {
594-
let current_def_id_parent = std::mem::replace(&mut self.current_def_id_parent, parent);
595-
let result = f(self);
596-
self.current_def_id_parent = current_def_id_parent;
597-
result
598-
}
599-
600580
fn make_owner_info(&mut self, node: hir::OwnerNode<'hir>) -> &'hir hir::OwnerInfo<'hir> {
601581
let attrs = std::mem::take(&mut self.attrs);
602582
let mut bodies = std::mem::take(&mut self.bodies);
@@ -773,7 +753,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
773753
LifetimeRes::Fresh { param, kind, .. } => {
774754
// Late resolution delegates to us the creation of the `LocalDefId`.
775755
let _def_id = self.create_def(
776-
self.current_hir_id_owner.def_id, // FIXME: should this use self.current_def_id_parent?
756+
self.current_hir_id_owner.def_id,
777757
param,
778758
kw::UnderscoreLifetime,
779759
DefKind::LifetimeParam,
@@ -1466,17 +1446,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14661446
let opaque_ty_hir_id = self.lower_node_id(opaque_ty_node_id);
14671447
debug!(?opaque_ty_def_id, ?opaque_ty_hir_id);
14681448

1469-
let opaque_ty_def = self.with_def_id_parent(opaque_ty_def_id, |this| {
1470-
let bounds = lower_item_bounds(this);
1471-
let opaque_ty_def = hir::OpaqueTy {
1472-
hir_id: opaque_ty_hir_id,
1473-
def_id: opaque_ty_def_id,
1474-
bounds,
1475-
origin,
1476-
span: this.lower_span(opaque_ty_span),
1477-
};
1478-
this.arena.alloc(opaque_ty_def)
1479-
});
1449+
let bounds = lower_item_bounds(self);
1450+
let opaque_ty_def = hir::OpaqueTy {
1451+
hir_id: opaque_ty_hir_id,
1452+
def_id: opaque_ty_def_id,
1453+
bounds,
1454+
origin,
1455+
span: self.lower_span(opaque_ty_span),
1456+
};
1457+
let opaque_ty_def = self.arena.alloc(opaque_ty_def);
14801458

14811459
hir::TyKind::OpaqueDef(opaque_ty_def)
14821460
}
@@ -2084,7 +2062,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20842062
} else {
20852063
// Construct an AnonConst where the expr is the "ty"'s path.
20862064

2087-
let parent_def_id = self.current_def_id_parent;
2065+
let parent_def_id = self.current_hir_id_owner.def_id;
20882066
let node_id = self.next_node_id();
20892067
let span = self.lower_span(span);
20902068

@@ -2108,9 +2086,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21082086
self.arena.alloc(hir::AnonConst {
21092087
def_id,
21102088
hir_id,
2111-
body: this.with_def_id_parent(def_id, |this| {
2112-
this.lower_const_body(path_expr.span, Some(&path_expr))
2113-
}),
2089+
body: this.lower_const_body(path_expr.span, Some(&path_expr)),
21142090
span,
21152091
})
21162092
});
@@ -2159,7 +2135,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21592135
None,
21602136
);
21612137

2162-
return ConstArg { hir_id: self.next_id(), kind: hir::ConstArgKind::Path(qpath) };
2138+
return ConstArg {
2139+
hir_id: self.lower_node_id(anon.id),
2140+
kind: hir::ConstArgKind::Path(qpath),
2141+
};
21632142
}
21642143

21652144
let lowered_anon = self.lower_anon_const_to_anon_const(anon);
@@ -2169,29 +2148,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21692148
/// See [`hir::ConstArg`] for when to use this function vs
21702149
/// [`Self::lower_anon_const_to_const_arg`].
21712150
fn lower_anon_const_to_anon_const(&mut self, c: &AnonConst) -> &'hir hir::AnonConst {
2172-
if c.value.is_potential_trivial_const_arg(true) {
2173-
// HACK(min_generic_const_args): see DefCollector::visit_anon_const
2174-
// Over there, we guess if this is a bare param and only create a def if
2175-
// we think it's not. However we may can guess wrong (see there for example)
2176-
// in which case we have to create the def here.
2177-
self.create_def(
2178-
self.current_def_id_parent,
2179-
c.id,
2180-
kw::Empty,
2181-
DefKind::AnonConst,
2182-
c.value.span,
2183-
);
2184-
}
2185-
21862151
self.arena.alloc(self.with_new_scopes(c.value.span, |this| {
21872152
let def_id = this.local_def_id(c.id);
21882153
let hir_id = this.lower_node_id(c.id);
21892154
hir::AnonConst {
21902155
def_id,
21912156
hir_id,
2192-
body: this.with_def_id_parent(def_id, |this| {
2193-
this.lower_const_body(c.value.span, Some(&c.value))
2194-
}),
2157+
body: this.lower_const_body(c.value.span, Some(&c.value)),
21952158
span: this.lower_span(c.value.span),
21962159
}
21972160
}))

Diff for: compiler/rustc_borrowck/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use rustc_infer::infer::{
3434
use rustc_middle::mir::tcx::PlaceTy;
3535
use rustc_middle::mir::*;
3636
use rustc_middle::query::Providers;
37+
use rustc_middle::ty::fold::fold_regions;
3738
use rustc_middle::ty::{self, ParamEnv, RegionVid, TyCtxt, TypingMode};
3839
use rustc_middle::{bug, span_bug};
3940
use rustc_mir_dataflow::impls::{
@@ -502,7 +503,7 @@ impl<'tcx> BorrowckInferCtxt<'tcx> {
502503
for data in tcx.typeck(def_id).concrete_opaque_types.iter().map(|(k, v)| (*k, *v)) {
503504
// HIR typeck did not infer the regions of the opaque, so we instantiate
504505
// them with fresh inference variables.
505-
let (key, hidden_ty) = tcx.fold_regions(data, |_, _| {
506+
let (key, hidden_ty) = fold_regions(tcx, data, |_, _| {
506507
self.next_nll_region_var_in_universe(
507508
NllRegionVariableOrigin::Existential { from_forall: false },
508509
ty::UniverseIndex::ROOT,

0 commit comments

Comments
 (0)