Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 9 pull requests #106730

Merged
merged 22 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0b5d6ae
Improve fluent error messages
Jan 5, 2023
9fd744b
add tests for div_duration_* functions
Xaeroxe Jan 7, 2023
eae615d
Remove unnecessary lseek syscall when using std::fs::read
chenyukang Jan 7, 2023
262ff86
Make translate_message return result and add tests
Jan 8, 2023
4c0c32c
Fix tests
Jan 8, 2023
36ee66c
Check impl's where clauses in consider_impl_candidate in experimental…
compiler-errors Jan 3, 2023
2855794
Use newtype for unused generic parameters
Noratrieb Dec 1, 2022
a4b859e
Delete unused polymorphization code
Noratrieb Dec 1, 2022
05c1ac0
Collect backtraces for delayed span-bugs too
compiler-errors Dec 31, 2022
f7bc68b
use with_capacity in read read_to_string
chenyukang Jan 10, 2023
aca2f88
Disable "split dwarf inlining" by default.
khuey Jan 11, 2023
d031bef
a
BoxyUwU Jan 11, 2023
cce2f5f
fix typo LocalItemId -> ItemLocalId
klensy Jan 11, 2023
0681a96
Rollup merge of #106321 - compiler-errors:delayed-bug-backtrace, r=Ni…
Noratrieb Jan 11, 2023
1693891
Rollup merge of #106397 - compiler-errors:new-solver-impl-wc, r=lcnr
Noratrieb Jan 11, 2023
7347655
Rollup merge of #106427 - mejrs:translation_errors, r=davidtwco
Noratrieb Jan 11, 2023
c962b07
Rollup merge of #106570 - Xaeroxe:div-duration-tests, r=JohnTitor
Noratrieb Jan 11, 2023
6e0c404
Rollup merge of #106648 - Nilstrieb:poly-cleanup, r=compiler-errors
Noratrieb Jan 11, 2023
9a820f7
Rollup merge of #106664 - chenyukang:yukang/fix-106597-remove-lseek, …
Noratrieb Jan 11, 2023
082ff0f
Rollup merge of #106709 - khuey:disable_split_dwarf_inlining_by_defau…
Noratrieb Jan 11, 2023
80c535f
Rollup merge of #106715 - BoxyUwU:new_solver_triagebot, r=lcnr
Noratrieb Jan 11, 2023
9aeef61
Rollup merge of #106717 - klensy:typo, r=lcnr
Noratrieb Jan 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions compiler/rustc_const_eval/src/interpret/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ where
let index = index
.try_into()
.expect("more generic parameters than can fit into a `u32`");
let is_used = unused_params.contains(index).map_or(true, |unused| !unused);
// Only recurse when generic parameters in fns, closures and generators
// are used and require substitution.
// Just in case there are closures or generators within this subst,
// recurse.
if is_used && subst.needs_subst() {
if unused_params.is_used(index) && subst.needs_subst() {
return subst.visit_with(self);
}
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1196,8 +1196,8 @@ static DEFAULT_HOOK: LazyLock<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send +
};

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

