From ba1c1d92c0080d85e3bd4822efa833afd9a05182 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Fri, 1 May 2020 13:28:54 +0200 Subject: [PATCH 1/2] Simplify field initialization in rustdoc --- src/librustdoc/test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index e2940efd49c0d..7deb95abcbde0 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -98,7 +98,7 @@ pub fn run(options: Options) -> i32 { externs: options.externs.clone(), unstable_features: UnstableFeatures::from_environment(), actually_rustdoc: true, - debugging_opts: config::DebuggingOptions { ..config::basic_debugging_options() }, + debugging_opts: config::basic_debugging_options(), edition: options.edition, target_triple: options.target.clone(), ..config::Options::default() From cd4c0b990e3a3dab34b5c91a99062f247c05bce6 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Fri, 1 May 2020 14:30:45 +0200 Subject: [PATCH 2/2] Abort compilation if tests use unleash but don't actually unleash anything --- .../transform/check_consts/validation.rs | 10 +++++-- src/librustc_session/session.rs | 29 +++++++++++++++++++ .../consts/miri_unleashed/mutating_global.rs | 1 - .../miri_unleashed/mutating_global.stderr | 2 +- .../consts/miri_unleashed/read_from_static.rs | 1 - .../recursive-zst-static.default.stderr | 6 ++-- src/test/ui/consts/recursive-zst-static.rs | 3 +- .../recursive-zst-static.unleash.stderr | 21 -------------- .../mir-dataflow/indirect-mutation-offset.rs | 13 +++------ .../indirect-mutation-offset.stderr | 2 +- 10 files changed, 47 insertions(+), 41 deletions(-) delete mode 100644 src/test/ui/consts/recursive-zst-static.unleash.stderr diff --git a/src/librustc_mir/transform/check_consts/validation.rs b/src/librustc_mir/transform/check_consts/validation.rs index 78cb60ea484e4..7c6500f53fab6 100644 --- a/src/librustc_mir/transform/check_consts/validation.rs +++ b/src/librustc_mir/transform/check_consts/validation.rs @@ -247,11 +247,17 @@ impl Validator<'mir, 'tcx> { return; } - // If an operation is supported in miri (and is not already controlled by a feature gate) it + // If an operation is supported in miri it // can be turned on with `-Zunleash-the-miri-inside-of-you`. - let is_unleashable = O::IS_SUPPORTED_IN_MIRI && O::feature_gate().is_none(); + let is_unleashable = O::IS_SUPPORTED_IN_MIRI; if is_unleashable && self.tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you { + // If all skipped operations could also be turned on by a feature gate, then we want + // to emit an error. So when we see a non-feature gate operation being skipped, disable + // that error reporting. + if O::feature_gate().is_none() { + self.tcx.sess.register_non_feature_unleash_skip(); + } self.tcx.sess.span_warn(span, "skipping const checks"); return; } diff --git a/src/librustc_session/session.rs b/src/librustc_session/session.rs index 3b7c2f268ce5d..d7539dedb8e86 100644 --- a/src/librustc_session/session.rs +++ b/src/librustc_session/session.rs @@ -142,6 +142,10 @@ pub struct Session { /// and immediately printing the backtrace to stderr. pub ctfe_backtrace: Lock, + /// This is used to ensure that not all "skipping const checks" from + /// `-Zunleash-the-miri-inside-of-you` are because of feature gates being skipped. + seen_non_feature_skip: Lock, + /// Base directory containing the `src/` for the Rust standard library, and /// potentially `rustc` as well, if we can can find it. Right now it's always /// `$sysroot/lib/rustlib/src/rust` (i.e. the `rustup` `rust-src` component). @@ -188,7 +192,29 @@ impl From<&'static lint::Lint> for DiagnosticMessageId { } } +impl Drop for Session { + fn drop(&mut self) { + // We've only seen feature gate related skips or no skips at all + if !*self.seen_non_feature_skip.get_mut() { + // And we have unleash enabled. + if self.opts.debugging_opts.unleash_the_miri_inside_of_you { + // Then that unleash is not necessary + panic!( + "`-Zunleash-the-miri-inside-of-you` unnecessary because it only unleashes + feature gates that could have been enabled via attributes. + Remove `-Zunleash-the-miri-inside-of-you` in order to let rustc tell you which + features you need.", + ); + } + } + } +} + impl Session { + pub fn register_non_feature_unleash_skip(&self) { + *self.seen_non_feature_skip.lock() = true; + } + pub fn local_crate_disambiguator(&self) -> CrateDisambiguator { *self.crate_disambiguator.get() } @@ -1081,6 +1107,8 @@ pub fn build_session_with_source_map( _ => CtfeBacktrace::Disabled, }); + let seen_non_feature_skip = Lock::new(false); + // Try to find a directory containing the Rust `src`, for more details see // the doc comment on the `real_rust_source_base_dir` field. let real_rust_source_base_dir = { @@ -1139,6 +1167,7 @@ pub fn build_session_with_source_map( confused_type_with_std_module: Lock::new(Default::default()), system_library_path: OneThread::new(RefCell::new(Default::default())), ctfe_backtrace, + seen_non_feature_skip, real_rust_source_base_dir, }; diff --git a/src/test/ui/consts/miri_unleashed/mutating_global.rs b/src/test/ui/consts/miri_unleashed/mutating_global.rs index 902fe0aa1e7e4..e27652efaacae 100644 --- a/src/test/ui/consts/miri_unleashed/mutating_global.rs +++ b/src/test/ui/consts/miri_unleashed/mutating_global.rs @@ -1,4 +1,3 @@ -// compile-flags: -Zunleash-the-miri-inside-of-you #![allow(const_err)] // Make sure we cannot mutate globals. diff --git a/src/test/ui/consts/miri_unleashed/mutating_global.stderr b/src/test/ui/consts/miri_unleashed/mutating_global.stderr index ba9dd56190ac1..c8770c8d76ad0 100644 --- a/src/test/ui/consts/miri_unleashed/mutating_global.stderr +++ b/src/test/ui/consts/miri_unleashed/mutating_global.stderr @@ -1,5 +1,5 @@ error[E0080]: could not evaluate static initializer - --> $DIR/mutating_global.rs:10:9 + --> $DIR/mutating_global.rs:9:9 | LL | GLOBAL = 99 | ^^^^^^^^^^^ modifying a static's initial value from another static's initializer diff --git a/src/test/ui/consts/miri_unleashed/read_from_static.rs b/src/test/ui/consts/miri_unleashed/read_from_static.rs index 821c501c9fcc5..c18227e0f5515 100644 --- a/src/test/ui/consts/miri_unleashed/read_from_static.rs +++ b/src/test/ui/consts/miri_unleashed/read_from_static.rs @@ -1,5 +1,4 @@ // run-pass -// compile-flags: -Zunleash-the-miri-inside-of-you #![feature(const_mut_refs)] #![allow(const_err)] diff --git a/src/test/ui/consts/recursive-zst-static.default.stderr b/src/test/ui/consts/recursive-zst-static.default.stderr index d424b22f000bf..cbc4ed2a24aea 100644 --- a/src/test/ui/consts/recursive-zst-static.default.stderr +++ b/src/test/ui/consts/recursive-zst-static.default.stderr @@ -1,17 +1,17 @@ error[E0391]: cycle detected when const-evaluating `FOO` - --> $DIR/recursive-zst-static.rs:10:18 + --> $DIR/recursive-zst-static.rs:9:18 | LL | static FOO: () = FOO; | ^^^ | note: ...which requires const-evaluating `FOO`... - --> $DIR/recursive-zst-static.rs:10:1 + --> $DIR/recursive-zst-static.rs:9:1 | LL | static FOO: () = FOO; | ^^^^^^^^^^^^^^^^^^^^^ = note: ...which again requires const-evaluating `FOO`, completing the cycle note: cycle used when const-evaluating + checking `FOO` - --> $DIR/recursive-zst-static.rs:10:1 + --> $DIR/recursive-zst-static.rs:9:1 | LL | static FOO: () = FOO; | ^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/consts/recursive-zst-static.rs b/src/test/ui/consts/recursive-zst-static.rs index 29a467c006a49..d6293c437eb9a 100644 --- a/src/test/ui/consts/recursive-zst-static.rs +++ b/src/test/ui/consts/recursive-zst-static.rs @@ -1,5 +1,4 @@ -// revisions: default unleash -//[unleash]compile-flags: -Zunleash-the-miri-inside-of-you +// revisions: default // This test ensures that we do not allow ZST statics to initialize themselves without ever // actually creating a value of that type. This is important, as the ZST may have private fields diff --git a/src/test/ui/consts/recursive-zst-static.unleash.stderr b/src/test/ui/consts/recursive-zst-static.unleash.stderr deleted file mode 100644 index d424b22f000bf..0000000000000 --- a/src/test/ui/consts/recursive-zst-static.unleash.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error[E0391]: cycle detected when const-evaluating `FOO` - --> $DIR/recursive-zst-static.rs:10:18 - | -LL | static FOO: () = FOO; - | ^^^ - | -note: ...which requires const-evaluating `FOO`... - --> $DIR/recursive-zst-static.rs:10:1 - | -LL | static FOO: () = FOO; - | ^^^^^^^^^^^^^^^^^^^^^ - = note: ...which again requires const-evaluating `FOO`, completing the cycle -note: cycle used when const-evaluating + checking `FOO` - --> $DIR/recursive-zst-static.rs:10:1 - | -LL | static FOO: () = FOO; - | ^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0391`. diff --git a/src/test/ui/mir-dataflow/indirect-mutation-offset.rs b/src/test/ui/mir-dataflow/indirect-mutation-offset.rs index caa307e269fe7..15ea925261591 100644 --- a/src/test/ui/mir-dataflow/indirect-mutation-offset.rs +++ b/src/test/ui/mir-dataflow/indirect-mutation-offset.rs @@ -1,5 +1,3 @@ -// compile-flags: -Zunleash-the-miri-inside-of-you - // This test demonstrates a shortcoming of the `MaybeMutBorrowedLocals` analysis. It does not // handle code that takes a reference to one field of a struct, then use pointer arithmetic to // transform it to another field of that same struct that may have interior mutability. For now, @@ -18,14 +16,11 @@ struct PartialInteriorMut { cell: UnsafeCell, } -#[rustc_mir(rustc_peek_indirectly_mutable,stop_after_dataflow)] +#[rustc_mir(rustc_peek_indirectly_mutable, stop_after_dataflow)] const BOO: i32 = { - let x = PartialInteriorMut { - zst: [], - cell: UnsafeCell::new(0), - }; + let x = PartialInteriorMut { zst: [], cell: UnsafeCell::new(0) }; - let p_zst: *const _ = &x.zst ; // Doesn't cause `x` to get marked as indirectly mutable. + let p_zst: *const _ = &x.zst; // Doesn't cause `x` to get marked as indirectly mutable. let rmut_cell = unsafe { // Take advantage of the fact that `zst` and `cell` are at the same location in memory. @@ -36,7 +31,7 @@ const BOO: i32 = { &mut *pmut_cell }; - *rmut_cell = 42; // Mutates `x` indirectly even though `x` is not marked indirectly mutable!!! + *rmut_cell = 42; // Mutates `x` indirectly even though `x` is not marked indirectly mutable!!! let val = *rmut_cell; unsafe { rustc_peek(x) }; //~ ERROR rustc_peek: bit not set diff --git a/src/test/ui/mir-dataflow/indirect-mutation-offset.stderr b/src/test/ui/mir-dataflow/indirect-mutation-offset.stderr index 8d3548ececdd9..2dce50b18ba03 100644 --- a/src/test/ui/mir-dataflow/indirect-mutation-offset.stderr +++ b/src/test/ui/mir-dataflow/indirect-mutation-offset.stderr @@ -1,5 +1,5 @@ error: rustc_peek: bit not set - --> $DIR/indirect-mutation-offset.rs:41:14 + --> $DIR/indirect-mutation-offset.rs:36:14 | LL | unsafe { rustc_peek(x) }; | ^^^^^^^^^^^^^