]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/ty/structural_impls.rs
Rollup merge of #67501 - oli-obk:test-slice-patterns, r=RalfJung
[rust.git] / src / librustc / ty / structural_impls.rs
index ce76a4c831b58772c79b37683a3d17051d855033..5e24c843025bfb78800e21df3ffc59a0c3b34d89 100644 (file)
@@ -2,17 +2,16 @@
 //! traits for various types in the Rust compiler. Most are written by
 //! hand, though we've recently added some macros and proc-macros to help with the tedium.
 
-use crate::hir::def::Namespace;
-use crate::hir::def_id::CRATE_DEF_INDEX;
-use crate::mir::ProjectionKind;
 use crate::mir::interpret;
-use crate::ty::{self, Lift, Ty, TyCtxt, InferConst};
+use crate::mir::ProjectionKind;
 use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
 use crate::ty::print::{FmtPrinter, Printer};
+use crate::ty::{self, InferConst, Lift, Ty, TyCtxt};
+use rustc_hir::def::Namespace;
+use rustc_hir::def_id::CRATE_DEF_INDEX;
+use rustc_index::vec::{Idx, IndexVec};
 
-use rustc_index::vec::{IndexVec, Idx};
 use smallvec::SmallVec;
-
 use std::fmt;
 use std::rc::Rc;
 use std::sync::Arc;
@@ -21,22 +20,17 @@ impl fmt::Debug for ty::GenericParamDef {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         let type_name = match self.kind {
             ty::GenericParamDefKind::Lifetime => "Lifetime",
-            ty::GenericParamDefKind::Type {..} => "Type",
+            ty::GenericParamDefKind::Type { .. } => "Type",
             ty::GenericParamDefKind::Const => "Const",
         };
-        write!(f, "{}({}, {:?}, {})",
-               type_name,
-               self.name,
-               self.def_id,
-               self.index)
+        write!(f, "{}({}, {:?}, {})", type_name, self.name, self.def_id, self.index)
     }
 }
 
 impl fmt::Debug for ty::TraitDef {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         ty::tls::with(|tcx| {
-            FmtPrinter::new(tcx, f, Namespace::TypeNS)
-                .print_def_path(self.def_id, &[])?;
+            FmtPrinter::new(tcx, f, Namespace::TypeNS).print_def_path(self.def_id, &[])?;
             Ok(())
         })
     }
@@ -45,37 +39,22 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 impl fmt::Debug for ty::AdtDef {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         ty::tls::with(|tcx| {
-            FmtPrinter::new(tcx, f, Namespace::TypeNS)
-                .print_def_path(self.did, &[])?;
+            FmtPrinter::new(tcx, f, Namespace::TypeNS).print_def_path(self.did, &[])?;
             Ok(())
         })
     }
 }
 
-impl fmt::Debug for ty::ClosureUpvar<'tcx> {
-    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        write!(f, "ClosureUpvar({:?},{:?})",
-               self.res,
-               self.ty)
-    }
-}
-
 impl fmt::Debug for ty::UpvarId {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        let name = ty::tls::with(|tcx| {
-            tcx.hir().name(self.var_path.hir_id)
-        });
-        write!(f, "UpvarId({:?};`{}`;{:?})",
-            self.var_path.hir_id,
-            name,
-            self.closure_expr_id)
+        let name = ty::tls::with(|tcx| tcx.hir().name(self.var_path.hir_id));
+        write!(f, "UpvarId({:?};`{}`;{:?})", self.var_path.hir_id, name, self.closure_expr_id)
     }
 }
 
 impl fmt::Debug for ty::UpvarBorrow<'tcx> {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        write!(f, "UpvarBorrow({:?}, {:?})",
-               self.kind, self.region)
+        write!(f, "UpvarBorrow({:?}, {:?})", self.kind, self.region)
     }
 }
 
