]> git.lizzy.rs Git - rust.git/commitdiff
make ValidationOperand generic so that we can reuse it in miri with a different Lvalu...
authorRalf Jung <post@ralfj.de>
Fri, 21 Jul 2017 21:49:01 +0000 (14:49 -0700)
committerRalf Jung <post@ralfj.de>
Sun, 30 Jul 2017 08:11:59 +0000 (01:11 -0700)
src/librustc/ich/impls_mir.rs
src/librustc/mir/mod.rs
src/librustc_mir/transform/add_validation.rs

index dc41f981ed57b3dbe2a5d1e41d20789087ee4872..bef35fdc2578cf3b390b54c78be18b701437c990 100644 (file)
@@ -243,7 +243,19 @@ fn hash_stable<W: StableHasherResult>(&self,
     }
 }
 
-impl_stable_hash_for!(struct mir::ValidationOperand<'tcx> { lval, ty, re, mutbl });
+impl<'a, 'gcx, 'tcx, T> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for mir::ValidationOperand<'tcx, T>
+    where T: HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
+{
+    fn hash_stable<W: StableHasherResult>(&self,
+                                          hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
+                                          hasher: &mut StableHasher<W>)
+    {
+        self.lval.hash_stable(hcx, hasher);
+        self.ty.hash_stable(hcx, hasher);
+        self.re.hash_stable(hcx, hasher);
+        self.mutbl.hash_stable(hcx, hasher);
+    }
+}
 
 impl_stable_hash_for!(enum mir::ValidationOp { Acquire, Release, Suspend(extent) });
 
index 4655f8a9c15ec2edc479df4b50e36eecbc4743ea..f8261f806296e97e3e320de9c5bbe68815b72333 100644 (file)
@@ -826,7 +826,7 @@ pub enum StatementKind<'tcx> {
     },
 
     /// Assert the given lvalues to be valid inhabitants of their type.
-    Validate(ValidationOp, Vec<ValidationOperand<'tcx>>),
+    Validate(ValidationOp, Vec<ValidationOperand<'tcx, Lvalue<'tcx>>>),
 
     /// Mark one terminating point of an extent (i.e. static region).
     /// (The starting point(s) arise implicitly from borrows.)
@@ -855,15 +855,16 @@ fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
     }
 }
 
+// This is generic so that it can be reused by miri
 #[derive(Clone, RustcEncodable, RustcDecodable)]
-pub struct ValidationOperand<'tcx> {
-    pub lval: Lvalue<'tcx>,
+pub struct ValidationOperand<'tcx, T> {
+    pub lval: T,
     pub ty: Ty<'tcx>,
     pub re: Option<CodeExtent>,
     pub mutbl: hir::Mutability,
 }
 
-impl<'tcx> Debug for ValidationOperand<'tcx> {
+impl<'tcx, T: Debug> Debug for ValidationOperand<'tcx, T> {
     fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
         write!(fmt, "{:?}@{:?}", self.lval, self.ty)?;
         if let Some(ce) = self.re {
@@ -1527,7 +1528,7 @@ fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
     }
 }
 
-impl<'tcx> TypeFoldable<'tcx> for ValidationOperand<'tcx> {
+impl<'tcx> TypeFoldable<'tcx> for ValidationOperand<'tcx, Lvalue<'tcx>> {
     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
         ValidationOperand {
             lval: self.lval.fold_with(folder),
index 1fe16fb98f22591cc2889898367a4628b8cad124..005d793cd8b537eb5c2c83b72dea2d2eda035626 100644 (file)
@@ -88,7 +88,7 @@ fn run_pass<'a, 'tcx>(&self,
         let local_decls = mir.local_decls.clone(); // TODO: Find a way to get rid of this clone.
 
         /// Convert an lvalue to a validation operand.
-        let lval_to_operand = |lval: Lvalue<'tcx>| -> ValidationOperand<'tcx> {
+        let lval_to_operand = |lval: Lvalue<'tcx>| -> ValidationOperand<'tcx, Lvalue<'tcx>> {
             let (re, mutbl) = lval_context(&lval, &local_decls, tcx);
             let ty = lval.ty(&local_decls, tcx).to_ty(tcx);
             ValidationOperand { lval, ty, re, mutbl }