@@ -30,6 +30,8 @@ use rustc_middle::{
3030 } ,
3131 ty:: { query:: ExternProviders , TyCtxt } ,
3232} ;
33+ use rustc_session:: config:: OptLevel ;
34+
3335use rustc_session:: { config:: CrateType , search_paths:: PathKind , CtfeBacktrace } ;
3436
3537use miri:: { BacktraceStyle , BorrowTrackerMethod , ProvenanceMode , RetagFields } ;
@@ -82,6 +84,21 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
8284 env:: set_current_dir ( cwd) . unwrap ( ) ;
8385 }
8486
87+ if tcx. sess . opts . optimize != OptLevel :: No {
88+ tcx. sess . warn ( "Miri does not support optimizations. If you have enabled optimizations \
89+ by selecting a Cargo profile (such as --release) which changes other profile settings \
90+ such as whether debug assertions and overflow checks are enabled, those settings are \
91+ still applied.") ;
92+ }
93+ if tcx. sess . mir_opt_level ( ) > 0 {
94+ tcx. sess . warn ( "You have explicitly enabled MIR optimizations, overriding Miri's default \
95+ which is to completely disable them. Any optimizations may hide UB that Miri would \
96+ otherwise detect, and it is not necessarily possible to predict what kind of UB will \
97+ be missed. If you are enabling optimizations to make Miri run faster, we advise using \
98+ cfg(miri) to shrink your workload instead. The impact of enabling MIR optimizations is \
99+ usually marginal at best.") ;
100+ }
101+
85102 if let Some ( return_code) = miri:: eval_entry ( tcx, entry_def_id, entry_type, config) {
86103 std:: process:: exit (
87104 i32:: try_from ( return_code) . expect ( "Return value was too large!" ) ,
0 commit comments