@@ -21,11 +21,12 @@ use rustc_errors::json::JsonEmitter;
2121use rustc_errors:: { Applicability , DiagnosticBuilder , DiagnosticId , ErrorReported } ;
2222use rustc_span:: edition:: Edition ;
2323use rustc_span:: source_map:: { self , FileLoader , MultiSpan , RealFileLoader , SourceMap , Span } ;
24- use rustc_span:: SourceFileHashAlgorithm ;
24+ use rustc_span:: { SourceFileHashAlgorithm , Symbol } ;
2525use rustc_target:: spec:: { PanicStrategy , RelocModel , RelroLevel , Target , TargetTriple , TlsModel } ;
2626
2727use std:: cell:: { self , RefCell } ;
2828use std:: env;
29+ use std:: fmt:: Write as _;
2930use std:: io:: Write ;
3031use std:: num:: NonZeroU32 ;
3132use std:: path:: PathBuf ;
@@ -142,6 +143,10 @@ pub struct Session {
142143 /// and immediately printing the backtrace to stderr.
143144 pub ctfe_backtrace : Lock < CtfeBacktrace > ,
144145
146+ /// This tracks whether `-Zunleash-the-miri-inside-of-you` was used to get around a
147+ /// feature gate. If yes, this file must fail to compile.
148+ miri_unleashed_features : Lock < FxHashSet < Symbol > > ,
149+
145150 /// Base directory containing the `src/` for the Rust standard library, and
146151 /// potentially `rustc` as well, if we can can find it. Right now it's always
147152 /// `$sysroot/lib/rustlib/src/rust` (i.e. the `rustup` `rust-src` component).
@@ -188,7 +193,36 @@ impl From<&'static lint::Lint> for DiagnosticMessageId {
188193 }
189194}
190195
196+ impl Drop for Session {
197+ fn drop ( & mut self ) {
198+ if !self . has_errors_or_delayed_span_bugs ( ) {
199+ let unleashed_features = self . miri_unleashed_features . get_mut ( ) ;
200+ if !unleashed_features. is_empty ( ) {
201+ // Join the strings (itertools has it but libstd does not...)
202+ let mut list = String :: new ( ) ;
203+ for feature in unleashed_features. iter ( ) {
204+ if !list. is_empty ( ) {
205+ list. push_str ( ", " ) ;
206+ }
207+ write ! ( & mut list, "{}" , feature) . unwrap ( ) ;
208+ }
209+ // We have skipped a feature gate, and not run into other errors... reject.
210+ panic ! (
211+ "`-Zunleash-the-miri-inside-of-you` may not be used to circumvent feature \
212+ gates, except when testing error paths in the CTFE engine.\n \
213+ The following feature flags are missing from this crate: {}",
214+ list,
215+ ) ;
216+ }
217+ }
218+ }
219+ }
220+
191221impl Session {
222+ pub fn miri_unleashed_feature ( & self , s : Symbol ) {
223+ self . miri_unleashed_features . lock ( ) . insert ( s) ;
224+ }
225+
192226 pub fn local_crate_disambiguator ( & self ) -> CrateDisambiguator {
193227 * self . crate_disambiguator . get ( )
194228 }
@@ -1139,6 +1173,7 @@ pub fn build_session_with_source_map(
11391173 confused_type_with_std_module : Lock :: new ( Default :: default ( ) ) ,
11401174 system_library_path : OneThread :: new ( RefCell :: new ( Default :: default ( ) ) ) ,
11411175 ctfe_backtrace,
1176+ miri_unleashed_features : Lock :: new ( Default :: default ( ) ) ,
11421177 real_rust_source_base_dir,
11431178 } ;
11441179
0 commit comments