Skip to content

Commit a0c61a9

Browse files
committed
Auto merge of #71631 - RalfJung:miri-unleash-the-gates, r=oli-obk
Miri: unleash all feature gates IMO it is silly to unleash features that do not even have a feature gate yet, but not unleash features that do. The only thing this achieves is making unleashed mode annoying to use as we have to figure out the feature flags to enable (and not always do the error messages say what that flag is). Given that the point of `-Z unleash-the-miri-inside-of-you` is to debug the Miri internals, I see no good reason for this extra hurdle. I cannot imagine a situation where we'd use that flag, realize the program also requires some feature gate, and then be like "oh I guess if this feature is unstable I will do something else". Instead, we'll always just add that flag to the code as well, so requiring the flag achieves nothing. r? @oli-obk @ecstatic-morse Fixes #71630
2 parents 65b4482 + 182133f commit a0c61a9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+385
-229
lines changed

src/librustc_interface/interface.rs

+1-1
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

+4-4
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,12 @@ impl Validator<'mir, 'tcx> {
247247
return;
248248
}
249249

250-
// If an operation is supported in miri (and is not already controlled by a feature gate) it
251-
// can be turned on with `-Zunleash-the-miri-inside-of-you`.
252-
let is_unleashable = O::IS_SUPPORTED_IN_MIRI && O::feature_gate().is_none();
250+
// If an operation is supported in miri it can be turned on with
251+
// `-Zunleash-the-miri-inside-of-you`.
252+
let is_unleashable = O::IS_SUPPORTED_IN_MIRI;
253253

254254
if is_unleashable && self.tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you {
255-
self.tcx.sess.span_warn(span, "skipping const checks");
255+
self.tcx.sess.miri_unleashed_feature(span, O::feature_gate());
256256
return;
257257
}
258258

src/librustc_session/session.rs

+47-1
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ 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};
24-
use rustc_span::SourceFileHashAlgorithm;
25+
use rustc_span::{SourceFileHashAlgorithm, Symbol};
2526
use rustc_target::spec::{PanicStrategy, RelocModel, RelroLevel, Target, TargetTriple, TlsModel};
2627

2728
use std::cell::{self, RefCell};
@@ -142,6 +143,12 @@ pub struct Session {
142143
/// and immediately printing the backtrace to stderr.
143144
pub ctfe_backtrace: Lock<CtfeBacktrace>,
144145

146+
/// This tracks where `-Zunleash-the-miri-inside-of-you` was used to get around a
147+
/// const check, optionally with the relevant feature gate. We use this to
148+
/// warn about unleashing, but with a single diagnostic instead of dozens that
149+
/// drown everything else in noise.
150+
miri_unleashed_features: Lock<Vec<(Span, Option<Symbol>)>>,
151+
145152
/// Base directory containing the `src/` for the Rust standard library, and
146153
/// potentially `rustc` as well, if we can can find it. Right now it's always
147154
/// `$sysroot/lib/rustlib/src/rust` (i.e. the `rustup` `rust-src` component).
@@ -189,6 +196,44 @@ impl From<&'static lint::Lint> for DiagnosticMessageId {
189196
}
190197

