Skip to content

Commit 48de123

Browse files
committed
Auto merge of #101857 - lcnr:make-dyn-again, r=jackh726
change `FnMutDelegate` to trait objects cc #100016 as mentioned in the last t-compiler meeting r? `@jackh726`
2 parents 672831a + 5669ce1 commit 48de123

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
lines changed

compiler/rustc_infer/src/infer/canonical/substitute.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,16 @@ where
7272
value
7373
} else {
7474
let delegate = FnMutDelegate {
75-
regions: |br: ty::BoundRegion| match var_values.var_values[br.var].unpack() {
75+
regions: &mut |br: ty::BoundRegion| match var_values.var_values[br.var].unpack() {
7676
GenericArgKind::Lifetime(l) => l,
7777
r => bug!("{:?} is a region but value is {:?}", br, r),
7878
},
79-
types: |bound_ty: ty::BoundTy| match var_values.var_values[bound_ty.var].unpack() {
79+
types: &mut |bound_ty: ty::BoundTy| match var_values.var_values[bound_ty.var].unpack() {
8080
GenericArgKind::Type(ty) => ty,
8181
r => bug!("{:?} is a type but value is {:?}", bound_ty, r),
8282
},
83-
consts: |bound_ct: ty::BoundVar, _| match var_values.var_values[bound_ct].unpack() {
83+
consts: &mut |bound_ct: ty::BoundVar, _| match var_values.var_values[bound_ct].unpack()
84+
{
8485
GenericArgKind::Const(ct) => ct,
8586
c => bug!("{:?} is a const but value is {:?}", bound_ct, c),
8687
},

compiler/rustc_infer/src/infer/higher_ranked/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,19 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
8181
let next_universe = self.create_next_universe();
8282

8383
let delegate = FnMutDelegate {
84-
regions: |br: ty::BoundRegion| {
84+
regions: &mut |br: ty::BoundRegion| {
8585
self.tcx.mk_region(ty::RePlaceholder(ty::PlaceholderRegion {
8686
universe: next_universe,
8787
name: br.kind,
8888
}))
8989
},
90-
types: |bound_ty: ty::BoundTy| {
90+
types: &mut |bound_ty: ty::BoundTy| {
9191
self.tcx.mk_ty(ty::Placeholder(ty::PlaceholderType {
9292
universe: next_universe,
9393
name: bound_ty.var,
9494
}))
9595
},
96-
consts: |bound_var: ty::BoundVar, ty| {
96+
consts: &mut |bound_var: ty::BoundVar, ty| {
9797
self.tcx.mk_const(ty::ConstS {
9898
kind: ty::ConstKind::Placeholder(ty::PlaceholderConst {
9999
universe: next_universe,

compiler/rustc_middle/src/ty/fold.rs

+13-17
Original file line numberDiff line numberDiff line change
@@ -388,17 +388,13 @@ pub trait BoundVarReplacerDelegate<'tcx> {
388388
fn replace_const(&mut self, bv: ty::BoundVar, ty: Ty<'tcx>) -> ty::Const<'tcx>;
389389
}
390390

391-
pub struct FnMutDelegate<R, T, C> {
392-
pub regions: R,
393-
pub types: T,
394-
pub consts: C,
391+
pub struct FnMutDelegate<'a, 'tcx> {
392+
pub regions: &'a mut (dyn FnMut(ty::BoundRegion) -> ty::Region<'tcx> + 'a),
393+
pub types: &'a mut (dyn FnMut(ty::BoundTy) -> Ty<'tcx> + 'a),
394+
pub consts: &'a mut (dyn FnMut(ty::BoundVar, Ty<'tcx>) -> ty::Const<'tcx> + 'a),
395395
}
396-
impl<'tcx, R, T, C> BoundVarReplacerDelegate<'tcx> for FnMutDelegate<R, T, C>
397-
where
398-
R: FnMut(ty::BoundRegion) -> ty::Region<'tcx>,
399-
T: FnMut(ty::BoundTy) -> Ty<'tcx>,
400-
C: FnMut(ty::BoundVar, Ty<'tcx>) -> ty::Const<'tcx>,
401-
{
396+
397+
impl<'a, 'tcx> BoundVarReplacerDelegate<'tcx> for FnMutDelegate<'a, 'tcx> {
402398
fn replace_region(&mut self, br: ty::BoundRegion) -> ty::Region<'tcx> {
403399
(self.regions)(br)
404400
}
@@ -522,7 +518,7 @@ impl<'tcx> TyCtxt<'tcx> {
522518
pub fn replace_late_bound_regions_uncached<T, F>(
523519
self,
524520
value: Binder<'tcx, T>,
525-
replace_regions: F,
521+
mut replace_regions: F,
526522
) -> T
527523
where
528524
F: FnMut(ty::BoundRegion) -> ty::Region<'tcx>,
@@ -533,9 +529,9 @@ impl<'tcx> TyCtxt<'tcx> {
533529
value
534530
} else {
535531
let delegate = FnMutDelegate {
536-
regions: replace_regions,
537-
types: |b| bug!("unexpected bound ty in binder: {b:?}"),
538-
consts: |b, ty| bug!("unexpected bound ct in binder: {b:?} {ty}"),
532+
regions: &mut replace_regions,
533+
types: &mut |b| bug!("unexpected bound ty in binder: {b:?}"),
534+
consts: &mut |b, ty| bug!("unexpected bound ct in binder: {b:?} {ty}"),
539535
};
540536
let mut replacer = BoundVarReplacer::new(self, delegate);
541537
value.fold_with(&mut replacer)
@@ -595,19 +591,19 @@ impl<'tcx> TyCtxt<'tcx> {
595591
self.replace_escaping_bound_vars_uncached(
596592
value,
597593
FnMutDelegate {
598-
regions: |r: ty::BoundRegion| {
594+
regions: &mut |r: ty::BoundRegion| {
599595
self.mk_region(ty::ReLateBound(
600596
ty::INNERMOST,
601597
ty::BoundRegion { var: shift_bv(r.var), kind: r.kind },
602598
))
603599
},
604-
types: |t: ty::BoundTy| {
600+
types: &mut |t: ty::BoundTy| {
605601
self.mk_ty(ty::Bound(
606602
ty::INNERMOST,
607603
ty::BoundTy { var: shift_bv(t.var), kind: t.kind },
608604
))
609605
},
610-
consts: |c, ty: Ty<'tcx>| {
606+
consts: &mut |c, ty: Ty<'tcx>| {
611607
self.mk_const(ty::ConstS {
612608
kind: ty::ConstKind::Bound(ty::INNERMOST, shift_bv(c)),
613609
ty,

0 commit comments

Comments
 (0)