Rollup merge of #136636 - bjorn3:error_cleanup, r=compiler-errors

Couple of minor cleanups to the diagnostic infrastructure
This commit is contained in:
Matthias Krüger 2025-02-06 21:56:28 +01:00 committed by GitHub
commit 79e5424e31
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 12 additions and 22 deletions

View file

@ -1024,7 +1024,7 @@ pub fn describe_flag_categories(early_dcx: &EarlyDiagCtxt, matches: &Matches) ->
let wall = matches.opt_strs("W");
if wall.iter().any(|x| *x == "all") {
print_wall_help();
rustc_errors::FatalError.raise();
return true;
}
// Don't handle -W help here, because we might first load additional lints.

View file

@ -1048,8 +1048,8 @@ impl<'a> DiagCtxtHandle<'a> {
/// bad results, such as spurious/uninteresting additional errors -- when
/// returning an error `Result` is difficult.
pub fn abort_if_errors(&self) {
if self.has_errors().is_some() {
FatalError.raise();
if let Some(guar) = self.has_errors() {
guar.raise_fatal();
}
}

View file

@ -442,7 +442,6 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
locale_resources.push(codegen_backend.locale_resource());
let mut sess = rustc_session::build_session(
early_dcx,
config.opts,
CompilerIO {
input: config.input,

View file

@ -65,7 +65,6 @@ where
static USING_INTERNAL_FEATURES: AtomicBool = AtomicBool::new(false);
let sess = build_session(
early_dcx,
sessopts,
io,
None,

View file

@ -26,7 +26,7 @@ use crate::parser::{ForceCollect, Parser};
use crate::{new_parser_from_source_str, source_str_to_stream, unwrap_or_emit_fatal};
fn psess() -> ParseSess {
ParseSess::new(vec![crate::DEFAULT_LOCALE_RESOURCE, crate::DEFAULT_LOCALE_RESOURCE])
ParseSess::new(vec![crate::DEFAULT_LOCALE_RESOURCE])
}
/// Map string to parser (via tts).
@ -41,10 +41,8 @@ fn string_to_parser(psess: &ParseSess, source_str: String) -> Parser<'_> {
fn create_test_handler(theme: OutputTheme) -> (DiagCtxt, Arc<SourceMap>, Arc<Mutex<Vec<u8>>>) {
let output = Arc::new(Mutex::new(Vec::new()));
let source_map = Arc::new(SourceMap::new(FilePathMapping::empty()));
let fallback_bundle = rustc_errors::fallback_fluent_bundle(
vec![crate::DEFAULT_LOCALE_RESOURCE, crate::DEFAULT_LOCALE_RESOURCE],
false,
);
let fallback_bundle =
rustc_errors::fallback_fluent_bundle(vec![crate::DEFAULT_LOCALE_RESOURCE], false);
let mut emitter = HumanEmitter::new(Box::new(Shared { data: output.clone() }), fallback_bundle)
.sm(Some(source_map.clone()))
.diagnostic_width(Some(140));

View file

@ -965,7 +965,6 @@ fn default_emitter(
#[allow(rustc::bad_opt_access)]
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
pub fn build_session(
early_dcx: EarlyDiagCtxt,
sopts: config::Options,
io: CompilerIO,
bundle: Option<Arc<rustc_errors::FluentBundle>>,
@ -990,14 +989,6 @@ pub fn build_session(
let cap_lints_allow = sopts.lint_cap.is_some_and(|cap| cap == lint::Allow);
let can_emit_warnings = !(warnings_allow || cap_lints_allow);
let host_triple = TargetTuple::from_tuple(config::host_tuple());
let (host, target_warnings) = Target::search(&host_triple, &sysroot).unwrap_or_else(|e| {
early_dcx.early_fatal(format!("Error loading host specification: {e}"))
});
for warning in target_warnings.warning_messages() {
early_dcx.early_warn(warning)
}
let fallback_bundle = fallback_fluent_bundle(
fluent_resources,
sopts.unstable_opts.translate_directionality_markers,
@ -1012,9 +1003,12 @@ pub fn build_session(
dcx = dcx.with_ice_file(ice_file);
}
// Now that the proper handler has been constructed, drop early_dcx to
// prevent accidental use.
drop(early_dcx);
let host_triple = TargetTuple::from_tuple(config::host_tuple());
let (host, target_warnings) = Target::search(&host_triple, &sysroot)
.unwrap_or_else(|e| dcx.handle().fatal(format!("Error loading host specification: {e}")));
for warning in target_warnings.warning_messages() {
dcx.handle().warn(warning)
}
let self_profiler = if let SwitchWithOptPath::Enabled(ref d) = sopts.unstable_opts.self_profile
{