191198
impl Session {
199+
pub fn miri_unleashed_feature(&self, span: Span, feature_gate: Option<Symbol>) {
200+
self.miri_unleashed_features.lock().push((span, feature_gate));
201+
}
202+
203+
fn check_miri_unleashed_features(&self) {
204+
let unleashed_features = self.miri_unleashed_features.lock();
205+
if !unleashed_features.is_empty() {
206+
let mut must_err = false;
207+
// Create a diagnostic pointing at where things got unleashed.
208+
let mut diag = self.struct_warn("skipping const checks");
209+
for &(span, feature_gate) in unleashed_features.iter() {
210+
// FIXME: `span_label` doesn't do anything, so we use "help" as a hack.
211+
if let Some(feature_gate) = feature_gate {
212+
diag.span_help(span, &format!("skipping check for `{}` feature", feature_gate));
213+
// The unleash flag must *not* be used to just "hack around" feature gates.
214+
must_err = true;
215+
} else {
216+
diag.span_help(span, "skipping check that does not even have a feature gate");
217+
}
218+
}
219+
diag.emit();
220+
// If we should err, make sure we did.
221+
if must_err && !self.has_errors() {
222+
// We have skipped a feature gate, and not run into other errors... reject.
223+
self.err(
224+
"`-Zunleash-the-miri-inside-of-you` may not be used to circumvent feature \
225+
gates, except when testing error paths in the CTFE engine",
226+
);
227+
}
228+
}
229+
}
230+
231+
/// Invoked all the way at the end to finish off diagnostics printing.
232+
pub fn finish_diagnostics(&self, registry: &Registry) {
233+
self.check_miri_unleashed_features();
234+
self.diagnostic().print_error_count(registry);
235+
}
236+
192237
pub fn local_crate_disambiguator(&self) -> CrateDisambiguator {
193238
*self.crate_disambiguator.get()
194239
}
@@ -1139,6 +1184,7 @@ pub fn build_session_with_source_map(
11391184
confused_type_with_std_module: Lock::new(Default::default()),
11401185
system_library_path: OneThread::new(RefCell::new(Default::default())),
11411186
ctfe_backtrace,
1187+
miri_unleashed_features: Lock::new(Default::default()),
11421188
real_rust_source_base_dir,
11431189
};
11441190

src/test/ui/consts/const-eval/const_fn_ptr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ const X: fn(usize) -> usize = double;
99
const X_CONST: fn(usize) -> usize = double_const;
1010

1111
const fn bar(x: usize) -> usize {
12-
X(x) //~ WARNING skipping const checks
12+
X(x)
1313
}
1414

1515
const fn bar_const(x: usize) -> usize {
16-
X_CONST(x) //~ WARNING skipping const checks
16+
X_CONST(x)
1717
}
1818

1919
const fn foo(x: fn(usize) -> usize, y: usize) -> usize {
20-
x(y) //~ WARNING skipping const checks
20+
x(y)
2121
}
2222

2323
fn main() {
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
warning: skipping const checks
2+
|
3+
help: skipping check that does not even have a feature gate
24
--> $DIR/const_fn_ptr.rs:12:5
35
|
46
LL | X(x)
57
| ^^^^
6-
7-
warning: skipping const checks
8+
help: skipping check that does not even have a feature gate
89
--> $DIR/const_fn_ptr.rs:16:5
910
|
1011
LL | X_CONST(x)
1112
| ^^^^^^^^^^
12-
13-
warning: skipping const checks
13+
help: skipping check that does not even have a feature gate
1414
--> $DIR/const_fn_ptr.rs:20:5
1515
|
1616
LL | x(y)
1717
| ^^^^
1818

19-
warning: 3 warnings emitted
19+
warning: 1 warning emitted
2020

src/test/ui/consts/const-eval/const_fn_ptr_fail.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const X: fn(usize) -> usize = double;
88

99
const fn bar(x: usize) -> usize {
1010
X(x) // FIXME: this should error someday
11-
//~^ WARN: skipping const checks
1211
}
1312

1413
fn main() {}

src/test/ui/consts/const-eval/const_fn_ptr_fail.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
warning: skipping const checks
2+
|
3+
help: skipping check that does not even have a feature gate
24
--> $DIR/const_fn_ptr_fail.rs:10:5
35
|
46
LL | X(x) // FIXME: this should error someday

src/test/ui/consts/const-eval/const_fn_ptr_fail2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn double(x: usize) -> usize {
1010
const X: fn(usize) -> usize = double;
1111

1212
const fn bar(x: fn(usize) -> usize, y: usize) -> usize {
13-
x(y) //~ WARN skipping const checks
13+
x(y)
1414
}
1515

1616
const Y: usize = bar(X, 2); // FIXME: should fail to typeck someday

src/test/ui/consts/const-eval/const_fn_ptr_fail2.stderr

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
warning: skipping const checks
2-
--> $DIR/const_fn_ptr_fail2.rs:13:5
3-
|
4-
LL | x(y)
5-
| ^^^^
6-
71
error[E0080]: evaluation of constant expression failed
82
--> $DIR/const_fn_ptr_fail2.rs:20:5
93
|
@@ -24,6 +18,14 @@ LL | assert_eq!(Z, 4);
2418
|
2519
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
2620

21+
warning: skipping const checks
22+
|
23+
help: skipping check that does not even have a feature gate
24+
--> $DIR/const_fn_ptr_fail2.rs:13:5
25+
|
26+
LL | x(y)
27+
| ^^^^
28+
2729
error: aborting due to 2 previous errors; 1 warning emitted
2830

2931
For more information about this error, try `rustc --explain E0080`.

src/test/ui/consts/const-points-to-static.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
#![allow(dead_code)]
44

55
const TEST: &u8 = &MY_STATIC;
6-
//~^ skipping const checks
7-
//~| it is undefined behavior to use this value
6+
//~^ ERROR it is undefined behavior to use this value
7+
//~| NOTE encountered a reference pointing to a static variable
8+
//~| NOTE
89

910
static MY_STATIC: u8 = 4;
1011

Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
warning: skipping const checks
2-
--> $DIR/const-points-to-static.rs:5:20
3-
|
4-
LL | const TEST: &u8 = &MY_STATIC;
5-
| ^^^^^^^^^
6-
71
error[E0080]: it is undefined behavior to use this value
82
--> $DIR/const-points-to-static.rs:5:1
93
|
@@ -12,6 +6,14 @@ LL | const TEST: &u8 = &MY_STATIC;
126
|
137
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
148

9+
warning: skipping const checks
10+
|
11+
help: skipping check that does not even have a feature gate
12+
--> $DIR/const-points-to-static.rs:5:20
13+
|
14+
LL | const TEST: &u8 = &MY_STATIC;
15+
| ^^^^^^^^^
16+
1517
error: aborting due to previous error; 1 warning emitted
1618

1719
For more information about this error, try `rustc --explain E0080`.

src/test/ui/consts/const-prop-read-static-in-const.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#![allow(dead_code)]
44

55
const TEST: u8 = MY_STATIC; //~ ERROR any use of this value will cause an error
6-
//~^ skipping const checks
76

87
static MY_STATIC: u8 = 4;
98

Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
warning: skipping const checks
2-
--> $DIR/const-prop-read-static-in-const.rs:5:18
3-
|
4-
LL | const TEST: u8 = MY_STATIC;
5-
| ^^^^^^^^^
6-
71
error: any use of this value will cause an error
82
--> $DIR/const-prop-read-static-in-const.rs:5:18
93
|
@@ -14,5 +8,13 @@ LL | const TEST: u8 = MY_STATIC;
148
|
159
= note: `#[deny(const_err)]` on by default
1610

11+
warning: skipping const checks
12+
|
13+
help: skipping check that does not even have a feature gate
14+
--> $DIR/const-prop-read-static-in-const.rs:5:18
15+
|
16+
LL | const TEST: u8 = MY_STATIC;
17+
| ^^^^^^^^^
18+
1719
error: aborting due to previous error; 1 warning emitted
1820

src/test/ui/consts/miri_unleashed/abi-mismatch.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ const extern "C" fn c_fn() {}
88

99
const fn call_rust_fn(my_fn: extern "Rust" fn()) {
1010
my_fn();
11-
//~^ WARN skipping const checks
12-
//~| ERROR could not evaluate static initializer
11+
//~^ ERROR could not evaluate static initializer
1312
//~| NOTE calling a function with ABI C using caller ABI Rust
1413
//~| NOTE inside `call_rust_fn`
1514
}
1615

1716
static VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) });
18-
//~^ WARN skipping const checks
19-
//~| NOTE inside `VAL`
17+
//~^ NOTE inside `VAL`
2018

