Skip to content

Commit

Permalink
Rollup merge of rust-lang#136636 - bjorn3:error_cleanup, r=compiler-e…
Browse files Browse the repository at this point in the history
…rrors

Couple of minor cleanups to the diagnostic infrastructure
  • Loading branch information
matthiaskrgr authored Feb 6, 2025
2 parents 3eb1ef8 + b9b2c3a commit 79e5424
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 22 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_interface/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ where
static USING_INTERNAL_FEATURES: AtomicBool = AtomicBool::new(false);

let sess = build_session(
early_dcx,
sessopts,
io,
None,
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_parse/src/parser/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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));
Expand Down
18 changes: 6 additions & 12 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>>,
Expand All @@ -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,
Expand All @@ -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
{
Expand Down

0 comments on commit 79e5424

Please sign in to comment.