|
3 | 3 | clippy::manual_range_contains,
|
4 | 4 | clippy::useless_format,
|
5 | 5 | clippy::field_reassign_with_default,
|
| 6 | + clippy::needless_lifetimes, |
6 | 7 | rustc::diagnostic_outside_of_impl,
|
7 | 8 | rustc::untranslatable_diagnostic
|
8 | 9 | )]
|
@@ -73,51 +74,47 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
|
73 | 74 | fn after_analysis<'tcx>(
|
74 | 75 | &mut self,
|
75 | 76 | _: &rustc_interface::interface::Compiler,
|
76 |
| - queries: &'tcx rustc_interface::Queries<'tcx>, |
| 77 | + tcx: TyCtxt<'tcx>, |
77 | 78 | ) -> 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 |
| - } |
| 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 | + } |
82 | 82 |
|
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 |
| - } |
| 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 | + } |
88 | 88 |
|
89 |
| - let (entry_def_id, entry_type) = entry_fn(tcx); |
90 |
| - let mut config = self.miri_config.clone(); |
| 89 | + let (entry_def_id, entry_type) = entry_fn(tcx); |
| 90 | + let mut config = self.miri_config.clone(); |
91 | 91 |
|
92 |
| - // Add filename to `miri` arguments. |
93 |
| - config.args.insert(0, tcx.sess.io.input.filestem().to_string()); |
| 92 | + // Add filename to `miri` arguments. |
| 93 | + config.args.insert(0, tcx.sess.io.input.filestem().to_string()); |
94 | 94 |
|
95 |
| - // Adjust working directory for interpretation. |
96 |
| - if let Some(cwd) = env::var_os("MIRI_CWD") { |
97 |
| - env::set_current_dir(cwd).unwrap(); |
98 |
| - } |
| 95 | + // Adjust working directory for interpretation. |
| 96 | + if let Some(cwd) = env::var_os("MIRI_CWD") { |
| 97 | + env::set_current_dir(cwd).unwrap(); |
| 98 | + } |
99 | 99 |
|
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 \ |
| 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 \ |
102 | 102 | of selecting a Cargo profile that enables optimizations (such as --release) is to apply \
|
103 | 103 | 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 \ |
| 104 | + } |
| 105 | + if tcx.sess.mir_opt_level() > 0 { |
| 106 | + tcx.dcx().warn("You have explicitly enabled MIR optimizations, overriding Miri's default \ |
107 | 107 | which is to completely disable them. Any optimizations may hide UB that Miri would \
|
108 | 108 | otherwise detect, and it is not necessarily possible to predict what kind of UB will \
|
109 | 109 | be missed. If you are enabling optimizations to make Miri run faster, we advise using \
|
110 | 110 | cfg(miri) to shrink your workload instead. The performance benefit of enabling MIR \
|
111 | 111 | optimizations is usually marginal at best.");
|
112 |
| - } |
| 112 | + } |
113 | 113 |
|
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 |
| - }); |
| 114 | + if let Some(return_code) = miri::eval_entry(tcx, entry_def_id, entry_type, config) { |
| 115 | + std::process::exit(i32::try_from(return_code).expect("Return value was too large!")); |
| 116 | + } |
| 117 | + tcx.dcx().abort_if_errors(); |
121 | 118 |
|
122 | 119 | Compilation::Stop
|
123 | 120 | }
|
@@ -193,20 +190,18 @@ impl rustc_driver::Callbacks for MiriBeRustCompilerCalls {
|
193 | 190 | fn after_analysis<'tcx>(
|
194 | 191 | &mut self,
|
195 | 192 | _: &rustc_interface::interface::Compiler,
|
196 |
| - queries: &'tcx rustc_interface::Queries<'tcx>, |
| 193 | + tcx: TyCtxt<'tcx>, |
197 | 194 | ) -> 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 |
| - }); |
| 195 | + if self.target_crate { |
| 196 | + // cargo-miri has patched the compiler flags to make these into check-only builds, |
| 197 | + // but we are still emulating regular rustc builds, which would perform post-mono |
| 198 | + // const-eval during collection. So let's also do that here, even if we might be |
| 199 | + // running with `--emit=metadata`. In particular this is needed to make |
| 200 | + // `compile_fail` doc tests trigger post-mono errors. |
| 201 | + // In general `collect_and_partition_mono_items` is not safe to call in check-only |
| 202 | + // builds, but we are setting `-Zalways-encode-mir` which avoids those issues. |
| 203 | + let _ = tcx.collect_and_partition_mono_items(()); |
| 204 | + } |
210 | 205 | Compilation::Continue
|
211 | 206 | }
|
212 | 207 | }
|
|
0 commit comments