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_len)]
|
||||||
#![feature(trusted_step)]
|
#![feature(trusted_step)]
|
||||||
#![feature(try_blocks)]
|
#![feature(try_blocks)]
|
||||||
|
#![feature(unwrap_infallible)]
|
||||||
#![recursion_limit = "256"]
|
#![recursion_limit = "256"]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|
|
@ -95,7 +95,8 @@ pub fn equal_up_to_regions(
|
||||||
// Leave consts and types unchanged.
|
// Leave consts and types unchanged.
|
||||||
ct_op: |ct| ct,
|
ct_op: |ct| ct,
|
||||||
ty_op: |ty| ty,
|
ty_op: |ty| ty,
|
||||||
}),
|
})
|
||||||
|
.into_ok(),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
tcx.infer_ctxt().enter(|infcx| infcx.can_eq(param_env, normalize(src), normalize(dest)).is_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(),
|
indices: FxHashMap::default(),
|
||||||
binder_index: ty::INNERMOST,
|
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
|
// Once we have canonicalized `out_value`, it should not
|
||||||
// contain anything that ties it to this inference context
|
// contain anything that ties it to this inference context
|
||||||
|
@ -621,7 +621,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
|
||||||
let infcx = self.infcx;
|
let infcx = self.infcx;
|
||||||
let bound_to = infcx.shallow_resolve(ty_var);
|
let bound_to = infcx.shallow_resolve(ty_var);
|
||||||
if bound_to != ty_var {
|
if bound_to != ty_var {
|
||||||
self.fold_ty(bound_to)
|
self.fold_ty(bound_to).into_ok()
|
||||||
} else {
|
} else {
|
||||||
let var = self.canonical_var(info, ty_var.into());
|
let var = self.canonical_var(info, ty_var.into());
|
||||||
self.tcx().mk_ty(ty::Bound(self.binder_index, 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 infcx = self.infcx;
|
||||||
let bound_to = infcx.shallow_resolve(const_var);
|
let bound_to = infcx.shallow_resolve(const_var);
|
||||||
if bound_to != const_var {
|
if bound_to != const_var {
|
||||||
self.fold_const(bound_to)
|
self.fold_const(bound_to).into_ok()
|
||||||
} else {
|
} else {
|
||||||
let var = self.canonical_var(info, const_var.into());
|
let var = self.canonical_var(info, const_var.into());
|
||||||
self.tcx().mk_const(ty::Const {
|
self.tcx().mk_const(ty::Const {
|
||||||
val: ty::ConstKind::Bound(self.binder_index, var),
|
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,
|
F: FnOnce(u32) -> ty::InferTy,
|
||||||
{
|
{
|
||||||
if let Some(ty) = opt_ty {
|
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) {
|
match self.ty_freshen_map.entry(key) {
|
||||||
|
@ -98,7 +98,7 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
|
||||||
F: FnOnce(u32) -> ty::InferConst<'tcx>,
|
F: FnOnce(u32) -> ty::InferConst<'tcx>,
|
||||||
{
|
{
|
||||||
if let Some(ct) = opt_ct {
|
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) {
|
match self.const_freshen_map.entry(key) {
|
||||||
|
|
|
@ -161,7 +161,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
{
|
{
|
||||||
Ok(value)
|
Ok(value)
|
||||||
} else {
|
} 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 {
|
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`
|
/// Returns the origin of the type variable identified by `vid`, or `None`
|
||||||
|
@ -1381,7 +1381,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
where
|
where
|
||||||
T: TypeFoldable<'tcx>,
|
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 {
|
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.
|
return value; // Avoid duplicated subst-folding.
|
||||||
}
|
}
|
||||||
let mut r = resolve::OpportunisticVarResolver::new(self);
|
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
|
/// Returns the first unresolved variable contained in `T`. In the
|
||||||
|
|
|
@ -418,7 +418,8 @@ struct Instantiator<'a, 'tcx> {
|
||||||
impl<'a, 'tcx> Instantiator<'a, 'tcx> {
|
impl<'a, 'tcx> Instantiator<'a, 'tcx> {
|
||||||
fn instantiate_opaque_types_in_map<T: TypeFoldable<'tcx>>(&mut self, value: T) -> T {
|
fn instantiate_opaque_types_in_map<T: TypeFoldable<'tcx>>(&mut self, value: T) -> T {
|
||||||
let tcx = self.infcx.tcx;
|
let tcx = self.infcx.tcx;
|
||||||
value.fold_with(&mut BottomUpFolder {
|
value
|
||||||
|
.fold_with(&mut BottomUpFolder {
|
||||||
tcx,
|
tcx,
|
||||||
ty_op: |ty| {
|
ty_op: |ty| {
|
||||||
if ty.references_error() {
|
if ty.references_error() {
|
||||||
|
@ -504,6 +505,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
|
||||||
lt_op: |lt| lt,
|
lt_op: |lt| lt,
|
||||||
ct_op: |ct| ct,
|
ct_op: |ct| ct,
|
||||||
})
|
})
|
||||||
|
.into_ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(self), level = "debug")]
|
#[instrument(skip(self), level = "debug")]
|
||||||
|
@ -556,7 +558,8 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
|
||||||
debug!(?predicate);
|
debug!(?predicate);
|
||||||
|
|
||||||
// We can't normalize associated types from `rustc_infer`, but we can eagerly register inference variables for them.
|
// 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 {
|
let predicate = predicate
|
||||||
|
.fold_with(&mut BottomUpFolder {
|
||||||
tcx,
|
tcx,
|
||||||
ty_op: |ty| match ty.kind() {
|
ty_op: |ty| match ty.kind() {
|
||||||
ty::Projection(projection_ty) => infcx.infer_projection(
|
ty::Projection(projection_ty) => infcx.infer_projection(
|
||||||
|
@ -570,7 +573,8 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
|
||||||
},
|
},
|
||||||
lt_op: |lt| lt,
|
lt_op: |lt| lt,
|
||||||
ct_op: |ct| ct,
|
ct_op: |ct| ct,
|
||||||
});
|
})
|
||||||
|
.into_ok();
|
||||||
debug!(?predicate);
|
debug!(?predicate);
|
||||||
|
|
||||||
if let ty::PredicateKind::Projection(projection) = predicate.kind().skip_binder() {
|
if let ty::PredicateKind::Projection(projection) = predicate.kind().skip_binder() {
|
||||||
|
|
|
@ -182,7 +182,7 @@ where
|
||||||
T: TypeFoldable<'tcx>,
|
T: TypeFoldable<'tcx>,
|
||||||
{
|
{
|
||||||
let mut full_resolver = FullTypeResolver { infcx, err: None };
|
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 {
|
match full_resolver.err {
|
||||||
None => Ok(result),
|
None => Ok(result),
|
||||||
Some(e) => Err(e),
|
Some(e) => Err(e),
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#![feature(control_flow_enum)]
|
#![feature(control_flow_enum)]
|
||||||
#![feature(min_specialization)]
|
#![feature(min_specialization)]
|
||||||
#![feature(label_break_value)]
|
#![feature(label_break_value)]
|
||||||
|
#![feature(unwrap_infallible)]
|
||||||
#![recursion_limit = "512"] // For rustdoc
|
#![recursion_limit = "512"] // For rustdoc
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|
|
@ -56,6 +56,7 @@
|
||||||
#![feature(try_blocks)]
|
#![feature(try_blocks)]
|
||||||
#![feature(try_reserve_kind)]
|
#![feature(try_reserve_kind)]
|
||||||
#![feature(nonzero_ops)]
|
#![feature(nonzero_ops)]
|
||||||
|
#![feature(unwrap_infallible)]
|
||||||
#![recursion_limit = "512"]
|
#![recursion_limit = "512"]
|
||||||
|
|
||||||
#[macro_use]
|
#[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> {
|
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
|
// N.B., use `super_fold_with` here. If we used `fold_with`, it
|
||||||
// could invoke the `erase_regions_ty` query recursively.
|
// 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> {
|
impl<'tcx> TyCtxt<'tcx> {
|
||||||
|
@ -27,7 +27,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
debug!("erase_regions({:?})", 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);
|
debug!("erase_regions = {:?}", value1);
|
||||||
value1
|
value1
|
||||||
}
|
}
|
||||||
|
|
|
@ -336,7 +336,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
where
|
where
|
||||||
T: TypeFoldable<'tcx>,
|
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`.
|
/// Invoke `callback` on every region appearing free in `value`.
|
||||||
|
@ -638,7 +638,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
value
|
value
|
||||||
} else {
|
} else {
|
||||||
let mut replacer = BoundVarReplacer::new(self, Some(&mut real_fld_r), None, None);
|
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)
|
(value, region_map)
|
||||||
}
|
}
|
||||||
|
@ -664,7 +664,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
} else {
|
} else {
|
||||||
let mut replacer =
|
let mut replacer =
|
||||||
BoundVarReplacer::new(self, Some(&mut fld_r), Some(&mut fld_t), Some(&mut fld_c));
|
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);
|
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)]
|
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||||
|
@ -1293,7 +1293,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
///
|
///
|
||||||
/// FIXME(@lcnr): explain this function a bit more
|
/// FIXME(@lcnr): explain this function a bit more
|
||||||
pub fn expose_default_const_substs<T: TypeFoldable<'tcx>>(self, v: T) -> T {
|
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.
|
// ..and polymorphize any closures/generators captured as upvars.
|
||||||
let upvars_ty = upvars_ty.unwrap();
|
let upvars_ty = upvars_ty.unwrap();
|
||||||
let polymorphized_upvars_ty = upvars_ty.fold_with(
|
let polymorphized_upvars_ty = upvars_ty.fold_with(
|
||||||
&mut PolymorphizationFolder { tcx });
|
&mut PolymorphizationFolder { tcx }).into_ok();
|
||||||
debug!("polymorphize: polymorphized_upvars_ty={:?}", polymorphized_upvars_ty);
|
debug!("polymorphize: polymorphized_upvars_ty={:?}", polymorphized_upvars_ty);
|
||||||
ty::GenericArg::from(polymorphized_upvars_ty)
|
ty::GenericArg::from(polymorphized_upvars_ty)
|
||||||
},
|
},
|
||||||
|
|
|
@ -35,7 +35,9 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
if !value.has_projections() {
|
if !value.has_projections() {
|
||||||
value
|
value
|
||||||
} else {
|
} 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,
|
name: &mut name,
|
||||||
region_map: BTreeMap::new(),
|
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;
|
let region_map = folder.region_map;
|
||||||
start_or_continue(&mut self, "", "> ");
|
start_or_continue(&mut self, "", "> ");
|
||||||
(new_value, region_map)
|
(new_value, region_map)
|
||||||
|
|
|
@ -439,7 +439,7 @@ impl<'tcx, T: TypeFoldable<'tcx>> Subst<'tcx> for T {
|
||||||
span: Option<Span>,
|
span: Option<Span>,
|
||||||
) -> T {
|
) -> T {
|
||||||
let mut folder = SubstFolder { tcx, substs, span, binders_passed: 0 };
|
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 {
|
if self.found_any_recursion {
|
||||||
return None;
|
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) {
|
if !self.check_recursion || self.seen_opaque_tys.insert(def_id) {
|
||||||
let expanded_ty = match self.expanded_cache.get(&(def_id, substs)) {
|
let expanded_ty = match self.expanded_cache.get(&(def_id, substs)) {
|
||||||
Some(expanded_ty) => expanded_ty,
|
Some(expanded_ty) => expanded_ty,
|
||||||
None => {
|
None => {
|
||||||
let generic_ty = self.tcx.type_of(def_id);
|
let generic_ty = self.tcx.type_of(def_id);
|
||||||
let concrete_ty = generic_ty.subst(self.tcx, substs);
|
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);
|
self.expanded_cache.insert((def_id, substs), expanded_ty);
|
||||||
expanded_ty
|
expanded_ty
|
||||||
}
|
}
|
||||||
|
@ -1092,7 +1092,7 @@ pub fn normalize_opaque_types(
|
||||||
check_recursion: false,
|
check_recursion: false,
|
||||||
tcx,
|
tcx,
|
||||||
};
|
};
|
||||||
val.fold_with(&mut visitor)
|
val.fold_with(&mut visitor).into_ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn provide(providers: &mut ty::query::Providers) {
|
pub fn provide(providers: &mut ty::query::Providers) {
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
#![feature(crate_visibility_modifier)]
|
#![feature(crate_visibility_modifier)]
|
||||||
#![feature(control_flow_enum)]
|
#![feature(control_flow_enum)]
|
||||||
|
#![feature(unwrap_infallible)]
|
||||||
#![recursion_limit = "512"] // For rustdoc
|
#![recursion_limit = "512"] // For rustdoc
|
||||||
|
|
||||||
#[macro_use]
|
#[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
|
// Convert the type from the function into a type valid outside
|
||||||
// the function, by replacing invalid regions with 'static,
|
// the function, by replacing invalid regions with 'static,
|
||||||
// after producing an error for each of them.
|
// after producing an error for each of them.
|
||||||
let definition_ty = instantiated_ty.fold_with(&mut ReverseMapper::new(
|
let definition_ty = instantiated_ty
|
||||||
|
.fold_with(&mut ReverseMapper::new(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
self.is_tainted_by_errors(),
|
self.is_tainted_by_errors(),
|
||||||
def_id,
|
def_id,
|
||||||
map,
|
map,
|
||||||
instantiated_ty,
|
instantiated_ty,
|
||||||
span,
|
span,
|
||||||
));
|
))
|
||||||
|
.into_ok();
|
||||||
debug!(?definition_ty);
|
debug!(?definition_ty);
|
||||||
|
|
||||||
definition_ty
|
definition_ty
|
||||||
|
@ -123,14 +125,14 @@ impl ReverseMapper<'tcx> {
|
||||||
) -> GenericArg<'tcx> {
|
) -> GenericArg<'tcx> {
|
||||||
assert!(!self.map_missing_regions_to_empty);
|
assert!(!self.map_missing_regions_to_empty);
|
||||||
self.map_missing_regions_to_empty = true;
|
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;
|
self.map_missing_regions_to_empty = false;
|
||||||
kind
|
kind
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_kind_normally(&mut self, kind: GenericArg<'tcx>) -> GenericArg<'tcx> {
|
fn fold_kind_normally(&mut self, kind: GenericArg<'tcx>) -> GenericArg<'tcx> {
|
||||||
assert!(!self.map_missing_regions_to_empty);
|
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(|_| {
|
self.probe(|_| {
|
||||||
let mut selcx = SelectionContext::new(self);
|
let mut selcx = SelectionContext::new(self);
|
||||||
|
|
||||||
let cleaned_pred =
|
let cleaned_pred = pred
|
||||||
pred.fold_with(&mut ParamToVarFolder { infcx: self, var_map: Default::default() });
|
.fold_with(&mut ParamToVarFolder { infcx: self, var_map: Default::default() })
|
||||||
|
.into_ok();
|
||||||
|
|
||||||
let cleaned_pred = super::project::normalize(
|
let cleaned_pred = super::project::normalize(
|
||||||
&mut selcx,
|
&mut selcx,
|
||||||
|
|
|
@ -339,7 +339,7 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
|
||||||
if !needs_normalization(&value, self.param_env.reveal()) {
|
if !needs_normalization(&value, self.param_env.reveal()) {
|
||||||
value
|
value
|
||||||
} else {
|
} else {
|
||||||
value.fold_with(self)
|
value.fold_with(self).into_ok()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -555,7 +555,7 @@ impl<'me, 'tcx> BoundVarReplacer<'me, 'tcx> {
|
||||||
universe_indices,
|
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)
|
(value, replacer.mapped_regions, replacer.mapped_types, replacer.mapped_consts)
|
||||||
}
|
}
|
||||||
|
@ -681,7 +681,7 @@ impl<'me, 'tcx> PlaceholderReplacer<'me, 'tcx> {
|
||||||
universe_indices,
|
universe_indices,
|
||||||
current_index: ty::INNERMOST,
|
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`
|
// when possible for this to work. See `auto-trait-projection-recursion.rs`
|
||||||
// for a case where this matters.
|
// for a case where this matters.
|
||||||
if progress.ty.has_infer_regions() {
|
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
|
progress
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@ impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> {
|
||||||
normalizer.universes.extend((0..max_visitor.escaping).map(|_| None));
|
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!(
|
info!(
|
||||||
"normalize::<{}>: result={:?} with {} obligations",
|
"normalize::<{}>: result={:?} with {} obligations",
|
||||||
std::any::type_name::<T>(),
|
std::any::type_name::<T>(),
|
||||||
|
|
|
@ -2222,6 +2222,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
.predicate
|
.predicate
|
||||||
.to_poly_trait_ref()
|
.to_poly_trait_ref()
|
||||||
.fold_with(&mut self.freshener)
|
.fold_with(&mut self.freshener)
|
||||||
|
.into_ok()
|
||||||
.with_constness(obligation.predicate.skip_binder().constness);
|
.with_constness(obligation.predicate.skip_binder().constness);
|
||||||
|
|
||||||
let dfn = previous_stack.cache.next_dfn();
|
let dfn = previous_stack.cache.next_dfn();
|
||||||
|
|
|
@ -45,7 +45,7 @@ impl<'tcx> RustIrDatabase<'tcx> {
|
||||||
predicates
|
predicates
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(wc, _)| wc.subst(self.interner.tcx, bound_vars))
|
.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()
|
.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 trait_ref = trait_ref.subst(self.interner.tcx, bound_vars);
|
||||||
let mut regions_substitutor =
|
let mut regions_substitutor =
|
||||||
lowering::RegionsSubstitutor::new(self.interner.tcx, self.reempty_placeholder);
|
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);
|
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 self_ty = self_ty.subst(self.interner.tcx, bound_vars);
|
||||||
let mut regions_substitutor =
|
let mut regions_substitutor =
|
||||||
lowering::RegionsSubstitutor::new(self.interner.tcx, self.reempty_placeholder);
|
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);
|
let lowered_ty = self_ty.lower_into(&self.interner);
|
||||||
|
|
||||||
parameters[0].assert_ty_ref(&self.interner).could_match(
|
parameters[0].assert_ty_ref(&self.interner).could_match(
|
||||||
|
@ -501,7 +501,8 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(bound, _)| bound.subst(self.interner.tcx, &bound_vars))
|
.map(|(bound, _)| bound.subst(self.interner.tcx, &bound_vars))
|
||||||
.map(|bound| {
|
.map(|bound| {
|
||||||
bound.fold_with(&mut ty::fold::BottomUpFolder {
|
bound
|
||||||
|
.fold_with(&mut ty::fold::BottomUpFolder {
|
||||||
tcx: self.interner.tcx,
|
tcx: self.interner.tcx,
|
||||||
ty_op: |ty| {
|
ty_op: |ty| {
|
||||||
if let ty::Opaque(def_id, substs) = *ty.kind() {
|
if let ty::Opaque(def_id, substs) = *ty.kind() {
|
||||||
|
@ -517,6 +518,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
|
||||||
lt_op: |lt| lt,
|
lt_op: |lt| lt,
|
||||||
ct_op: |ct| ct,
|
ct_op: |ct| ct,
|
||||||
})
|
})
|
||||||
|
.into_ok()
|
||||||
})
|
})
|
||||||
.filter_map(|bound| {
|
.filter_map(|bound| {
|
||||||
LowerInto::<
|
LowerInto::<
|
||||||
|
|
|
@ -817,7 +817,7 @@ crate fn collect_bound_vars<'tcx, T: TypeFoldable<'tcx>>(
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut bound_var_substitutor = NamedBoundVarSubstitutor::new(tcx, &named_parameters);
|
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() {
|
for var in named_parameters.values() {
|
||||||
parameters.insert(*var, chalk_ir::VariableKind::Lifetime);
|
parameters.insert(*var, chalk_ir::VariableKind::Lifetime);
|
||||||
|
|
|
@ -49,12 +49,12 @@ crate fn evaluate_goal<'tcx>(
|
||||||
|
|
||||||
let mut params_substitutor =
|
let mut params_substitutor =
|
||||||
ParamsSubstitutor::new(tcx, placeholders_collector.next_ty_placeholder);
|
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
|
// FIXME(chalk): we really should be substituting these back in the solution
|
||||||
let _params: FxHashMap<usize, ParamTy> = params_substitutor.params;
|
let _params: FxHashMap<usize, ParamTy> = params_substitutor.params;
|
||||||
|
|
||||||
let mut regions_substitutor = RegionsSubstitutor::new(tcx, reempty_placeholder);
|
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();
|
let max_universe = obligation.max_universe.index();
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#![feature(crate_visibility_modifier)]
|
#![feature(crate_visibility_modifier)]
|
||||||
#![feature(in_band_lifetimes)]
|
#![feature(in_band_lifetimes)]
|
||||||
#![feature(nll)]
|
#![feature(nll)]
|
||||||
|
#![feature(unwrap_infallible)]
|
||||||
#![recursion_limit = "256"]
|
#![recursion_limit = "256"]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|
|
@ -442,8 +442,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let mut eraser = TypeParamEraser(self, expr.span);
|
let mut eraser = TypeParamEraser(self, expr.span);
|
||||||
let needs_bound = self
|
let needs_bound = self
|
||||||
.lookup_op_method(
|
.lookup_op_method(
|
||||||
eraser.fold_ty(lhs_ty),
|
eraser.fold_ty(lhs_ty).into_ok(),
|
||||||
&[eraser.fold_ty(rhs_ty)],
|
&[eraser.fold_ty(rhs_ty).into_ok()],
|
||||||
Op::Binary(op, is_assign),
|
Op::Binary(op, is_assign),
|
||||||
)
|
)
|
||||||
.is_ok();
|
.is_ok();
|
||||||
|
|
|
@ -658,7 +658,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
||||||
T: TypeFoldable<'tcx>,
|
T: TypeFoldable<'tcx>,
|
||||||
{
|
{
|
||||||
let mut resolver = Resolver::new(self.fcx, span, self.body);
|
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() {
|
if cfg!(debug_assertions) && x.needs_infer() {
|
||||||
span_bug!(span.to_span(self.fcx.tcx), "writeback: `{:?}` has inference variables", x);
|
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.
|
// Suggesting unnameable types won't help.
|
||||||
let mut mk_nameable = MakeNameable::new(tcx);
|
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 };
|
let sugg_ty = if mk_nameable.success { Some(ty) } else { None };
|
||||||
if let Some(sugg_ty) = sugg_ty {
|
if let Some(sugg_ty) = sugg_ty {
|
||||||
err.span_suggestion(
|
err.span_suggestion(
|
||||||
|
@ -785,7 +785,7 @@ fn infer_placeholder_type<'a>(
|
||||||
|
|
||||||
if !ty.references_error() {
|
if !ty.references_error() {
|
||||||
let mut mk_nameable = MakeNameable::new(tcx);
|
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 };
|
let sugg_ty = if mk_nameable.success { Some(ty) } else { None };
|
||||||
if let Some(sugg_ty) = sugg_ty {
|
if let Some(sugg_ty) = sugg_ty {
|
||||||
diag.span_suggestion(
|
diag.span_suggestion(
|
||||||
|
|
|
@ -71,8 +71,11 @@ fn diagnostic_hir_wf_check<'tcx>(
|
||||||
fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx>) {
|
fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx>) {
|
||||||
self.tcx.infer_ctxt().enter(|infcx| {
|
self.tcx.infer_ctxt().enter(|infcx| {
|
||||||
let mut fulfill = traits::FulfillmentContext::new();
|
let mut fulfill = traits::FulfillmentContext::new();
|
||||||
let tcx_ty =
|
let tcx_ty = self
|
||||||
self.icx.to_ty(ty).fold_with(&mut EraseAllBoundRegions { tcx: self.tcx });
|
.icx
|
||||||
|
.to_ty(ty)
|
||||||
|
.fold_with(&mut EraseAllBoundRegions { tcx: self.tcx })
|
||||||
|
.into_ok();
|
||||||
let cause = traits::ObligationCause::new(
|
let cause = traits::ObligationCause::new(
|
||||||
ty.span,
|
ty.span,
|
||||||
self.hir_id,
|
self.hir_id,
|
||||||
|
|
|
@ -71,6 +71,7 @@ This API is completely unstable and subject to change.
|
||||||
#![feature(slice_partition_dedup)]
|
#![feature(slice_partition_dedup)]
|
||||||
#![feature(control_flow_enum)]
|
#![feature(control_flow_enum)]
|
||||||
#![feature(hash_drain_filter)]
|
#![feature(hash_drain_filter)]
|
||||||
|
#![feature(unwrap_infallible)]
|
||||||
#![recursion_limit = "256"]
|
#![recursion_limit = "256"]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|
|
@ -449,7 +449,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.map(|p| p.fold_with(&mut replacer));
|
.map(|p| p.fold_with(&mut replacer).into_ok());
|
||||||
|
|
||||||
let mut generic_params =
|
let mut generic_params =
|
||||||
(tcx.generics_of(item_def_id), tcx.explicit_predicates_of(item_def_id))
|
(tcx.generics_of(item_def_id), tcx.explicit_predicates_of(item_def_id))
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#![feature(type_ascription)]
|
#![feature(type_ascription)]
|
||||||
#![feature(iter_intersperse)]
|
#![feature(iter_intersperse)]
|
||||||
#![recursion_limit = "256"]
|
#![recursion_limit = "256"]
|
||||||
|
#![feature(unwrap_infallible)]
|
||||||
#![warn(rustc::internal)]
|
#![warn(rustc::internal)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue