diff options
| author | Ralf Jung <post@ralfj.de> | 2017-07-21 14:49:01 -0700 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2017-07-30 01:11:59 -0700 |
| commit | e869cf2be74372db55b64eb549f4dc0e6b5a667b (patch) | |
| tree | 0f1cf2eba8a6f9d30e9b207d02bf3f55f1a0f926 /src | |
| parent | 60096b9e8259ba227a0a85fc1a16dca5d3fd2217 (diff) | |
| download | rust-e869cf2be74372db55b64eb549f4dc0e6b5a667b.tar.gz rust-e869cf2be74372db55b64eb549f4dc0e6b5a667b.zip | |
make ValidationOperand generic so that we can reuse it in miri with a different Lvalue type
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/ich/impls_mir.rs | 14 | ||||
| -rw-r--r-- | src/librustc/mir/mod.rs | 11 | ||||
| -rw-r--r-- | src/librustc_mir/transform/add_validation.rs | 2 |
3 files changed, 20 insertions, 7 deletions
diff --git a/src/librustc/ich/impls_mir.rs b/src/librustc/ich/impls_mir.rs index dc41f981ed5..bef35fdc257 100644 --- a/src/librustc/ich/impls_mir.rs +++ b/src/librustc/ich/impls_mir.rs @@ -243,7 +243,19 @@ for mir::StatementKind<'tcx> { } } -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) }); diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 4655f8a9c15..f8261f80629 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -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 @@ impl Debug for ValidationOp { } } +// 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 @@ impl<'tcx> TypeFoldable<'tcx> for BasicBlockData<'tcx> { } } -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), diff --git a/src/librustc_mir/transform/add_validation.rs b/src/librustc_mir/transform/add_validation.rs index 1fe16fb98f2..005d793cd8b 100644 --- a/src/librustc_mir/transform/add_validation.rs +++ b/src/librustc_mir/transform/add_validation.rs @@ -88,7 +88,7 @@ impl MirPass for AddValidation { 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 } |
