@@ -33,6 +33,14 @@ use crate::{
3333 DropErrorDetailsExt , TaskAbortExt as _,
3434} ;
3535
36+ macro_rules! kvs {
37+ ( $( $k: expr => $v: expr) ,+$( , ) ?) => {
38+ [
39+ $( ( Into :: into( $k) , Into :: into( $v) ) , ) +
40+ ] . into_iter( )
41+ } ;
42+ }
43+
3644pub mod limits;
3745
3846#[ derive( Debug , Clone , PartialEq , Eq ) ]
@@ -393,7 +401,7 @@ impl LowerRequest for ExecuteRequest {
393401
394402 let mut envs = HashMap :: new ( ) ;
395403 if self . backtrace {
396- envs. insert ( "RUST_BACKTRACE" . to_owned ( ) , "1" . to_owned ( ) ) ;
404+ envs. extend ( kvs ! ( "RUST_BACKTRACE" => "1" ) ) ;
397405 }
398406
399407 ExecuteCommandRequest {
@@ -522,7 +530,7 @@ impl LowerRequest for CompileRequest {
522530 }
523531 let mut envs = HashMap :: new ( ) ;
524532 if self . backtrace {
525- envs. insert ( "RUST_BACKTRACE" . to_owned ( ) , "1" . to_owned ( ) ) ;
533+ envs. extend ( kvs ! ( "RUST_BACKTRACE" => "1" ) ) ;
526534 }
527535
528536 ExecuteCommandRequest {
@@ -660,6 +668,7 @@ pub struct MiriRequest {
660668 pub channel : Channel ,
661669 pub crate_type : CrateType ,
662670 pub edition : Edition ,
671+ pub tests : bool ,
663672 pub aliasing_model : AliasingModel ,
664673 pub code : String ,
665674}
@@ -680,12 +689,25 @@ impl LowerRequest for MiriRequest {
680689 miriflags. push ( "-Zmiri-tree-borrows" ) ;
681690 }
682691
692+ miriflags. push ( "-Zmiri-disable-isolation" ) ;
693+
683694 let miriflags = miriflags. join ( " " ) ;
684695
696+ let subcommand = if self . tests { "test" } else { "run" } ;
697+
685698 ExecuteCommandRequest {
686699 cmd : "cargo" . to_owned ( ) ,
687- args : vec ! [ "miri-playground" . to_owned( ) ] ,
688- envs : HashMap :: from_iter ( [ ( "MIRIFLAGS" . to_owned ( ) , miriflags) ] ) ,
700+ args : [ "miri" , subcommand] . map ( Into :: into) . into ( ) ,
701+ envs : kvs ! {
702+ "MIRIFLAGS" => miriflags,
703+ // Be sure that `cargo miri` will not build a new
704+ // sysroot. Creating a sysroot takes a while and Miri
705+ // will build one by default if it's missing. If
706+ // `MIRI_SYSROOT` is set and the sysroot is missing,
707+ // it will error instead.
708+ "MIRI_SYSROOT" => "/playground/.cache/miri" ,
709+ }
710+ . collect ( ) ,
689711 cwd : None ,
690712 }
691713 }
@@ -1802,6 +1824,8 @@ impl Container {
18021824 . await
18031825 . context ( AcquirePermitSnafu ) ?;
18041826
1827+ trace ! ( ?execute_cargo, "starting cargo task" ) ;
1828+
18051829 let ( stdin_tx, mut stdin_rx) = mpsc:: channel ( 8 ) ;
18061830 let ( stdout_tx, stdout_rx) = mpsc:: channel ( 8 ) ;
18071831 let ( stderr_tx, stderr_rx) = mpsc:: channel ( 8 ) ;
@@ -3954,15 +3978,15 @@ mod tests {
39543978 channel : Channel :: Nightly ,
39553979 crate_type : CrateType :: Binary ,
39563980 edition : Edition :: Rust2021 ,
3981+ tests : false ,
39573982 aliasing_model : AliasingModel :: Stacked ,
39583983 code : String :: new ( ) ,
39593984 } ;
39603985
39613986 #[ tokio:: test]
39623987 #[ snafu:: report]
39633988 async fn miri ( ) -> Result < ( ) > {
3964- // cargo-miri-playground only exists inside the container
3965- let coordinator = new_coordinator_docker ( ) ;
3989+ let coordinator = new_coordinator ( ) ;
39663990
39673991 let req = MiriRequest {
39683992 code : r#"
@@ -3987,6 +4011,36 @@ mod tests {
39874011 Ok ( ( ) )
39884012 }
39894013
4014+ #[ tokio:: test]
4015+ #[ snafu:: report]
4016+ async fn miri_tests ( ) -> Result < ( ) > {
4017+ let coordinator = new_coordinator ( ) ;
4018+
4019+ let req = MiriRequest {
4020+ tests : true ,
4021+ code : r#"
4022+ #[test]
4023+ fn oops() {
4024+ unsafe { core::mem::MaybeUninit::<u8>::uninit().assume_init() };
4025+ }
4026+ "#
4027+ . into ( ) ,
4028+ ..ARBITRARY_MIRI_REQUEST
4029+ } ;
4030+
4031+ let response = coordinator. miri ( req) . with_timeout ( ) . await . unwrap ( ) ;
4032+
4033+ assert ! ( !response. success, "stderr: {}" , response. stderr) ;
4034+
4035+ assert_contains ! ( response. stderr, "Undefined Behavior" ) ;
4036+ assert_contains ! ( response. stderr, "using uninitialized data" ) ;
4037+ assert_contains ! ( response. stderr, "operation requires initialized memory" ) ;
4038+
4039+ coordinator. shutdown ( ) . await ?;
4040+
4041+ Ok ( ( ) )
4042+ }
4043+
39904044 const ARBITRARY_MACRO_EXPANSION_REQUEST : MacroExpansionRequest = MacroExpansionRequest {
39914045 channel : Channel :: Nightly ,
39924046 crate_type : CrateType :: Library ( LibraryType :: Cdylib ) ,
0 commit comments