@@ -110,15 +89,9 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 impl fmt::Debug for ty::RegionKind {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         match *self {
-            ty::ReEarlyBound(ref data) => {
-                write!(f, "ReEarlyBound({}, {})",
-                        data.index,
-                        data.name)
-            }
+            ty::ReEarlyBound(ref data) => write!(f, "ReEarlyBound({}, {})", data.index, data.name),
 
-            ty::ReClosureBound(ref vid) => {
-                write!(f, "ReClosureBound({:?})", vid)
-            }
+            ty::ReClosureBound(ref vid) => write!(f, "ReClosureBound({:?})", vid),
 
             ty::ReLateBound(binder_id, ref bound_region) => {
                 write!(f, "ReLateBound({:?}, {:?})", binder_id, bound_region)
@@ -132,9 +105,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 
             ty::ReVar(ref vid) => vid.fmt(f),
 
-            ty::RePlaceholder(placeholder) => {
-                write!(f, "RePlaceholder({:?})", placeholder)
-            }
+            ty::RePlaceholder(placeholder) => write!(f, "RePlaceholder({:?})", placeholder),
 
             ty::ReEmpty => write!(f, "ReEmpty"),
 
@@ -162,8 +133,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 
 impl fmt::Debug for ty::FnSig<'tcx> {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        write!(f, "({:?}; c_variadic: {})->{:?}",
-                self.inputs(), self.c_variadic, self.output())
+        write!(f, "({:?}; c_variadic: {})->{:?}", self.inputs(), self.c_variadic, self.output())
     }
 }
 
@@ -270,12 +240,9 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
             ty::Predicate::TypeOutlives(ref pair) => pair.fmt(f),
             ty::Predicate::Projection(ref pair) => pair.fmt(f),
             ty::Predicate::WellFormed(ty) => write!(f, "WellFormed({:?})", ty),
-            ty::Predicate::ObjectSafe(trait_def_id) => {
-                write!(f, "ObjectSafe({:?})", trait_def_id)
-            }
+            ty::Predicate::ObjectSafe(trait_def_id) => write!(f, "ObjectSafe({:?})", trait_def_id),
             ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) => {
-                write!(f, "ClosureKind({:?}, {:?}, {:?})",
-                    closure_def_id, closure_substs, kind)
+                write!(f, "ClosureKind({:?}, {:?}, {:?})", closure_def_id, closure_substs, kind)
             }
             ty::Predicate::ConstEvaluatable(def_id, substs) => {
                 write!(f, "ConstEvaluatable({:?}, {:?})", def_id, substs)
@@ -300,13 +267,13 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
     crate::middle::region::Scope,
     ::syntax::ast::FloatTy,
     ::syntax::ast::NodeId,
-    ::syntax_pos::symbol::Symbol,
-    crate::hir::def::Res,
-    crate::hir::def_id::DefId,
-    crate::hir::InlineAsmInner,
-    crate::hir::MatchSource,
-    crate::hir::Mutability,
-    crate::hir::Unsafety,
+    ::rustc_span::symbol::Symbol,
+    ::rustc_hir::def::Res,
+    ::rustc_hir::def_id::DefId,
+    ::rustc_hir::InlineAsmInner,
+    ::rustc_hir::MatchSource,
+    ::rustc_hir::Mutability,
+    ::rustc_hir::Unsafety,
     ::rustc_target::spec::abi::Abi,
     crate::mir::Local,
     crate::mir::Promoted,
@@ -329,7 +296,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
     crate::ty::RegionVid,
     crate::ty::UniverseIndex,
     crate::ty::Variance,
-    ::syntax_pos::Span,
+    ::rustc_span::Span,
 }
 
 ///////////////////////////////////////////////////////////////////////////
@@ -346,10 +313,9 @@ fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
 impl<'tcx, A: Lift<'tcx>, B: Lift<'tcx>, C: Lift<'tcx>> Lift<'tcx> for (A, B, C) {
     type Lifted = (A::Lifted, B::Lifted, C::Lifted);
     fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
-        tcx.lift(&self.0).and_then(|a| {
-            tcx.lift(&self.1).and_then(|b| tcx.lift(&self.2).map(|c| (a, b, c)))
-        })
-   }
+        tcx.lift(&self.0)
+            .and_then(|a| tcx.lift(&self.1).and_then(|b| tcx.lift(&self.2).map(|c| (a, b, c))))
+    }
 }
 
 impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Option<T> {
@@ -357,7 +323,7 @@ impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Option<T> {
     fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
         match *self {
             Some(ref x) => tcx.lift(x).map(Some),
-            None => Some(None)
+            None => Some(None),
         }
     }
 }
@@ -367,7 +333,7 @@ impl<'tcx, T: Lift<'tcx>, E: Lift<'tcx>> Lift<'tcx> for Result<T, E> {
     fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
         match *self {
             Ok(ref x) => tcx.lift(x).map(Ok),
-            Err(ref e) => tcx.lift(e).map(Err)
+            Err(ref e) => tcx.lift(e).map(Err),
         }
     }
 }
