Skip to content

Commit bf9504b

Browse files
committed
Auto merge of #120984 - matthiaskrgr:rollup-tld0avy, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - #118983 (Warn on references casting to bigger memory layout) - #119451 (Gate PR CI on clippy correctness lints) - #120273 (compiletest: few naive improvements) - #120889 (Implement Instant for UEFI) - #120938 (Implement sys/thread for UEFI) - #120950 (Fix async closures in CTFE) - #120958 (Dejargonize `subst`) - #120965 (Add lahfsahf and prfchw target feature) - #120970 (add another test for promoteds-in-static) - #120979 (Update books) Failed merges: - #120973 (allow static_mut_ref in some tests that specifically test mutable statics) r? `@ghost` `@rustbot` modify labels: rollup
2 parents b381d3a + 8066015 commit bf9504b

File tree

177 files changed

+1289
-635
lines changed

Some content is hidden

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

177 files changed

+1289
-635
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
691691

692692
// If the type is opaque/param/closure, and it is Fn or FnMut, let's suggest (mutably)
693693
// borrowing the type, since `&mut F: FnMut` iff `F: FnMut` and similarly for `Fn`.
694-
// These types seem reasonably opaque enough that they could be substituted with their
694+
// These types seem reasonably opaque enough that they could be instantiated with their
695695
// borrowed variants in a function body when we see a move error.
696696
let borrow_level = match *ty.kind() {
697697
ty::Param(_) => tcx
@@ -3158,7 +3158,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
31583158
) -> Option<AnnotatedBorrowFnSignature<'tcx>> {
31593159
// Define a fallback for when we can't match a closure.
31603160
let fallback = || {
3161-
let is_closure = self.infcx.tcx.is_closure_or_coroutine(self.mir_def_id().to_def_id());
3161+
let is_closure = self.infcx.tcx.is_closure_like(self.mir_def_id().to_def_id());
31623162
if is_closure {
31633163
None
31643164
} else {
@@ -3369,7 +3369,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
33693369
sig: ty::PolyFnSig<'tcx>,
33703370
) -> Option<AnnotatedBorrowFnSignature<'tcx>> {
33713371
debug!("annotate_fn_sig: did={:?} sig={:?}", did, sig);
3372-
let is_closure = self.infcx.tcx.is_closure_or_coroutine(did.to_def_id());
3372+
let is_closure = self.infcx.tcx.is_closure_like(did.to_def_id());
33733373
let fn_hir_id = self.infcx.tcx.local_def_id_to_hir_id(did);
33743374
let fn_decl = self.infcx.tcx.hir().fn_decl_by_hir_id(fn_hir_id)?;
33753375

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
6767
local,
6868
projection: [proj_base @ .., ProjectionElem::Field(upvar_index, _)],
6969
} => {
70-
debug_assert!(is_closure_or_coroutine(
70+
debug_assert!(is_closure_like(
7171
Place::ty_from(local, proj_base, self.body, self.infcx.tcx).ty
7272
));
7373

@@ -126,9 +126,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
126126
{
127127
item_msg = access_place_desc;
128128
debug_assert!(self.body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty.is_ref());
129-
debug_assert!(is_closure_or_coroutine(
130-
the_place_err.ty(self.body, self.infcx.tcx).ty
131-
));
129+
debug_assert!(is_closure_like(the_place_err.ty(self.body, self.infcx.tcx).ty));
132130

133131
reason = if self.is_upvar_field_projection(access_place.as_ref()).is_some() {
134132
", as it is a captured variable in a `Fn` closure".to_string()
@@ -389,7 +387,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
389387
local,
390388
projection: [proj_base @ .., ProjectionElem::Field(upvar_index, _)],
391389
} => {
392-
debug_assert!(is_closure_or_coroutine(
390+
debug_assert!(is_closure_like(
393391
Place::ty_from(local, proj_base, self.body, self.infcx.tcx).ty
394392
));
395393

@@ -1474,7 +1472,8 @@ fn suggest_ampmut<'tcx>(
14741472
}
14751473
}
14761474

1477-
fn is_closure_or_coroutine(ty: Ty<'_>) -> bool {
1475+
/// If the type is a `Coroutine`, `Closure`, or `CoroutineClosure`
1476+
fn is_closure_like(ty: Ty<'_>) -> bool {
14781477
ty.is_closure() || ty.is_coroutine() || ty.is_coroutine_closure()
14791478
}
14801479

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
4545
/// be allowed:
4646
/// `fn f<'a: 'b, 'b: 'a>(x: *mut &'b i32) -> impl Sized + 'a { x }`
4747
///
48-
/// Then we map the regions in both the type and the subst to their
48+
/// Then we map the regions in both the type and the generic parameters to their
4949
/// `external_name` giving `concrete_type = &'a i32`,
5050
/// `args = ['static, 'a]`. This will then allow
5151
/// `infer_opaque_definition_from_instantiation` to determine that
@@ -77,9 +77,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
7777
let args = opaque_type_key.args;
7878
debug!(?concrete_type, ?args);
7979

80-
let mut subst_regions = vec![self.universal_regions.fr_static];
80+
let mut arg_regions = vec![self.universal_regions.fr_static];
8181

82-
let to_universal_region = |vid, subst_regions: &mut Vec<_>| {
82+
let to_universal_region = |vid, arg_regions: &mut Vec<_>| {
8383
trace!(?vid);
8484
let scc = self.constraint_sccs.scc(vid);
8585
trace!(?scc);
@@ -88,11 +88,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
8888
}) {
8989
Some(region) => {
9090
let vid = self.universal_regions.to_region_vid(region);
91-
subst_regions.push(vid);
91+
arg_regions.push(vid);
9292
region
9393
}
9494
None => {
95-
subst_regions.push(vid);
95+
arg_regions.push(vid);
9696
ty::Region::new_error_with_message(
9797
infcx.tcx,
9898
concrete_type.span,
@@ -106,10 +106,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
106106
// This will ensure they get precedence when folding the regions in the concrete type.
107107
if let Some(&ci) = member_constraints.get(&opaque_type_key) {
108108
for &vid in self.member_constraints.choice_regions(ci) {
109-
to_universal_region(vid, &mut subst_regions);
109+
to_universal_region(vid, &mut arg_regions);
110110
}
111111
}
112-
debug!(?subst_regions);
112+
debug!(?arg_regions);
113113

114114
// Next, insert universal regions from args, so we can translate regions that appear
115115
// in them but are not subject to member constraints, for instance closure args.
@@ -119,18 +119,18 @@ impl<'tcx> RegionInferenceContext<'tcx> {
119119
return region;
120120
}
121121
let vid = self.to_region_vid(region);
122-
to_universal_region(vid, &mut subst_regions)
122+
to_universal_region(vid, &mut arg_regions)
123123
});
124124
debug!(?universal_args);
125-
debug!(?subst_regions);
125+
debug!(?arg_regions);
126126

127127
// Deduplicate the set of regions while keeping the chosen order.
128-
let subst_regions = subst_regions.into_iter().collect::<FxIndexSet<_>>();
129-
debug!(?subst_regions);
128+
let arg_regions = arg_regions.into_iter().collect::<FxIndexSet<_>>();
129+
debug!(?arg_regions);
130130

131131
let universal_concrete_type =
132132
infcx.tcx.fold_regions(concrete_type, |region, _| match *region {
133-
ty::ReVar(vid) => subst_regions
133+
ty::ReVar(vid) => arg_regions
134134
.iter()
135135
.find(|ur_vid| self.eval_equal(vid, **ur_vid))
136136
.and_then(|ur_vid| self.definitions[*ur_vid].external_name)

compiler/rustc_borrowck/src/type_check/input_output.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
2929
pub(super) fn check_signature_annotation(&mut self, body: &Body<'tcx>) {
3030
let mir_def_id = body.source.def_id().expect_local();
3131

32-
if !self.tcx().is_closure_or_coroutine(mir_def_id.to_def_id()) {
32+
if !self.tcx().is_closure_like(mir_def_id.to_def_id()) {
3333
return;
3434
}
3535

compiler/rustc_codegen_llvm/src/attributes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ pub fn from_fn_attrs<'ll, 'tcx>(
479479
// `+multivalue` feature because the purpose of the wasm abi is to match
480480
// the WebAssembly specification, which has this feature. This won't be
481481
// needed when LLVM enables this `multivalue` feature by default.
482-
if !cx.tcx.is_closure_or_coroutine(instance.def_id()) {
482+
if !cx.tcx.is_closure_like(instance.def_id()) {
483483
let abi = cx.tcx.fn_sig(instance.def_id()).skip_binder().abi();
484484
if abi == Abi::Wasm {
485485
function_features.push("+multivalue".to_string());

compiler/rustc_codegen_llvm/src/llvm_util.rs

+1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ pub fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> LLVMFeature<'a> {
213213
("x86", "rdrand") => LLVMFeature::new("rdrnd"),
214214
("x86", "bmi1") => LLVMFeature::new("bmi"),
215215
("x86", "cmpxchg16b") => LLVMFeature::new("cx16"),
216+
("x86", "lahfsahf") => LLVMFeature::new("sahf"),
216217
("aarch64", "rcpc2") => LLVMFeature::new("rcpc-immo"),
217218
("aarch64", "dpb") => LLVMFeature::new("ccpp"),
218219
("aarch64", "dpb2") => LLVMFeature::new("ccdp"),

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
229229
}
230230
sym::thread_local => codegen_fn_attrs.flags |= CodegenFnAttrFlags::THREAD_LOCAL,
231231
sym::track_caller => {
232-
let is_closure = tcx.is_closure_or_coroutine(did.to_def_id());
232+
let is_closure = tcx.is_closure_like(did.to_def_id());
233233

234234
if !is_closure
235235
&& let Some(fn_sig) = fn_sig()
@@ -274,7 +274,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
274274
}
275275
}
276276
sym::target_feature => {
277-
if !tcx.is_closure_or_coroutine(did.to_def_id())
277+
if !tcx.is_closure_like(did.to_def_id())
278278
&& let Some(fn_sig) = fn_sig()
279279
&& fn_sig.skip_binder().unsafety() == hir::Unsafety::Normal
280280
{
@@ -529,7 +529,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
529529
// would result in this closure being compiled without the inherited target features, but this
530530
// is probably a poor usage of `#[inline(always)]` and easily avoided by not using the attribute.
531531
if tcx.features().target_feature_11
532-
&& tcx.is_closure_or_coroutine(did.to_def_id())
532+
&& tcx.is_closure_like(did.to_def_id())
533533
&& codegen_fn_attrs.inline != InlineAttr::Always
534534
{
535535
let owner_id = tcx.parent(did.to_def_id());

compiler/rustc_codegen_ssa/src/target_features.rs

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ pub fn from_target_feature(
7777
Some(sym::aarch64_ver_target_feature) => rust_features.aarch64_ver_target_feature,
7878
Some(sym::csky_target_feature) => rust_features.csky_target_feature,
7979
Some(sym::loongarch_target_feature) => rust_features.loongarch_target_feature,
80+
Some(sym::lahfsahf_target_feature) => rust_features.lahfsahf_target_feature,
81+
Some(sym::prfchw_target_feature) => rust_features.prfchw_target_feature,
8082
Some(name) => bug!("unknown target feature gate {}", name),
8183
None => true,
8284
};

compiler/rustc_const_eval/src/interpret/eval_context.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -554,18 +554,20 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
554554

555555
/// Call this on things you got out of the MIR (so it is as generic as the current
556556
/// stack frame), to bring it into the proper environment for this interpreter.
557-
pub(super) fn subst_from_current_frame_and_normalize_erasing_regions<
557+
pub(super) fn instantiate_from_current_frame_and_normalize_erasing_regions<
558558
T: TypeFoldable<TyCtxt<'tcx>>,
559559
>(
560560
&self,
561561
value: T,
562562
) -> Result<T, ErrorHandled> {
563-
self.subst_from_frame_and_normalize_erasing_regions(self.frame(), value)
563+
self.instantiate_from_frame_and_normalize_erasing_regions(self.frame(), value)
564564
}
565565

566566
/// Call this on things you got out of the MIR (so it is as generic as the provided
567567
/// stack frame), to bring it into the proper environment for this interpreter.
568-
pub(super) fn subst_from_frame_and_normalize_erasing_regions<T: TypeFoldable<TyCtxt<'tcx>>>(
568+
pub(super) fn instantiate_from_frame_and_normalize_erasing_regions<
569+
T: TypeFoldable<TyCtxt<'tcx>>,
570+
>(
569571
&self,
570572
frame: &Frame<'mir, 'tcx, M::Provenance, M::FrameExtra>,
571573
value: T,
@@ -656,7 +658,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
656658

657659
let layout = from_known_layout(self.tcx, self.param_env, layout, || {
658660
let local_ty = frame.body.local_decls[local].ty;
659-
let local_ty = self.subst_from_frame_and_normalize_erasing_regions(frame, local_ty)?;
661+
let local_ty =
662+
self.instantiate_from_frame_and_normalize_erasing_regions(frame, local_ty)?;
660663
self.layout_of(local_ty)
661664
})?;
662665

@@ -791,8 +794,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
791794
// Make sure all the constants required by this frame evaluate successfully (post-monomorphization check).
792795
if M::POST_MONO_CHECKS {
793796
for &const_ in &body.required_consts {
794-
let c =
795-
self.subst_from_current_frame_and_normalize_erasing_regions(const_.const_)?;
797+
let c = self
798+
.instantiate_from_current_frame_and_normalize_erasing_regions(const_.const_)?;
796799
c.eval(*self.tcx, self.param_env, Some(const_.span)).map_err(|err| {
797800
err.emit_note(*self.tcx);
798801
err

compiler/rustc_const_eval/src/interpret/operand.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -696,9 +696,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
696696
trace!("eval_place_to_op: got {:?}", op);
697697
// Sanity-check the type we ended up with.
698698
if cfg!(debug_assertions) {
699-
let normalized_place_ty = self.subst_from_current_frame_and_normalize_erasing_regions(
700-
mir_place.ty(&self.frame().body.local_decls, *self.tcx).ty,
701-
)?;
699+
let normalized_place_ty = self
700+
.instantiate_from_current_frame_and_normalize_erasing_regions(
701+
mir_place.ty(&self.frame().body.local_decls, *self.tcx).ty,
702+
)?;
702703
if !mir_assign_valid_types(
703704
*self.tcx,
704705
self.param_env,
@@ -731,8 +732,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
731732
&Copy(place) | &Move(place) => self.eval_place_to_op(place, layout)?,
732733

733734
Constant(constant) => {
734-
let c =
735-
self.subst_from_current_frame_and_normalize_erasing_regions(constant.const_)?;
735+
let c = self.instantiate_from_current_frame_and_normalize_erasing_regions(
736+
constant.const_,
737+
)?;
736738

737739
// This can still fail:
738740
// * During ConstProp, with `TooGeneric` or since the `required_consts` were not all

compiler/rustc_const_eval/src/interpret/place.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -542,9 +542,10 @@ where
542542
trace!("{:?}", self.dump_place(&place));
543543
// Sanity-check the type we ended up with.
544544
if cfg!(debug_assertions) {
545-
let normalized_place_ty = self.subst_from_current_frame_and_normalize_erasing_regions(
546-
mir_place.ty(&self.frame().body.local_decls, *self.tcx).ty,
547-
)?;
545+
let normalized_place_ty = self
546+
.instantiate_from_current_frame_and_normalize_erasing_regions(
547+
mir_place.ty(&self.frame().body.local_decls, *self.tcx).ty,
548+
)?;
548549
if !mir_assign_valid_types(
549550
*self.tcx,
550551
self.param_env,

compiler/rustc_const_eval/src/interpret/step.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
235235
}
236236

237237
NullaryOp(ref null_op, ty) => {
238-
let ty = self.subst_from_current_frame_and_normalize_erasing_regions(ty)?;
238+
let ty = self.instantiate_from_current_frame_and_normalize_erasing_regions(ty)?;
239239
let layout = self.layout_of(ty)?;
240240
if let mir::NullOp::SizeOf | mir::NullOp::AlignOf = null_op
241241
&& layout.is_unsized()
@@ -276,7 +276,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
276276
Cast(cast_kind, ref operand, cast_ty) => {
277277
let src = self.eval_operand(operand, None)?;
278278
let cast_ty =
279-
self.subst_from_current_frame_and_normalize_erasing_regions(cast_ty)?;
279+
self.instantiate_from_current_frame_and_normalize_erasing_regions(cast_ty)?;
280280
self.cast(&src, cast_kind, cast_ty, &dest)?;
281281
}
282282

compiler/rustc_const_eval/src/interpret/terminator.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
173173
Drop { place, target, unwind, replace: _ } => {
174174
let frame = self.frame();
175175
let ty = place.ty(&frame.body.local_decls, *self.tcx).ty;
176-
let ty = self.subst_from_frame_and_normalize_erasing_regions(frame, ty)?;
176+
let ty = self.instantiate_from_frame_and_normalize_erasing_regions(frame, ty)?;
177177
let instance = Instance::resolve_drop_in_place(*self.tcx, ty);
178178
if let ty::InstanceDef::DropGlue(_, None) = instance.def {
179179
// This is the branch we enter if and only if the dropped type has no drop glue
@@ -672,8 +672,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
672672
// Construct the destination place for this argument. At this point all
673673
// locals are still dead, so we cannot construct a `PlaceTy`.
674674
let dest = mir::Place::from(local);
675-
// `layout_of_local` does more than just the substitution we need to get the
676-
// type, but the result gets cached so this avoids calling the substitution
675+
// `layout_of_local` does more than just the instantiation we need to get the
676+
// type, but the result gets cached so this avoids calling the instantiation
677677
// query *again* the next time this local is accessed.
678678
let ty = self.layout_of_local(self.frame(), local, None)?.ty;
679679
if Some(local) == body.spread_arg {

compiler/rustc_const_eval/src/interpret/util.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ where
1919
}
2020

2121
struct FoundParam;
22-
struct UsedParamsNeedSubstVisitor<'tcx> {
22+
struct UsedParamsNeedInstantiationVisitor<'tcx> {
2323
tcx: TyCtxt<'tcx>,
2424
}
2525

26-
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for UsedParamsNeedSubstVisitor<'tcx> {
26+
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for UsedParamsNeedInstantiationVisitor<'tcx> {
2727
type BreakTy = FoundParam;
2828

2929
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
@@ -34,21 +34,22 @@ where
3434
match *ty.kind() {
3535
ty::Param(_) => ControlFlow::Break(FoundParam),
3636
ty::Closure(def_id, args)
37+
| ty::CoroutineClosure(def_id, args, ..)
3738
| ty::Coroutine(def_id, args, ..)
3839
| ty::FnDef(def_id, args) => {
3940
let instance = ty::InstanceDef::Item(def_id);
4041
let unused_params = self.tcx.unused_generic_params(instance);
41-
for (index, subst) in args.into_iter().enumerate() {
42+
for (index, arg) in args.into_iter().enumerate() {
4243
let index = index
4344
.try_into()
4445
.expect("more generic parameters than can fit into a `u32`");
4546
// Only recurse when generic parameters in fns, closures and coroutines
4647
// are used and have to be instantiated.
4748
//
48-
// Just in case there are closures or coroutines within this subst,
49+
// Just in case there are closures or coroutines within this arg,
4950
// recurse.
50-
if unused_params.is_used(index) && subst.has_param() {
51-
return subst.visit_with(self);
51+
if unused_params.is_used(index) && arg.has_param() {
52+
return arg.visit_with(self);
5253
}
5354
}
5455
ControlFlow::Continue(())
@@ -65,7 +66,7 @@ where
6566
}
6667
}
6768

68-
let mut vis = UsedParamsNeedSubstVisitor { tcx };
69+
let mut vis = UsedParamsNeedInstantiationVisitor { tcx };
6970
if matches!(ty.visit_with(&mut vis), ControlFlow::Break(FoundParam)) {
7071
throw_inval!(TooGeneric);
7172
} else {

0 commit comments

Comments
 (0)