Skip to content

Commit 85a1572

Browse files
Unwrap the results of type folders
1 parent 7308b76 commit 85a1572

File tree

29 files changed

+171
-150
lines changed

29 files changed

+171
-150
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
519519
indices: FxHashMap::default(),
520520
binder_index: ty::INNERMOST,
521521
};
522-
let out_value = value.fold_with(&mut canonicalizer);
522+
let out_value = value.fold_with(&mut canonicalizer).into_ok();
523523

524524
// Once we have canonicalized `out_value`, it should not
525525
// contain anything that ties it to this inference context
@@ -637,7 +637,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
637637
let infcx = self.infcx.expect("encountered ty-var without infcx");
638638
let bound_to = infcx.shallow_resolve(ty_var);
639639
if bound_to != ty_var {
640-
self.fold_ty(bound_to)
640+
self.fold_ty(bound_to).into_ok()
641641
} else {
642642
let var = self.canonical_var(info, ty_var.into());
643643
self.tcx().mk_ty(ty::Bound(self.binder_index, var.into()))
@@ -656,12 +656,12 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
656656
let infcx = self.infcx.expect("encountered const-var without infcx");
657657
let bound_to = infcx.shallow_resolve(const_var);
658658
if bound_to != const_var {
659-
self.fold_const(bound_to)
659+
self.fold_const(bound_to).into_ok()
660660
} else {
661661
let var = self.canonical_var(info, const_var.into());
662662
self.tcx().mk_const(ty::Const {
663663
val: ty::ConstKind::Bound(self.binder_index, var),
664-
ty: self.fold_ty(const_var.ty),
664+
ty: self.fold_ty(const_var.ty).into_ok(),
665665
})
666666
}
667667
}

compiler/rustc_infer/src/infer/freshen.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
7070
F: FnOnce(u32) -> ty::InferTy,
7171
{
7272
if let Some(ty) = opt_ty {
73-
return ty.fold_with(self);
73+
return ty.fold_with(self).into_ok();
7474
}
7575

7676
match self.ty_freshen_map.entry(key) {
@@ -96,7 +96,7 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
9696
F: FnOnce(u32) -> ty::InferConst<'tcx>,
9797
{
9898
if let Some(ct) = opt_ct {
99-
return ct.fold_with(self);
99+
return ct.fold_with(self).into_ok();
100100
}
101101

102102
match self.const_freshen_map.entry(key) {

compiler/rustc_infer/src/infer/fudge.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
162162
{
163163
Ok(value)
164164
} else {
165-
Ok(value.fold_with(&mut fudger))
165+
Ok(value.fold_with(&mut fudger).into_ok())
166166
}
167167
}
168168
}

compiler/rustc_infer/src/infer/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
635635
}
636636

637637
pub fn freshen<T: TypeFoldable<'tcx>>(&self, t: T) -> T {
638-
t.fold_with(&mut self.freshener())
638+
t.fold_with(&mut self.freshener()).into_ok()
639639
}
640640

641641
pub fn type_var_diverges(&'a self, ty: Ty<'_>) -> bool {
@@ -1287,7 +1287,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
12871287
where
12881288
T: TypeFoldable<'tcx>,
12891289
{
1290-
value.fold_with(&mut ShallowResolver { infcx: self })
1290+
value.fold_with(&mut ShallowResolver { infcx: self }).into_ok()
12911291
}
12921292

12931293
pub fn root_var(&self, var: ty::TyVid) -> ty::TyVid {
@@ -1308,7 +1308,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13081308
return value; // Avoid duplicated subst-folding.
13091309
}
13101310
let mut r = resolve::OpportunisticVarResolver::new(self);
1311-
value.fold_with(&mut r)
1311+
value.fold_with(&mut r).into_ok()
13121312
}
13131313

13141314
/// Returns the first unresolved variable contained in `T`. In the

