Skip to content

Commit ef4046e

Browse files
committed
Auto merge of rust-lang#106730 - Nilstrieb:rollup-f7p8dsa, r=Nilstrieb
Rollup of 9 pull requests Successful merges: - rust-lang#106321 (Collect and emit proper backtraces for `delay_span_bug`s) - rust-lang#106397 (Check `impl`'s `where` clauses in `consider_impl_candidate` in experimental solver) - rust-lang#106427 (Improve fluent error messages) - rust-lang#106570 (add tests for div_duration_* functions) - rust-lang#106648 (Polymorphization cleanup) - rust-lang#106664 (Remove unnecessary lseek syscall when using std::fs::read) - rust-lang#106709 (Disable "split dwarf inlining" by default.) - rust-lang#106715 (Autolabel and ping wg for changes to new solver) - rust-lang#106717 (fix typo LocalItemId -> ItemLocalId) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents b22c152 + 9aeef61 commit ef4046e

File tree

25 files changed

+550
-198
lines changed

25 files changed

+550
-198
lines changed

compiler/rustc_const_eval/src/interpret/util.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,11 @@ where
4040
let index = index
4141
.try_into()
4242
.expect("more generic parameters than can fit into a `u32`");
43-
let is_used = unused_params.contains(index).map_or(true, |unused| !unused);
4443
// Only recurse when generic parameters in fns, closures and generators
4544
// are used and require substitution.
4645
// Just in case there are closures or generators within this subst,
4746
// recurse.
48-
if is_used && subst.needs_subst() {
47+
if unused_params.is_used(index) && subst.needs_subst() {
4948
return subst.visit_with(self);
5049
}
5150
}

compiler/rustc_driver/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1196,8 +1196,8 @@ static DEFAULT_HOOK: LazyLock<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send +
11961196
};
11971197

