@@ -60,7 +60,7 @@ use std::path::PathBuf;
6060use std:: process:: { self , Command , Stdio } ;
6161use std:: str;
6262use std:: sync:: atomic:: { AtomicBool , Ordering } ;
63- use std:: sync:: OnceLock ;
63+ use std:: sync:: { Arc , OnceLock } ;
6464use std:: time:: { Instant , SystemTime } ;
6565use time:: format_description:: well_known:: Rfc3339 ;
6666use time:: OffsetDateTime ;
@@ -224,11 +224,18 @@ pub struct RunCompiler<'a, 'b> {
224224 file_loader: Option <Box <dyn FileLoader + Send + Sync >>,
225225 make_codegen_backend:
226226 Option <Box <dyn FnOnce ( & config:: Options ) -> Box <dyn CodegenBackend > + Send >>,
227+ using_internal_features: Arc <std:: sync:: atomic:: AtomicBool >,
227228}
228229
229230impl <' a, ' b> RunCompiler <' a, ' b> {
230231 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+ }
232239 }
233240
234241 /// Set a custom codegen backend.
@@ -260,9 +267,23 @@ impl<'a, 'b> RunCompiler<'a, 'b> {
260267 self
261268 }
262269
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+
263278 /// Parse args and run the compiler.
264279 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+ )
266287 }
267288}
268289
@@ -273,6 +294,7 @@ fn run_compiler(
273294 make_codegen_backend: Option <
274295 Box <dyn FnOnce ( & config:: Options ) -> Box <dyn CodegenBackend > + Send >,
275296 >,
297+ using_internal_features: Arc <std:: sync:: atomic:: AtomicBool >,
276298) -> interface:: Result <( ) > {
277299 let mut early_error_handler = EarlyErrorHandler :: new( ErrorOutputType :: default ( ) ) ;
278300
@@ -316,6 +338,7 @@ fn run_compiler(
316338 override_queries: None ,
317339 make_codegen_backend,
318340 registry: diagnostics_registry( ) ,
341+ using_internal_features,
319342 expanded_args: args,
320343 } ;
321344
@@ -1323,8 +1346,12 @@ fn ice_path() -> &'static Option<PathBuf> {
13231346/// If you have no extra info to report, pass the empty closure `|_| ()` as the argument to
13241347/// extra_info.
13251348///
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+ ///
13261353/// 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 > {
13281355 // If the user has not explicitly overridden "RUST_BACKTRACE", then produce
13291356 // full backtraces. When a compiler ICE happens, we want to gather
13301357 // 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))
13351362 std:: env:: set_var( "RUST_BACKTRACE" , "full" ) ;
13361363 }
13371364
1365+ let using_internal_features = Arc :: new( std:: sync:: atomic:: AtomicBool :: default ( ) ) ;
1366+ let using_internal_features_hook = using_internal_features. clone( ) ;
13381367 panic:: update_hook( Box :: new(
13391368 move |default_hook: & ( dyn Fn ( & PanicInfo <' _>) + Send + Sync + ' static ) ,
13401369 info: & PanicInfo <' _>| {
@@ -1384,9 +1413,11 @@ pub fn install_ice_hook(bug_report_url: &'static str, extra_info: fn(&Handler))
13841413 }
13851414
13861415 // 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 ) ;
13881417 } ,
13891418 ) ) ;
1419+
1420+ using_internal_features
13901421}
13911422
13921423/// 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))
13951426///
13961427/// When `install_ice_hook` is called, this function will be called as the panic
13971428/// 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+ ) {
13991435 let fallback_bundle =
14001436 rustc_errors:: fallback_fluent_bundle( crate :: DEFAULT_LOCALE_RESOURCES . to_vec( ) , false ) ;
14011437 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(
14121448 handler. emit_err( session_diagnostics:: Ice ) ;
14131449 }
14141450
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+ }
14161456
14171457 let version = util:: version_str!( ) . unwrap_or( "unknown_version" ) ;
14181458 let triple = config:: host_triple( ) ;
@@ -1496,7 +1536,7 @@ pub fn main() -> ! {
14961536 init_rustc_env_logger( & handler) ;
14971537 signal_handler:: install( ) ;
14981538 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 , |_| ( ) ) ;
15001540 let exit_code = catch_with_exit_code( || {
15011541 let args = env:: args_os( )
15021542 . enumerate( )
@@ -1506,7 +1546,9 @@ pub fn main() -> ! {
15061546 } )
15071547 } )
15081548 . 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( )
15101552 } ) ;
15111553
15121554 if let Some ( format) = callbacks. time_passes {
0 commit comments