@@ -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: Option <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: None ,
238+ }
232239 }
233240
234241 /// Set a custom codegen backend.
@@ -260,9 +267,25 @@ 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+ pub fn set_using_internal_features(
273+ & mut self ,
274+ using_internal_features: Option <Arc <AtomicBool >>,
275+ ) -> & mut Self {
276+ self . using_internal_features = using_internal_features;
277+ self
278+ }
279+
263280 /// Parse args and run the compiler.
264281 pub fn run( self ) -> interface:: Result <( ) > {
265- run_compiler( self . at_args, self . callbacks, self . file_loader, self . make_codegen_backend)
282+ run_compiler(
283+ self . at_args,
284+ self . callbacks,
285+ self . file_loader,
286+ self . make_codegen_backend,
287+ self . using_internal_features,
288+ )
266289 }
267290}
268291
@@ -273,6 +296,7 @@ fn run_compiler(
273296 make_codegen_backend: Option <
274297 Box <dyn FnOnce ( & config:: Options ) -> Box <dyn CodegenBackend > + Send >,
275298 >,
299+ using_internal_features: Option <Arc <std:: sync:: atomic:: AtomicBool >>,
276300) -> interface:: Result <( ) > {
277301 let mut early_error_handler = EarlyErrorHandler :: new( ErrorOutputType :: default ( ) ) ;
278302
@@ -316,6 +340,7 @@ fn run_compiler(
316340 override_queries: None ,
317341 make_codegen_backend,
318342 registry: diagnostics_registry( ) ,
343+ using_internal_features,
319344 expanded_args: args,
320345 } ;
321346
@@ -1323,8 +1348,16 @@ fn ice_path() -> &'static Option<PathBuf> {
13231348/// If you have no extra info to report, pass the empty closure `|_| ()` as the argument to
13241349/// extra_info.
13251350///
1351+ /// If emitting the "please submit a bug" message is fine when internal features are enabled, `None`
1352+ /// can be passed as the `using_internal_features`. To hide the note, pass in a bool that is also passed
1353+ /// to [`RunCompiler::set_using_internal_features`].
1354+ ///
13261355/// 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 ) ) {
1356+ pub fn install_ice_hook(
1357+ bug_report_url: & ' static str ,
1358+ extra_info: fn ( & Handler ) ,
1359+ using_internal_features: Option <Arc <AtomicBool >>,
1360+ ) {
13281361 // If the user has not explicitly overridden "RUST_BACKTRACE", then produce
13291362 // full backtraces. When a compiler ICE happens, we want to gather
13301363 // as much information as possible to present in the issue opened
@@ -1384,7 +1417,7 @@ pub fn install_ice_hook(bug_report_url: &'static str, extra_info: fn(&Handler))
13841417 }
13851418
13861419 // Print the ICE message
1387- report_ice( info, bug_report_url, extra_info) ;
1420+ report_ice( info, bug_report_url, extra_info, using_internal_features . clone ( ) ) ;
13881421 } ,
13891422 ) ) ;
13901423}
@@ -1395,7 +1428,12 @@ pub fn install_ice_hook(bug_report_url: &'static str, extra_info: fn(&Handler))
13951428///
13961429/// When `install_ice_hook` is called, this function will be called as the panic
13971430/// hook.
1398- fn report_ice( info: & panic:: PanicInfo <' _>, bug_report_url: & str , extra_info: fn ( & Handler ) ) {
1431+ fn report_ice(
1432+ info: & panic:: PanicInfo <' _>,
1433+ bug_report_url: & str ,
1434+ extra_info: fn ( & Handler ) ,
1435+ using_internal_features: Option <Arc <AtomicBool >>,
1436+ ) {
13991437 let fallback_bundle =
14001438 rustc_errors:: fallback_fluent_bundle( crate :: DEFAULT_LOCALE_RESOURCES . to_vec( ) , false ) ;
14011439 let emitter = Box :: new( rustc_errors:: emitter:: EmitterWriter :: stderr(
@@ -1412,7 +1450,13 @@ fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str, extra_info: fn(
14121450 handler. emit_err( session_diagnostics:: Ice ) ;
14131451 }
14141452
1415- handler. emit_note( session_diagnostics:: IceBugReport { bug_report_url } ) ;
1453+ if using_internal_features
1454+ . map_or( false , |internal| internal. load( std:: sync:: atomic:: Ordering :: Relaxed ) )
1455+ {
1456+ handler. emit_note( session_diagnostics:: IceBugReportInternalFeature ) ;
1457+ } else {
1458+ handler. emit_note( session_diagnostics:: IceBugReport { bug_report_url } ) ;
1459+ }
14161460
14171461 let version = util:: version_str!( ) . unwrap_or( "unknown_version" ) ;
14181462 let triple = config:: host_triple( ) ;
@@ -1493,10 +1537,12 @@ pub fn main() -> ! {
14931537
14941538 let handler = EarlyErrorHandler :: new( ErrorOutputType :: default ( ) ) ;
14951539
1540+ let using_internal_features = Some ( Arc :: default ( ) ) ;
1541+
14961542 init_rustc_env_logger( & handler) ;
14971543 signal_handler:: install( ) ;
14981544 let mut callbacks = TimePassesCallbacks :: default ( ) ;
1499- install_ice_hook( DEFAULT_BUG_REPORT_URL , |_| ( ) ) ;
1545+ install_ice_hook( DEFAULT_BUG_REPORT_URL , |_| ( ) , using_internal_features . clone ( ) ) ;
15001546 let exit_code = catch_with_exit_code( || {
15011547 let args = env:: args_os( )
15021548 . enumerate( )
@@ -1506,7 +1552,9 @@ pub fn main() -> ! {
15061552 } )
15071553 } )
15081554 . collect:: <Vec <_>>( ) ;
1509- RunCompiler :: new( & args, & mut callbacks) . run( )
1555+ let mut run = RunCompiler :: new( & args, & mut callbacks) ;
1556+ run. set_using_internal_features( using_internal_features) ;
1557+ run. run( )
15101558 } ) ;
15111559
15121560 if let Some ( format) = callbacks. time_passes {
0 commit comments