@@ -397,8 +363,7 @@ impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for [T] {
     type Lifted = Vec<T::Lifted>;
     fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
         // type annotation needed to inform `projection_must_outlive`
-        let mut result : Vec<<T as Lift<'tcx>>::Lifted>
-            = Vec::with_capacity(self.len());
+        let mut result: Vec<<T as Lift<'tcx>>::Lifted> = Vec::with_capacity(self.len());
         for x in self {
             if let Some(value) = tcx.lift(x) {
                 result.push(value);
@@ -420,29 +385,21 @@ fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
 impl<'tcx, I: Idx, T: Lift<'tcx>> Lift<'tcx> for IndexVec<I, T> {
     type Lifted = IndexVec<I, T::Lifted>;
     fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
-        self.iter()
-            .map(|e| tcx.lift(e))
-            .collect()
+        self.iter().map(|e| tcx.lift(e)).collect()
     }
 }
 
 impl<'a, 'tcx> Lift<'tcx> for ty::TraitRef<'a> {
     type Lifted = ty::TraitRef<'tcx>;
     fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
-        tcx.lift(&self.substs).map(|substs| ty::TraitRef {
-            def_id: self.def_id,
-            substs,
-        })
+        tcx.lift(&self.substs).map(|substs| ty::TraitRef { def_id: self.def_id, substs })
     }
 }
 
 impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialTraitRef<'a> {
     type Lifted = ty::ExistentialTraitRef<'tcx>;
     fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
-        tcx.lift(&self.substs).map(|substs| ty::ExistentialTraitRef {
-            def_id: self.def_id,
-            substs,
-        })
+        tcx.lift(&self.substs).map(|substs| ty::ExistentialTraitRef { def_id: self.def_id, substs })
     }
 }
 
@@ -450,9 +407,7 @@ impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialPredicate<'a> {
     type Lifted = ty::ExistentialPredicate<'tcx>;
     fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
         match self {
-            ty::ExistentialPredicate::Trait(x) => {
-                tcx.lift(x).map(ty::ExistentialPredicate::Trait)
-            }
+            ty::ExistentialPredicate::Trait(x) => tcx.lift(x).map(ty::ExistentialPredicate::Trait),
             ty::ExistentialPredicate::Projection(x) => {
                 tcx.lift(x).map(ty::ExistentialPredicate::Projection)
             }
@@ -466,9 +421,7 @@ fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
 impl<'a, 'tcx> Lift<'tcx> for ty::TraitPredicate<'a> {
     type Lifted = ty::TraitPredicate<'tcx>;
     fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<ty::TraitPredicate<'tcx>> {
-        tcx.lift(&self.trait_ref).map(|trait_ref| ty::TraitPredicate {
-            trait_ref,
-        })
+        tcx.lift(&self.trait_ref).map(|trait_ref| ty::TraitPredicate { trait_ref })
     }
 }
 
@@ -493,36 +446,26 @@ fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
 impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionTy<'a> {
     type Lifted = ty::ProjectionTy<'tcx>;
     fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<ty::ProjectionTy<'tcx>> {
-        tcx.lift(&self.substs).map(|substs| {
-            ty::ProjectionTy {
-                item_def_id: self.item_def_id,
-                substs,
-            }
-        })
+        tcx.lift(&self.substs)
+            .map(|substs| ty::ProjectionTy { item_def_id: self.item_def_id, substs })
     }
 }
 
 impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionPredicate<'a> {
     type Lifted = ty::ProjectionPredicate<'tcx>;
     fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<ty::ProjectionPredicate<'tcx>> {
-        tcx.lift(&(self.projection_ty, self.ty)).map(|(projection_ty, ty)| {
-            ty::ProjectionPredicate {
-                projection_ty,
-                ty,
-            }
-        })
+        tcx.lift(&(self.projection_ty, self.ty))
+            .map(|(projection_ty, ty)| ty::ProjectionPredicate { projection_ty, ty })
     }
 }
 
 impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialProjection<'a> {
     type Lifted = ty::ExistentialProjection<'tcx>;
     fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
-        tcx.lift(&self.substs).map(|substs| {
-            ty::ExistentialProjection {
-                substs,
-                ty: tcx.lift(&self.ty).expect("type must lift when substs do"),
-                item_def_id: self.item_def_id,
-            }
+        tcx.lift(&self.substs).map(|substs| ty::ExistentialProjection {
+            substs,
+            ty: tcx.lift(&self.ty).expect("type must lift when substs do"),
+            item_def_id: self.item_def_id,
         })
     }
 }
