]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/ty/util.rs
Auto merge of #54743 - ljedrz:cleanup_ty_p2, r=zackmdavis
[rust.git] / src / librustc / ty / util.rs
index 4d7bab3cf433b23fc611b2e3e8cab5ed210740c6..dfe42e0c6610904e579161e2cc5e6b2d27c0bcc3 100644 (file)
@@ -119,17 +119,17 @@ fn disr_incr<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, val: Option<Discr<'tc
 impl IntTypeExt for attr::IntType {
     fn to_ty<'a, 'gcx, 'tcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
         match *self {
-            SignedInt(ast::IntTy::I8)      => tcx.types.i8,
-            SignedInt(ast::IntTy::I16)     => tcx.types.i16,
-            SignedInt(ast::IntTy::I32)     => tcx.types.i32,
-            SignedInt(ast::IntTy::I64)     => tcx.types.i64,
+            SignedInt(ast::IntTy::I8)       => tcx.types.i8,
+            SignedInt(ast::IntTy::I16)      => tcx.types.i16,
+            SignedInt(ast::IntTy::I32)      => tcx.types.i32,
+            SignedInt(ast::IntTy::I64)      => tcx.types.i64,
             SignedInt(ast::IntTy::I128)     => tcx.types.i128,
-            SignedInt(ast::IntTy::Isize)   => tcx.types.isize,
+            SignedInt(ast::IntTy::Isize)    => tcx.types.isize,
             UnsignedInt(ast::UintTy::U8)    => tcx.types.u8,
             UnsignedInt(ast::UintTy::U16)   => tcx.types.u16,
             UnsignedInt(ast::UintTy::U32)   => tcx.types.u32,
             UnsignedInt(ast::UintTy::U64)   => tcx.types.u64,
-            UnsignedInt(ast::UintTy::U128)   => tcx.types.u128,
+            UnsignedInt(ast::UintTy::U128)  => tcx.types.u128,
             UnsignedInt(ast::UintTy::Usize) => tcx.types.usize,
         }
     }
@@ -205,11 +205,11 @@ pub fn can_type_implement_copy<'a>(self,
             let mut infringing = Vec::new();
             for variant in &adt.variants {
                 for field in &variant.fields {
-                    let span = tcx.def_span(field.did);
                     let ty = field.ty(tcx, substs);
                     if ty.references_error() {
                         continue;
                     }
+                    let span = tcx.def_span(field.did);
                     let cause = ObligationCause { span, ..ObligationCause::dummy() };
                     let ctx = traits::FulfillmentContext::new();
                     match traits::fully_normalize(&infcx, ctx, cause, self, &ty) {
@@ -257,16 +257,13 @@ pub fn type_id_hash(self, ty: Ty<'tcx>) -> u64 {
 
 impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
     pub fn has_error_field(self, ty: Ty<'tcx>) -> bool {
-        match ty.sty {
-            ty::Adt(def, substs) => {
-                for field in def.all_fields() {
-                    let field_ty = field.ty(self, substs);
-                    if let Error = field_ty.sty {
-                        return true;
-                    }
+        if let ty::Adt(def, substs) = ty.sty {
+            for field in def.all_fields() {
+                let field_ty = field.ty(self, substs);
+                if let Error = field_ty.sty {
+                    return true;
                 }
             }
-            _ => (),
         }
         false
     }
@@ -421,7 +418,7 @@ pub fn calculate_dtor(
         let ty = self.type_of(adt_did);
         self.for_each_relevant_impl(drop_trait, ty, |impl_did| {
             if let Some(item) = self.associated_items(impl_did).next() {
-                if let Ok(()) = validate(self, impl_did) {
+                if validate(self, impl_did).is_ok() {
                     dtor_did = Some(item.def_id);
                 }
             }
@@ -513,7 +510,9 @@ pub fn destructor_constraints(self, def: &'tcx ty::AdtDef)
                         false
                     }
                 }
-            }).map(|(&item_param, _)| item_param).collect();
+            })
+            .map(|(&item_param, _)| item_param)
+            .collect();
         debug!("destructor_constraint({:?}) = {:?}", def.did, result);
         result
     }
@@ -674,8 +673,8 @@ pub fn needs_drop(&'tcx self,
     pub fn is_representable(&'tcx self,
                             tcx: TyCtxt<'a, 'tcx, 'tcx>,
                             sp: Span)
-                            -> Representability {
-
+                            -> Representability
+    {
         // Iterate until something non-representable is found
         fn fold_repr<It: Iterator<Item=Representability>>(iter: It) -> Representability {
             iter.fold(Representability::Representable, |r1, r2| {
@@ -904,20 +903,17 @@ fn needs_drop_raw<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
     let (param_env, ty) = query.into_parts();
 
     let needs_drop = |ty: Ty<'tcx>| -> bool {
-        match tcx.try_needs_drop_raw(DUMMY_SP, param_env.and(ty)) {
-            Ok(v) => v,
-            Err(mut bug) => {
-                // Cycles should be reported as an error by `check_representable`.
-                //
-                // Consider the type as not needing drop in the meanwhile to
-                // avoid further errors.
-                //
-                // In case we forgot to emit a bug elsewhere, delay our
-                // diagnostic to get emitted as a compiler bug.
-                bug.delay_as_bug();
-                false
-            }
-        }
+        tcx.try_needs_drop_raw(DUMMY_SP, param_env.and(ty)).unwrap_or_else(|mut bug| {
+            // Cycles should be reported as an error by `check_representable`.
+            //
+            // Consider the type as not needing drop in the meanwhile to
+            // avoid further errors.
+            //
+            // In case we forgot to emit a bug elsewhere, delay our
+            // diagnostic to get emitted as a compiler bug.
+            bug.delay_as_bug();
+            false
+        })
     };
 
     assert!(!ty.needs_infer());