@@ -73,51 +73,47 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
7373 fn after_analysis < ' tcx > (
7474 & mut self ,
7575 _: & rustc_interface:: interface:: Compiler ,
76- queries : & ' tcx rustc_interface :: Queries < ' tcx > ,
76+ tcx : TyCtxt < ' tcx > ,
7777 ) -> Compilation {
78- queries. global_ctxt ( ) . unwrap ( ) . enter ( |tcx| {
79- if tcx. sess . dcx ( ) . has_errors_or_delayed_bugs ( ) . is_some ( ) {
80- tcx. dcx ( ) . fatal ( "miri cannot be run on programs that fail compilation" ) ;
81- }
78+ if tcx. sess . dcx ( ) . has_errors_or_delayed_bugs ( ) . is_some ( ) {
79+ tcx. dcx ( ) . fatal ( "miri cannot be run on programs that fail compilation" ) ;
80+ }
8281
83- let early_dcx = EarlyDiagCtxt :: new ( tcx. sess . opts . error_format ) ;
84- init_late_loggers ( & early_dcx, tcx) ;
85- if !tcx. crate_types ( ) . contains ( & CrateType :: Executable ) {
86- tcx. dcx ( ) . fatal ( "miri only makes sense on bin crates" ) ;
87- }
82+ let early_dcx = EarlyDiagCtxt :: new ( tcx. sess . opts . error_format ) ;
83+ init_late_loggers ( & early_dcx, tcx) ;
84+ if !tcx. crate_types ( ) . contains ( & CrateType :: Executable ) {
85+ tcx. dcx ( ) . fatal ( "miri only makes sense on bin crates" ) ;
86+ }
8887
89- let ( entry_def_id, entry_type) = entry_fn ( tcx) ;
90- let mut config = self . miri_config . clone ( ) ;
88+ let ( entry_def_id, entry_type) = entry_fn ( tcx) ;
89+ let mut config = self . miri_config . clone ( ) ;
9190
92- // Add filename to `miri` arguments.
93- config. args . insert ( 0 , tcx. sess . io . input . filestem ( ) . to_string ( ) ) ;
91+ // Add filename to `miri` arguments.
92+ config. args . insert ( 0 , tcx. sess . io . input . filestem ( ) . to_string ( ) ) ;
9493
95- // Adjust working directory for interpretation.
96- if let Some ( cwd) = env:: var_os ( "MIRI_CWD" ) {
97- env:: set_current_dir ( cwd) . unwrap ( ) ;
98- }
94+ // Adjust working directory for interpretation.
95+ if let Some ( cwd) = env:: var_os ( "MIRI_CWD" ) {
96+ env:: set_current_dir ( cwd) . unwrap ( ) ;
97+ }
9998
100- if tcx. sess . opts . optimize != OptLevel :: No {
101- tcx. dcx ( ) . warn ( "Miri does not support optimizations: the opt-level is ignored. The only effect \
99+ if tcx. sess . opts . optimize != OptLevel :: No {
100+ tcx. dcx ( ) . warn ( "Miri does not support optimizations: the opt-level is ignored. The only effect \
102101 of selecting a Cargo profile that enables optimizations (such as --release) is to apply \
103102 its remaining settings, such as whether debug assertions and overflow checks are enabled.") ;
104- }
105- if tcx. sess . mir_opt_level ( ) > 0 {
106- tcx. dcx ( ) . warn ( "You have explicitly enabled MIR optimizations, overriding Miri's default \
103+ }
104+ if tcx. sess . mir_opt_level ( ) > 0 {
105+ tcx. dcx ( ) . warn ( "You have explicitly enabled MIR optimizations, overriding Miri's default \
107106 which is to completely disable them. Any optimizations may hide UB that Miri would \
108107 otherwise detect, and it is not necessarily possible to predict what kind of UB will \
109108 be missed. If you are enabling optimizations to make Miri run faster, we advise using \
110109 cfg(miri) to shrink your workload instead. The performance benefit of enabling MIR \
111110 optimizations is usually marginal at best.") ;
112- }
111+ }
113112
114- if let Some ( return_code) = miri:: eval_entry ( tcx, entry_def_id, entry_type, config) {
115- std:: process:: exit (
116- i32:: try_from ( return_code) . expect ( "Return value was too large!" ) ,
117- ) ;
118- }
119- tcx. dcx ( ) . abort_if_errors ( ) ;
120- } ) ;
113+ if let Some ( return_code) = miri:: eval_entry ( tcx, entry_def_id, entry_type, config) {
114+ std:: process:: exit ( i32:: try_from ( return_code) . expect ( "Return value was too large!" ) ) ;
115+ }
116+ tcx. dcx ( ) . abort_if_errors ( ) ;
121117
122118 Compilation :: Stop
123119 }
@@ -193,20 +189,18 @@ impl rustc_driver::Callbacks for MiriBeRustCompilerCalls {
193189 fn after_analysis < ' tcx > (
194190 & mut self ,
195191 _: & rustc_interface:: interface:: Compiler ,
196- queries : & ' tcx rustc_interface :: Queries < ' tcx > ,
192+ tcx : TyCtxt < ' tcx > ,
197193 ) -> Compilation {
198- queries. global_ctxt ( ) . unwrap ( ) . enter ( |tcx| {
199- if self . target_crate {
200- // cargo-miri has patched the compiler flags to make these into check-only builds,
201- // but we are still emulating regular rustc builds, which would perform post-mono
202- // const-eval during collection. So let's also do that here, even if we might be
203- // running with `--emit=metadata`. In particular this is needed to make
204- // `compile_fail` doc tests trigger post-mono errors.
205- // In general `collect_and_partition_mono_items` is not safe to call in check-only
206- // builds, but we are setting `-Zalways-encode-mir` which avoids those issues.
207- let _ = tcx. collect_and_partition_mono_items ( ( ) ) ;
208- }
209- } ) ;
194+ if self . target_crate {
195+ // cargo-miri has patched the compiler flags to make these into check-only builds,
196+ // but we are still emulating regular rustc builds, which would perform post-mono
197+ // const-eval during collection. So let's also do that here, even if we might be
198+ // running with `--emit=metadata`. In particular this is needed to make
199+ // `compile_fail` doc tests trigger post-mono errors.
200+ // In general `collect_and_partition_mono_items` is not safe to call in check-only
201+ // builds, but we are setting `-Zalways-encode-mir` which avoids those issues.
202+ let _ = tcx. collect_and_partition_mono_items ( ( ) ) ;
203+ }
210204 Compilation :: Continue
211205 }
212206}
0 commit comments