Skip to content

Commit 4f9b9a4

Browse files
committed
Remove the need to manually call set_using_internal_features
1 parent b2728d5 commit 4f9b9a4

File tree

10 files changed

+36
-93
lines changed

10 files changed

+36
-93
lines changed

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ use std::io::{self, IsTerminal, Read, Write};
2828
use std::panic::{self, PanicHookInfo, catch_unwind};
2929
use std::path::{Path, PathBuf};
3030
use std::process::{self, Command, Stdio};
31+
use std::sync::OnceLock;
3132
use std::sync::atomic::{AtomicBool, Ordering};
32-
use std::sync::{Arc, OnceLock};
3333
use std::time::{Instant, SystemTime};
3434
use std::{env, str};
3535

@@ -214,18 +214,11 @@ pub struct RunCompiler<'a> {
214214
file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
215215
make_codegen_backend:
216216
Option<Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>>,
217-
using_internal_features: Arc<std::sync::atomic::AtomicBool>,
218217
}
219218

220219
impl<'a> RunCompiler<'a> {
221220
pub fn new(at_args: &'a [String], callbacks: &'a mut (dyn Callbacks + Send)) -> Self {
222-
Self {
223-
at_args,
224-
callbacks,
225-
file_loader: None,
226-
make_codegen_backend: None,
227-
using_internal_features: Arc::default(),
228-
}
221+
Self { at_args, callbacks, file_loader: None, make_codegen_backend: None }
229222
}
230223

231224
/// Set a custom codegen backend.
@@ -257,23 +250,9 @@ impl<'a> RunCompiler<'a> {
257250
self
258251
}
259252

260-
/// Set the session-global flag that checks whether internal features have been used,
261-
/// suppressing the message about submitting an issue in ICEs when enabled.
262-
#[must_use]
263-
pub fn set_using_internal_features(mut self, using_internal_features: Arc<AtomicBool>) -> Self {
264-
self.using_internal_features = using_internal_features;
265-
self
266-
}
267-
268253
/// Parse args and run the compiler.
269254
pub fn run(self) {
270-
run_compiler(
271-
self.at_args,
272-
self.callbacks,
273-
self.file_loader,
274-
self.make_codegen_backend,
275-
self.using_internal_features,
276-
);
255+
run_compiler(self.at_args, self.callbacks, self.file_loader, self.make_codegen_backend);
277256
}
278257
}
279258

@@ -284,7 +263,6 @@ fn run_compiler(
284263
make_codegen_backend: Option<
285264
Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>,
286265
>,
287-
using_internal_features: Arc<std::sync::atomic::AtomicBool>,
288266
) {
289267
let mut default_early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default());
290268

@@ -331,7 +309,7 @@ fn run_compiler(
331309
override_queries: None,
332310
make_codegen_backend,
333311
registry: diagnostics_registry(),
334-
using_internal_features,
312+
using_internal_features: &USING_INTERNAL_FEATURES,
335313
expanded_args: args,
336314
};
337315

@@ -1350,6 +1328,8 @@ fn ice_path_with_config(config: Option<&UnstableOptions>) -> &'static Option<Pat
13501328
})
13511329
}
13521330

1331+
pub static USING_INTERNAL_FEATURES: AtomicBool = AtomicBool::new(false);
1332+
13531333
/// Installs a panic hook that will print the ICE message on unexpected panics.
13541334
///
13551335
/// The hook is intended to be useable even by external tools. You can pass a custom
@@ -1360,15 +1340,8 @@ fn ice_path_with_config(config: Option<&UnstableOptions>) -> &'static Option<Pat
13601340
/// If you have no extra info to report, pass the empty closure `|_| ()` as the argument to
13611341
/// extra_info.
13621342
///
1363-
/// Returns a flag that can be set to disable the note for submitting a bug. This can be passed to
1364-
/// [`RunCompiler::set_using_internal_features`] to let macro expansion set it when encountering
1365-
/// internal features.
1366-
///
13671343
/// A custom rustc driver can skip calling this to set up a custom ICE hook.
1368-
pub fn install_ice_hook(
1369-
bug_report_url: &'static str,
1370-
extra_info: fn(&DiagCtxt),
1371-
) -> Arc<AtomicBool> {
1344+
pub fn install_ice_hook(bug_report_url: &'static str, extra_info: fn(&DiagCtxt)) {
13721345
// If the user has not explicitly overridden "RUST_BACKTRACE", then produce
13731346
// full backtraces. When a compiler ICE happens, we want to gather
13741347
// as much information as possible to present in the issue opened
@@ -1385,8 +1358,6 @@ pub fn install_ice_hook(
13851358
}
13861359
}
13871360

1388-
let using_internal_features = Arc::new(std::sync::atomic::AtomicBool::default());
1389-
let using_internal_features_hook = Arc::clone(&using_internal_features);
13901361
panic::update_hook(Box::new(
13911362
move |default_hook: &(dyn Fn(&PanicHookInfo<'_>) + Send + Sync + 'static),
13921363
info: &PanicHookInfo<'_>| {
@@ -1438,11 +1409,9 @@ pub fn install_ice_hook(
14381409
}
14391410

14401411
// Print the ICE message
1441-
report_ice(info, bug_report_url, extra_info, &using_internal_features_hook);
1412+
report_ice(info, bug_report_url, extra_info, &USING_INTERNAL_FEATURES);
14421413
},
14431414
));
1444-
1445-
using_internal_features
14461415
}
14471416

