Skip to content

Commit 4017691

Browse files
committed
rustc_codegen_ssa
1 parent 8981fea commit 4017691

File tree

2 files changed

+32
-25
lines changed

2 files changed

+32
-25
lines changed

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -560,10 +560,10 @@ fn produce_final_output_artifacts(
560560
};
561561

562562
let copy_if_one_unit = |output_type: OutputType, keep_numbered: bool| {
563-
if compiled_modules.modules.len() == 1 {
563+
if let [module] = &compiled_modules.modules[..] {
564564
// 1) Only one codegen unit. In this case it's no difficulty
565565
// to copy `foo.0.x` to `foo.x`.
566-
let module_name = Some(&compiled_modules.modules[0].name[..]);
566+
let module_name = Some(&module.name[..]);
567567
let path = crate_output.temp_path(output_type, module_name);
568568
let output = crate_output.path(output_type);
569569
if !output_type.is_text_output() && output.is_tty() {
@@ -695,8 +695,8 @@ fn produce_final_output_artifacts(
695695
}
696696

697697
if sess.opts.json_artifact_notifications {
698-
if compiled_modules.modules.len() == 1 {
699-
compiled_modules.modules[0].for_each_output(|_path, ty| {
698+
if let [module] = &compiled_modules.modules[..] {
699+
module.for_each_output(|_path, ty| {
700700
if sess.opts.output_types.contains_key(&ty) {
701701
let descr = ty.shorthand();
702702
// for single cgu file is renamed to drop cgu specific suffix
@@ -852,7 +852,7 @@ pub(crate) fn compute_per_cgu_lto_type(
852852
// require LTO so the request for LTO is always unconditionally
853853
// passed down to the backend, but we don't actually want to do
854854
// anything about it yet until we've got a final product.
855-
let is_rlib = sess_crate_types.len() == 1 && sess_crate_types[0] == CrateType::Rlib;
855+
let is_rlib = matches!(sess_crate_types, [CrateType::Rlib]);
856856

857857
match sess_lto {
858858
Lto::ThinLocal if !linker_does_lto && !is_allocator => ComputedLtoType::Thin,

compiler/rustc_errors/src/lib.rs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
#![feature(associated_type_defaults)]
1515
#![feature(box_into_inner)]
1616
#![feature(box_patterns)]
17+
#![feature(debug_closure_helpers)]
1718
#![feature(error_reporter)]
19+
#![feature(exact_size_is_empty)]
1820
#![feature(extract_if)]
1921
#![feature(if_let_guard)]
2022
#![feature(let_chains)]
@@ -35,6 +37,7 @@ use std::backtrace::{Backtrace, BacktraceStatus};
3537
use std::borrow::Cow;
3638
use std::cell::Cell;
3739
use std::error::Report;
40+
use std::fmt::Write as _;
3841
use std::hash::Hash;
3942
use std::io::Write;
4043
use std::num::NonZero;
@@ -994,17 +997,17 @@ impl<'a> DiagCtxtHandle<'a> {
994997
count => Cow::from(format!("aborting due to {count} previous errors")),
995998
};
996999

997-
match (errors.len(), warnings.len()) {
998-
(0, 0) => return,
999-
(0, _) => {
1000+
match (errors.is_empty(), warnings.is_empty()) {
1001+
(true, true) => return,
1002+
(true, _) => {
10001003
// Use `ForceWarning` rather than `Warning` to guarantee emission, e.g. with a
10011004
// configuration like `--cap-lints allow --force-warn bare_trait_objects`.
10021005
inner.emit_diagnostic(
10031006
DiagInner::new(ForceWarning(None), DiagMessage::Str(warnings)),
10041007
None,
10051008
);
10061009
}
1007-
(_, 0) => {
1010+
(_, true) => {
10081011
inner.emit_diagnostic(DiagInner::new(Error, errors), self.tainted_with_errors);
10091012
}
10101013
(_, _) => {
@@ -1029,28 +1032,32 @@ impl<'a> DiagCtxtHandle<'a> {
10291032
}
10301033
})
10311034
.collect::<Vec<_>>();
1032-
if !error_codes.is_empty() {
1033-
error_codes.sort();
1034-
if error_codes.len() > 1 {
1035-
let limit = if error_codes.len() > 9 { 9 } else { error_codes.len() };
1036-
let msg1 = format!(
1037-
"Some errors have detailed explanations: {}{}",
1038-
error_codes[..limit].join(", "),
1039-
if error_codes.len() > 9 { "..." } else { "." }
1035+
error_codes.sort();
1036+
match &error_codes[..] {
1037+
[code] => {
1038+
let msg = format!(
1039+
"For more information about this error, try `rustc --explain {code}`.",
10401040
);
1041+
inner.emit_diagnostic(DiagInner::new(FailureNote, msg), None);
1042+
}
1043+
[first_code, error_codes @ ..] => {
1044+
let error_codes = fmt::from_fn(|f| {
1045+
f.write_str(first_code)?;
1046+
let mut error_codes = error_codes.iter();
1047+
for code in error_codes.by_ref().take(8) {
1048+
write!(f, ", {code}")?;
1049+
}
1050+
if error_codes.is_empty() { f.write_char('.') } else { f.write_str("...") }
1051+
});
1052+
// let limit = error_codes.len().max(9);
1053+
let msg1 = format!("Some errors have detailed explanations: {error_codes}");
10411054
let msg2 = format!(
1042-
"For more information about an error, try `rustc --explain {}`.",
1043-
&error_codes[0]
1055+
"For more information about an error, try `rustc --explain {first_code}`.",
10441056
);
10451057
inner.emit_diagnostic(DiagInner::new(FailureNote, msg1), None);
10461058
inner.emit_diagnostic(DiagInner::new(FailureNote, msg2), None);
1047-
} else {
1048-
let msg = format!(
1049-
"For more information about this error, try `rustc --explain {}`.",
1050-
&error_codes[0]
1051-
);
1052-
inner.emit_diagnostic(DiagInner::new(FailureNote, msg), None);
10531059
}
1060+
_ => {}
10541061
}
10551062
}
10561063
}

0 commit comments

Comments
 (0)