@@ -21,11 +21,12 @@ use rustc_errors::json::JsonEmitter;
21
21
use rustc_errors:: { Applicability , DiagnosticBuilder , DiagnosticId , ErrorReported } ;
22
22
use rustc_span:: edition:: Edition ;
23
23
use rustc_span:: source_map:: { self , FileLoader , MultiSpan , RealFileLoader , SourceMap , Span } ;
24
- use rustc_span:: SourceFileHashAlgorithm ;
24
+ use rustc_span:: { SourceFileHashAlgorithm , Symbol } ;
25
25
use rustc_target:: spec:: { PanicStrategy , RelocModel , RelroLevel , Target , TargetTriple , TlsModel } ;
26
26
27
27
use std:: cell:: { self , RefCell } ;
28
28
use std:: env;
29
+ use std:: fmt:: Write as _;
29
30
use std:: io:: Write ;
30
31
use std:: num:: NonZeroU32 ;
31
32
use std:: path:: PathBuf ;
@@ -142,6 +143,10 @@ pub struct Session {
142
143
/// and immediately printing the backtrace to stderr.
143
144
pub ctfe_backtrace : Lock < CtfeBacktrace > ,
144
145
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
+
145
150
/// Base directory containing the `src/` for the Rust standard library, and
146
151
/// potentially `rustc` as well, if we can can find it. Right now it's always
147
152
/// `$sysroot/lib/rustlib/src/rust` (i.e. the `rustup` `rust-src` component).
@@ -188,7 +193,36 @@ impl From<&'static lint::Lint> for DiagnosticMessageId {
188
193
}
189
194
}
190
195
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
+
191
221
impl Session {
222
+ pub fn miri_unleashed_feature ( & self , s : Symbol ) {
223
+ self . miri_unleashed_features . lock ( ) . insert ( s) ;
224
+ }
225
+
192
226
pub fn local_crate_disambiguator ( & self ) -> CrateDisambiguator {
193
227
* self . crate_disambiguator . get ( )
194
228
}
@@ -1139,6 +1173,7 @@ pub fn build_session_with_source_map(
1139
1173
confused_type_with_std_module : Lock :: new ( Default :: default ( ) ) ,
1140
1174
system_library_path : OneThread :: new ( RefCell :: new ( Default :: default ( ) ) ) ,
1141
1175
ctfe_backtrace,
1176
+ miri_unleashed_features : Lock :: new ( Default :: default ( ) ) ,
1142
1177
real_rust_source_base_dir,
1143
1178
} ;
1144
1179
0 commit comments