Skip to content

Commit 79e5424

Browse files
authored
Rollup merge of #136636 - bjorn3:error_cleanup, r=compiler-errors
Couple of minor cleanups to the diagnostic infrastructure
2 parents 3eb1ef8 + b9b2c3a commit 79e5424

File tree

6 files changed

+12
-22
lines changed

6 files changed

+12
-22
lines changed

compiler/rustc_driver_impl/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ pub fn describe_flag_categories(early_dcx: &EarlyDiagCtxt, matches: &Matches) ->
10241024
let wall = matches.opt_strs("W");
10251025
if wall.iter().any(|x| *x == "all") {
10261026
print_wall_help();
1027-
rustc_errors::FatalError.raise();
1027+
return true;
10281028
}
10291029

10301030
// Don't handle -W help here, because we might first load additional lints.

compiler/rustc_errors/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1048,8 +1048,8 @@ impl<'a> DiagCtxtHandle<'a> {
10481048
/// bad results, such as spurious/uninteresting additional errors -- when
10491049
/// returning an error `Result` is difficult.
10501050
pub fn abort_if_errors(&self) {
1051-
if self.has_errors().is_some() {
1052-
FatalError.raise();
1051+
if let Some(guar) = self.has_errors() {
1052+
guar.raise_fatal();
10531053
}
10541054
}
10551055

compiler/rustc_interface/src/interface.rs

-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,6 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
442442
locale_resources.push(codegen_backend.locale_resource());
443443

444444
let mut sess = rustc_session::build_session(
445-
early_dcx,
446445
config.opts,
447446
CompilerIO {
448447
input: config.input,

compiler/rustc_interface/src/tests.rs

-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ where
6565
static USING_INTERNAL_FEATURES: AtomicBool = AtomicBool::new(false);
6666

6767
let sess = build_session(
68-
early_dcx,
6968
sessopts,
7069
io,
7170
None,

compiler/rustc_parse/src/parser/tests.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::parser::{ForceCollect, Parser};
2626
use crate::{new_parser_from_source_str, source_str_to_stream, unwrap_or_emit_fatal};
2727

2828
fn psess() -> ParseSess {
29-
ParseSess::new(vec![crate::DEFAULT_LOCALE_RESOURCE, crate::DEFAULT_LOCALE_RESOURCE])
29+
ParseSess::new(vec![crate::DEFAULT_LOCALE_RESOURCE])
3030
}
3131

3232
/// Map string to parser (via tts).
@@ -41,10 +41,8 @@ fn string_to_parser(psess: &ParseSess, source_str: String) -> Parser<'_> {
4141
fn create_test_handler(theme: OutputTheme) -> (DiagCtxt, Arc<SourceMap>, Arc<Mutex<Vec<u8>>>) {
4242
let output = Arc::new(Mutex::new(Vec::new()));
4343
let source_map = Arc::new(SourceMap::new(FilePathMapping::empty()));
44-
let fallback_bundle = rustc_errors::fallback_fluent_bundle(
45-
vec![crate::DEFAULT_LOCALE_RESOURCE, crate::DEFAULT_LOCALE_RESOURCE],
46-
false,
47-
);
44+
let fallback_bundle =
45+
rustc_errors::fallback_fluent_bundle(vec![crate::DEFAULT_LOCALE_RESOURCE], false);
4846
let mut emitter = HumanEmitter::new(Box::new(Shared { data: output.clone() }), fallback_bundle)
4947
.sm(Some(source_map.clone()))
5048
.diagnostic_width(Some(140));

compiler/rustc_session/src/session.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,6 @@ fn default_emitter(
965965
#[allow(rustc::bad_opt_access)]
966966
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
967967
pub fn build_session(
968-
early_dcx: EarlyDiagCtxt,
969968
sopts: config::Options,
970969
io: CompilerIO,
971970
bundle: Option<Arc<rustc_errors::FluentBundle>>,
@@ -990,14 +989,6 @@ pub fn build_session(
990989
let cap_lints_allow = sopts.lint_cap.is_some_and(|cap| cap == lint::Allow);
991990
let can_emit_warnings = !(warnings_allow || cap_lints_allow);
992991

993-
let host_triple = TargetTuple::from_tuple(config::host_tuple());
994-
let (host, target_warnings) = Target::search(&host_triple, &sysroot).unwrap_or_else(|e| {
995-
early_dcx.early_fatal(format!("Error loading host specification: {e}"))
996-
});
997-
for warning in target_warnings.warning_messages() {
998-
early_dcx.early_warn(warning)
999-
}
1000-
1001992
let fallback_bundle = fallback_fluent_bundle(
1002993
fluent_resources,
1003994
sopts.unstable_opts.translate_directionality_markers,
@@ -1012,9 +1003,12 @@ pub fn build_session(
10121003
dcx = dcx.with_ice_file(ice_file);
10131004
}
10141005

1015-
// Now that the proper handler has been constructed, drop early_dcx to
1016-
// prevent accidental use.
1017-
drop(early_dcx);
1006+
let host_triple = TargetTuple::from_tuple(config::host_tuple());
1007+
let (host, target_warnings) = Target::search(&host_triple, &sysroot)
1008+
.unwrap_or_else(|e| dcx.handle().fatal(format!("Error loading host specification: {e}")));
1009+
for warning in target_warnings.warning_messages() {
1010+
dcx.handle().warn(warning)
1011+
}
10181012

10191013
let self_profiler = if let SwitchWithOptPath::Enabled(ref d) = sopts.unstable_opts.self_profile
10201014
{

0 commit comments

Comments
 (0)