@@ -531,12 +474,8 @@ impl<'a, 'tcx> Lift<'tcx> for ty::Predicate<'a> {
     type Lifted = ty::Predicate<'tcx>;
     fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
         match *self {
-            ty::Predicate::Trait(ref binder) => {
-                tcx.lift(binder).map(ty::Predicate::Trait)
-            }
-            ty::Predicate::Subtype(ref binder) => {
-                tcx.lift(binder).map(ty::Predicate::Subtype)
-            }
+            ty::Predicate::Trait(ref binder) => tcx.lift(binder).map(ty::Predicate::Trait),
+            ty::Predicate::Subtype(ref binder) => tcx.lift(binder).map(ty::Predicate::Subtype),
             ty::Predicate::RegionOutlives(ref binder) => {
                 tcx.lift(binder).map(ty::Predicate::RegionOutlives)
             }
@@ -546,22 +485,17 @@ fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
             ty::Predicate::Projection(ref binder) => {
                 tcx.lift(binder).map(ty::Predicate::Projection)
             }
-            ty::Predicate::WellFormed(ty) => {
-                tcx.lift(&ty).map(ty::Predicate::WellFormed)
-            }
+            ty::Predicate::WellFormed(ty) => tcx.lift(&ty).map(ty::Predicate::WellFormed),
             ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) => {
-                tcx.lift(&closure_substs)
-                   .map(|closure_substs| ty::Predicate::ClosureKind(closure_def_id,
-                                                                    closure_substs,
-                                                                    kind))
+                tcx.lift(&closure_substs).map(|closure_substs| {
+                    ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind)
+                })
             }
             ty::Predicate::ObjectSafe(trait_def_id) => {
                 Some(ty::Predicate::ObjectSafe(trait_def_id))
             }
             ty::Predicate::ConstEvaluatable(def_id, substs) => {
-                tcx.lift(&substs).map(|substs| {
-                    ty::Predicate::ConstEvaluatable(def_id, substs)
-                })
+                tcx.lift(&substs).map(|substs| ty::Predicate::ConstEvaluatable(def_id, substs))
             }
         }
     }
@@ -577,12 +511,10 @@ fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
 impl<'a, 'tcx> Lift<'tcx> for ty::ParamEnv<'a> {
     type Lifted = ty::ParamEnv<'tcx>;
     fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
-        tcx.lift(&self.caller_bounds).map(|caller_bounds| {
-            ty::ParamEnv {
-                reveal: self.reveal,
-                caller_bounds,
-                def_id: self.def_id,
-            }
+        tcx.lift(&self.caller_bounds).map(|caller_bounds| ty::ParamEnv {
+            reveal: self.reveal,
+            caller_bounds,
+            def_id: self.def_id,
         })
     }
 }
@@ -591,12 +523,7 @@ impl<'a, 'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::ParamEnvAnd<'a, T> {
     type Lifted = ty::ParamEnvAnd<'tcx, T::Lifted>;
     fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
         tcx.lift(&self.param_env).and_then(|param_env| {
-            tcx.lift(&self.value).map(|value| {
-                ty::ParamEnvAnd {
-                    param_env,
-                    value,
-                }
-            })
+            tcx.lift(&self.value).map(|value| ty::ParamEnvAnd { param_env, value })
         })
     }
 }
@@ -604,18 +531,14 @@ fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
 impl<'a, 'tcx> Lift<'tcx> for ty::ClosureSubsts<'a> {
     type Lifted = ty::ClosureSubsts<'tcx>;
     fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
-        tcx.lift(&self.substs).map(|substs| {
-            ty::ClosureSubsts { substs }
-        })
+        tcx.lift(&self.substs).map(|substs| ty::ClosureSubsts { substs })
     }
 }
 
 impl<'a, 'tcx> Lift<'tcx> for ty::GeneratorSubsts<'a> {
     type Lifted = ty::GeneratorSubsts<'tcx>;
     fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
-        tcx.lift(&self.substs).map(|substs| {
-            ty::GeneratorSubsts { substs }
-        })
+        tcx.lift(&self.substs).map(|substs| ty::GeneratorSubsts { substs })
     }
 }
 
@@ -623,9 +546,7 @@ impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::Adjustment<'a> {
     type Lifted = ty::adjustment::Adjustment<'tcx>;
     fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
         tcx.lift(&self.kind).and_then(|kind| {
-            tcx.lift(&self.target).map(|target| {
-                ty::adjustment::Adjustment { kind, target }
-            })
+            tcx.lift(&self.target).map(|target| ty::adjustment::Adjustment { kind, target })
         })
     }
 }
