Skip to content

Commit 89666ab

Browse files
committed
fix miri-unleash delayed sanity checking
1 parent 17ca7a0 commit 89666ab

File tree

5 files changed

+24
-19
lines changed

5 files changed

+24
-19
lines changed

src/librustc_interface/interface.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ pub fn run_compiler_in_existing_thread_pool<R>(
193193

194194
let r = {
195195
let _sess_abort_error = OnDrop(|| {
196-
compiler.sess.diagnostic().print_error_count(registry);
196+
compiler.sess.finish_diagnostics(registry);
197197
});
198198

199199
f(&compiler)

src/librustc_mir/transform/check_consts/validation.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ impl Validator<'mir, 'tcx> {
256256
// Use `def_span` to deduplicate all warnings for the same const.
257257
self.tcx.sess.span_warn(self.tcx.def_span(self.def_id), "skipping const checks");
258258
if let Some(feature) = O::feature_gate() {
259+
// We'd like to use `delay_span_bug` here, but we cannot as that ICEs
260+
// before codegen has the chance to emit errors. So we use a custom system instead.
259261
self.tcx.sess.miri_unleashed_feature(feature);
260262
}
261263
return;

src/librustc_session/session.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use rustc_data_structures::sync::{
1818
use rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitterWriter;
1919
use rustc_errors::emitter::{Emitter, EmitterWriter, HumanReadableErrorType};
2020
use rustc_errors::json::JsonEmitter;
21+
use rustc_errors::registry::Registry;
2122
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticId, ErrorReported};
2223
use rustc_span::edition::Edition;
2324
use rustc_span::source_map::{self, FileLoader, MultiSpan, RealFileLoader, SourceMap, Span};
@@ -193,10 +194,14 @@ impl From<&'static lint::Lint> for DiagnosticMessageId {
193194
}
194195
}
195196

196-
impl Drop for Session {
197-
fn drop(&mut self) {
197+
impl Session {
198+
pub fn miri_unleashed_feature(&self, s: Symbol) {
199+
self.miri_unleashed_features.lock().insert(s);
200+
}
201+
202+
fn check_miri_unleashed_features(&self) {
198203
if !self.has_errors_or_delayed_span_bugs() {
199-
let unleashed_features = self.miri_unleashed_features.get_mut();
204+
let unleashed_features = self.miri_unleashed_features.lock();
200205
if !unleashed_features.is_empty() {
201206
// Join the strings (itertools has it but libstd does not...)
202207
let mut list = String::new();
@@ -207,20 +212,20 @@ impl Drop for Session {
207212
write!(&mut list, "{}", feature).unwrap();
208213
}
209214
// We have skipped a feature gate, and not run into other errors... reject.
210-
panic!(
215+
self.err(&format!(
211216
"`-Zunleash-the-miri-inside-of-you` may not be used to circumvent feature \
212217
gates, except when testing error paths in the CTFE engine.\n\
213218
The following feature flags are missing from this crate: {}",
214219
list,
215-
);
220+
));
216221
}
217222
}
218223
}
219-
}
220224

221-
impl Session {
222-
pub fn miri_unleashed_feature(&self, s: Symbol) {
223-
self.miri_unleashed_features.lock().insert(s);
225+
/// Invoked all the way at the end to finish off diagnostics printing.
226+
pub fn finish_diagnostics(&self, registry: &Registry) {
227+
self.check_miri_unleashed_features();
228+
self.diagnostic().print_error_count(registry);
224229
}
225230

226231
pub fn local_crate_disambiguator(&self) -> CrateDisambiguator {

src/test/ui/consts/miri_unleashed/const_refers_to_static.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// build-fail
22
// compile-flags: -Zunleash-the-miri-inside-of-you -Zdeduplicate-diagnostics
33
#![allow(const_err)]
4-
#![feature(const_raw_ptr_deref)] // FIXME: cannot remove because then rustc thinks there is no error
5-
#![crate_type = "lib"]
64

75
use std::sync::atomic::AtomicUsize;
86
use std::sync::atomic::Ordering;
@@ -26,7 +24,7 @@ static mut MUTABLE: u32 = 0;
2624
const READ_MUT: u32 = unsafe { MUTABLE };
2725
//~^ WARN skipping const checks
2826

29-
pub fn main() {
27+
fn main() {
3028
MUTATE_INTERIOR_MUT;
3129
//~^ ERROR: erroneous constant used
3230
READ_INTERIOR_MUT;

src/test/ui/consts/miri_unleashed/const_refers_to_static.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: skipping const checks
2-
--> $DIR/const_refers_to_static.rs:13:1
2+
--> $DIR/const_refers_to_static.rs:11:1
33
|
44
LL | / const MUTATE_INTERIOR_MUT: usize = {
55
LL | |
@@ -9,7 +9,7 @@ LL | | };
99
| |__^
1010

1111
warning: skipping const checks
12-
--> $DIR/const_refers_to_static.rs:19:1
12+
--> $DIR/const_refers_to_static.rs:17:1
1313
|
1414
LL | / const READ_INTERIOR_MUT: usize = {
1515
LL | |
@@ -19,25 +19,25 @@ LL | | };
1919
| |__^
2020

2121
warning: skipping const checks
22-
--> $DIR/const_refers_to_static.rs:26:1
22+
--> $DIR/const_refers_to_static.rs:24:1
2323
|
2424
LL | const READ_MUT: u32 = unsafe { MUTABLE };
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2626

2727
error[E0080]: erroneous constant used
28-
--> $DIR/const_refers_to_static.rs:30:5
28+
--> $DIR/const_refers_to_static.rs:28:5
2929
|
3030
LL | MUTATE_INTERIOR_MUT;
3131
| ^^^^^^^^^^^^^^^^^^^ referenced constant has errors
3232

3333
error[E0080]: erroneous constant used
34-
--> $DIR/const_refers_to_static.rs:32:5
34+
--> $DIR/const_refers_to_static.rs:30:5
3535
|
3636
LL | READ_INTERIOR_MUT;
3737
| ^^^^^^^^^^^^^^^^^ referenced constant has errors
3838

3939
error[E0080]: erroneous constant used
40-
--> $DIR/const_refers_to_static.rs:34:5
40+
--> $DIR/const_refers_to_static.rs:32:5
4141
|
4242
LL | READ_MUT;
4343
| ^^^^^^^^ referenced constant has errors

0 commit comments

Comments
 (0)