Unwrap the results of type folders
Co-authored-by: Alan Egerton <eggyal@gmail.com>
This commit is contained in:
parent
6dc3dae46f
commit
30bf20a692
34 changed files with 191 additions and 167 deletions
|
@ -23,6 +23,7 @@ Rust MIR: a lowered representation of Rust.
|
|||
#![feature(trusted_len)]
|
||||
#![feature(trusted_step)]
|
||||
#![feature(try_blocks)]
|
||||
#![feature(unwrap_infallible)]
|
||||
#![recursion_limit = "256"]
|
||||
|
||||
#[macro_use]
|
||||
|
|
|
@ -95,7 +95,8 @@ pub fn equal_up_to_regions(
|
|||
// Leave consts and types unchanged.
|
||||
ct_op: |ct| ct,
|
||||
ty_op: |ty| ty,
|
||||
}),
|
||||
})
|
||||
.into_ok(),
|
||||
)
|
||||
};
|
||||
tcx.infer_ctxt().enter(|infcx| infcx.can_eq(param_env, normalize(src), normalize(dest)).is_ok())
|
||||
|
|
|
@ -503,7 +503,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
|
|||
indices: FxHashMap::default(),
|
||||
binder_index: ty::INNERMOST,
|
||||
};
|
||||
let out_value = value.fold_with(&mut canonicalizer);
|
||||
let out_value = value.fold_with(&mut canonicalizer).into_ok();
|
||||
|
||||
// Once we have canonicalized `out_value`, it should not
|
||||
// contain anything that ties it to this inference context
|
||||
|
@ -621,7 +621,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
|
|||
let infcx = self.infcx;
|
||||
let bound_to = infcx.shallow_resolve(ty_var);
|
||||
if bound_to != ty_var {
|
||||
self.fold_ty(bound_to)
|
||||
self.fold_ty(bound_to).into_ok()
|
||||
} else {
|
||||
let var = self.canonical_var(info, ty_var.into());
|
||||
self.tcx().mk_ty(ty::Bound(self.binder_index, var.into()))
|
||||
|
@ -640,12 +640,12 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
|
|||
let infcx = self.infcx;
|
||||
let bound_to = infcx.shallow_resolve(const_var);
|
||||
if bound_to != const_var {
|
||||
self.fold_const(bound_to)
|
||||
self.fold_const(bound_to).into_ok()
|
||||
} else {
|
||||
let var = self.canonical_var(info, const_var.into());
|
||||
self.tcx().mk_const(ty::Const {
|
||||
val: ty::ConstKind::Bound(self.binder_index, var),
|
||||
ty: self.fold_ty(const_var.ty),
|
||||
ty: self.fold_ty(const_var.ty).into_ok(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
|
|||
F: FnOnce(u32) -> ty::InferTy,
|
||||
{
|
||||
if let Some(ty) = opt_ty {
|
||||
return ty.fold_with(self);
|
||||
return ty.fold_with(self).into_ok();
|
||||
}
|
||||
|
||||
match self.ty_freshen_map.entry(key) {
|
||||
|
@ -98,7 +98,7 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
|
|||
F: FnOnce(u32) -> ty::InferConst<'tcx>,
|
||||
{
|
||||
if let Some(ct) = opt_ct {
|
||||
return ct.fold_with(self);
|
||||
return ct.fold_with(self).into_ok();
|
||||
}
|
||||
|
||||
match self.const_freshen_map.entry(key) {
|
||||
|
|
|
@ -161,7 +161,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
{
|
||||
Ok(value)
|
||||
} else {
|
||||
Ok(value.fold_with(&mut fudger))
|
||||
Ok(value.fold_with(&mut fudger).into_ok())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -681,7 +681,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
}
|
||||
|
||||
pub fn freshen<T: TypeFoldable<'tcx>>(&self, t: T) -> T {
|
||||
t.fold_with(&mut self.freshener())
|
||||
t.fold_with(&mut self.freshener()).into_ok()
|
||||
}
|
||||
|
||||
/// Returns the origin of the type variable identified by `vid`, or `None`
|
||||
|
@ -1381,7 +1381,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
value.fold_with(&mut ShallowResolver { infcx: self })
|
||||
value.fold_with(&mut ShallowResolver { infcx: self }).into_ok()
|
||||
}
|
||||
|
||||
pub fn root_var(&self, var: ty::TyVid) -> ty::TyVid {
|
||||
|
@ -1402,7 +1402,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
return value; // Avoid duplicated subst-folding.
|
||||
}
|
||||
let mut r = resolve::OpportunisticVarResolver::new(self);
|
||||
value.fold_with(&mut r)
|
||||
value.fold_with(&mut r).into_ok()
|
||||
}
|
||||
|
||||
/// Returns the first unresolved variable contained in `T`. In the
|
||||
|
|
|
@ -418,92 +418,94 @@ struct Instantiator<'a, 'tcx> {
|
|||
impl<'a, 'tcx> Instantiator<'a, 'tcx> {
|
||||
fn instantiate_opaque_types_in_map<T: TypeFoldable<'tcx>>(&mut self, value: T) -> T {
|
||||
let tcx = self.infcx.tcx;
|
||||
value.fold_with(&mut BottomUpFolder {
|
||||
tcx,
|
||||
ty_op: |ty| {
|
||||
if ty.references_error() {
|
||||
return tcx.ty_error();
|
||||
} else if let ty::Opaque(def_id, substs) = ty.kind() {
|
||||
// Check that this is `impl Trait` type is
|
||||
// declared by `parent_def_id` -- i.e., one whose
|
||||
// value we are inferring. At present, this is
|
||||
// always true during the first phase of
|
||||
// type-check, but not always true later on during
|
||||
// NLL. Once we support named opaque types more fully,
|
||||
// this same scenario will be able to arise during all phases.
|
||||
//
|
||||
// Here is an example using type alias `impl Trait`
|
||||
// that indicates the distinction we are checking for:
|
||||
//
|
||||
// ```rust
|
||||
// mod a {
|
||||
// pub type Foo = impl Iterator;
|
||||
// pub fn make_foo() -> Foo { .. }
|
||||
// }
|
||||
//
|
||||
// mod b {
|
||||
// fn foo() -> a::Foo { a::make_foo() }
|
||||
// }
|
||||
// ```
|
||||
//
|
||||
// Here, the return type of `foo` references an
|
||||
// `Opaque` indeed, but not one whose value is
|
||||
// presently being inferred. You can get into a
|
||||
// similar situation with closure return types
|
||||
// today:
|
||||
//
|
||||
// ```rust
|
||||
// fn foo() -> impl Iterator { .. }
|
||||
// fn bar() {
|
||||
// let x = || foo(); // returns the Opaque assoc with `foo`
|
||||
// }
|
||||
// ```
|
||||
if let Some(def_id) = def_id.as_local() {
|
||||
let opaque_hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
|
||||
let parent_def_id = self.infcx.defining_use_anchor;
|
||||
let def_scope_default = || {
|
||||
let opaque_parent_hir_id = tcx.hir().get_parent_item(opaque_hir_id);
|
||||
parent_def_id == tcx.hir().local_def_id(opaque_parent_hir_id)
|
||||
};
|
||||
let (in_definition_scope, origin) =
|
||||
match tcx.hir().expect_item(opaque_hir_id).kind {
|
||||
// Anonymous `impl Trait`
|
||||
hir::ItemKind::OpaqueTy(hir::OpaqueTy {
|
||||
impl_trait_fn: Some(parent),
|
||||
origin,
|
||||
..
|
||||
}) => (parent == parent_def_id.to_def_id(), origin),
|
||||
// Named `type Foo = impl Bar;`
|
||||
hir::ItemKind::OpaqueTy(hir::OpaqueTy {
|
||||
impl_trait_fn: None,
|
||||
origin,
|
||||
..
|
||||
}) => (
|
||||
may_define_opaque_type(tcx, parent_def_id, opaque_hir_id),
|
||||
origin,
|
||||
),
|
||||
_ => (def_scope_default(), hir::OpaqueTyOrigin::TyAlias),
|
||||
value
|
||||
.fold_with(&mut BottomUpFolder {
|
||||
tcx,
|
||||
ty_op: |ty| {
|
||||
if ty.references_error() {
|
||||
return tcx.ty_error();
|
||||
} else if let ty::Opaque(def_id, substs) = ty.kind() {
|
||||
// Check that this is `impl Trait` type is
|
||||
// declared by `parent_def_id` -- i.e., one whose
|
||||
// value we are inferring. At present, this is
|
||||
// always true during the first phase of
|
||||
// type-check, but not always true later on during
|
||||
// NLL. Once we support named opaque types more fully,
|
||||
// this same scenario will be able to arise during all phases.
|
||||
//
|
||||
// Here is an example using type alias `impl Trait`
|
||||
// that indicates the distinction we are checking for:
|
||||
//
|
||||
// ```rust
|
||||
// mod a {
|
||||
// pub type Foo = impl Iterator;
|
||||
// pub fn make_foo() -> Foo { .. }
|
||||
// }
|
||||
//
|
||||
// mod b {
|
||||
// fn foo() -> a::Foo { a::make_foo() }
|
||||
// }
|
||||
// ```
|
||||
//
|
||||
// Here, the return type of `foo` references an
|
||||
// `Opaque` indeed, but not one whose value is
|
||||
// presently being inferred. You can get into a
|
||||
// similar situation with closure return types
|
||||
// today:
|
||||
//
|
||||
// ```rust
|
||||
// fn foo() -> impl Iterator { .. }
|
||||
// fn bar() {
|
||||
// let x = || foo(); // returns the Opaque assoc with `foo`
|
||||
// }
|
||||
// ```
|
||||
if let Some(def_id) = def_id.as_local() {
|
||||
let opaque_hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
|
||||
let parent_def_id = self.infcx.defining_use_anchor;
|
||||
let def_scope_default = || {
|
||||
let opaque_parent_hir_id = tcx.hir().get_parent_item(opaque_hir_id);
|
||||
parent_def_id == tcx.hir().local_def_id(opaque_parent_hir_id)
|
||||
};
|
||||
if in_definition_scope {
|
||||
let opaque_type_key =
|
||||
OpaqueTypeKey { def_id: def_id.to_def_id(), substs };
|
||||
return self.fold_opaque_ty(ty, opaque_type_key, origin);
|
||||
}
|
||||
let (in_definition_scope, origin) =
|
||||
match tcx.hir().expect_item(opaque_hir_id).kind {
|
||||
// Anonymous `impl Trait`
|
||||
hir::ItemKind::OpaqueTy(hir::OpaqueTy {
|
||||
impl_trait_fn: Some(parent),
|
||||
origin,
|
||||
..
|
||||
}) => (parent == parent_def_id.to_def_id(), origin),
|
||||
// Named `type Foo = impl Bar;`
|
||||
hir::ItemKind::OpaqueTy(hir::OpaqueTy {
|
||||
impl_trait_fn: None,
|
||||
origin,
|
||||
..
|
||||
}) => (
|
||||
may_define_opaque_type(tcx, parent_def_id, opaque_hir_id),
|
||||
origin,
|
||||
),
|
||||
_ => (def_scope_default(), hir::OpaqueTyOrigin::TyAlias),
|
||||
};
|
||||
if in_definition_scope {
|
||||
let opaque_type_key =
|
||||
OpaqueTypeKey { def_id: def_id.to_def_id(), substs };
|
||||
return self.fold_opaque_ty(ty, opaque_type_key, origin);
|
||||
}
|
||||
|
||||
debug!(
|
||||
"instantiate_opaque_types_in_map: \
|
||||
debug!(
|
||||
"instantiate_opaque_types_in_map: \
|
||||
encountered opaque outside its definition scope \
|
||||
def_id={:?}",
|
||||
def_id,
|
||||
);
|
||||
def_id,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ty
|
||||
},
|
||||
lt_op: |lt| lt,
|
||||
ct_op: |ct| ct,
|
||||
})
|
||||
ty
|
||||
},
|
||||
lt_op: |lt| lt,
|
||||
ct_op: |ct| ct,
|
||||
})
|
||||
.into_ok()
|
||||
}
|
||||
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
|
@ -556,21 +558,23 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
|
|||
debug!(?predicate);
|
||||
|
||||
// We can't normalize associated types from `rustc_infer`, but we can eagerly register inference variables for them.
|
||||
let predicate = predicate.fold_with(&mut BottomUpFolder {
|
||||
tcx,
|
||||
ty_op: |ty| match ty.kind() {
|
||||
ty::Projection(projection_ty) => infcx.infer_projection(
|
||||
self.param_env,
|
||||
*projection_ty,
|
||||
traits::ObligationCause::misc(self.value_span, self.body_id),
|
||||
0,
|
||||
&mut self.obligations,
|
||||
),
|
||||
_ => ty,
|
||||
},
|
||||
lt_op: |lt| lt,
|
||||
ct_op: |ct| ct,
|
||||
});
|
||||
let predicate = predicate
|
||||
.fold_with(&mut BottomUpFolder {
|
||||
tcx,
|
||||
ty_op: |ty| match ty.kind() {
|
||||
ty::Projection(projection_ty) => infcx.infer_projection(
|
||||
self.param_env,
|
||||
*projection_ty,
|
||||
traits::ObligationCause::misc(self.value_span, self.body_id),
|
||||
0,
|
||||
&mut self.obligations,
|
||||
),
|
||||
_ => ty,
|
||||
},
|
||||
lt_op: |lt| lt,
|
||||
ct_op: |ct| ct,
|
||||
})
|
||||
.into_ok();
|
||||
debug!(?predicate);
|
||||
|
||||
if let ty::PredicateKind::Projection(projection) = predicate.kind().skip_binder() {
|
||||
|
|
|
@ -182,7 +182,7 @@ where
|
|||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
let mut full_resolver = FullTypeResolver { infcx, err: None };
|
||||
let result = value.fold_with(&mut full_resolver);
|
||||
let result = value.fold_with(&mut full_resolver).into_ok();
|
||||
match full_resolver.err {
|
||||
None => Ok(result),
|
||||
Some(e) => Err(e),
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#![feature(control_flow_enum)]
|
||||
#![feature(min_specialization)]
|
||||
#![feature(label_break_value)]
|
||||
#![feature(unwrap_infallible)]
|
||||
#![recursion_limit = "512"] // For rustdoc
|
||||
|
||||
#[macro_use]
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
#![feature(try_blocks)]
|
||||
#![feature(try_reserve_kind)]
|
||||
#![feature(nonzero_ops)]
|
||||
#![feature(unwrap_infallible)]
|
||||
#![recursion_limit = "512"]
|
||||
|
||||
#[macro_use]
|
||||
|
|
|
@ -9,7 +9,7 @@ pub(super) fn provide(providers: &mut ty::query::Providers) {
|
|||
fn erase_regions_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||
// N.B., use `super_fold_with` here. If we used `fold_with`, it
|
||||
// could invoke the `erase_regions_ty` query recursively.
|
||||
ty.super_fold_with(&mut RegionEraserVisitor { tcx })
|
||||
ty.super_fold_with(&mut RegionEraserVisitor { tcx }).into_ok()
|
||||
}
|
||||
|
||||
impl<'tcx> TyCtxt<'tcx> {
|
||||
|
@ -27,7 +27,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
return value;
|
||||
}
|
||||
debug!("erase_regions({:?})", value);
|
||||
let value1 = value.fold_with(&mut RegionEraserVisitor { tcx: self });
|
||||
let value1 = value.fold_with(&mut RegionEraserVisitor { tcx: self }).into_ok();
|
||||
debug!("erase_regions = {:?}", value1);
|
||||
value1
|
||||
}
|
||||
|
|
|
@ -336,7 +336,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
value.fold_with(&mut RegionFolder::new(self, skipped_regions, &mut f))
|
||||
value.fold_with(&mut RegionFolder::new(self, skipped_regions, &mut f)).into_ok()
|
||||
}
|
||||
|
||||
/// Invoke `callback` on every region appearing free in `value`.
|
||||
|
@ -638,7 +638,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
value
|
||||
} else {
|
||||
let mut replacer = BoundVarReplacer::new(self, Some(&mut real_fld_r), None, None);
|
||||
value.fold_with(&mut replacer)
|
||||
value.fold_with(&mut replacer).into_ok()
|
||||
};
|
||||
(value, region_map)
|
||||
}
|
||||
|
@ -664,7 +664,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
} else {
|
||||
let mut replacer =
|
||||
BoundVarReplacer::new(self, Some(&mut fld_r), Some(&mut fld_t), Some(&mut fld_c));
|
||||
value.fold_with(&mut replacer)
|
||||
value.fold_with(&mut replacer).into_ok()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1030,7 +1030,7 @@ where
|
|||
{
|
||||
debug!("shift_vars(value={:?}, amount={})", value, amount);
|
||||
|
||||
value.fold_with(&mut Shifter::new(tcx, amount))
|
||||
value.fold_with(&mut Shifter::new(tcx, amount)).into_ok()
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||
|
@ -1293,7 +1293,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
///
|
||||
/// FIXME(@lcnr): explain this function a bit more
|
||||
pub fn expose_default_const_substs<T: TypeFoldable<'tcx>>(self, v: T) -> T {
|
||||
v.fold_with(&mut ExposeDefaultConstSubstsFolder { tcx: self })
|
||||
v.fold_with(&mut ExposeDefaultConstSubstsFolder { tcx: self }).into_ok()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -669,7 +669,7 @@ fn polymorphize<'tcx>(
|
|||
// ..and polymorphize any closures/generators captured as upvars.
|
||||
let upvars_ty = upvars_ty.unwrap();
|
||||
let polymorphized_upvars_ty = upvars_ty.fold_with(
|
||||
&mut PolymorphizationFolder { tcx });
|
||||
&mut PolymorphizationFolder { tcx }).into_ok();
|
||||
debug!("polymorphize: polymorphized_upvars_ty={:?}", polymorphized_upvars_ty);
|
||||
ty::GenericArg::from(polymorphized_upvars_ty)
|
||||
},
|
||||
|
|
|
@ -35,7 +35,9 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
if !value.has_projections() {
|
||||
value
|
||||
} else {
|
||||
value.fold_with(&mut NormalizeAfterErasingRegionsFolder { tcx: self, param_env })
|
||||
value
|
||||
.fold_with(&mut NormalizeAfterErasingRegionsFolder { tcx: self, param_env })
|
||||
.into_ok()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2193,7 +2193,7 @@ impl<F: fmt::Write> FmtPrinter<'_, 'tcx, F> {
|
|||
name: &mut name,
|
||||
region_map: BTreeMap::new(),
|
||||
};
|
||||
let new_value = value.clone().skip_binder().fold_with(&mut folder);
|
||||
let new_value = value.clone().skip_binder().fold_with(&mut folder).into_ok();
|
||||
let region_map = folder.region_map;
|
||||
start_or_continue(&mut self, "", "> ");
|
||||
(new_value, region_map)
|
||||
|
|
|
@ -439,7 +439,7 @@ impl<'tcx, T: TypeFoldable<'tcx>> Subst<'tcx> for T {
|
|||
span: Option<Span>,
|
||||
) -> T {
|
||||
let mut folder = SubstFolder { tcx, substs, span, binders_passed: 0 };
|
||||
self.fold_with(&mut folder)
|
||||
self.fold_with(&mut folder).into_ok()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -574,14 +574,14 @@ impl<'tcx> OpaqueTypeExpander<'tcx> {
|
|||
if self.found_any_recursion {
|
||||
return None;
|
||||
}
|
||||
let substs = substs.fold_with(self);
|
||||
let substs = substs.fold_with(self).into_ok();
|
||||
if !self.check_recursion || self.seen_opaque_tys.insert(def_id) {
|
||||
let expanded_ty = match self.expanded_cache.get(&(def_id, substs)) {
|
||||
Some(expanded_ty) => expanded_ty,
|
||||
None => {
|
||||
let generic_ty = self.tcx.type_of(def_id);
|
||||
let concrete_ty = generic_ty.subst(self.tcx, substs);
|
||||
let expanded_ty = self.fold_ty(concrete_ty);
|
||||
let expanded_ty = self.fold_ty(concrete_ty).into_ok();
|
||||
self.expanded_cache.insert((def_id, substs), expanded_ty);
|
||||
expanded_ty
|
||||
}
|
||||
|
@ -1092,7 +1092,7 @@ pub fn normalize_opaque_types(
|
|||
check_recursion: false,
|
||||
tcx,
|
||||
};
|
||||
val.fold_with(&mut visitor)
|
||||
val.fold_with(&mut visitor).into_ok()
|
||||
}
|
||||
|
||||
pub fn provide(providers: &mut ty::query::Providers) {
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#![feature(never_type)]
|
||||
#![feature(crate_visibility_modifier)]
|
||||
#![feature(control_flow_enum)]
|
||||
#![feature(unwrap_infallible)]
|
||||
#![recursion_limit = "512"] // For rustdoc
|
||||
|
||||
#[macro_use]
|
||||
|
|
|
@ -65,14 +65,16 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
// Convert the type from the function into a type valid outside
|
||||
// the function, by replacing invalid regions with 'static,
|
||||
// after producing an error for each of them.
|
||||
let definition_ty = instantiated_ty.fold_with(&mut ReverseMapper::new(
|
||||
self.tcx,
|
||||
self.is_tainted_by_errors(),
|
||||
def_id,
|
||||
map,
|
||||
instantiated_ty,
|
||||
span,
|
||||
));
|
||||
let definition_ty = instantiated_ty
|
||||
.fold_with(&mut ReverseMapper::new(
|
||||
self.tcx,
|
||||
self.is_tainted_by_errors(),
|
||||
def_id,
|
||||
map,
|
||||
instantiated_ty,
|
||||
span,
|
||||
))
|
||||
.into_ok();
|
||||
debug!(?definition_ty);
|
||||
|
||||
definition_ty
|
||||
|
@ -123,14 +125,14 @@ impl ReverseMapper<'tcx> {
|
|||
) -> GenericArg<'tcx> {
|
||||
assert!(!self.map_missing_regions_to_empty);
|
||||
self.map_missing_regions_to_empty = true;
|
||||
let kind = kind.fold_with(self);
|
||||
let kind = kind.fold_with(self).into_ok();
|
||||
self.map_missing_regions_to_empty = false;
|
||||
kind
|
||||
}
|
||||
|
||||
fn fold_kind_normally(&mut self, kind: GenericArg<'tcx>) -> GenericArg<'tcx> {
|
||||
assert!(!self.map_missing_regions_to_empty);
|
||||
kind.fold_with(self)
|
||||
kind.fold_with(self).into_ok()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1916,8 +1916,9 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
self.probe(|_| {
|
||||
let mut selcx = SelectionContext::new(self);
|
||||
|
||||
let cleaned_pred =
|
||||
pred.fold_with(&mut ParamToVarFolder { infcx: self, var_map: Default::default() });
|
||||
let cleaned_pred = pred
|
||||
.fold_with(&mut ParamToVarFolder { infcx: self, var_map: Default::default() })
|
||||
.into_ok();
|
||||
|
||||
let cleaned_pred = super::project::normalize(
|
||||
&mut selcx,
|
||||
|
|
|
@ -339,7 +339,7 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
|
|||
if !needs_normalization(&value, self.param_env.reveal()) {
|
||||
value
|
||||
} else {
|
||||
value.fold_with(self)
|
||||
value.fold_with(self).into_ok()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -555,7 +555,7 @@ impl<'me, 'tcx> BoundVarReplacer<'me, 'tcx> {
|
|||
universe_indices,
|
||||
};
|
||||
|
||||
let value = value.super_fold_with(&mut replacer);
|
||||
let value = value.super_fold_with(&mut replacer).into_ok();
|
||||
|
||||
(value, replacer.mapped_regions, replacer.mapped_types, replacer.mapped_consts)
|
||||
}
|
||||
|
@ -681,7 +681,7 @@ impl<'me, 'tcx> PlaceholderReplacer<'me, 'tcx> {
|
|||
universe_indices,
|
||||
current_index: ty::INNERMOST,
|
||||
};
|
||||
value.super_fold_with(&mut replacer)
|
||||
value.super_fold_with(&mut replacer).into_ok()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1546,7 +1546,8 @@ fn confirm_candidate<'cx, 'tcx>(
|
|||
// when possible for this to work. See `auto-trait-projection-recursion.rs`
|
||||
// for a case where this matters.
|
||||
if progress.ty.has_infer_regions() {
|
||||
progress.ty = OpportunisticRegionResolver::new(selcx.infcx()).fold_ty(progress.ty);
|
||||
progress.ty =
|
||||
OpportunisticRegionResolver::new(selcx.infcx()).fold_ty(progress.ty).into_ok();
|
||||
}
|
||||
progress
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> {
|
|||
normalizer.universes.extend((0..max_visitor.escaping).map(|_| None));
|
||||
}
|
||||
}
|
||||
let result = value.fold_with(&mut normalizer);
|
||||
let result = value.fold_with(&mut normalizer).into_ok();
|
||||
info!(
|
||||
"normalize::<{}>: result={:?} with {} obligations",
|
||||
std::any::type_name::<T>(),
|
||||
|
|
|
@ -2222,6 +2222,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
.predicate
|
||||
.to_poly_trait_ref()
|
||||
.fold_with(&mut self.freshener)
|
||||
.into_ok()
|
||||
.with_constness(obligation.predicate.skip_binder().constness);
|
||||
|
||||
let dfn = previous_stack.cache.next_dfn();
|
||||
|
|
|
@ -45,7 +45,7 @@ impl<'tcx> RustIrDatabase<'tcx> {
|
|||
predicates
|
||||
.iter()
|
||||
.map(|(wc, _)| wc.subst(self.interner.tcx, bound_vars))
|
||||
.map(|wc| wc.fold_with(&mut regions_substitutor))
|
||||
.map(|wc| wc.fold_with(&mut regions_substitutor).into_ok())
|
||||
.filter_map(|wc| LowerInto::<Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>>>::lower_into(wc, &self.interner)).collect()
|
||||
}
|
||||
|
||||
|
@ -287,7 +287,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
|
|||
let trait_ref = trait_ref.subst(self.interner.tcx, bound_vars);
|
||||
let mut regions_substitutor =
|
||||
lowering::RegionsSubstitutor::new(self.interner.tcx, self.reempty_placeholder);
|
||||
let trait_ref = trait_ref.fold_with(&mut regions_substitutor);
|
||||
let trait_ref = trait_ref.fold_with(&mut regions_substitutor).into_ok();
|
||||
|
||||
let where_clauses = self.where_clauses_for(def_id, bound_vars);
|
||||
|
||||
|
@ -335,7 +335,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
|
|||
let self_ty = self_ty.subst(self.interner.tcx, bound_vars);
|
||||
let mut regions_substitutor =
|
||||
lowering::RegionsSubstitutor::new(self.interner.tcx, self.reempty_placeholder);
|
||||
let self_ty = self_ty.fold_with(&mut regions_substitutor);
|
||||
let self_ty = self_ty.fold_with(&mut regions_substitutor).into_ok();
|
||||
let lowered_ty = self_ty.lower_into(&self.interner);
|
||||
|
||||
parameters[0].assert_ty_ref(&self.interner).could_match(
|
||||
|
@ -501,22 +501,24 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
|
|||
.iter()
|
||||
.map(|(bound, _)| bound.subst(self.interner.tcx, &bound_vars))
|
||||
.map(|bound| {
|
||||
bound.fold_with(&mut ty::fold::BottomUpFolder {
|
||||
tcx: self.interner.tcx,
|
||||
ty_op: |ty| {
|
||||
if let ty::Opaque(def_id, substs) = *ty.kind() {
|
||||
if def_id == opaque_ty_id.0 && substs == identity_substs {
|
||||
return self.interner.tcx.mk_ty(ty::Bound(
|
||||
ty::INNERMOST,
|
||||
ty::BoundTy::from(ty::BoundVar::from_u32(0)),
|
||||
));
|
||||
bound
|
||||
.fold_with(&mut ty::fold::BottomUpFolder {
|
||||
tcx: self.interner.tcx,
|
||||
ty_op: |ty| {
|
||||
if let ty::Opaque(def_id, substs) = *ty.kind() {
|
||||
if def_id == opaque_ty_id.0 && substs == identity_substs {
|
||||
return self.interner.tcx.mk_ty(ty::Bound(
|
||||
ty::INNERMOST,
|
||||
ty::BoundTy::from(ty::BoundVar::from_u32(0)),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
ty
|
||||
},
|
||||
lt_op: |lt| lt,
|
||||
ct_op: |ct| ct,
|
||||
})
|
||||
ty
|
||||
},
|
||||
lt_op: |lt| lt,
|
||||
ct_op: |ct| ct,
|
||||
})
|
||||
.into_ok()
|
||||
})
|
||||
.filter_map(|bound| {
|
||||
LowerInto::<
|
||||
|
|
|
@ -817,7 +817,7 @@ crate fn collect_bound_vars<'tcx, T: TypeFoldable<'tcx>>(
|
|||
.collect();
|
||||
|
||||
let mut bound_var_substitutor = NamedBoundVarSubstitutor::new(tcx, &named_parameters);
|
||||
let new_ty = ty.skip_binder().fold_with(&mut bound_var_substitutor);
|
||||
let new_ty = ty.skip_binder().fold_with(&mut bound_var_substitutor).into_ok();
|
||||
|
||||
for var in named_parameters.values() {
|
||||
parameters.insert(*var, chalk_ir::VariableKind::Lifetime);
|
||||
|
|
|
@ -49,12 +49,12 @@ crate fn evaluate_goal<'tcx>(
|
|||
|
||||
let mut params_substitutor =
|
||||
ParamsSubstitutor::new(tcx, placeholders_collector.next_ty_placeholder);
|
||||
let obligation = obligation.fold_with(&mut params_substitutor);
|
||||
let obligation = obligation.fold_with(&mut params_substitutor).into_ok();
|
||||
// FIXME(chalk): we really should be substituting these back in the solution
|
||||
let _params: FxHashMap<usize, ParamTy> = params_substitutor.params;
|
||||
|
||||
let mut regions_substitutor = RegionsSubstitutor::new(tcx, reempty_placeholder);
|
||||
let obligation = obligation.fold_with(&mut regions_substitutor);
|
||||
let obligation = obligation.fold_with(&mut regions_substitutor).into_ok();
|
||||
|
||||
let max_universe = obligation.max_universe.index();
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#![feature(crate_visibility_modifier)]
|
||||
#![feature(in_band_lifetimes)]
|
||||
#![feature(nll)]
|
||||
#![feature(unwrap_infallible)]
|
||||
#![recursion_limit = "256"]
|
||||
|
||||
#[macro_use]
|
||||
|
|
|
@ -442,8 +442,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
let mut eraser = TypeParamEraser(self, expr.span);
|
||||
let needs_bound = self
|
||||
.lookup_op_method(
|
||||
eraser.fold_ty(lhs_ty),
|
||||
&[eraser.fold_ty(rhs_ty)],
|
||||
eraser.fold_ty(lhs_ty).into_ok(),
|
||||
&[eraser.fold_ty(rhs_ty).into_ok()],
|
||||
Op::Binary(op, is_assign),
|
||||
)
|
||||
.is_ok();
|
||||
|
|
|
@ -658,7 +658,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
|||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
let mut resolver = Resolver::new(self.fcx, span, self.body);
|
||||
let x = x.fold_with(&mut resolver);
|
||||
let x = x.fold_with(&mut resolver).into_ok();
|
||||
if cfg!(debug_assertions) && x.needs_infer() {
|
||||
span_bug!(span.to_span(self.fcx.tcx), "writeback: `{:?}` has inference variables", x);
|
||||
}
|
||||
|
|
|
@ -761,7 +761,7 @@ fn infer_placeholder_type<'a>(
|
|||
|
||||
// Suggesting unnameable types won't help.
|
||||
let mut mk_nameable = MakeNameable::new(tcx);
|
||||
let ty = mk_nameable.fold_ty(ty);
|
||||
let ty = mk_nameable.fold_ty(ty).into_ok();
|
||||
let sugg_ty = if mk_nameable.success { Some(ty) } else { None };
|
||||
if let Some(sugg_ty) = sugg_ty {
|
||||
err.span_suggestion(
|
||||
|
@ -785,7 +785,7 @@ fn infer_placeholder_type<'a>(
|
|||
|
||||
if !ty.references_error() {
|
||||
let mut mk_nameable = MakeNameable::new(tcx);
|
||||
let ty = mk_nameable.fold_ty(ty);
|
||||
let ty = mk_nameable.fold_ty(ty).into_ok();
|
||||
let sugg_ty = if mk_nameable.success { Some(ty) } else { None };
|
||||
if let Some(sugg_ty) = sugg_ty {
|
||||
diag.span_suggestion(
|
||||
|
|
|
@ -71,8 +71,11 @@ fn diagnostic_hir_wf_check<'tcx>(
|
|||
fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx>) {
|
||||
self.tcx.infer_ctxt().enter(|infcx| {
|
||||
let mut fulfill = traits::FulfillmentContext::new();
|
||||
let tcx_ty =
|
||||
self.icx.to_ty(ty).fold_with(&mut EraseAllBoundRegions { tcx: self.tcx });
|
||||
let tcx_ty = self
|
||||
.icx
|
||||
.to_ty(ty)
|
||||
.fold_with(&mut EraseAllBoundRegions { tcx: self.tcx })
|
||||
.into_ok();
|
||||
let cause = traits::ObligationCause::new(
|
||||
ty.span,
|
||||
self.hir_id,
|
||||
|
|
|
@ -71,6 +71,7 @@ This API is completely unstable and subject to change.
|
|||
#![feature(slice_partition_dedup)]
|
||||
#![feature(control_flow_enum)]
|
||||
#![feature(hash_drain_filter)]
|
||||
#![feature(unwrap_infallible)]
|
||||
#![recursion_limit = "256"]
|
||||
|
||||
#[macro_use]
|
||||
|
|
|
@ -449,7 +449,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
|
|||
_ => false,
|
||||
}
|
||||
})
|
||||
.map(|p| p.fold_with(&mut replacer));
|
||||
.map(|p| p.fold_with(&mut replacer).into_ok());
|
||||
|
||||
let mut generic_params =
|
||||
(tcx.generics_of(item_def_id), tcx.explicit_predicates_of(item_def_id))
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#![feature(type_ascription)]
|
||||
#![feature(iter_intersperse)]
|
||||
#![recursion_limit = "256"]
|
||||
#![feature(unwrap_infallible)]
|
||||
#![warn(rustc::internal)]
|
||||
|
||||
#[macro_use]
|
||||
|
|
Loading…
Add table
Reference in a new issue