@@ -634,10 +555,8 @@ impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::Adjust<'a> {
     type Lifted = ty::adjustment::Adjust<'tcx>;
     fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
         match *self {
-            ty::adjustment::Adjust::NeverToAny =>
-                Some(ty::adjustment::Adjust::NeverToAny),
-            ty::adjustment::Adjust::Pointer(ptr) =>
-                Some(ty::adjustment::Adjust::Pointer(ptr)),
+            ty::adjustment::Adjust::NeverToAny => Some(ty::adjustment::Adjust::NeverToAny),
+            ty::adjustment::Adjust::Pointer(ptr) => Some(ty::adjustment::Adjust::Pointer(ptr)),
             ty::adjustment::Adjust::Deref(ref overloaded) => {
                 tcx.lift(overloaded).map(ty::adjustment::Adjust::Deref)
             }
@@ -651,12 +570,8 @@ fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
 impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::OverloadedDeref<'a> {
     type Lifted = ty::adjustment::OverloadedDeref<'tcx>;
     fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
-        tcx.lift(&self.region).map(|region| {
-            ty::adjustment::OverloadedDeref {
-                region,
-                mutbl: self.mutbl,
-            }
-        })
+        tcx.lift(&self.region)
+            .map(|region| ty::adjustment::OverloadedDeref { region, mutbl: self.mutbl })
     }
 }
 
@@ -667,9 +582,7 @@ fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
             ty::adjustment::AutoBorrow::Ref(r, m) => {
                 tcx.lift(&r).map(|r| ty::adjustment::AutoBorrow::Ref(r, m))
             }
-            ty::adjustment::AutoBorrow::RawPtr(m) => {
-                Some(ty::adjustment::AutoBorrow::RawPtr(m))
-            }
+            ty::adjustment::AutoBorrow::RawPtr(m) => Some(ty::adjustment::AutoBorrow::RawPtr(m)),
         }
     }
 }
@@ -678,25 +591,18 @@ impl<'a, 'tcx> Lift<'tcx> for ty::GenSig<'a> {
     type Lifted = ty::GenSig<'tcx>;
     fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
         tcx.lift(&(self.yield_ty, self.return_ty))
-           .map(|(yield_ty, return_ty)| {
-               ty::GenSig {
-                   yield_ty,
-                   return_ty,
-               }
-           })
+            .map(|(yield_ty, return_ty)| ty::GenSig { yield_ty, return_ty })
     }
 }
 
 impl<'a, 'tcx> Lift<'tcx> for ty::FnSig<'a> {
     type Lifted = ty::FnSig<'tcx>;
     fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
-        tcx.lift(&self.inputs_and_output).map(|x| {
-            ty::FnSig {
-                inputs_and_output: x,
-                c_variadic: self.c_variadic,
-                unsafety: self.unsafety,
-                abi: self.abi,
-            }
+        tcx.lift(&self.inputs_and_output).map(|x| ty::FnSig {
+            inputs_and_output: x,
+            c_variadic: self.c_variadic,
+            unsafety: self.unsafety,
+            abi: self.abi,
         })
     }
 }
@@ -705,12 +611,7 @@ impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::error::ExpectedFound<T> {
     type Lifted = ty::error::ExpectedFound<T::Lifted>;
     fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
         tcx.lift(&self.expected).and_then(|expected| {
-            tcx.lift(&self.found).map(|found| {
-                ty::error::ExpectedFound {
-                    expected,
-                    found,
-                }
-            })
+            tcx.lift(&self.found).map(|found| ty::error::ExpectedFound { expected, found })
         })
     }
 }
@@ -729,13 +630,13 @@ fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
             FixedArraySize(x) => FixedArraySize(x),
             ArgCount => ArgCount,
             RegionsDoesNotOutlive(a, b) => {
-                return tcx.lift(&(a, b)).map(|(a, b)| RegionsDoesNotOutlive(a, b))
+                return tcx.lift(&(a, b)).map(|(a, b)| RegionsDoesNotOutlive(a, b));
             }
             RegionsInsufficientlyPolymorphic(a, b) => {
-                return tcx.lift(&b).map(|b| RegionsInsufficientlyPolymorphic(a, b))
+                return tcx.lift(&b).map(|b| RegionsInsufficientlyPolymorphic(a, b));
             }
             RegionsOverlyPolymorphic(a, b) => {
-                return tcx.lift(&b).map(|b| RegionsOverlyPolymorphic(a, b))
+                return tcx.lift(&b).map(|b| RegionsOverlyPolymorphic(a, b));
             }
             RegionsPlaceholderMismatch => RegionsPlaceholderMismatch,
             IntMismatch(x) => IntMismatch(x),
