Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 19121e8

Browse files
authoredMar 23, 2025
Unrolled build for rust-lang#138786
Rollup merge of rust-lang#138786 - bjorn3:driver_code_move, r=compiler-errors Move some driver code around `--emit mir`, `#[rustc_symbol_name]` and `#[rustc_def_path]` now run before codegen and thus work even if codegen fails. This can help with debugging.
2 parents b48576b + cd929bf commit 19121e8

File tree

10 files changed

+37
-43
lines changed

10 files changed

+37
-43
lines changed
 

‎compiler/rustc_driver_impl/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
driver_impl_cant_emit_mir = could not emit MIR: {$error}
2+
13
driver_impl_ice = the compiler unexpectedly panicked. this is a bug.
24
driver_impl_ice_bug_report = we would appreciate a bug report: {$bug_report_url}
35
driver_impl_ice_bug_report_internal_feature = using internal features is not supported and expected to cause internal compiler errors when used incorrectly

‎compiler/rustc_driver_impl/src/lib.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ mod signal_handler {
108108
}
109109

110110
use crate::session_diagnostics::{
111-
RLinkEmptyVersionNumber, RLinkEncodingVersionMismatch, RLinkRustcVersionMismatch,
111+
CantEmitMIR, RLinkEmptyVersionNumber, RLinkEncodingVersionMismatch, RLinkRustcVersionMismatch,
112112
RLinkWrongFileType, RlinkCorruptFile, RlinkNotAFile, RlinkUnableToRead, UnstableFeatureUsage,
113113
};
114114

@@ -243,12 +243,17 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
243243
return;
244244
}
245245

246+
let input = make_input(&default_early_dcx, &matches.free);
247+
let has_input = input.is_some();
246248
let (odir, ofile) = make_output(&matches);
249+
250+
drop(default_early_dcx);
251+
247252
let mut config = interface::Config {
248253
opts: sopts,
249254
crate_cfg: matches.opt_strs("cfg"),
250255
crate_check_cfg: matches.opt_strs("check-cfg"),
251-
input: Input::File(PathBuf::new()),
256+
input: input.unwrap_or(Input::File(PathBuf::new())),
252257
output_file: ofile,
253258
output_dir: odir,
254259
ice_file,
@@ -265,16 +270,6 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
265270
expanded_args: args,
266271
};
267272

268-
let has_input = match make_input(&default_early_dcx, &matches.free) {
269-
Some(input) => {
270-
config.input = input;
271-
true // has input: normal compilation
272-
}
273-
None => false, // no input: we will exit early
274-
};
275-
276-
drop(default_early_dcx);
277-
278273
callbacks.config(&mut config);
279274

280275
let registered_lints = config.register_lints.is_some();
@@ -379,6 +374,12 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
379374
return early_exit();
380375
}
381376

377+
if tcx.sess.opts.output_types.contains_key(&OutputType::Mir) {
378+
if let Err(error) = rustc_mir_transform::dump_mir::emit_mir(tcx) {
379+
tcx.dcx().emit_fatal(CantEmitMIR { error });
380+
}
381+
}
382+
382383
Some(Linker::codegen_and_build_linker(tcx, &*compiler.codegen_backend))
383384
});
384385

@@ -407,7 +408,7 @@ fn dump_feature_usage_metrics(tcxt: TyCtxt<'_>, metrics_dir: &Path) {
407408
}
408409
}
409410

