diff options
| author | Ralf Jung <post@ralfj.de> | 2017-08-24 09:14:36 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-08-24 09:14:36 +0200 |
| commit | 3f3fadae6f9071ac1796f441323af6376fb01677 (patch) | |
| tree | 9c4f29a5b4cd3ca3b4edd7481a009f321b75a5f9 | |
| parent | 66108be99d6736d63e47c2f7f5b75ab703822557 (diff) | |
| parent | ae10b23a7c59ad28d5eceb8df042f38802064da0 (diff) | |
| download | rust-3f3fadae6f9071ac1796f441323af6376fb01677.tar.gz rust-3f3fadae6f9071ac1796f441323af6376fb01677.zip | |
Merge pull request #301 from RalfJung/mir-validate
More validation tests
| -rw-r--r-- | .travis.yml | 1 | ||||
| -rw-r--r-- | tests/compile-fail/validation_buggy_as_mut_slice.rs | 20 | ||||
| -rw-r--r-- | tests/run-pass/validation_lifetime_resolution.rs | 30 |
3 files changed, 51 insertions, 0 deletions
diff --git a/.travis.yml b/.travis.yml index ef15fa98d3f..c1d01419869 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ before_script: - cargo install xargo - export RUST_SYSROOT=$HOME/rust script: +- set -e - | # get ourselves a MIR-ful libstd xargo/build.sh diff --git a/tests/compile-fail/validation_buggy_as_mut_slice.rs b/tests/compile-fail/validation_buggy_as_mut_slice.rs new file mode 100644 index 00000000000..98eca8d3607 --- /dev/null +++ b/tests/compile-fail/validation_buggy_as_mut_slice.rs @@ -0,0 +1,20 @@ +#![allow(unused_variables)] + +// For some reason, the error location is different when using fullmir +// error-pattern: in conflict with lock WriteLock + +mod safe { + use std::slice::from_raw_parts_mut; + + pub fn as_mut_slice<T>(self_: &Vec<T>) -> &mut [T] { + unsafe { + from_raw_parts_mut(self_.as_ptr() as *mut T, self_.len()) + } + } +} + +fn main() { + let v = vec![0,1,2]; + let v1_ = safe::as_mut_slice(&v); + let v2_ = safe::as_mut_slice(&v); +} diff --git a/tests/run-pass/validation_lifetime_resolution.rs b/tests/run-pass/validation_lifetime_resolution.rs new file mode 100644 index 00000000000..4d919f73525 --- /dev/null +++ b/tests/run-pass/validation_lifetime_resolution.rs @@ -0,0 +1,30 @@ +trait Id { + type Out; + + fn id(self) -> Self::Out; +} + +impl<'a> Id for &'a mut i32 { + type Out = &'a mut i32; + + fn id(self) -> Self { self } +} + +impl<'a> Id for &'a mut u32 { + type Out = &'a mut u32; + + fn id(self) -> Self { self } +} + +fn foo<T>(mut x: T) where for<'a> &'a mut T: Id +{ + let x = &mut x; + let _y = x.id(); + // Inspecting the trace should show that _y has a type involving a local lifetime, when it gets validated. + // Unfortunately, there doesn't seem to be a way to actually have a test fail if it does not have the right + // type. Currently, this is NOT working correctly; see <https://github.com/solson/miri/issues/298>. +} + +fn main() { + foo(3) +} |