14481417
/// Prints the ICE message, including query stack, but without backtrace.
@@ -1583,13 +1552,11 @@ pub fn main() -> ! {
15831552
init_rustc_env_logger(&early_dcx);
15841553
signal_handler::install();
15851554
let mut callbacks = TimePassesCallbacks::default();
1586-
let using_internal_features = install_ice_hook(DEFAULT_BUG_REPORT_URL, |_| ());
1555+
install_ice_hook(DEFAULT_BUG_REPORT_URL, |_| ());
15871556
install_ctrlc_handler();
15881557

15891558
let exit_code = catch_with_exit_code(|| {
1590-
RunCompiler::new(&args::raw_args(&early_dcx)?, &mut callbacks)
1591-
.set_using_internal_features(using_internal_features)
1592-
.run();
1559+
RunCompiler::new(&args::raw_args(&early_dcx)?, &mut callbacks).run();
15931560
Ok(())
15941561
});
15951562

compiler/rustc_interface/src/interface.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::path::PathBuf;
22
use std::result;
3-
use std::sync::Arc;
43

54
use rustc_ast::{LitKind, MetaItemKind, token};
65
use rustc_codegen_ssa::traits::CodegenBackend;
@@ -347,7 +346,7 @@ pub struct Config {
347346
/// enabled. Makes it so that "please report a bug" is hidden, as ICEs with
348347
/// internal features are wontfix, and they are usually the cause of the ICEs.
349348
/// None signifies that this is not tracked.
350-
pub using_internal_features: Arc<std::sync::atomic::AtomicBool>,
349+
pub using_internal_features: &'static std::sync::atomic::AtomicBool,
351350

352351
/// All commandline args used to invoke the compiler, with @file args fully expanded.
353352
/// This will only be used within debug info, e.g. in the pdb file on windows

compiler/rustc_interface/src/tests.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use std::collections::{BTreeMap, BTreeSet};
33
use std::num::NonZero;
44
use std::path::{Path, PathBuf};
5-
use std::sync::Arc;
5+
use std::sync::atomic::AtomicBool;
66

77
use rustc_data_structures::profiling::TimePassesFormat;
88
use rustc_errors::emitter::HumanReadableErrorType;
@@ -62,6 +62,8 @@ where
6262
temps_dir,
6363
};
6464

65+
static USING_INTERNAL_FEATURES: AtomicBool = AtomicBool::new(false);
66+
6567
let sess = build_session(
6668
early_dcx,
6769
sessopts,
@@ -74,7 +76,7 @@ where
7476
sysroot,
7577
"",
7678
None,
77-
Arc::default(),
79+
&USING_INTERNAL_FEATURES,
7880
Default::default(),
7981
);
8082
let cfg = parse_cfg(sess.dcx(), matches.opt_strs("cfg"));

compiler/rustc_session/src/session.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ pub struct Session {
189189
/// enabled. Makes it so that "please report a bug" is hidden, as ICEs with
190190
/// internal features are wontfix, and they are usually the cause of the ICEs.
191191
/// None signifies that this is not tracked.
192-
pub using_internal_features: Arc<AtomicBool>,
192+
pub using_internal_features: &'static AtomicBool,
193193

194194
/// All commandline args used to invoke the compiler, with @file args fully expanded.
195195
/// This will only be used within debug info, e.g. in the pdb file on windows
@@ -966,7 +966,7 @@ pub fn build_session(
966966
sysroot: PathBuf,
967967
cfg_version: &'static str,
968968
ice_file: Option<PathBuf>,
969-
using_internal_features: Arc<AtomicBool>,
969+
using_internal_features: &'static AtomicBool,
970970
expanded_args: Vec<String>,
971971
) -> Session {
972972
// FIXME: This is not general enough to make the warning lint completely override

src/librustdoc/core.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use std::sync::atomic::AtomicBool;
2-
use std::sync::{Arc, LazyLock};
1+
use std::sync::LazyLock;
32
use std::{io, mem};
43

54
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
65
use rustc_data_structures::sync::Lrc;
76
use rustc_data_structures::unord::UnordSet;
7+
use rustc_driver::USING_INTERNAL_FEATURES;
88
use rustc_errors::TerminalUrl;
99
use rustc_errors::codes::*;
1010
use rustc_errors::emitter::{
@@ -221,7 +221,6 @@ pub(crate) fn create_config(
221221
..
222222
}: RustdocOptions,
223223
RenderOptions { document_private, .. }: &RenderOptions,
224-
using_internal_features: Arc<AtomicBool>,
225224
) -> rustc_interface::Config {
226225
// Add the doc cfg into the doc build.
227226
cfgs.push("doc".to_string());
@@ -316,7 +315,7 @@ pub(crate) fn create_config(
316315
make_codegen_backend: None,
317316
registry: rustc_driver::diagnostics_registry(),
318317
ice_file: None,
319-
using_internal_features,
318+
using_internal_features: &USING_INTERNAL_FEATURES,
320319
expanded_args,
321320
}
322321
}

src/librustdoc/doctest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ pub(crate) fn run(dcx: DiagCtxtHandle<'_>, input: Input, options: RustdocOptions
193193
make_codegen_backend: None,
194194
registry: rustc_driver::diagnostics_registry(),
195195
ice_file: None,
196-
using_internal_features: Arc::default(),
196+
using_internal_features: &rustc_driver::USING_INTERNAL_FEATURES,
197197
expanded_args: options.expanded_args.clone(),
198198
};
199199

src/librustdoc/lib.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ extern crate tikv_jemalloc_sys as jemalloc_sys;
7373
use std::env::{self, VarError};
7474
use std::io::{self, IsTerminal};
7575
use std::process;
76-
use std::sync::Arc;
77-
use std::sync::atomic::AtomicBool;
7876

7977
use rustc_errors::DiagCtxtHandle;
8078
use rustc_interface::interface;
@@ -158,7 +156,7 @@ pub fn main() {
158156

159157
let mut early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default());
160158

161-
let using_internal_features = rustc_driver::install_ice_hook(
159+
rustc_driver::install_ice_hook(
162160
"https://github.com/rust-lang/rust/issues/new\
163161
?labels=C-bug%2C+I-ICE%2C+T-rustdoc&template=ice.md",
164162
|_| (),
@@ -179,7 +177,7 @@ pub fn main() {
179177

180178
let exit_code = rustc_driver::catch_with_exit_code(|| {
181179
let at_args = rustc_driver::args::raw_args(&early_dcx)?;
182-
main_args(&mut early_dcx, &at_args, using_internal_features);
180+
main_args(&mut early_dcx, &at_args);
183181
Ok(())
184182
});
185183
process::exit(exit_code);
@@ -768,11 +766,7 @@ fn run_merge_finalize(opt: config::RenderOptions) -> Result<(), error::Error> {
768766
Ok(())
769767
}
770768

771-
fn main_args(
772-
early_dcx: &mut EarlyDiagCtxt,
773-
at_args: &[String],
774-
using_internal_features: Arc<AtomicBool>,
775-
) {
769+
fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) {
776770
// Throw away the first argument, the name of the binary.
777771
// In case of at_args being empty, as might be the case by
778772
// passing empty argument array to execve under some platforms,
@@ -825,8 +819,7 @@ fn main_args(
825819
(false, Some(md_input)) => {
826820
let md_input = md_input.to_owned();
827821
let edition = options.edition;
828-
let config =
829-
core::create_config(input, options, &render_options, using_internal_features);
822+
let config = core::create_config(input, options, &render_options);
830823

831824
// `markdown::render` can invoke `doctest::make_test`, which
832825
// requires session globals and a thread pool, so we use
@@ -859,7 +852,7 @@ fn main_args(
859852
let scrape_examples_options = options.scrape_examples_options.clone();
860853
let bin_crate = options.bin_crate;
861854

862-
let config = core::create_config(input, options, &render_options, using_internal_features);
855+
let config = core::create_config(input, options, &render_options);
863856

864857
let registered_lints = config.register_lints.is_some();
865858

src/tools/clippy/src/driver.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ pub fn main() {
186186

187187
rustc_driver::init_rustc_env_logger(&early_dcx);
188188

189-
let using_internal_features = rustc_driver::install_ice_hook(BUG_REPORT_URL, |dcx| {
189+
rustc_driver::install_ice_hook(BUG_REPORT_URL, |dcx| {
190190
// FIXME: this macro calls unwrap internally but is called in a panicking context! It's not
191191
// as simple as moving the call from the hook to main, because `install_ice_hook` doesn't
192192
// accept a generic closure.
@@ -295,13 +295,9 @@ pub fn main() {
295295
let clippy_enabled = !cap_lints_allow && relevant_package && !info_query;
296296
if clippy_enabled {
297297
args.extend(clippy_args);
298-
rustc_driver::RunCompiler::new(&args, &mut ClippyCallbacks { clippy_args_var })
299-
.set_using_internal_features(using_internal_features)
300-
.run();
298+
rustc_driver::RunCompiler::new(&args, &mut ClippyCallbacks { clippy_args_var }).run();
301299
} else {
302-
rustc_driver::RunCompiler::new(&args, &mut RustcCallbacks { clippy_args_var })
303-
.set_using_internal_features(using_internal_features)
304-
.run();
300+
rustc_driver::RunCompiler::new(&args, &mut RustcCallbacks { clippy_args_var }).run();
305301
}
306302
Ok(())
307303
}))

src/tools/miri/src/bin/miri.rs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use std::ops::Range;
3030
use std::path::PathBuf;
3131
use std::str::FromStr;
3232
use std::sync::atomic::{AtomicI32, Ordering};
33-
use std::sync::{Arc, Once};
33+
use std::sync::Once;
3434

3535
use miri::{
3636
BacktraceStyle, BorrowTrackerMethod, MiriConfig, MiriEntryFnType,ProvenanceMode, RetagFields, ValidationMode,
@@ -370,13 +370,10 @@ fn init_late_loggers(early_dcx: &EarlyDiagCtxt, tcx: TyCtxt<'_>) {
370370
fn run_compiler_and_exit(
371371
args: &[String],
372372
callbacks: &mut (dyn rustc_driver::Callbacks + Send),
373-
using_internal_features: Arc<std::sync::atomic::AtomicBool>,
374373
) -> ! {
375374
// Invoke compiler, and handle return code.
376375
let exit_code = rustc_driver::catch_with_exit_code(move || {
377-
rustc_driver::RunCompiler::new(args, callbacks)
378-
.set_using_internal_features(using_internal_features)
379-
.run();
376+
rustc_driver::RunCompiler::new(args, callbacks).run();
380377
Ok(())
381378
});
382379
std::process::exit(exit_code)
@@ -467,8 +464,7 @@ fn main() {
467464
// If the environment asks us to actually be rustc, then do that.
468465
if let Some(crate_kind) = env::var_os("MIRI_BE_RUSTC") {
469466
// Earliest rustc setup.
470-
let using_internal_features =
471-
rustc_driver::install_ice_hook(rustc_driver::DEFAULT_BUG_REPORT_URL, |_| ());
467+
rustc_driver::install_ice_hook(rustc_driver::DEFAULT_BUG_REPORT_URL, |_| ());
472468
rustc_driver::init_rustc_env_logger(&early_dcx);
473469

474470
let target_crate = if crate_kind == "target" {
@@ -492,16 +488,11 @@ fn main() {
492488
}
493489

494490
// We cannot use `rustc_driver::main` as we want it to use `args` as the CLI arguments.
495-
run_compiler_and_exit(
496-
&args,
497-
&mut MiriBeRustCompilerCalls { target_crate },
498-
using_internal_features,
499-
)
491+
run_compiler_and_exit(&args, &mut MiriBeRustCompilerCalls { target_crate })
500492
}
501493

502494
// Add an ICE bug report hook.
503-
let using_internal_features =
504-
rustc_driver::install_ice_hook("https://github.com/rust-lang/miri/issues/new", |_| ());
495+
rustc_driver::install_ice_hook("https://github.com/rust-lang/miri/issues/new", |_| ());
505496

506497
// Init loggers the Miri way.
507498
init_early_loggers(&early_dcx);
@@ -735,9 +726,5 @@ fn main() {
735726

736727
debug!("rustc arguments: {:?}", rustc_args);
737728
debug!("crate arguments: {:?}", miri_config.args);
738-
run_compiler_and_exit(
739-
&rustc_args,
740-
&mut MiriCompilerCalls::new(miri_config, many_seeds),
741-
using_internal_features,
742-
)
729+
run_compiler_and_exit(&rustc_args, &mut MiriCompilerCalls::new(miri_config, many_seeds))
743730
}

tests/ui-fulldeps/run-compiler-twice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fn compile(code: String, output: PathBuf, sysroot: PathBuf, linker: Option<&Path
7272
override_queries: None,
7373
make_codegen_backend: None,
7474
registry: rustc_driver::diagnostics_registry(),
75-
using_internal_features: std::sync::Arc::default(),
75+
using_internal_features: &rustc_driver::USING_INTERNAL_FEATURES,
7676
expanded_args: Default::default(),
7777
};
7878

0 commit comments

Comments
 (0)