410-
// Extract output directory and file from matches.
411+
/// Extract output directory and file from matches.
411412
fn make_output(matches: &getopts::Matches) -> (Option<PathBuf>, Option<OutFileName>) {
412413
let odir = matches.opt_str("out-dir").map(|o| PathBuf::from(&o));
413414
let ofile = matches.opt_str("o").map(|o| match o.as_str() {

‎compiler/rustc_driver_impl/src/session_diagnostics.rs

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ use std::error::Error;
22

33
use rustc_macros::{Diagnostic, Subdiagnostic};
44

5+
#[derive(Diagnostic)]
6+
#[diag(driver_impl_cant_emit_mir)]
7+
pub struct CantEmitMIR {
8+
pub error: std::io::Error,
9+
}
10+
511
#[derive(Diagnostic)]
612
#[diag(driver_impl_rlink_unable_to_read)]
713
pub(crate) struct RlinkUnableToRead {

‎compiler/rustc_interface/messages.ftl

-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ interface_abi_required_feature =
33
.note = this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
44
interface_abi_required_feature_issue = for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>
55
6-
interface_cant_emit_mir =
7-
could not emit MIR: {$error}
8-
96
interface_crate_name_does_not_match = `--crate-name` and `#[crate_name]` are required to match, but `{$crate_name}` != `{$attr_crate_name}`
107
118
interface_crate_name_invalid = crate names cannot start with a `-`, but `{$crate_name}` has a leading hyphen

‎compiler/rustc_interface/src/errors.rs

-6
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,6 @@ pub struct TempsDirError;
7373
#[diag(interface_out_dir_error)]
7474
pub struct OutDirError;
7575

76-
#[derive(Diagnostic)]
77-
#[diag(interface_cant_emit_mir)]
78-
pub struct CantEmitMIR {
79-
pub error: io::Error,
80-
}
81-
8276
#[derive(Diagnostic)]
8377
#[diag(interface_rustc_error_fatal)]
8478
pub struct RustcErrorFatal {

‎compiler/rustc_interface/src/passes.rs

+9-15
Original file line numberDiff line numberDiff line change
@@ -1078,16 +1078,22 @@ pub(crate) fn start_codegen<'tcx>(
10781078
codegen_backend: &dyn CodegenBackend,
10791079
tcx: TyCtxt<'tcx>,
10801080
) -> Box<dyn Any> {
1081+
// Hook for UI tests.
1082+
check_for_rustc_errors_attr(tcx);
1083+
1084+
// Don't run this test assertions when not doing codegen. Compiletest tries to build
1085+
// build-fail tests in check mode first and expects it to not give an error in that case.
1086+
if tcx.sess.opts.output_types.should_codegen() {
1087+
rustc_symbol_mangling::test::report_symbol_names(tcx);
1088+
}
1089+
10811090
// Don't do code generation if there were any errors. Likewise if
10821091
// there were any delayed bugs, because codegen will likely cause
10831092
// more ICEs, obscuring the original problem.
10841093
if let Some(guar) = tcx.sess.dcx().has_errors_or_delayed_bugs() {
10851094
guar.raise_fatal();
10861095
}
10871096

1088-
// Hook for UI tests.
1089-
check_for_rustc_errors_attr(tcx);
1090-
10911097
info!("Pre-codegen\n{:?}", tcx.debug_stats());
10921098

10931099
let (metadata, need_metadata_module) = rustc_metadata::fs::encode_and_write_metadata(tcx);
@@ -1096,20 +1102,8 @@ pub(crate) fn start_codegen<'tcx>(
10961102
codegen_backend.codegen_crate(tcx, metadata, need_metadata_module)
10971103
});
10981104

1099-
// Don't run this test assertions when not doing codegen. Compiletest tries to build
1100-
// build-fail tests in check mode first and expects it to not give an error in that case.
1101-
if tcx.sess.opts.output_types.should_codegen() {
1102-
rustc_symbol_mangling::test::report_symbol_names(tcx);
1103-
}
1104-
11051105
info!("Post-codegen\n{:?}", tcx.debug_stats());
11061106

1107-
if tcx.sess.opts.output_types.contains_key(&OutputType::Mir) {
1108-
if let Err(error) = rustc_mir_transform::dump_mir::emit_mir(tcx) {
1109-
tcx.dcx().emit_fatal(errors::CantEmitMIR { error });
1110-
}
1111-
}
1112-
11131107
// This must run after monomorphization so that all generic types
11141108
// have been instantiated.
11151109
if tcx.sess.opts.unstable_opts.print_type_sizes {

‎compiler/rustc_passes/messages.ftl

+2-2
Original file line numberDiff line numberDiff line change
@@ -811,8 +811,8 @@ passes_unused_duplicate =
811811
passes_unused_empty_lints_note =
812812
attribute `{$name}` with an empty list has no effect
813813
814-
passes_unused_linker_warnings_note =
815-
the `linker_warnings` lint can only be controlled at the root of a crate that needs to be linked
814+
passes_unused_linker_messages_note =
815+
the `linker_messages` lint can only be controlled at the root of a crate that needs to be linked
816816
817817
passes_unused_multiple =
818818
multiple `{$name}` attributes

‎compiler/rustc_passes/src/check_attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2402,7 +2402,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
24022402
.iter()
24032403
.all(|kind| matches!(kind, CrateType::Rlib | CrateType::Staticlib));
24042404
if never_needs_link {
2405-
errors::UnusedNote::LinkerWarningsBinaryCrateOnly
2405+
errors::UnusedNote::LinkerMessagesBinaryCrateOnly
24062406
} else {
24072407
return;
24082408
}

‎compiler/rustc_passes/src/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -770,8 +770,8 @@ pub(crate) enum UnusedNote {
770770
NoLints { name: Symbol },
771771
#[note(passes_unused_default_method_body_const_note)]
772772
DefaultMethodBodyConst,
773-
#[note(passes_unused_linker_warnings_note)]
774-
LinkerWarningsBinaryCrateOnly,
773+
#[note(passes_unused_linker_messages_note)]
774+
LinkerMessagesBinaryCrateOnly,
775775
}
776776

777777
#[derive(LintDiagnostic)]

‎tests/ui/lint/linker-warning.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ warning: unused attribute
1616
LL | #![allow(linker_messages)]
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute
1818
|
19-
= note: the `linker_warnings` lint can only be controlled at the root of a crate that needs to be linked
19+
= note: the `linker_messages` lint can only be controlled at the root of a crate that needs to be linked
2020

2121
warning: 2 warnings emitted
2222

0 commit comments

Comments
 (0)
Failed to load comments.