File tree 4 files changed +31
-14
lines changed
compiler/rustc_driver_impl/src
4 files changed +31
-14
lines changed Original file line number Diff line number Diff line change @@ -1307,7 +1307,11 @@ fn ice_path() -> &'static Option<PathBuf> {
1307
1307
/// internal features.
1308
1308
///
1309
1309
/// A custom rustc driver can skip calling this to set up a custom ICE hook.
1310
- pub fn install_ice_hook(
1310
+ ///
1311
+ /// # Unsafety
1312
+ ///
1313
+ /// This function modifies the environment and has the same safety as [`std::env::set_var`].
1314
+ pub unsafe fn install_ice_hook(
1311
1315
bug_report_url: & ' static str ,
1312
1316
extra_info: fn ( & DiagCtxt ) ,
1313
1317
) -> Arc <AtomicBool > {
@@ -1520,7 +1524,8 @@ pub fn main() -> ! {
1520
1524
init_rustc_env_logger( & early_dcx) ;
1521
1525
signal_handler:: install( ) ;
1522
1526
let mut callbacks = TimePassesCallbacks :: default ( ) ;
1523
- let using_internal_features = install_ice_hook( DEFAULT_BUG_REPORT_URL , |_| ( ) ) ;
1527
+ // We're single-threaded at this point, so it's okay to call `install_ice_hook`.
1528
+ let using_internal_features = unsafe { install_ice_hook( DEFAULT_BUG_REPORT_URL , |_| ( ) ) } ;
1524
1529
install_ctrlc_handler( ) ;
1525
1530
1526
1531
let exit_code = catch_with_exit_code( || {
Original file line number Diff line number Diff line change @@ -181,13 +181,16 @@ pub fn main() {
181
181
182
182
rustc_driver:: init_rustc_env_logger ( & early_dcx) ;
183
183
184
- let using_internal_features = rustc_driver:: install_ice_hook ( BUG_REPORT_URL , |handler| {
185
- // FIXME: this macro calls unwrap internally but is called in a panicking context! It's not
186
- // as simple as moving the call from the hook to main, because `install_ice_hook` doesn't
187
- // accept a generic closure.
188
- let version_info = rustc_tools_util:: get_version_info!( ) ;
189
- handler. note ( format ! ( "Clippy version: {version_info}" ) ) ;
190
- } ) ;
184
+ // We're single-threaded at this point, so it's okay to call `install_ice_hook`.
185
+ let using_internal_features = unsafe {
186
+ rustc_driver:: install_ice_hook ( BUG_REPORT_URL , |handler| {
187
+ // FIXME: this macro calls unwrap internally but is called in a panicking context! It's not
188
+ // as simple as moving the call from the hook to main, because `install_ice_hook` doesn't
189
+ // accept a generic closure.
190
+ let version_info = rustc_tools_util:: get_version_info!( ) ;
191
+ handler. note ( format ! ( "Clippy version: {version_info}" ) ) ;
192
+ } )
193
+ } ;
191
194
192
195
exit ( rustc_driver:: catch_with_exit_code ( move || {
193
196
let mut orig_args = rustc_driver:: args:: raw_args ( & early_dcx) ?;
Original file line number Diff line number Diff line change @@ -371,8 +371,11 @@ fn main() {
371
371
// If the environment asks us to actually be rustc, then do that.
372
372
if let Some ( crate_kind) = env:: var_os ( "MIRI_BE_RUSTC" ) {
373
373
// Earliest rustc setup.
374
- let using_internal_features =
375
- rustc_driver:: install_ice_hook ( rustc_driver:: DEFAULT_BUG_REPORT_URL , |_| ( ) ) ;
374
+ //
375
+ // We're single-threaded at this point, so it's okay to call `install_ice_hook`.
376
+ let using_internal_features = unsafe {
377
+ rustc_driver:: install_ice_hook ( rustc_driver:: DEFAULT_BUG_REPORT_URL , |_| ( ) )
378
+ } ;
376
379
rustc_driver:: init_rustc_env_logger ( & early_dcx) ;
377
380
378
381
let target_crate = if crate_kind == "target" {
@@ -393,8 +396,11 @@ fn main() {
393
396
}
394
397
395
398
// Add an ICE bug report hook.
396
- let using_internal_features =
397
- rustc_driver:: install_ice_hook ( "https://github.com/rust-lang/miri/issues/new" , |_| ( ) ) ;
399
+ //
400
+ // We're single-threaded at this point, so it's okay to call `install_ice_hook`.
401
+ let using_internal_features = unsafe {
402
+ rustc_driver:: install_ice_hook ( "https://github.com/rust-lang/miri/issues/new" , |_| ( ) )
403
+ } ;
398
404
399
405
// Init loggers the Miri way.
400
406
init_early_loggers ( & early_dcx) ;
Original file line number Diff line number Diff line change @@ -28,7 +28,10 @@ const BUG_REPORT_URL: &str = "https://github.com/rust-lang/rustfmt/issues/new?la
28
28
extern crate rustc_driver;
29
29
30
30
fn main ( ) {
31
- rustc_driver:: install_ice_hook ( BUG_REPORT_URL , |_| ( ) ) ;
31
+ // We're single-threaded at this point, so it's okay to call `install_ice_hook`.
32
+ unsafe {
33
+ rustc_driver:: install_ice_hook ( BUG_REPORT_URL , |_| ( ) ) ;
34
+ }
32
35
33
36
tracing_subscriber:: fmt ( )
34
37
. with_env_filter ( EnvFilter :: from_env ( "RUSTFMT_LOG" ) )
You can’t perform that action at this time.
0 commit comments