@@ -758,24 +659,23 @@ impl<'a, 'tcx> Lift<'tcx> for ty::InstanceDef<'a> {
     type Lifted = ty::InstanceDef<'tcx>;
     fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
         match *self {
-            ty::InstanceDef::Item(def_id) =>
-                Some(ty::InstanceDef::Item(def_id)),
-            ty::InstanceDef::VtableShim(def_id) =>
-                Some(ty::InstanceDef::VtableShim(def_id)),
-            ty::InstanceDef::ReifyShim(def_id) =>
-                Some(ty::InstanceDef::ReifyShim(def_id)),
-            ty::InstanceDef::Intrinsic(def_id) =>
-                Some(ty::InstanceDef::Intrinsic(def_id)),
-            ty::InstanceDef::FnPtrShim(def_id, ref ty) =>
-                Some(ty::InstanceDef::FnPtrShim(def_id, tcx.lift(ty)?)),
-            ty::InstanceDef::Virtual(def_id, n) =>
-                Some(ty::InstanceDef::Virtual(def_id, n)),
-            ty::InstanceDef::ClosureOnceShim { call_once } =>
-                Some(ty::InstanceDef::ClosureOnceShim { call_once }),
-            ty::InstanceDef::DropGlue(def_id, ref ty) =>
-                Some(ty::InstanceDef::DropGlue(def_id, tcx.lift(ty)?)),
-            ty::InstanceDef::CloneShim(def_id, ref ty) =>
-                Some(ty::InstanceDef::CloneShim(def_id, tcx.lift(ty)?)),
+            ty::InstanceDef::Item(def_id) => Some(ty::InstanceDef::Item(def_id)),
+            ty::InstanceDef::VtableShim(def_id) => Some(ty::InstanceDef::VtableShim(def_id)),
+            ty::InstanceDef::ReifyShim(def_id) => Some(ty::InstanceDef::ReifyShim(def_id)),
+            ty::InstanceDef::Intrinsic(def_id) => Some(ty::InstanceDef::Intrinsic(def_id)),
+            ty::InstanceDef::FnPtrShim(def_id, ref ty) => {
+                Some(ty::InstanceDef::FnPtrShim(def_id, tcx.lift(ty)?))
+            }
+            ty::InstanceDef::Virtual(def_id, n) => Some(ty::InstanceDef::Virtual(def_id, n)),
+            ty::InstanceDef::ClosureOnceShim { call_once } => {
+                Some(ty::InstanceDef::ClosureOnceShim { call_once })
+            }
+            ty::InstanceDef::DropGlue(def_id, ref ty) => {
+                Some(ty::InstanceDef::DropGlue(def_id, tcx.lift(ty)?))
+            }
+            ty::InstanceDef::CloneShim(def_id, ref ty) => {
+                Some(ty::InstanceDef::CloneShim(def_id, tcx.lift(ty)?))
+            }
         }
     }
 }
@@ -938,53 +838,36 @@ fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
                 VtableShim(did) => VtableShim(did.fold_with(folder)),
                 ReifyShim(did) => ReifyShim(did.fold_with(folder)),
                 Intrinsic(did) => Intrinsic(did.fold_with(folder)),
-                FnPtrShim(did, ty) => FnPtrShim(
-                    did.fold_with(folder),
-                    ty.fold_with(folder),
-                ),
-                Virtual(did, i) => Virtual(
-                    did.fold_with(folder),
-                    i,
-                ),
-                ClosureOnceShim { call_once } => ClosureOnceShim {
-                    call_once: call_once.fold_with(folder),
-                },
-                DropGlue(did, ty) => DropGlue(
-                    did.fold_with(folder),
-                    ty.fold_with(folder),
-                ),
-                CloneShim(did, ty) => CloneShim(
-                    did.fold_with(folder),
-                    ty.fold_with(folder),
-                ),
+                FnPtrShim(did, ty) => FnPtrShim(did.fold_with(folder), ty.fold_with(folder)),
+                Virtual(did, i) => Virtual(did.fold_with(folder), i),
+                ClosureOnceShim { call_once } => {
+                    ClosureOnceShim { call_once: call_once.fold_with(folder) }
+                }
+                DropGlue(did, ty) => DropGlue(did.fold_with(folder), ty.fold_with(folder)),
+                CloneShim(did, ty) => CloneShim(did.fold_with(folder), ty.fold_with(folder)),
             },
         }
     }
 
     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
         use crate::ty::InstanceDef::*;
