@@ -60,7 +60,7 @@ use std::path::PathBuf;
60
60
use std:: process:: { self , Command , Stdio } ;
61
61
use std:: str;
62
62
use std:: sync:: atomic:: { AtomicBool , Ordering } ;
63
- use std:: sync:: OnceLock ;
63
+ use std:: sync:: { Arc , OnceLock } ;
64
64
use std:: time:: { Instant , SystemTime } ;
65
65
use time:: format_description:: well_known:: Rfc3339 ;
66
66
use time:: OffsetDateTime ;
@@ -224,11 +224,18 @@ pub struct RunCompiler<'a, 'b> {
224
224
file_loader: Option <Box <dyn FileLoader + Send + Sync >>,
225
225
make_codegen_backend:
226
226
Option <Box <dyn FnOnce ( & config:: Options ) -> Box <dyn CodegenBackend > + Send >>,
227
+ using_internal_features: Arc <std:: sync:: atomic:: AtomicBool >,
227
228
}
228
229
229
230
impl <' a, ' b> RunCompiler <' a, ' b> {
230
231
pub fn new( at_args: & ' a [ String ] , callbacks: & ' b mut ( dyn Callbacks + Send ) ) -> Self {
231
- Self { at_args, callbacks, file_loader: None , make_codegen_backend: None }
232
+ Self {
233
+ at_args,
234
+ callbacks,
235
+ file_loader: None ,
236
+ make_codegen_backend: None ,
237
+ using_internal_features: Arc :: default ( ) ,
238
+ }
232
239
}
233
240
234
241
/// Set a custom codegen backend.
@@ -260,9 +267,23 @@ impl<'a, 'b> RunCompiler<'a, 'b> {
260
267
self
261
268
}
262
269
270
+ /// Set the session-global flag that checks whether internal features have been used,
271
+ /// suppressing the message about submitting an issue in ICEs when enabled.
272
+ #[ must_use]
273
+ pub fn set_using_internal_features( mut self , using_internal_features: Arc <AtomicBool >) -> Self {
274
+ self . using_internal_features = using_internal_features;
275
+ self
276
+ }
277
+
263
278
/// Parse args and run the compiler.
264
279
pub fn run( self ) -> interface:: Result <( ) > {
265
- run_compiler( self . at_args, self . callbacks, self . file_loader, self . make_codegen_backend)
280
+ run_compiler(
281
+ self . at_args,
282
+ self . callbacks,
283
+ self . file_loader,
284
+ self . make_codegen_backend,
285
+ self . using_internal_features,
286
+ )
266
287
}
267
288
}
268
289
@@ -273,6 +294,7 @@ fn run_compiler(
273
294
make_codegen_backend: Option <
274
295
Box <dyn FnOnce ( & config:: Options ) -> Box <dyn CodegenBackend > + Send >,
275
296
>,
297
+ using_internal_features: Arc <std:: sync:: atomic:: AtomicBool >,
276
298
) -> interface:: Result <( ) > {
277
299
let mut early_error_handler = EarlyErrorHandler :: new( ErrorOutputType :: default ( ) ) ;
278
300
@@ -316,6 +338,7 @@ fn run_compiler(
316
338
override_queries: None ,
317
339
make_codegen_backend,
318
340
registry: diagnostics_registry( ) ,
341
+ using_internal_features,
319
342
expanded_args: args,
320
343
} ;
321
344
@@ -1323,8 +1346,12 @@ fn ice_path() -> &'static Option<PathBuf> {
1323
1346
/// If you have no extra info to report, pass the empty closure `|_| ()` as the argument to
1324
1347
/// extra_info.
1325
1348
///
1349
+ /// Returns a flag that can be set to disable the note for submitting a bug. This can be passed to
1350
+ /// [`RunCompiler::set_using_internal_features`] to let macro expansion set it when encountering
1351
+ /// internal features.
1352
+ ///
1326
1353
/// A custom rustc driver can skip calling this to set up a custom ICE hook.
1327
- pub fn install_ice_hook( bug_report_url: & ' static str , extra_info: fn ( & Handler ) ) {
1354
+ pub fn install_ice_hook( bug_report_url: & ' static str , extra_info: fn ( & Handler ) ) -> Arc < AtomicBool > {
1328
1355
// If the user has not explicitly overridden "RUST_BACKTRACE", then produce
1329
1356
// full backtraces. When a compiler ICE happens, we want to gather
1330
1357
// as much information as possible to present in the issue opened
@@ -1335,6 +1362,8 @@ pub fn install_ice_hook(bug_report_url: &'static str, extra_info: fn(&Handler))
1335
1362
std:: env:: set_var( "RUST_BACKTRACE" , "full" ) ;
1336
1363
}
1337
1364
1365
+ let using_internal_features = Arc :: new( std:: sync:: atomic:: AtomicBool :: default ( ) ) ;
1366
+ let using_internal_features_hook = using_internal_features. clone( ) ;
1338
1367
panic:: update_hook( Box :: new(
1339
1368
move |default_hook: & ( dyn Fn ( & PanicInfo <' _>) + Send + Sync + ' static ) ,
1340
1369
info: & PanicInfo <' _>| {
@@ -1384,9 +1413,11 @@ pub fn install_ice_hook(bug_report_url: &'static str, extra_info: fn(&Handler))
1384
1413
}
1385
1414
1386
1415
// Print the ICE message
1387
- report_ice( info, bug_report_url, extra_info) ;
1416
+ report_ice( info, bug_report_url, extra_info, & using_internal_features_hook ) ;
1388
1417
} ,
1389
1418
) ) ;
1419
+
1420
+ using_internal_features
1390
1421
}
1391
1422
1392
1423
/// Prints the ICE message, including query stack, but without backtrace.
@@ -1395,7 +1426,12 @@ pub fn install_ice_hook(bug_report_url: &'static str, extra_info: fn(&Handler))
1395
1426
///
1396
1427
/// When `install_ice_hook` is called, this function will be called as the panic
1397
1428
/// hook.
1398
- fn report_ice( info: & panic:: PanicInfo <' _>, bug_report_url: & str , extra_info: fn ( & Handler ) ) {
1429
+ fn report_ice(
1430
+ info: & panic:: PanicInfo <' _>,
1431
+ bug_report_url: & str ,
1432
+ extra_info: fn ( & Handler ) ,
1433
+ using_internal_features: & AtomicBool ,
1434
+ ) {
1399
1435
let fallback_bundle =
1400
1436
rustc_errors:: fallback_fluent_bundle( crate :: DEFAULT_LOCALE_RESOURCES . to_vec( ) , false ) ;
1401
1437
let emitter = Box :: new( rustc_errors:: emitter:: EmitterWriter :: stderr(
@@ -1412,7 +1448,11 @@ fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str, extra_info: fn(
1412
1448
handler. emit_err( session_diagnostics:: Ice ) ;
1413
1449
}
1414
1450
1415
- handler. emit_note( session_diagnostics:: IceBugReport { bug_report_url } ) ;
1451
+ if using_internal_features. load( std:: sync:: atomic:: Ordering :: Relaxed ) {
1452
+ handler. emit_note( session_diagnostics:: IceBugReportInternalFeature ) ;
1453
+ } else {
1454
+ handler. emit_note( session_diagnostics:: IceBugReport { bug_report_url } ) ;
1455
+ }
1416
1456
1417
1457
let version = util:: version_str!( ) . unwrap_or( "unknown_version" ) ;
1418
1458
let triple = config:: host_triple( ) ;
@@ -1496,7 +1536,7 @@ pub fn main() -> ! {
1496
1536
init_rustc_env_logger( & handler) ;
1497
1537
signal_handler:: install( ) ;
1498
1538
let mut callbacks = TimePassesCallbacks :: default ( ) ;
1499
- install_ice_hook( DEFAULT_BUG_REPORT_URL , |_| ( ) ) ;
1539
+ let using_internal_features = install_ice_hook( DEFAULT_BUG_REPORT_URL , |_| ( ) ) ;
1500
1540
let exit_code = catch_with_exit_code( || {
1501
1541
let args = env:: args_os( )
1502
1542
. enumerate( )
@@ -1506,7 +1546,9 @@ pub fn main() -> ! {
1506
1546
} )
1507
1547
} )
1508
1548
. collect:: <Vec <_>>( ) ;
1509
- RunCompiler :: new( & args, & mut callbacks) . run( )
1549
+ RunCompiler :: new( & args, & mut callbacks)
1550
+ . set_using_internal_features( using_internal_features)
1551
+ . run( )
1510
1552
} ) ;
1511
1553
1512
1554
if let Some ( format) = callbacks. time_passes {
0 commit comments