Skip to content

Commit 42eefbb

Browse files
authored
Unrolled build for #150861
Rollup merge of #150861 - folding-cleanups, r=lcnr Folding/`ReErased` cleanups Various cleanups I found while reading this code closely, mostly involving folding and the use of `ReErased`. r? @lcnr
2 parents 1377169 + e7036b1 commit 42eefbb

File tree

13 files changed

+25
-74
lines changed

13 files changed

+25
-74
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1520,7 +1520,6 @@ pub(crate) fn apply_vcall_visibility_metadata<'ll, 'tcx>(
15201520
// Unwrap potential addrspacecast
15211521
let vtable = find_vtable_behind_cast(vtable);
15221522
let trait_ref_self = trait_ref.with_self_ty(cx.tcx, ty);
1523-
let trait_ref_self = cx.tcx.erase_and_anonymize_regions(trait_ref_self);
15241523
let trait_def_id = trait_ref_self.def_id;
15251524
let trait_vis = cx.tcx.visibility(trait_def_id);
15261525

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_infer::infer::TyCtxtInferExt;
1313
use rustc_middle::mir::interpret::{CTFE_ALLOC_SALT, read_target_uint, write_target_uint};
1414
use rustc_middle::mir::{self, BinOp, ConstValue, NonDivergingIntrinsic};
1515
use rustc_middle::ty::layout::TyAndLayout;
16-
use rustc_middle::ty::{FloatTy, PolyExistentialPredicate, Ty, TyCtxt, TypeFoldable};
16+
use rustc_middle::ty::{FloatTy, PolyExistentialPredicate, Ty, TyCtxt};
1717
use rustc_middle::{bug, span_bug, ty};
1818
use rustc_span::{Symbol, sym};
1919
use rustc_trait_selection::traits::{Obligation, ObligationCause, ObligationCtxt};
@@ -243,13 +243,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
243243
ocx.register_obligations(preds.iter().map(|pred: PolyExistentialPredicate<'_>| {
244244
let pred = pred.with_self_ty(tcx, tp_ty);
245245
// Lifetimes can only be 'static because of the bound on T
246-
let pred = pred.fold_with(&mut ty::BottomUpFolder {
247-
tcx,
248-
ty_op: |ty| ty,
249-
lt_op: |lt| {
250-
if lt == tcx.lifetimes.re_erased { tcx.lifetimes.re_static } else { lt }
251-
},
252-
ct_op: |ct| ct,
246+
let pred = ty::fold_regions(tcx, pred, |r, _| {
247+
if r == tcx.lifetimes.re_erased { tcx.lifetimes.re_static } else { r }
253248
});
254249
Obligation::new(tcx, ObligationCause::dummy(), param_env, pred)
255250
}));

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -508,23 +508,18 @@ fn sanity_check_found_hidden_type<'tcx>(
508508
return Ok(());
509509
}
510510
}
511-
let strip_vars = |ty: Ty<'tcx>| {
512-
ty.fold_with(&mut BottomUpFolder {
513-
tcx,
514-
ty_op: |t| t,
515-
ct_op: |c| c,
516-
lt_op: |l| match l.kind() {
517-
RegionKind::ReVar(_) => tcx.lifetimes.re_erased,
518-
_ => l,
519-
},
511+
let erase_re_vars = |ty: Ty<'tcx>| {
512+
fold_regions(tcx, ty, |r, _| match r.kind() {
513+
RegionKind::ReVar(_) => tcx.lifetimes.re_erased,
514+
_ => r,
520515
})
521516
};
522517
// Closures frequently end up containing erased lifetimes in their final representation.
523518
// These correspond to lifetime variables that never got resolved, so we patch this up here.
524-
ty.ty = strip_vars(ty.ty);
519+
ty.ty = erase_re_vars(ty.ty);
525520
// Get the hidden type.
526521
let hidden_ty = tcx.type_of(key.def_id).instantiate(tcx, key.args);
527-
let hidden_ty = strip_vars(hidden_ty);
522+
let hidden_ty = erase_re_vars(hidden_ty);
528523

529524
// If the hidden types differ, emit a type mismatch diagnostic.
530525
if hidden_ty == ty.ty {

compiler/rustc_next_trait_solver/src/delegate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {
8686

8787
fn is_transmutable(
8888
&self,
89-
dst: <Self::Interner as Interner>::Ty,
9089
src: <Self::Interner as Interner>::Ty,
90+
dst: <Self::Interner as Interner>::Ty,
9191
assume: <Self::Interner as Interner>::Const,
9292
) -> Result<Certainty, NoSolution>;
9393
}

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,8 +1170,8 @@ where
11701170

11711171
pub(super) fn is_transmutable(
11721172
&mut self,
1173-
dst: I::Ty,
11741173
src: I::Ty,
1174+
dst: I::Ty,
11751175
assume: I::Const,
11761176
) -> Result<Certainty, NoSolution> {
11771177
self.delegate.is_transmutable(dst, src, assume)

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2781,11 +2781,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
27812781
self.tcx.instantiate_bound_regions_with_erased(trait_pred),
27822782
);
27832783

2784-
let src_and_dst = rustc_transmute::Types {
2785-
dst: trait_pred.trait_ref.args.type_at(0),
2786-
src: trait_pred.trait_ref.args.type_at(1),
2787-
};
2788-
27892784
let ocx = ObligationCtxt::new(self);
27902785
let Ok(assume) = ocx.structurally_normalize_const(
27912786
&obligation.cause,
@@ -2812,7 +2807,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
28122807
let err_msg = format!("`{src}` cannot be safely transmuted into `{dst}`");
28132808

28142809
match rustc_transmute::TransmuteTypeEnv::new(self.infcx.tcx)
2815-
.is_transmutable(src_and_dst, assume)
2810+
.is_transmutable(src, dst, assume)
28162811
{
28172812
Answer::No(reason) => {
28182813
let safe_transmute_explanation = match reason {

compiler/rustc_trait_selection/src/solve/delegate.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<
294294
// register candidates. We probably need to register >1 since we may have an OR of ANDs.
295295
fn is_transmutable(
296296
&self,
297-
dst: Ty<'tcx>,
298297
src: Ty<'tcx>,
298+
dst: Ty<'tcx>,
299299
assume: ty::Const<'tcx>,
300300
) -> Result<Certainty, NoSolution> {
301301
// Erase regions because we compute layouts in `rustc_transmute`,
@@ -307,9 +307,7 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<
307307
};
308308

309309
// FIXME(transmutability): This really should be returning nested goals for `Answer::If*`
310-
match rustc_transmute::TransmuteTypeEnv::new(self.0.tcx)
311-
.is_transmutable(rustc_transmute::Types { src, dst }, assume)
312-
{
310+
match rustc_transmute::TransmuteTypeEnv::new(self.0.tcx).is_transmutable(src, dst, assume) {
313311
rustc_transmute::Answer::Yes => Ok(Certainty::Yes),
314312
rustc_transmute::Answer::No(_) | rustc_transmute::Answer::If(_) => Err(NoSolution),
315313
}

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
365365

366366
debug!(?src, ?dst);
367367
let mut transmute_env = rustc_transmute::TransmuteTypeEnv::new(self.infcx.tcx);
368-
let maybe_transmutable =
369-
transmute_env.is_transmutable(rustc_transmute::Types { dst, src }, assume);
368+
let maybe_transmutable = transmute_env.is_transmutable(src, dst, assume);
370369

371370
let fully_flattened = match maybe_transmutable {
372371
Answer::No(_) => Err(SelectionError::Unimplemented)?,

compiler/rustc_transmute/src/lib.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,6 @@ mod rustc {
9393

9494
use super::*;
9595

96-
/// The source and destination types of a transmutation.
97-
#[derive(Debug, Clone, Copy)]
98-
pub struct Types<'tcx> {
99-
/// The source type.
100-
pub src: Ty<'tcx>,
101-
/// The destination type.
102-
pub dst: Ty<'tcx>,
103-
}
104-
10596
pub struct TransmuteTypeEnv<'tcx> {
10697
tcx: TyCtxt<'tcx>,
10798
}
@@ -113,13 +104,12 @@ mod rustc {
113104

114105
pub fn is_transmutable(
115106
&mut self,
116-
types: Types<'tcx>,
107+
src: Ty<'tcx>,
108+
dst: Ty<'tcx>,
117109
assume: crate::Assume,
118110
) -> crate::Answer<Region<'tcx>, Ty<'tcx>> {
119-
crate::maybe_transmutable::MaybeTransmutableQuery::new(
120-
types.src, types.dst, assume, self.tcx,
121-
)
122-
.answer()
111+
crate::maybe_transmutable::MaybeTransmutableQuery::new(src, dst, assume, self.tcx)
112+
.answer()
123113
}
124114
}
125115

compiler/rustc_ty_utils/src/instance.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,6 @@ fn resolve_associated_item<'tcx>(
222222
return Err(guar);
223223
}
224224

225-
let args = tcx.erase_and_anonymize_regions(args);
226-
227225
// We check that the impl item is compatible with the trait item
228226
// because otherwise we may ICE in const eval due to type mismatches,
229227
// signature incompatibilities, etc.

0 commit comments

Comments
 (0)