-        self.substs.visit_with(visitor) ||
-        match self.def {
-            Item(did) | VtableShim(did) | ReifyShim(did) | Intrinsic(did) | Virtual(did, _) => {
-                did.visit_with(visitor)
-            },
-            FnPtrShim(did, ty) | CloneShim(did, ty) => {
-                did.visit_with(visitor) || ty.visit_with(visitor)
-            },
-            DropGlue(did, ty) => {
-                did.visit_with(visitor) || ty.visit_with(visitor)
-            },
-            ClosureOnceShim { call_once } => call_once.visit_with(visitor),
-        }
+        self.substs.visit_with(visitor)
+            || match self.def {
+                Item(did) | VtableShim(did) | ReifyShim(did) | Intrinsic(did) | Virtual(did, _) => {
+                    did.visit_with(visitor)
+                }
+                FnPtrShim(did, ty) | CloneShim(did, ty) => {
+                    did.visit_with(visitor) || ty.visit_with(visitor)
+                }
+                DropGlue(did, ty) => did.visit_with(visitor) || ty.visit_with(visitor),
+                ClosureOnceShim { call_once } => call_once.visit_with(visitor),
+            }
     }
 }
 
 impl<'tcx> TypeFoldable<'tcx> for interpret::GlobalId<'tcx> {
     fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
-        Self {
-            instance: self.instance.fold_with(folder),
-            promoted: self.promoted
-        }
+        Self { instance: self.instance.fold_with(folder), promoted: self.promoted }
     }
 
     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
@@ -999,21 +882,15 @@ fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
             ty::Array(typ, sz) => ty::Array(typ.fold_with(folder), sz.fold_with(folder)),
             ty::Slice(typ) => ty::Slice(typ.fold_with(folder)),
             ty::Adt(tid, substs) => ty::Adt(tid, substs.fold_with(folder)),
-            ty::Dynamic(ref trait_ty, ref region) =>
-                ty::Dynamic(trait_ty.fold_with(folder), region.fold_with(folder)),
-            ty::Tuple(ts) => ty::Tuple(ts.fold_with(folder)),
-            ty::FnDef(def_id, substs) => {
-                ty::FnDef(def_id, substs.fold_with(folder))
+            ty::Dynamic(ref trait_ty, ref region) => {
+                ty::Dynamic(trait_ty.fold_with(folder), region.fold_with(folder))
             }
+            ty::Tuple(ts) => ty::Tuple(ts.fold_with(folder)),
+            ty::FnDef(def_id, substs) => ty::FnDef(def_id, substs.fold_with(folder)),
             ty::FnPtr(f) => ty::FnPtr(f.fold_with(folder)),
-            ty::Ref(ref r, ty, mutbl) => {
-                ty::Ref(r.fold_with(folder), ty.fold_with(folder), mutbl)
-            }
+            ty::Ref(ref r, ty, mutbl) => ty::Ref(r.fold_with(folder), ty.fold_with(folder), mutbl),
             ty::Generator(did, substs, movability) => {
-                ty::Generator(
-                    did,
-                    substs.fold_with(folder),
-                    movability)
+                ty::Generator(did, substs.fold_with(folder), movability)
             }
             ty::GeneratorWitness(types) => ty::GeneratorWitness(types.fold_with(folder)),
             ty::Closure(did, substs) => ty::Closure(did, substs.fold_with(folder)),
@@ -1023,26 +900,22 @@ fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
             }
             ty::Opaque(did, substs) => ty::Opaque(did, substs.fold_with(folder)),
 
-            ty::Bool |
-            ty::Char |
-            ty::Str |
-            ty::Int(_) |
-            ty::Uint(_) |
-            ty::Float(_) |
-            ty::Error |
-            ty::Infer(_) |
-            ty::Param(..) |
-            ty::Bound(..) |
-            ty::Placeholder(..) |
-            ty::Never |
-            ty::Foreign(..) => return self,
+            ty::Bool
+            | ty::Char
+            | ty::Str
+            | ty::Int(_)
+            | ty::Uint(_)
+            | ty::Float(_)
+            | ty::Error
+            | ty::Infer(_)
+            | ty::Param(..)
+            | ty::Bound(..)
+            | ty::Placeholder(..)
+            | ty::Never
+            ty::Foreign(..) => return self,
         };
 
-        if self.kind == kind {
-            self
-        } else {
-            folder.tcx().mk_ty(kind)
-        }
+        if self.kind == kind { self } else { folder.tcx().mk_ty(kind) }
     }
 
     fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