compiler/rustc_infer/src/infer/resolve.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ where
177177
T: TypeFoldable<'tcx>,
178178
{
179179
let mut full_resolver = FullTypeResolver { infcx, err: None };
180-
let result = value.fold_with(&mut full_resolver);
180+
let result = value.fold_with(&mut full_resolver).into_ok();
181181
match full_resolver.err {
182182
None => Ok(result),
183183
Some(e) => Err(e),

compiler/rustc_infer/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#![cfg_attr(bootstrap, feature(or_patterns))]
2424
#![feature(in_band_lifetimes)]
2525
#![feature(control_flow_enum)]
26+
#![feature(unwrap_infallible)]
2627
#![recursion_limit = "512"] // For rustdoc
2728

2829
#[macro_use]

compiler/rustc_middle/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#![feature(associated_type_defaults)]
5252
#![feature(iter_zip)]
5353
#![feature(thread_local_const_init)]
54+
#![feature(unwrap_infallible)]
5455
#![recursion_limit = "512"]
5556

5657
#[macro_use]

compiler/rustc_middle/src/ty/erase_regions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub(super) fn provide(providers: &mut ty::query::Providers) {
99
fn erase_regions_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
1010
// N.B., use `super_fold_with` here. If we used `fold_with`, it
1111
// could invoke the `erase_regions_ty` query recursively.
12-
ty.super_fold_with(&mut RegionEraserVisitor { tcx })
12+
ty.super_fold_with(&mut RegionEraserVisitor { tcx }).into_ok()
1313
}
1414

1515
impl<'tcx> TyCtxt<'tcx> {
@@ -25,7 +25,7 @@ impl<'tcx> TyCtxt<'tcx> {
2525
return value;
2626
}
2727
debug!("erase_regions({:?})", value);
28-
let value1 = value.fold_with(&mut RegionEraserVisitor { tcx: self });
28+
let value1 = value.fold_with(&mut RegionEraserVisitor { tcx: self }).into_ok();
2929
debug!("erase_regions = {:?}", value1);
3030
value1
3131
}

compiler/rustc_middle/src/ty/fold.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ impl<'tcx> TyCtxt<'tcx> {
282282
where
283283
T: TypeFoldable<'tcx>,
284284
{
285-
value.fold_with(&mut RegionFolder::new(self, skipped_regions, &mut f))
285+
value.fold_with(&mut RegionFolder::new(self, skipped_regions, &mut f)).into_ok()
286286
}
287287

288288
/// Invoke `callback` on every region appearing free in `value`.
@@ -582,7 +582,7 @@ impl<'tcx> TyCtxt<'tcx> {
582582
value
583583
} else {
584584
let mut replacer = BoundVarReplacer::new(self, Some(&mut real_fld_r), None, None);
585-
value.fold_with(&mut replacer)
585+
value.fold_with(&mut replacer).into_ok()
586586
};
587587
(value, region_map)
588588
}
@@ -608,7 +608,7 @@ impl<'tcx> TyCtxt<'tcx> {
608608
} else {
609609
let mut replacer =
610610
BoundVarReplacer::new(self, Some(&mut fld_r), Some(&mut fld_t), Some(&mut fld_c));
611-
value.fold_with(&mut replacer)
611+
value.fold_with(&mut replacer).into_ok()
612612
}
613613
}
614614

@@ -1051,7 +1051,7 @@ where
10511051
{
10521052
debug!("shift_vars(value={:?}, amount={})", value, amount);
10531053

1054-
value.fold_with(&mut Shifter::new(tcx, amount))
1054+
value.fold_with(&mut Shifter::new(tcx, amount)).into_ok()
10551055
}
10561056

10571057
#[derive(Debug, PartialEq, Eq, Copy, Clone)]

compiler/rustc_middle/src/ty/instance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ fn polymorphize<'tcx>(
589589
// ..and polymorphize any closures/generators captured as upvars.
590590
let upvars_ty = upvars_ty.unwrap();
591591
let polymorphized_upvars_ty = upvars_ty.fold_with(
592-
&mut PolymorphizationFolder { tcx });
592+
&mut PolymorphizationFolder { tcx }).into_ok();
593593
debug!("polymorphize: polymorphized_upvars_ty={:?}", polymorphized_upvars_ty);
594594
ty::GenericArg::from(polymorphized_upvars_ty)
595595
},

compiler/rustc_middle/src/ty/normalize_erasing_regions.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ impl<'tcx> TyCtxt<'tcx> {
3535
if !value.has_projections() {
3636
value
3737
} else {
38-
value.fold_with(&mut NormalizeAfterErasingRegionsFolder { tcx: self, param_env })
38+
value
39+
.fold_with(&mut NormalizeAfterErasingRegionsFolder { tcx: self, param_env })
40+
.into_ok()
3941
}
4042
}
4143

compiler/rustc_middle/src/ty/subst.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ impl<'tcx, T: TypeFoldable<'tcx>> Subst<'tcx> for T {
431431
span: Option<Span>,
432432
) -> T {
433433
let mut folder = SubstFolder { tcx, substs, span, binders_passed: 0 };
434-
self.fold_with(&mut folder)
434+
self.fold_with(&mut folder).into_ok()
435435
}
436436
}
437437

compiler/rustc_middle/src/ty/util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -571,14 +571,14 @@ impl<'tcx> OpaqueTypeExpander<'tcx> {
571571
if self.found_recursion {
572572
return None;
573573
}
574-
let substs = substs.fold_with(self);
574+
let substs = substs.fold_with(self).into_ok();
575575
if !self.check_recursion || self.seen_opaque_tys.insert(def_id) {
576576
let expanded_ty = match self.expanded_cache.get(&(def_id, substs)) {
577577
Some(expanded_ty) => expanded_ty,
578578
None => {
579579
let generic_ty = self.tcx.type_of(def_id);
580580
let concrete_ty = generic_ty.subst(self.tcx, substs);
581-
let expanded_ty = self.fold_ty(concrete_ty);
581+
let expanded_ty = self.fold_ty(concrete_ty).into_ok();
582582
self.expanded_cache.insert((def_id, substs), expanded_ty);
583583
expanded_ty
584584
}
@@ -1073,7 +1073,7 @@ pub fn normalize_opaque_types(
10731073
check_recursion: false,
10741074
tcx,
10751075
};
1076-
val.fold_with(&mut visitor)
1076+
val.fold_with(&mut visitor).into_ok()
10771077
}
10781078

10791079
pub fn provide(providers: &mut ty::query::Providers) {

compiler/rustc_mir/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Rust MIR: a lowered representation of Rust.
3030
#![cfg_attr(bootstrap, feature(or_patterns))]
3131
#![feature(once_cell)]
3232
#![feature(control_flow_enum)]
33+
#![feature(unwrap_infallible)]
3334
#![recursion_limit = "256"]
3435

3536
#[macro_use]

compiler/rustc_mir/src/transform/validate.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ pub fn equal_up_to_regions(
9595
// Leave consts and types unchanged.
9696
ct_op: |ct| ct,
9797
ty_op: |ty| ty,
98-
}),
98+
})
99+
.into_ok(),
99100
)
100101
};
101102
tcx.infer_ctxt().enter(|infcx| infcx.can_eq(param_env, normalize(src), normalize(dest)).is_ok())

0 commit comments

Comments
 (0)