use crate::mir;
use crate::ty::codec::{TyDecoder, TyEncoder};
-use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
+use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder, TypeVisitor};
use crate::ty::sty::{ClosureSubsts, GeneratorSubsts, InlineConstSubsts};
use crate::ty::{self, Lift, List, ParamConst, Ty, TyCtxt};
}
}
-impl fmt::Debug for GenericArg<'tcx> {
+impl<'tcx> fmt::Debug for GenericArg<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.unpack() {
GenericArgKind::Lifetime(lt) => lt.fmt(f),
}
impl<'tcx> TypeFoldable<'tcx> for GenericArg<'tcx> {
- fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
+ fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
+ self,
+ folder: &mut F,
+ ) -> Result<Self, F::Error> {
match self.unpack() {
- GenericArgKind::Lifetime(lt) => lt.fold_with(folder).map(Into::into),
- GenericArgKind::Type(ty) => ty.fold_with(folder).map(Into::into),
- GenericArgKind::Const(ct) => ct.fold_with(folder).map(Into::into),
+ GenericArgKind::Lifetime(lt) => lt.try_fold_with(folder).map(Into::into),
+ GenericArgKind::Type(ty) => ty.try_fold_with(folder).map(Into::into),
+ GenericArgKind::Const(ct) => ct.try_fold_with(folder).map(Into::into),
}
}
}
impl<'tcx> TypeFoldable<'tcx> for SubstsRef<'tcx> {
- fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
+ fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
+ self,
+ folder: &mut F,
+ ) -> Result<Self, F::Error> {
// This code is hot enough that it's worth specializing for the most
// common length lists, to avoid the overhead of `SmallVec` creation.
// The match arms are in order of frequency. The 1, 2, and 0 cases are
// calling `intern_substs`.
match self.len() {
1 => {
- let param0 = self[0].fold_with(folder)?;
+ let param0 = self[0].try_fold_with(folder)?;
if param0 == self[0] { Ok(self) } else { Ok(folder.tcx().intern_substs(&[param0])) }
}
2 => {
- let param0 = self[0].fold_with(folder)?;
- let param1 = self[1].fold_with(folder)?;
+ let param0 = self[0].try_fold_with(folder)?;
+ let param1 = self[1].try_fold_with(folder)?;
if param0 == self[0] && param1 == self[1] {
Ok(self)
} else {
0 => Ok(self),
_ => {
let params: SmallVec<[_; 8]> =
- self.iter().map(|k| k.fold_with(folder)).collect::<Result<_, _>>()?;
+ self.iter().map(|k| k.try_fold_with(folder)).collect::<Result<_, _>>()?;
if params[..] == self[..] {
Ok(self)
} else {
span: Option<Span>,
) -> T {
let mut folder = SubstFolder { tcx, substs, span, binders_passed: 0 };
- self.fold_with(&mut folder).into_ok()
+ self.fold_with(&mut folder)
}
}
fn fold_binder<T: TypeFoldable<'tcx>>(
&mut self,
t: ty::Binder<'tcx, T>,
- ) -> Result<ty::Binder<'tcx, T>, Self::Error> {
+ ) -> ty::Binder<'tcx, T> {
self.binders_passed += 1;
- let t = t.super_fold_with(self)?;
+ let t = t.super_fold_with(self);
self.binders_passed -= 1;
- Ok(t)
+ t
}
- fn fold_region(&mut self, r: ty::Region<'tcx>) -> Result<ty::Region<'tcx>, Self::Error> {
+ fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
// Note: This routine only handles regions that are bound on
// type declarations and other outer declarations, not those
// bound in *fn types*. Region substitution of the bound
ty::ReEarlyBound(data) => {
let rk = self.substs.get(data.index as usize).map(|k| k.unpack());
match rk {
- Some(GenericArgKind::Lifetime(lt)) => Ok(self.shift_region_through_binders(lt)),
+ Some(GenericArgKind::Lifetime(lt)) => self.shift_region_through_binders(lt),
_ => {
let span = self.span.unwrap_or(DUMMY_SP);
let msg = format!(
}
}
}
- _ => Ok(r),
+ _ => r,
}
}
- fn fold_ty(&mut self, t: Ty<'tcx>) -> Result<Ty<'tcx>, Self::Error> {
+ fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
if !t.potentially_needs_subst() {
- return Ok(t);
+ return t;
}
match *t.kind() {
- ty::Param(p) => Ok(self.ty_for_param(p, t)),
+ ty::Param(p) => self.ty_for_param(p, t),
_ => t.super_fold_with(self),
}
}
- fn fold_const(
- &mut self,
- c: &'tcx ty::Const<'tcx>,
- ) -> Result<&'tcx ty::Const<'tcx>, Self::Error> {
+ fn fold_const(&mut self, c: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
if let ty::ConstKind::Param(p) = c.val {
- Ok(self.const_for_param(p, c))
+ self.const_for_param(p, c)
} else {
c.super_fold_with(self)
}
}
#[inline]
- fn fold_mir_const(
- &mut self,
- c: mir::ConstantKind<'tcx>,
- ) -> Result<mir::ConstantKind<'tcx>, Self::Error> {
+ fn fold_mir_const(&mut self, c: mir::ConstantKind<'tcx>) -> mir::ConstantKind<'tcx> {
c.super_fold_with(self)
}
}