]> git.lizzy.rs Git - rust.git/commitdiff
add env var emulation test, and fix it complaining about leaks
authorRalf Jung <post@ralfj.de>
Tue, 16 Oct 2018 10:44:04 +0000 (12:44 +0200)
committerRalf Jung <post@ralfj.de>
Tue, 16 Oct 2018 16:35:27 +0000 (18:35 +0200)
src/lib.rs
tests/run-pass/env.rs [new file with mode: 0644]

index 9ac703e2675b1c7da368f886df8090b2f0a3f047..47eaee6dfac32a946d3cda844883bc3da3ac5c38 100644 (file)
@@ -215,11 +215,22 @@ pub enum MiriMemoryKind {
 }
 
 impl Into<MemoryKind<MiriMemoryKind>> for MiriMemoryKind {
+    #[inline(always)]
     fn into(self) -> MemoryKind<MiriMemoryKind> {
         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 (file)
index 0000000..c0bf883
--- /dev/null
@@ -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()));
+}