about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPaul Daniel Faria <nashenas88@users.noreply.github.com>2017-11-12 00:41:29 -0500
committerNiko Matsakis <niko@alum.mit.edu>2017-11-22 03:51:55 -0500
commit527a5dd2517f7ca7857ebd006a3cc6bcd0abec39 (patch)
tree5cc26776fa1f64bf51c3a6d095d03cab2aa06353
parent47c6db09ee35810005274017abcd0798d6978a47 (diff)
downloadrust-527a5dd2517f7ca7857ebd006a3cc6bcd0abec39.tar.gz
rust-527a5dd2517f7ca7857ebd006a3cc6bcd0abec39.zip
Normalize LvalueTy for ops and format code to satisfy tidy check
-rw-r--r--src/librustc_mir/transform/type_check.rs63
1 files changed, 39 insertions, 24 deletions
diff --git a/src/librustc_mir/transform/type_check.rs b/src/librustc_mir/transform/type_check.rs
index 96264222eae..6888225de75 100644
--- a/src/librustc_mir/transform/type_check.rs
+++ b/src/librustc_mir/transform/type_check.rs
@@ -1012,23 +1012,27 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
         }
     }
 
-    fn aggregate_field_ty(&mut self, ak: &Box<AggregateKind<'tcx>>, field: usize, location: Location)
-        -> Result<Ty<'tcx>, FieldAccessError>
-    {
+    fn aggregate_field_ty(
+        &mut self,
+        ak: &Box<AggregateKind<'tcx>>,
+        field: usize,
+        location: Location,
+    ) -> Result<Ty<'tcx>, FieldAccessError> {
         let tcx = self.tcx();
 
         let (variant, substs) = match **ak {
-            AggregateKind::Adt(def, variant, substs, _) => { // handle unions?
+            AggregateKind::Adt(def, variant, substs, _) => {
+                // handle unions?
                 (&def.variants[variant], substs)
-            },
+            }
             AggregateKind::Closure(def_id, substs) => {
                 return match substs.upvar_tys(def_id, tcx).nth(field) {
                     Some(ty) => Ok(ty),
                     None => Err(FieldAccessError::OutOfRange {
-                        field_count: substs.upvar_tys(def_id, tcx).count()
+                        field_count: substs.upvar_tys(def_id, tcx).count(),
                     }),
                 }
-            },
+            }
             AggregateKind::Generator(def_id, substs, _) => {
                 if let Some(ty) = substs.upvar_tys(def_id, tcx).nth(field) {
                     return Ok(ty);
@@ -1037,22 +1041,24 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
                 return match substs.field_tys(def_id, tcx).nth(field) {
                     Some(ty) => Ok(ty),
                     None => Err(FieldAccessError::OutOfRange {
-                        field_count: substs.field_tys(def_id, tcx).count() + 1
+                        field_count: substs.field_tys(def_id, tcx).count() + 1,
                     }),
-                }
-            },
+                };
+            }
             AggregateKind::Array(ty) => {
                 return Ok(ty);
-            },
+            }
             AggregateKind::Tuple => {
                 unreachable!("This should have been covered in check_rvalues");
-            },
+            }
         };
 
         if let Some(field) = variant.fields.get(field) {
             Ok(self.normalize(&field.ty(tcx, substs), location))
         } else {
-            Err(FieldAccessError::OutOfRange { field_count: variant.fields.len() })
+            Err(FieldAccessError::OutOfRange {
+                field_count: variant.fields.len(),
+            })
         }
     }
 
@@ -1062,7 +1068,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
             Rvalue::Aggregate(ak, ops) => {
                 match **ak {
                     // tuple rvalue field type is always the type of the op. Nothing to check here.
-                    AggregateKind::Tuple => { },
+                    AggregateKind::Tuple => {}
                     _ => {
                         for (i, op) in ops.iter().enumerate() {
                             let field_ty = match self.aggregate_field_ty(ak, i, location) {
@@ -1073,27 +1079,36 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
                                         rv,
                                         "accessed field #{} but variant only has {}",
                                         i,
-                                        field_count);
+                                        field_count
+                                    );
                                     continue;
-                                },
+                                }
                             };
                             let op_ty = match op {
-                                Operand::Consume(lv) => lv.ty(mir, tcx).to_ty(tcx),
+                                Operand::Consume(lv) => {
+                                    self.normalize(&lv.ty(mir, tcx), location).to_ty(tcx)
+                                }
                                 Operand::Constant(c) => c.ty,
                             };
-                            if let Err(terr) = self.sub_types(op_ty, field_ty, location.at_successor_within_block()) {
-                                span_mirbug!(
+                            if let Err(terr) = self.sub_types(
+                                op_ty,
+                                field_ty,
+                                location.at_successor_within_block(),
+                            )
+                                {
+                                    span_mirbug!(
                                     self,
                                     rv,
                                     "{:?} is not a subtype of {:?}: {:?}",
                                     op_ty,
                                     field_ty,
-                                    terr);
-                            }
+                                    terr
+                                );
+                                }
                         }
-                    },
+                    }
                 }
-            },
+            }
             // FIXME: These other cases have to be implemented in future PRs
             Rvalue::Use(..) |
             Rvalue::Repeat(..) |
@@ -1104,7 +1119,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
             Rvalue::CheckedBinaryOp(..) |
             Rvalue::UnaryOp(..) |
             Rvalue::Discriminant(..) |
-            Rvalue::NullaryOp(..) => { }
+            Rvalue::NullaryOp(..) => {}
         }
     }