From 348f782085ea60cbda5a1bd0beb8cd62b0ebd142 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 16 Oct 2018 12:44:04 +0200 Subject: [PATCH] add env var emulation test, and fix it complaining about leaks --- src/lib.rs | 11 +++++++++++ tests/run-pass/env.rs | 7 +++++++ 2 files changed, 18 insertions(+) create mode 100644 tests/run-pass/env.rs diff --git a/src/lib.rs b/src/lib.rs index 9ac703e2675b..47eaee6dfac3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -215,11 +215,22 @@ pub enum MiriMemoryKind { } impl Into> for MiriMemoryKind { + #[inline(always)] fn into(self) -> MemoryKind { MemoryKind::Machine(self) } } +impl MayLeak for MiriMemoryKind { + #[inline(always)] + fn may_leak(self) -> bool { + use MiriMemoryKind::*; + match self { + Rust | C => false, + Env | MutStatic => true, + } + } +} #[derive(Clone, PartialEq, Eq)] pub struct Evaluator<'tcx> { diff --git a/tests/run-pass/env.rs b/tests/run-pass/env.rs new file mode 100644 index 000000000000..c0bf883daf9c --- /dev/null +++ b/tests/run-pass/env.rs @@ -0,0 +1,7 @@ +use std::env; + +fn main() { + assert_eq!(env::var("MIRI_TEST"), Err(env::VarError::NotPresent)); + env::set_var("MIRI_TEST", "the answer"); + assert_eq!(env::var("MIRI_TEST"), Ok("the answer".to_owned())); +}