2119
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
warning: skipping const checks
1+
error[E0080]: could not evaluate static initializer
22
--> $DIR/abi-mismatch.rs:10:5
33
|
44
LL | my_fn();
55
| ^^^^^^^
6+
| |
7+
| calling a function with ABI C using caller ABI Rust
8+
| inside `call_rust_fn` at $DIR/abi-mismatch.rs:10:5
9+
...
10+
LL | static VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) });
11+
| --------------------------------------------------------------------- inside `VAL` at $DIR/abi-mismatch.rs:16:18
612

713
warning: skipping const checks
8-
--> $DIR/abi-mismatch.rs:17:40
914
|
10-
LL | static VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) });
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12-
13-
error[E0080]: could not evaluate static initializer
15+
help: skipping check that does not even have a feature gate
1416
--> $DIR/abi-mismatch.rs:10:5
1517
|
1618
LL | my_fn();
1719
| ^^^^^^^
18-
| |
19-
| calling a function with ABI C using caller ABI Rust
20-
| inside `call_rust_fn` at $DIR/abi-mismatch.rs:10:5
21-
...
20+
help: skipping check that does not even have a feature gate
21+
--> $DIR/abi-mismatch.rs:16:40
22+
|
2223
LL | static VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) });
23-
| --------------------------------------------------------------------- inside `VAL` at $DIR/abi-mismatch.rs:17:18
24+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2425

25-
error: aborting due to previous error; 2 warnings emitted
26+
error: aborting due to previous error; 1 warning emitted
2627

2728
For more information about this error, try `rustc --explain E0080`.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ trait Foo<T> {
1111
}
1212

1313
trait Bar<T, U: Foo<T>> {
14-
const F: u32 = (U::X, 42).1; //~ WARN skipping const checks
14+
const F: u32 = (U::X, 42).1;
1515
}
1616

1717
impl Foo<u32> for () {
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
warning: skipping const checks
2-
--> $DIR/assoc_const.rs:14:20
3-
|
4-
LL | const F: u32 = (U::X, 42).1;
5-
| ^^^^^^^^^^
6-
71
error[E0080]: erroneous constant used
82
--> $DIR/assoc_const.rs:31:13
93
|
104
LL | let y = <String as Bar<Vec<u32>, String>>::F;
115
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
126

7+
warning: skipping const checks
8+
|
9+
help: skipping check that does not even have a feature gate
10+
--> $DIR/assoc_const.rs:14:20
11+
|
12+
LL | const F: u32 = (U::X, 42).1;
13+
| ^^^^^^^^^^
14+
1315
error: aborting due to previous error; 1 warning emitted
1416

1517
For more information about this error, try `rustc --explain E0080`.
+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// compile-flags: -Zunleash-the-miri-inside-of-you
2-
#![feature(const_mut_refs, box_syntax)]
2+
#![feature(box_syntax)]
33
#![allow(const_err)]
44

55
use std::mem::ManuallyDrop;
@@ -8,7 +8,6 @@ fn main() {}
88

99
static TEST_BAD: &mut i32 = {
1010
&mut *(box 0)
11-
//~^ WARN skipping const check
12-
//~| ERROR could not evaluate static initializer
11+
//~^ ERROR could not evaluate static initializer
1312
//~| NOTE heap allocations
1413
};

0 commit comments

Comments
 (0)