@@ -1055,15 +928,14 @@ fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
             ty::Array(typ, sz) => typ.visit_with(visitor) || sz.visit_with(visitor),
             ty::Slice(typ) => typ.visit_with(visitor),
             ty::Adt(_, substs) => substs.visit_with(visitor),
-            ty::Dynamic(ref trait_ty, ref reg) =>
-                trait_ty.visit_with(visitor) || reg.visit_with(visitor),
+            ty::Dynamic(ref trait_ty, ref reg) => {
+                trait_ty.visit_with(visitor) || reg.visit_with(visitor)
+            }
             ty::Tuple(ts) => ts.visit_with(visitor),
             ty::FnDef(_, substs) => substs.visit_with(visitor),
             ty::FnPtr(ref f) => f.visit_with(visitor),
             ty::Ref(r, ty, _) => r.visit_with(visitor) || ty.visit_with(visitor),
-            ty::Generator(_did, ref substs, _) => {
-                substs.visit_with(visitor)
-            }
+            ty::Generator(_did, ref substs, _) => substs.visit_with(visitor),
             ty::GeneratorWitness(ref types) => types.visit_with(visitor),
             ty::Closure(_did, ref substs) => substs.visit_with(visitor),
             ty::Projection(ref data) | ty::UnnormalizedProjection(ref data) => {
@@ -1071,19 +943,19 @@ fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
             }
             ty::Opaque(_, ref substs) => substs.visit_with(visitor),
 
-            ty::Bool |
-            ty::Char |
-            ty::Str |
-            ty::Int(_) |
-            ty::Uint(_) |
-            ty::Float(_) |
-            ty::Error |
-            ty::Infer(_) |
-            ty::Bound(..) |
-            ty::Placeholder(..) |
-            ty::Param(..) |
-            ty::Never |
-            ty::Foreign(..) => false,
+            ty::Bool
+            | ty::Char
+            | ty::Str
+            | ty::Int(_)
+            | ty::Uint(_)
+            | ty::Float(_)
+            | ty::Error
+            | ty::Infer(_)
+            | ty::Bound(..)
+            | ty::Placeholder(..)
+            | ty::Param(..)
+            | ty::Never
+            ty::Foreign(..) => false,
         }
     }
 
@@ -1121,11 +993,7 @@ fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
             // Don't bother interning if nothing changed, which is the common
             // case.
             let v = self.iter().map(|p| p.fold_with(folder)).collect::<SmallVec<[_; 8]>>();
-            if v[..] == self[..] {
-                self
-            } else {
-                folder.tcx().intern_predicates(&v)
-            }
+            if v[..] == self[..] { self } else { folder.tcx().intern_predicates(&v) }
         }
     }
 
@@ -1148,10 +1016,7 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Const<'tcx> {
     fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
         let ty = self.ty.fold_with(folder);
         let val = self.val.fold_with(folder);
-        folder.tcx().mk_const(ty::Const {
-            ty,
-            val
-        })
+        folder.tcx().mk_const(ty::Const { ty, val })
     }
 
     fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
@@ -1172,10 +1037,12 @@ fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
         match *self {
             ty::ConstKind::Infer(ic) => ty::ConstKind::Infer(ic.fold_with(folder)),
             ty::ConstKind::Param(p) => ty::ConstKind::Param(p.fold_with(folder)),
-            ty::ConstKind::Unevaluated(did, substs)
-                => ty::ConstKind::Unevaluated(did, substs.fold_with(folder)),
-            ty::ConstKind::Value(_) | ty::ConstKind::Bound(..)
-            | ty::ConstKind::Placeholder(..) => *self,
+            ty::ConstKind::Unevaluated(did, substs) => {
+                ty::ConstKind::Unevaluated(did, substs.fold_with(folder))
+            }
+            ty::ConstKind::Value(_) | ty::ConstKind::Bound(..) | ty::ConstKind::Placeholder(..) => {
+                *self
+            }
         }
     }
 
@@ -1184,8 +1051,9 @@ fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
             ty::ConstKind::Infer(ic) => ic.visit_with(visitor),
             ty::ConstKind::Param(p) => p.visit_with(visitor),
             ty::ConstKind::Unevaluated(_, substs) => substs.visit_with(visitor),
-            ty::ConstKind::Value(_) | ty::ConstKind::Bound(..)
-            | ty::ConstKind::Placeholder(_) => false,
+            ty::ConstKind::Value(_) | ty::ConstKind::Bound(..) | ty::ConstKind::Placeholder(_) => {
+                false
+            }
         }
     }
 }