Merge branch 'master' into oli-obk-patch-1
This commit is contained in:
commit
f42b708568
16
.travis.yml
16
.travis.yml
@ -11,7 +11,7 @@ os:
|
||||
- osx
|
||||
|
||||
before_script:
|
||||
# macOS weirdness (https://github.com/travis-ci/travis-ci/issues/6307)
|
||||
# macOS weirdness (https://github.com/travis-ci/travis-ci/issues/6307, https://github.com/travis-ci/travis-ci/issues/10165)
|
||||
- if [[ "$TRAVIS_OS_NAME" == osx ]]; then rvm get stable; fi
|
||||
# Compute the rust version we use. We do not use "language: rust" to have more control here.
|
||||
- |
|
||||
@ -28,8 +28,6 @@ before_script:
|
||||
- rustup target add i686-unknown-linux-gnu
|
||||
- rustup target add i686-pc-windows-gnu
|
||||
- rustup target add i686-pc-windows-msvc
|
||||
- rustup component add rust-src
|
||||
- cargo install xargo || echo "Skipping xargo install"
|
||||
|
||||
script:
|
||||
- set -e
|
||||
@ -39,11 +37,15 @@ script:
|
||||
cargo test --release --all-features &&
|
||||
cargo install --all-features --force --path .
|
||||
- |
|
||||
# get ourselves a MIR-full libstd
|
||||
xargo/build.sh &&
|
||||
export MIRI_SYSROOT=~/.xargo/HOST
|
||||
# Get ourselves a MIR-full libstd, and use it henceforth
|
||||
cargo miri setup &&
|
||||
if [ "$TRAVIS_OS_NAME" == osx ]; then
|
||||
export MIRI_SYSROOT=~/Library/Caches/miri.miri.miri/HOST
|
||||
else
|
||||
export MIRI_SYSROOT=~/.cache/miri/HOST
|
||||
fi
|
||||
- |
|
||||
# run all tests with full mir
|
||||
# Test miri with full MIR
|
||||
cargo test --release --all-features
|
||||
- |
|
||||
# Test cargo integration
|
||||
|
@ -35,6 +35,7 @@ required-features = ["rustc_tests"]
|
||||
[dependencies]
|
||||
byteorder = { version = "1.1", features = ["i128"]}
|
||||
cargo_metadata = { version = "0.6", optional = true }
|
||||
directories = { version = "1.0", optional = true }
|
||||
env_logger = "0.5"
|
||||
log = "0.4"
|
||||
|
||||
@ -42,7 +43,8 @@ log = "0.4"
|
||||
vergen = "3"
|
||||
|
||||
[features]
|
||||
cargo_miri = ["cargo_metadata"]
|
||||
default = ["cargo_miri"]
|
||||
cargo_miri = ["cargo_metadata", "directories"]
|
||||
rustc_tests = []
|
||||
|
||||
[dev-dependencies]
|
||||
|
79
README.md
79
README.md
@ -42,7 +42,7 @@ in this directory.
|
||||
|
||||
[rustup]: https://www.rustup.rs
|
||||
|
||||
## Running Miri
|
||||
## Running Miri on tiny examples
|
||||
|
||||
```sh
|
||||
cargo +nightly run -- -Zmiri-disable-validation tests/run-pass/vecs.rs # Or whatever test you like.
|
||||
@ -51,74 +51,47 @@ cargo +nightly run -- -Zmiri-disable-validation tests/run-pass/vecs.rs # Or what
|
||||
We have to disable validation because that can lead to errors when libstd is not
|
||||
compiled the right way.
|
||||
|
||||
## Running Miri with full libstd
|
||||
|
||||
Per default libstd does not contain the MIR of non-polymorphic functions, and
|
||||
also does not contain some extra MIR statements that miri needs for validation.
|
||||
When Miri hits a call to such a function, execution terminates, and even when
|
||||
the MIR is present, validation can fail. To fix this, it is possible to compile
|
||||
libstd with full MIR:
|
||||
|
||||
```sh
|
||||
rustup component add --toolchain nightly rust-src
|
||||
cargo +nightly install xargo
|
||||
rustup run nightly xargo/build.sh
|
||||
```
|
||||
|
||||
Now you can run Miri against the libstd compiled by xargo:
|
||||
|
||||
```sh
|
||||
MIRI_SYSROOT=~/.xargo/HOST cargo +nightly run tests/run-pass-fullmir/hashmap.rs
|
||||
```
|
||||
|
||||
Notice that you will have to re-run the last step of the preparations above
|
||||
(`xargo/build.sh`) when your toolchain changes (e.g., when you update the
|
||||
nightly).
|
||||
|
||||
## Running Miri on your own project('s test suite)
|
||||
|
||||
Install Miri as a cargo subcommand with `cargo +nightly install --all-features
|
||||
--path .`. Be aware that if you used `rustup override set` to fix a particular
|
||||
Rust version for the miri directory, that will *not* apply to your own project
|
||||
directory! You have to use a consistent Rust version for building miri and your
|
||||
project for this to work, so remember to either always specify the nightly
|
||||
version manually, overriding it in your project directory as well, or use
|
||||
`rustup default nightly` (or `rustup default nightly-YYYY-MM-DD`) to globally
|
||||
make `nightly` the default toolchain.
|
||||
Install Miri as a cargo subcommand:
|
||||
|
||||
We assume that you have prepared a MIR-enabled libstd as described above. Now
|
||||
compile your project and its dependencies against that libstd:
|
||||
```sh
|
||||
cargo +nightly install --git https://github.com/solson/miri/ miri
|
||||
```
|
||||
|
||||
1. Run `cargo clean` to eliminate any cached dependencies that were built against
|
||||
the non-MIR `libstd`.
|
||||
2. To run all tests in your project through, Miri, use
|
||||
`MIRI_SYSROOT=~/.xargo/HOST cargo +nightly miri test`. **NOTE**: This is
|
||||
currently broken, see the discussion in
|
||||
[#479](https://github.com/solson/miri/issues/479).
|
||||
3. If you have a binary project, you can run it through Miri using
|
||||
`MIRI_SYSROOT=~/.xargo/HOST cargo +nightly miri`.
|
||||
Be aware that if you used `rustup override set` to fix a particular Rust version
|
||||
for the miri directory, that will *not* apply to your own project directory!
|
||||
You have to use a consistent Rust version for building miri and your project for
|
||||
this to work, so remember to either always specify the nightly version manually,
|
||||
overriding it in your project directory as well, or use `rustup default nightly`
|
||||
(or `rustup default nightly-YYYY-MM-DD`) to globally make `nightly` the default
|
||||
toolchain.
|
||||
|
||||
1. Run `cargo clean` to eliminate any cached dependencies. Miri needs your
|
||||
dependencies to be compiled the right way, that would not happen if they have
|
||||
previously already been compiled.
|
||||
2. To run all tests in your project through Miri, use `cargo +nightly miri test`.
|
||||
**NOTE**: This is currently broken, see the discussion in
|
||||
[#479](https://github.com/solson/miri/issues/479).
|
||||
3. If you have a binary project, you can run it through Miri using `cargo
|
||||
+nightly miri run`.
|
||||
|
||||
### Common Problems
|
||||
|
||||
When using the above instructions, you may encounter a number of confusing compiler
|
||||
errors.
|
||||
|
||||
#### "constant evaluation error: no mir for `<function>`"
|
||||
|
||||
You may have forgotten to set `MIRI_SYSROOT` when calling `cargo miri`, and
|
||||
your program called into `std` or `core`. Be sure to set `MIRI_SYSROOT=~/.xargo/HOST`.
|
||||
|
||||
#### "found possibly newer version of crate `std` which `<dependency>` depends on"
|
||||
|
||||
Your build directory may contain artifacts from an earlier build that did/did not
|
||||
have `MIRI_SYSROOT` set. Run `cargo clean` before switching from non-Miri to Miri
|
||||
builds and vice-versa.
|
||||
Your build directory may contain artifacts from an earlier build that have/have
|
||||
not been built for Miri. Run `cargo clean` before switching from non-Miri to
|
||||
Miri builds and vice-versa.
|
||||
|
||||
#### "found crate `std` compiled by an incompatible version of rustc"
|
||||
|
||||
You may be running `cargo miri` with a different compiler version than the one
|
||||
used to build the MIR-enabled `std`. Be sure to consistently use the same toolchain,
|
||||
which should be the toolchain specified in the `rust-version` file.
|
||||
used to build the custom libstd that Miri uses, and Miri failed to detect that.
|
||||
Try deleting `~/.cache/miri`.
|
||||
|
||||
## Miri `-Z` flags
|
||||
|
||||
|
16
appveyor.yml
16
appveyor.yml
@ -21,25 +21,19 @@ install:
|
||||
- rustup-init.exe -y --default-host %TARGET% --default-toolchain %RUST_TOOLCHAIN%
|
||||
- set PATH=%USERPROFILE%\.cargo\bin;%PATH%
|
||||
- rustc --version
|
||||
# Customize installation.
|
||||
- rustup component add rust-src
|
||||
- cargo install xargo
|
||||
# Prepare a libstd with MIR (cannot use bash script, obviously).
|
||||
# The flags here should be kept in sync with `add_miri_default_args` in `src/lib.rs`.
|
||||
- cd xargo
|
||||
- set RUSTFLAGS=-Zalways-encode-mir -Zmir-emit-retag -Zmir-opt-level=0
|
||||
- xargo build
|
||||
- set RUSTFLAGS=
|
||||
- cd ..
|
||||
|
||||
build: false
|
||||
|
||||
test_script:
|
||||
- set RUSTFLAGS=-g
|
||||
- set RUST_BACKTRACE=1
|
||||
# Test plain miri
|
||||
- cargo build --release --all-features --all-targets
|
||||
- cargo test --release --all-features
|
||||
- set MIRI_SYSROOT=%USERPROFILE%\.xargo\HOST
|
||||
# Get ourselves a MIR-full libstd, and use it henceforth
|
||||
- cargo run --release --all-features --bin cargo-miri -- miri setup
|
||||
- set MIRI_SYSROOT=%USERPROFILE%\AppData\Local\miri\miri\cache\HOST
|
||||
# Test miri with full MIR
|
||||
- cargo test --release --all-features
|
||||
|
||||
notifications:
|
||||
|
@ -8,10 +8,10 @@ and the working directory to contain the cargo-miri-test project.
|
||||
import sys, subprocess
|
||||
|
||||
def test_cargo_miri():
|
||||
print("==> Testing `cargo miri` <==")
|
||||
print("==> Testing `cargo miri run` <==")
|
||||
## Call `cargo miri`, capture all output
|
||||
p = subprocess.Popen(
|
||||
["cargo", "miri", "-q"],
|
||||
["cargo", "miri", "run", "-q"],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE
|
||||
)
|
||||
|
@ -1,14 +1,21 @@
|
||||
#![feature(inner_deref)]
|
||||
|
||||
extern crate cargo_metadata;
|
||||
|
||||
use std::path::{PathBuf, Path};
|
||||
use std::io::Write;
|
||||
use std::io::{self, Write};
|
||||
use std::process::Command;
|
||||
|
||||
use std::fs::{self, File};
|
||||
|
||||
const CARGO_MIRI_HELP: &str = r#"Interprets bin crates
|
||||
|
||||
Usage:
|
||||
cargo miri [options] [--] [<opts>...]
|
||||
cargo miri [subcommand] [options] [--] [<opts>...]
|
||||
|
||||
Subcommands:
|
||||
run Run binaries (default)
|
||||
test Run tests
|
||||
setup Only perform automatic setup, but without asking questions (for getting a proper libstd)
|
||||
|
||||
Common options:
|
||||
-h, --help Print this message
|
||||
@ -25,6 +32,13 @@ it to configure the resource limits
|
||||
available resource limits are `memory_size`, `step_limit`, `stack_limit`
|
||||
"#;
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
enum MiriCommand {
|
||||
Run,
|
||||
Test,
|
||||
Setup,
|
||||
}
|
||||
|
||||
fn show_help() {
|
||||
println!("{}", CARGO_MIRI_HELP);
|
||||
}
|
||||
@ -34,6 +48,145 @@ fn show_version() {
|
||||
env!("CARGO_PKG_VERSION"), env!("VERGEN_SHA_SHORT"), env!("VERGEN_COMMIT_DATE"));
|
||||
}
|
||||
|
||||
fn show_error(msg: String) -> ! {
|
||||
eprintln!("fatal error: {}", msg);
|
||||
std::process::exit(1)
|
||||
}
|
||||
|
||||
fn list_targets(mut args: impl Iterator<Item=String>) -> impl Iterator<Item=cargo_metadata::Target> {
|
||||
// We need to get the manifest, and then the metadata, to enumerate targets.
|
||||
let manifest_path_arg = args.find(|val| {
|
||||
val.starts_with("--manifest-path=")
|
||||
});
|
||||
|
||||
let mut metadata = if let Ok(metadata) = cargo_metadata::metadata(
|
||||
manifest_path_arg.as_ref().map(AsRef::as_ref),
|
||||
)
|
||||
{
|
||||
metadata
|
||||
} else {
|
||||
show_error(format!("error: Could not obtain cargo metadata."));
|
||||
};
|
||||
|
||||
let manifest_path = manifest_path_arg.map(|arg| {
|
||||
PathBuf::from(Path::new(&arg["--manifest-path=".len()..]))
|
||||
});
|
||||
|
||||
let current_dir = std::env::current_dir();
|
||||
|
||||
let package_index = metadata
|
||||
.packages
|
||||
.iter()
|
||||
.position(|package| {
|
||||
let package_manifest_path = Path::new(&package.manifest_path);
|
||||
if let Some(ref manifest_path) = manifest_path {
|
||||
package_manifest_path == manifest_path
|
||||
} else {
|
||||
let current_dir = current_dir.as_ref().expect(
|
||||
"could not read current directory",
|
||||
);
|
||||
let package_manifest_directory = package_manifest_path.parent().expect(
|
||||
"could not find parent directory of package manifest",
|
||||
);
|
||||
package_manifest_directory == current_dir
|
||||
}
|
||||
})
|
||||
.expect("could not find matching package");
|
||||
let package = metadata.packages.remove(package_index);
|
||||
|
||||
// Finally we got the list of targets to build
|
||||
package.targets.into_iter()
|
||||
}
|
||||
|
||||
fn ask(question: &str) {
|
||||
let mut buf = String::new();
|
||||
print!("{} [Y/n] ", question);
|
||||
io::stdout().flush().unwrap();
|
||||
io::stdin().read_line(&mut buf).unwrap();
|
||||
match buf.trim().to_lowercase().as_ref() {
|
||||
"" | "y" | "yes" => {}, // proceed
|
||||
"n" | "no" => show_error(format!("Aborting as per your request")),
|
||||
a => show_error(format!("I do not understand `{}`", a))
|
||||
};
|
||||
}
|
||||
|
||||
/// Perform the setup requires to make `cargo miri` work: Getting a custom-built libstd. Then sets MIRI_SYSROOT.
|
||||
/// Skipped if MIRI_SYSROOT is already set, in that case we expect the user has done all this already.
|
||||
fn setup(ask_user: bool) {
|
||||
if std::env::var("MIRI_SYSROOT").is_ok() {
|
||||
return;
|
||||
}
|
||||
|
||||
// First, we need xargo
|
||||
if Command::new("xargo").arg("--version").output().is_err()
|
||||
{
|
||||
if ask_user {
|
||||
ask("It seems you do not have xargo installed. I will run `cargo install xargo`. Proceed?");
|
||||
} else {
|
||||
println!("Installing xargo: `cargo install xargo`");
|
||||
}
|
||||
if !Command::new("cargo").args(&["install", "xargo"]).status().unwrap().success() {
|
||||
show_error(format!("Failed to install xargo"));
|
||||
}
|
||||
}
|
||||
|
||||
// Then, we also need rust-src. Let's see if it is already installed.
|
||||
let sysroot = Command::new("rustc").args(&["--print", "sysroot"]).output().unwrap().stdout;
|
||||
let sysroot = std::str::from_utf8(&sysroot[..]).unwrap();
|
||||
let src = Path::new(sysroot.trim_end_matches('\n')).join("lib").join("rustlib").join("src");
|
||||
if !src.exists() {
|
||||
if ask_user {
|
||||
ask("It seems you do not have the rust-src component installed. I will run `rustup component add rust-src`. Proceed?");
|
||||
} else {
|
||||
println!("Installing rust-src component: `rustup component add rust-src`");
|
||||
}
|
||||
if !Command::new("rustup").args(&["component", "add", "rust-src"]).status().unwrap().success() {
|
||||
show_error(format!("Failed to install rust-src component"));
|
||||
}
|
||||
}
|
||||
|
||||
// Next, we need our own libstd. We will do this work in whatever is a good cache dir for this platform.
|
||||
let dirs = directories::ProjectDirs::from("miri", "miri", "miri").unwrap();
|
||||
let dir = dirs.cache_dir();
|
||||
if !dir.exists() {
|
||||
println!("Creating `{}` and using it for miri's build of libstd", dir.display());
|
||||
fs::create_dir_all(&dir).unwrap();
|
||||
}
|
||||
// The interesting bit: Xargo.toml
|
||||
File::create(dir.join("Xargo.toml")).unwrap()
|
||||
.write_all(br#"
|
||||
[dependencies.std]
|
||||
features = ["panic_unwind"]
|
||||
|
||||
[dependencies.test]
|
||||
stage = 1
|
||||
"#).unwrap();
|
||||
// The boring bits: A dummy project for xargo
|
||||
File::create(dir.join("Cargo.toml")).unwrap()
|
||||
.write_all(br#"
|
||||
[package]
|
||||
name = "miri-xargo"
|
||||
description = "A dummy project for building libstd with xargo."
|
||||
version = "0.0.0"
|
||||
|
||||
[lib]
|
||||
path = "lib.rs"
|
||||
"#).unwrap();
|
||||
File::create(dir.join("lib.rs")).unwrap();
|
||||
// Run xargo
|
||||
if !Command::new("xargo").arg("build").arg("-q")
|
||||
.current_dir(&dir)
|
||||
.env("RUSTFLAGS", miri::miri_default_args().join(" "))
|
||||
.env("XARGO_HOME", dir.to_str().unwrap())
|
||||
.status().unwrap().success()
|
||||
{
|
||||
show_error(format!("Failed to run xargo"));
|
||||
}
|
||||
|
||||
// That should be it!
|
||||
std::env::set_var("MIRI_SYSROOT", dir.join("HOST"));
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Check for version and help flags even when invoked as 'cargo-miri'
|
||||
if std::env::args().any(|a| a == "--help" || a == "-h") {
|
||||
@ -51,61 +204,31 @@ fn main() {
|
||||
// binary so that we come back in the other branch, and dispatch
|
||||
// the invocations to rustc and miri, respectively.
|
||||
|
||||
let test = std::env::args().nth(2).map_or(false, |text| text == "test");
|
||||
let skip = if test { 3 } else { 2 };
|
||||
|
||||
// We need to get the manifest, and then the metadata, to enumerate targets.
|
||||
let manifest_path_arg = std::env::args().skip(skip).find(|val| {
|
||||
val.starts_with("--manifest-path=")
|
||||
});
|
||||
|
||||
let mut metadata = if let Ok(metadata) = cargo_metadata::metadata(
|
||||
manifest_path_arg.as_ref().map(AsRef::as_ref),
|
||||
)
|
||||
{
|
||||
metadata
|
||||
} else {
|
||||
let _ = std::io::stderr().write_fmt(format_args!(
|
||||
"error: Could not obtain cargo metadata."
|
||||
));
|
||||
std::process::exit(101);
|
||||
let (subcommand, skip) = match std::env::args().nth(2).deref() {
|
||||
Some("test") => (MiriCommand::Test, 3),
|
||||
Some("run") => (MiriCommand::Run, 3),
|
||||
Some("setup") => (MiriCommand::Setup, 3),
|
||||
// Default command, if there is an option or nothing
|
||||
Some(s) if s.starts_with("-") => (MiriCommand::Run, 2),
|
||||
None => (MiriCommand::Run, 2),
|
||||
// Unvalid command
|
||||
Some(s) => {
|
||||
show_error(format!("Unknown command `{}`", s))
|
||||
}
|
||||
};
|
||||
|
||||
let manifest_path = manifest_path_arg.map(|arg| {
|
||||
PathBuf::from(Path::new(&arg["--manifest-path=".len()..]))
|
||||
});
|
||||
// We always setup
|
||||
let ask = subcommand != MiriCommand::Setup;
|
||||
setup(ask);
|
||||
|
||||
let current_dir = std::env::current_dir();
|
||||
|
||||
let package_index = metadata
|
||||
.packages
|
||||
.iter()
|
||||
.position(|package| {
|
||||
let package_manifest_path = Path::new(&package.manifest_path);
|
||||
if let Some(ref manifest_path) = manifest_path {
|
||||
package_manifest_path == manifest_path
|
||||
} else {
|
||||
let current_dir = current_dir.as_ref().expect(
|
||||
"could not read current directory",
|
||||
);
|
||||
let package_manifest_directory = package_manifest_path.parent().expect(
|
||||
"could not find parent directory of package manifest",
|
||||
);
|
||||
package_manifest_directory == current_dir
|
||||
}
|
||||
})
|
||||
.expect("could not find matching package");
|
||||
let package = metadata.packages.remove(package_index);
|
||||
|
||||
// Finally we got the metadata, iterate all targets and see for which ones
|
||||
// we do anything.
|
||||
for target in package.targets {
|
||||
// Now run the command.
|
||||
for target in list_targets(std::env::args().skip(skip)) {
|
||||
let args = std::env::args().skip(skip);
|
||||
let kind = target.kind.get(0).expect(
|
||||
"badly formatted cargo metadata: target::kind is an empty array",
|
||||
);
|
||||
match (test, &kind[..]) {
|
||||
(true, "test") => {
|
||||
match (subcommand, &kind[..]) {
|
||||
(MiriCommand::Test, "test") => {
|
||||
// For test binaries we call `cargo rustc --test target -- <rustc args>`
|
||||
if let Err(code) = process(
|
||||
vec!["--test".to_string(), target.name].into_iter().chain(
|
||||
@ -116,7 +239,7 @@ fn main() {
|
||||
std::process::exit(code);
|
||||
}
|
||||
}
|
||||
(true, "lib") => {
|
||||
(MiriCommand::Test, "lib") => {
|
||||
// For libraries we call `cargo rustc -- --test <rustc args>`
|
||||
// Notice now that `--test` is a rustc arg rather than a cargo arg. This tells
|
||||
// rustc to build a test harness which calls all #[test] functions. We don't
|
||||
@ -131,7 +254,7 @@ fn main() {
|
||||
std::process::exit(code);
|
||||
}
|
||||
}
|
||||
(false, "bin") => {
|
||||
(MiriCommand::Run, "bin") => {
|
||||
// For ordinary binaries we call `cargo rustc --bin target -- <rustc args>`
|
||||
if let Err(code) = process(
|
||||
vec!["--bin".to_string(), target.name].into_iter().chain(
|
||||
|
@ -1,6 +1,6 @@
|
||||
#![feature(rustc_private)]
|
||||
|
||||
#![cfg_attr(feature = "cargo-clippy", allow(cast_lossless))]
|
||||
#![allow(clippy::cast_lossless)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
@ -54,8 +54,7 @@ pub use crate::stacked_borrows::{Borrow, Stack, Stacks, BorStackItem};
|
||||
/// set per default, for maximal validation power.
|
||||
pub fn miri_default_args() -> &'static [&'static str] {
|
||||
// The flags here should be kept in sync with what bootstrap adds when `test-miri` is
|
||||
// set, which happens in `bootstrap/bin/rustc.rs` in the rustc sources; and also
|
||||
// kept in sync with `xargo/build.sh` in this repo and `appveyor.yml`.
|
||||
// set, which happens in `bootstrap/bin/rustc.rs` in the rustc sources.
|
||||
&["-Zalways-encode-mir", "-Zmir-emit-retag", "-Zmir-opt-level=0"]
|
||||
}
|
||||
|
||||
|
@ -2,5 +2,5 @@
|
||||
fn main() {
|
||||
let v = [1i8, 2];
|
||||
let x = &v[1] as *const i8;
|
||||
let _ = unsafe { x.offset(isize::min_value()) };
|
||||
let _val = unsafe { x.offset(isize::min_value()) };
|
||||
}
|
||||
|
@ -12,5 +12,5 @@ pub enum Foo {
|
||||
|
||||
fn main() {
|
||||
let f = unsafe { std::mem::transmute::<i32, Foo>(42) };
|
||||
let _ = mem::discriminant(&f);
|
||||
let _val = mem::discriminant(&f);
|
||||
}
|
||||
|
@ -3,5 +3,5 @@ fn main() {
|
||||
let y = &x;
|
||||
let z = &y as *const &i32 as *const usize;
|
||||
let ptr_bytes = unsafe { *z }; // the actual deref is fine, because we read the entire pointer at once
|
||||
let _ = ptr_bytes / 432; //~ ERROR invalid arithmetic on pointers that would leak base addresses
|
||||
let _val = ptr_bytes / 432; //~ ERROR invalid arithmetic on pointers that would leak base addresses
|
||||
}
|
||||
|
@ -3,5 +3,5 @@ fn main() {
|
||||
let y = &x;
|
||||
let z = &y as *const &i32 as *const u8;
|
||||
// the deref fails, because we are reading only a part of the pointer
|
||||
let _ = unsafe { *z }; //~ ERROR tried to access part of a pointer value as raw bytes
|
||||
let _val = unsafe { *z }; //~ ERROR tried to access part of a pointer value as raw bytes
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
fn main() {
|
||||
let val = 13usize;
|
||||
let addr = &val as *const _ as usize;
|
||||
let _ = addr & 13; //~ ERROR access part of a pointer value as raw bytes
|
||||
let _val = addr & 13; //~ ERROR access part of a pointer value as raw bytes
|
||||
}
|
||||
|
@ -4,5 +4,5 @@ fn main() {
|
||||
let x = x as *const i32;
|
||||
let x = x as u8; //~ ERROR a raw memory access tried to access part of a pointer value as raw bytes
|
||||
let x = x as *const i32;
|
||||
let _ = unsafe { *x };
|
||||
let _val = unsafe { *x };
|
||||
}
|
||||
|
@ -3,6 +3,6 @@
|
||||
fn main() {
|
||||
// Can't offset an integer pointer by non-zero offset.
|
||||
unsafe {
|
||||
let _ = (1 as *mut u8).offset(1);
|
||||
let _val = (1 as *mut u8).offset(1);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,6 @@ fn main() {
|
||||
let ptr = Box::into_raw(Box::new(0u32));
|
||||
// Can't start with an integer pointer and get to something usable
|
||||
unsafe {
|
||||
let _ = (1 as *mut u8).offset(ptr as isize);
|
||||
let _val = (1 as *mut u8).offset(ptr as isize);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
fn main() {
|
||||
let val = 13usize;
|
||||
let addr = &val as *const _ as usize;
|
||||
let _ = addr % 16; //~ ERROR access part of a pointer value as raw bytes
|
||||
let _val = addr % 16; //~ ERROR access part of a pointer value as raw bytes
|
||||
}
|
||||
|
@ -4,5 +4,5 @@ fn main() {
|
||||
let ptr = Box::into_raw(Box::new(0u32));
|
||||
// Can't start with an integer pointer and get to something usable
|
||||
let ptr = (1 as *mut u8).wrapping_offset(ptr as isize);
|
||||
let _ = unsafe { *ptr };
|
||||
let _val = unsafe { *ptr };
|
||||
}
|
||||
|
@ -10,5 +10,5 @@ fn main() {
|
||||
let bad = unsafe {
|
||||
std::mem::transmute::<&[u8], [u8; 8]>(&[1u8])
|
||||
};
|
||||
let _ = bad[0] + bad[bad.len()-1]; //~ ERROR a raw memory access tried to access part of a pointer value as raw bytes
|
||||
let _val = bad[0] + bad[bad.len()-1]; //~ ERROR a raw memory access tried to access part of a pointer value as raw bytes
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
fn main() {
|
||||
assert!(std::char::from_u32(-1_i32 as u32).is_none());
|
||||
let _ = match unsafe { std::mem::transmute::<i32, char>(-1) } { //~ ERROR encountered 4294967295, but expected something less or equal to 1114111
|
||||
let _val = match unsafe { std::mem::transmute::<i32, char>(-1) } { //~ ERROR encountered 4294967295, but expected something less or equal to 1114111
|
||||
'a' => {true},
|
||||
'b' => {false},
|
||||
_ => {true},
|
||||
|
@ -1,4 +1,4 @@
|
||||
fn main() {
|
||||
let x = &() as *const () as *const i32;
|
||||
let _ = unsafe { *x }; //~ ERROR access memory with alignment 1, but alignment 4 is required
|
||||
let _val = unsafe { *x }; //~ ERROR access memory with alignment 1, but alignment 4 is required
|
||||
}
|
||||
|
@ -3,6 +3,6 @@ use std::panic::{catch_unwind, AssertUnwindSafe};
|
||||
|
||||
fn main() {
|
||||
let mut i = 3;
|
||||
let _ = catch_unwind(AssertUnwindSafe(|| {i -= 2;} ));
|
||||
let _val = catch_unwind(AssertUnwindSafe(|| {i -= 2;} ));
|
||||
println!("{}", i);
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
fn main() {
|
||||
let _ = ::std::str::from_utf8(b"a");
|
||||
let _val = ::std::str::from_utf8(b"a");
|
||||
}
|
||||
|
@ -5,15 +5,15 @@ use std::sync;
|
||||
|
||||
fn main() {
|
||||
let m = sync::Mutex::new(0);
|
||||
let _ = m.lock();
|
||||
drop(m.lock());
|
||||
drop(m);
|
||||
|
||||
// We don't provide RwLock on Windows
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
{
|
||||
let rw = sync::RwLock::new(0);
|
||||
let _ = rw.read();
|
||||
let _ = rw.write();
|
||||
drop(rw.read());
|
||||
drop(rw.write());
|
||||
drop(rw);
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ fn main() {
|
||||
// this closure never by val uses its captures
|
||||
// so it's basically a fn(&self)
|
||||
// the shim used to not drop the `x`
|
||||
let x = move || { let _ = x; };
|
||||
let x = move || { let _val = x; };
|
||||
f(x);
|
||||
}
|
||||
assert!(ran_drop);
|
||||
|
@ -3,5 +3,5 @@
|
||||
fn main() {
|
||||
// With the nested Vec, this is calling Offset(Unique::empty(), 0) on drop.
|
||||
let args : Vec<Vec<i32>> = Vec::new();
|
||||
let _ = box args;
|
||||
let _val = box args;
|
||||
}
|
||||
|
@ -13,5 +13,5 @@
|
||||
fn main() {
|
||||
let functions: [Box<Fn() -> Option<()>>; 1] = [Box::new(|| None)];
|
||||
|
||||
let _: Option<Vec<()>> = functions.iter().map(|f| (*f)()).collect();
|
||||
let _val: Option<Vec<()>> = functions.iter().map(|f| (*f)()).collect();
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ fn main() {
|
||||
let mut x = 0;
|
||||
{
|
||||
let wrapper = Box::new(Wrapper(&mut x, 123));
|
||||
let _: Box<Wrapper<Send>> = wrapper;
|
||||
let _val: Box<Wrapper<Send>> = wrapper;
|
||||
}
|
||||
assert_eq!(432, x)
|
||||
}
|
||||
|
@ -15,5 +15,5 @@ trait Foo {}
|
||||
impl Foo for [u8; 2] {}
|
||||
|
||||
fn main() {
|
||||
let _: Arc<Foo + Send> = Arc::new([3, 4]);
|
||||
let _val: Arc<Foo + Send> = Arc::new([3, 4]);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
pub fn main() {
|
||||
let bytes: [u8; 8] = unsafe { ::std::mem::transmute(0u64) };
|
||||
let _: &[u8] = &bytes;
|
||||
let _val: &[u8] = &bytes;
|
||||
}
|
||||
|
@ -27,6 +27,6 @@ fn foo(i:isize, j: char) -> Foo {
|
||||
|
||||
pub fn main() {
|
||||
let (tx, rx) = channel();
|
||||
let _ = tx.send(foo(42, 'c'));
|
||||
let _ = rx;
|
||||
tx.send(foo(42, 'c')).unwrap();
|
||||
let _val = rx;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ fn slice_of_zst() {
|
||||
fn foo<T>(v: &[T]) -> Option<&[T]> {
|
||||
let mut it = v.iter();
|
||||
for _ in 0..5 {
|
||||
let _ = it.next();
|
||||
it.next();
|
||||
}
|
||||
Some(it.as_slice())
|
||||
}
|
||||
@ -12,7 +12,7 @@ fn slice_of_zst() {
|
||||
fn foo_mut<T>(v: &mut [T]) -> Option<&mut [T]> {
|
||||
let mut it = v.iter_mut();
|
||||
for _ in 0..5 {
|
||||
let _ = it.next();
|
||||
it.next();
|
||||
}
|
||||
Some(it.into_slice())
|
||||
}
|
||||
|
4
xargo/Cargo.lock
generated
4
xargo/Cargo.lock
generated
@ -1,4 +0,0 @@
|
||||
[[package]]
|
||||
name = "miri-xargo"
|
||||
version = "0.0.0"
|
||||
|
@ -1,6 +0,0 @@
|
||||
[package]
|
||||
name = "miri-xargo"
|
||||
description = "A dummy project for building libstd with xargo."
|
||||
version = "0.0.0"
|
||||
|
||||
[dependencies]
|
@ -1,5 +0,0 @@
|
||||
[dependencies.std]
|
||||
features = ["panic_unwind", "backtrace"]
|
||||
|
||||
[dependencies.test]
|
||||
stage = 1
|
@ -1,4 +0,0 @@
|
||||
#!/bin/sh
|
||||
cd "$(dirname "$0")"
|
||||
# The flags here should be kept in sync with `add_miri_default_args` in `src/lib.rs`.
|
||||
RUSTFLAGS='-Zalways-encode-mir -Zmir-emit-retag -Zmir-opt-level=0' xargo build
|
Loading…
x
Reference in New Issue
Block a user