// Separate the output with an empty line
Expand Down Expand Up @@ -1235,7 +1235,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
// a .span_bug or .bug call has already printed what
// it wants to print.
if !info.payload().is::<rustc_errors::ExplicitBug>()
&& !info.payload().is::<rustc_errors::GoodPathBug>()
&& !info.payload().is::<rustc_errors::DelayedBugPanic>()
{
let mut d = rustc_errors::Diagnostic::new(rustc_errors::Level::Bug, "unexpected panic");
handler.emit_diagnostic(&mut d);
Expand Down
11 changes: 7 additions & 4 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use rustc_error_messages::{FluentArgs, SpanLabel};
use rustc_span::hygiene::{ExpnKind, MacroKind};
use std::borrow::Cow;
use std::cmp::{max, min, Reverse};
use std::error::Report;
use std::io::prelude::*;
use std::io::{self, IsTerminal};
use std::iter;
Expand Down Expand Up @@ -250,7 +251,7 @@ pub trait Emitter: Translate {
let mut primary_span = diag.span.clone();
let suggestions = diag.suggestions.as_deref().unwrap_or(&[]);
if let Some((sugg, rest)) = suggestions.split_first() {
let msg = self.translate_message(&sugg.msg, fluent_args);
let msg = self.translate_message(&sugg.msg, fluent_args).map_err(Report::new).unwrap();
if rest.is_empty() &&
// ^ if there is only one suggestion
// don't display multi-suggestions as labels
Expand Down Expand Up @@ -1325,7 +1326,7 @@ impl EmitterWriter {
// very *weird* formats
// see?
for (text, style) in msg.iter() {
let text = self.translate_message(text, args);
let text = self.translate_message(text, args).map_err(Report::new).unwrap();
let lines = text.split('\n').collect::<Vec<_>>();
if lines.len() > 1 {
for (i, line) in lines.iter().enumerate() {
Expand Down Expand Up @@ -1387,7 +1388,7 @@ impl EmitterWriter {
label_width += 2;
}
for (text, _) in msg.iter() {
let text = self.translate_message(text, args);
let text = self.translate_message(text, args).map_err(Report::new).unwrap();
// Account for newlines to align output to its label.
for (line, text) in normalize_whitespace(&text).lines().enumerate() {
buffer.append(
Expand Down Expand Up @@ -2301,7 +2302,9 @@ impl FileWithAnnotatedLines {
hi.col_display += 1;
}

let label = label.as_ref().map(|m| emitter.translate_message(m, args).to_string());
let label = label.as_ref().map(|m| {
emitter.translate_message(m, args).map_err(Report::new).unwrap().to_string()
});

if lo.line != hi.line {
let ml = MultilineAnnotation {
Expand Down
137 changes: 137 additions & 0 deletions compiler/rustc_errors/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
use rustc_error_messages::{
fluent_bundle::resolver::errors::{ReferenceKind, ResolverError},
FluentArgs, FluentError,
};
use std::borrow::Cow;
use std::error::Error;
use std::fmt;

#[derive(Debug)]
pub enum TranslateError<'args> {
One {
id: &'args Cow<'args, str>,
args: &'args FluentArgs<'args>,
kind: TranslateErrorKind<'args>,
},
Two {
primary: Box<TranslateError<'args>>,
fallback: Box<TranslateError<'args>>,
},
}

impl<'args> TranslateError<'args> {
pub fn message(id: &'args Cow<'args, str>, args: &'args FluentArgs<'args>) -> Self {
Self::One { id, args, kind: TranslateErrorKind::MessageMissing }
}
pub fn primary(id: &'args Cow<'args, str>, args: &'args FluentArgs<'args>) -> Self {
Self::One { id, args, kind: TranslateErrorKind::PrimaryBundleMissing }
}
pub fn attribute(
id: &'args Cow<'args, str>,
args: &'args FluentArgs<'args>,
attr: &'args str,
) -> Self {
Self::One { id, args, kind: TranslateErrorKind::AttributeMissing { attr } }
}
pub fn value(id: &'args Cow<'args, str>, args: &'args FluentArgs<'args>) -> Self {
Self::One { id, args, kind: TranslateErrorKind::ValueMissing }
}

pub fn fluent(
id: &'args Cow<'args, str>,
args: &'args FluentArgs<'args>,
errs: Vec<FluentError>,
) -> Self {
Self::One { id, args, kind: TranslateErrorKind::Fluent { errs } }
}

pub fn and(self, fallback: TranslateError<'args>) -> TranslateError<'args> {
Self::Two { primary: Box::new(self), fallback: Box::new(fallback) }
}
}

#[derive(Debug)]
pub enum TranslateErrorKind<'args> {
MessageMissing,
PrimaryBundleMissing,
AttributeMissing { attr: &'args str },
ValueMissing,
Fluent { errs: Vec<FluentError> },
}

impl fmt::Display for TranslateError<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use TranslateErrorKind::*;

match self {
Self::One { id, args, kind } => {
writeln!(f, "failed while formatting fluent string `{id}`: ")?;
match kind {
MessageMissing => writeln!(f, "message was missing")?,
PrimaryBundleMissing => writeln!(f, "the primary bundle was missing")?,
AttributeMissing { attr } => {
writeln!(f, "the attribute `{attr}` was missing")?;
writeln!(f, "help: add `.{attr} = <message>`")?;
}
ValueMissing => writeln!(f, "the value was missing")?,
Fluent { errs } => {
for err in errs {
match err {
FluentError::ResolverError(ResolverError::Reference(
ReferenceKind::Message { id, .. }
| ReferenceKind::Variable { id, .. },
)) => {
if args.iter().any(|(arg_id, _)| arg_id == id) {
writeln!(
f,
"argument `{id}` exists but was not referenced correctly"
)?;
writeln!(f, "help: try using `{{${id}}}` instead")?;
} else {
writeln!(
f,
"the fluent string has an argument `{id}` that was not found."
)?;
let vars: Vec<&str> =
args.iter().map(|(a, _v)| a).collect();
match &*vars {
[] => writeln!(f, "help: no arguments are available")?,
[one] => writeln!(
f,
"help: the argument `{one}` is available"
)?,
[first, middle @ .., last] => {
write!(f, "help: the arguments `{first}`")?;
for a in middle {
write!(f, ", `{a}`")?;
}
writeln!(f, " and `{last}` are available")?;
}
}
}
}
_ => writeln!(f, "{err}")?,
}
}
}
}
}
// If someone cares about primary bundles, they'll probably notice it's missing
// regardless or will be using `debug_assertions`
// so we skip the arm below this one to avoid confusing the regular user.
Self::Two { primary: box Self::One { kind: PrimaryBundleMissing, .. }, fallback } => {
fmt::Display::fmt(fallback, f)?;
}
Self::Two { primary, fallback } => {
writeln!(
f,
"first, fluent formatting using the primary bundle failed:\n {primary}\n \
while attempting to recover by using the fallback bundle instead, another error occurred:\n{fallback}"
)?;
}
}
Ok(())
}
}

impl Error for TranslateError<'_> {}
9 changes: 7 additions & 2 deletions compiler/rustc_errors/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use rustc_data_structures::sync::Lrc;
use rustc_error_messages::FluentArgs;
use rustc_span::hygiene::ExpnData;
use rustc_span::Span;
use std::error::Report;
use std::io::{self, Write};
use std::path::Path;
use std::sync::{Arc, Mutex};
Expand Down Expand Up @@ -321,7 +322,8 @@ impl Diagnostic {
fn from_errors_diagnostic(diag: &crate::Diagnostic, je: &JsonEmitter) -> Diagnostic {
let args = to_fluent_args(diag.args());
let sugg = diag.suggestions.iter().flatten().map(|sugg| {
let translated_message = je.translate_message(&sugg.msg, &args);
let translated_message =
je.translate_message(&sugg.msg, &args).map_err(Report::new).unwrap();
Diagnostic {
message: translated_message.to_string(),
code: None,
Expand Down Expand Up @@ -411,7 +413,10 @@ impl DiagnosticSpan {
Self::from_span_etc(
span.span,
span.is_primary,
span.label.as_ref().map(|m| je.translate_message(m, args)).map(|m| m.to_string()),
span.label
.as_ref()
.map(|m| je.translate_message(m, args).unwrap())
.map(|m| m.to_string()),
suggestion,
je,
)
Expand Down
Loading