11981198
// Invoke the default handler, which prints the actual panic message and optionally a backtrace
1199-
// Don't do this for `GoodPathBug`, which already emits its own more useful backtrace.
1200-
if !info.payload().is::<rustc_errors::GoodPathBug>() {
1199+
// Don't do this for delayed bugs, which already emit their own more useful backtrace.
1200+
if !info.payload().is::<rustc_errors::DelayedBugPanic>() {
12011201
(*DEFAULT_HOOK)(info);
12021202

12031203
// Separate the output with an empty line
@@ -1235,7 +1235,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
12351235
// a .span_bug or .bug call has already printed what
12361236
// it wants to print.
12371237
if !info.payload().is::<rustc_errors::ExplicitBug>()
1238-
&& !info.payload().is::<rustc_errors::GoodPathBug>()
1238+
&& !info.payload().is::<rustc_errors::DelayedBugPanic>()
12391239
{
12401240
let mut d = rustc_errors::Diagnostic::new(rustc_errors::Level::Bug, "unexpected panic");
12411241
handler.emit_diagnostic(&mut d);

compiler/rustc_errors/src/emitter.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use rustc_error_messages::{FluentArgs, SpanLabel};
2828
use rustc_span::hygiene::{ExpnKind, MacroKind};
2929
use std::borrow::Cow;
3030
use std::cmp::{max, min, Reverse};
31+
use std::error::Report;
3132
use std::io::prelude::*;
3233
use std::io::{self, IsTerminal};
3334
use std::iter;
@@ -250,7 +251,7 @@ pub trait Emitter: Translate {
250251
let mut primary_span = diag.span.clone();
251252
let suggestions = diag.suggestions.as_deref().unwrap_or(&[]);
252253
if let Some((sugg, rest)) = suggestions.split_first() {
253-
let msg = self.translate_message(&sugg.msg, fluent_args);
254+
let msg = self.translate_message(&sugg.msg, fluent_args).map_err(Report::new).unwrap();
254255
if rest.is_empty() &&
255256
// ^ if there is only one suggestion
256257
// don't display multi-suggestions as labels
@@ -1325,7 +1326,7 @@ impl EmitterWriter {
13251326
// very *weird* formats
13261327
// see?
13271328
for (text, style) in msg.iter() {
1328-
let text = self.translate_message(text, args);
1329+
let text = self.translate_message(text, args).map_err(Report::new).unwrap();
13291330
let lines = text.split('\n').collect::<Vec<_>>();
13301331
if lines.len() > 1 {
13311332
for (i, line) in lines.iter().enumerate() {
@@ -1387,7 +1388,7 @@ impl EmitterWriter {
13871388
label_width += 2;
13881389
}
13891390
for (text, _) in msg.iter() {
1390-
let text = self.translate_message(text, args);
1391+
let text = self.translate_message(text, args).map_err(Report::new).unwrap();
13911392
// Account for newlines to align output to its label.
13921393
for (line, text) in normalize_whitespace(&text).lines().enumerate() {
13931394
buffer.append(
@@ -2301,7 +2302,9 @@ impl FileWithAnnotatedLines {
23012302
hi.col_display += 1;
23022303
}
23032304

2304-
let label = label.as_ref().map(|m| emitter.translate_message(m, args).to_string());
2305+
let label = label.as_ref().map(|m| {
2306+
emitter.translate_message(m, args).map_err(Report::new).unwrap().to_string()
2307+
});
23052308

23062309
if lo.line != hi.line {
23072310
let ml = MultilineAnnotation {

compiler/rustc_errors/src/error.rs

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
use rustc_error_messages::{
2+
fluent_bundle::resolver::errors::{ReferenceKind, ResolverError},
3+
FluentArgs, FluentError,
4+
};
5+
use std::borrow::Cow;
6+
use std::error::Error;
7+
use std::fmt;
8+
9+
#[derive(Debug)]
10+
pub enum TranslateError<'args> {
11+
One {
12+
id: &'args Cow<'args, str>,
13+
args: &'args FluentArgs<'args>,
14+
kind: TranslateErrorKind<'args>,
15+
},
16+
Two {
17+
primary: Box<TranslateError<'args>>,
18+
fallback: Box<TranslateError<'args>>,
19+
},
20+
}
21+
22+
impl<'args> TranslateError<'args> {
23+
pub fn message(id: &'args Cow<'args, str>, args: &'args FluentArgs<'args>) -> Self {
24+
Self::One { id, args, kind: TranslateErrorKind::MessageMissing }
25+
}
26+
pub fn primary(id: &'args Cow<'args, str>, args: &'args FluentArgs<'args>) -> Self {
27+
Self::One { id, args, kind: TranslateErrorKind::PrimaryBundleMissing }
28+
}
29+
pub fn attribute(
30+
id: &'args Cow<'args, str>,
31+
args: &'args FluentArgs<'args>,
32+
attr: &'args str,
33+
) -> Self {
34+
Self::One { id, args, kind: TranslateErrorKind::AttributeMissing { attr } }
35+
}
36+
pub fn value(id: &'args Cow<'args, str>, args: &'args FluentArgs<'args>) -> Self {
37+
Self::One { id, args, kind: TranslateErrorKind::ValueMissing }
38+
}
39+
40+
pub fn fluent(
41+
id: &'args Cow<'args, str>,
42+
args: &'args FluentArgs<'args>,
43+
errs: Vec<FluentError>,
44+
) -> Self {
45+
Self::One { id, args, kind: TranslateErrorKind::Fluent { errs } }
46+
}
47+
48+
pub fn and(self, fallback: TranslateError<'args>) -> TranslateError<'args> {
49+
Self::Two { primary: Box::new(self), fallback: Box::new(fallback) }
50+
}
51+
}
52+
53+
#[derive(Debug)]
54+
pub enum TranslateErrorKind<'args> {
55+
MessageMissing,
56+
PrimaryBundleMissing,
57+
AttributeMissing { attr: &'args str },
58+
ValueMissing,
59+
Fluent { errs: Vec<FluentError> },
60+
}
61+
62+
impl fmt::Display for TranslateError<'_> {
63+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
64+
use TranslateErrorKind::*;
65+
66+
match self {
67+
Self::One { id, args, kind } => {
68+
writeln!(f, "failed while formatting fluent string `{id}`: ")?;
69+
match kind {
70+
MessageMissing => writeln!(f, "message was missing")?,
71+
PrimaryBundleMissing => writeln!(f, "the primary bundle was missing")?,
72+
AttributeMissing { attr } => {
73+
writeln!(f, "the attribute `{attr}` was missing")?;
74+
writeln!(f, "help: add `.{attr} = <message>`")?;
75+
}
76+
ValueMissing => writeln!(f, "the value was missing")?,
77+
Fluent { errs } => {
78+
for err in errs {
79+
match err {
80+
FluentError::ResolverError(ResolverError::Reference(
81+
ReferenceKind::Message { id, .. }
82+
| ReferenceKind::Variable { id, .. },
83+
)) => {
84+
if args.iter().any(|(arg_id, _)| arg_id == id) {
85+
writeln!(
86+
f,
87+
"argument `{id}` exists but was not referenced correctly"
88+
)?;
89+
writeln!(f, "help: try using `{{${id}}}` instead")?;
90+
} else {
91+
writeln!(
92+
f,
93+
"the fluent string has an argument `{id}` that was not found."
94+
)?;
95+
let vars: Vec<&str> =
96+
args.iter().map(|(a, _v)| a).collect();
97+
match &*vars {
98+
[] => writeln!(f, "help: no arguments are available")?,
99+
[one] => writeln!(
100+
f,
101+
"help: the argument `{one}` is available"
102+
)?,
103+
[first, middle @ .., last] => {
104+
write!(f, "help: the arguments `{first}`")?;
105+
for a in middle {
106+
write!(f, ", `{a}`")?;
107+
}
108+
writeln!(f, " and `{last}` are available")?;
109+
}
110+
}
111+
}
112+
}
113+
_ => writeln!(f, "{err}")?,
114+
}
115+
}
116+
}
117+
}
118+
}
119+
// If someone cares about primary bundles, they'll probably notice it's missing
120+
// regardless or will be using `debug_assertions`
121+
// so we skip the arm below this one to avoid confusing the regular user.
122+
Self::Two { primary: box Self::One { kind: PrimaryBundleMissing, .. }, fallback } => {
123+
fmt::Display::fmt(fallback, f)?;
124+
}
125+
Self::Two { primary, fallback } => {
126+
writeln!(
127+
f,
128+
"first, fluent formatting using the primary bundle failed:\n {primary}\n \
129+
while attempting to recover by using the fallback bundle instead, another error occurred:\n{fallback}"
130+
)?;
131+
}
132+
}
133+
Ok(())
134+
}
135+
}
136+
137+
impl Error for TranslateError<'_> {}

compiler/rustc_errors/src/json.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use rustc_data_structures::sync::Lrc;
2424
use rustc_error_messages::FluentArgs;
2525
use rustc_span::hygiene::ExpnData;
2626
use rustc_span::Span;
27+
use std::error::Report;
2728
use std::io::{self, Write};
2829
use std::path::Path;
2930
use std::sync::{Arc, Mutex};
@@ -321,7 +322,8 @@ impl Diagnostic {
321322
fn from_errors_diagnostic(diag: &crate::Diagnostic, je: &JsonEmitter) -> Diagnostic {
322323
let args = to_fluent_args(diag.args());
323324
let sugg = diag.suggestions.iter().flatten().map(|sugg| {
324-
let translated_message = je.translate_message(&sugg.msg, &args);
325+
let translated_message =
326+
je.translate_message(&sugg.msg, &args).map_err(Report::new).unwrap();
325327
Diagnostic {
326328
message: translated_message.to_string(),
327329
code: None,
@@ -411,7 +413,10 @@ impl DiagnosticSpan {
411413
Self::from_span_etc(
412414
span.span,
413415
span.is_primary,
414-
span.label.as_ref().map(|m| je.translate_message(m, args)).map(|m| m.to_string()),
416+
span.label
417+
.as_ref()
418+
.map(|m| je.translate_message(m, args).unwrap())
419+
.map(|m| m.to_string()),
415420
suggestion,
416421
je,
417422
)

0 commit comments

Comments
 (0)