summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_errors
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /compiler/rustc_errors
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_errors')
-rw-r--r--compiler/rustc_errors/Cargo.toml4
-rw-r--r--compiler/rustc_errors/messages.ftl22
-rw-r--r--compiler/rustc_errors/src/diagnostic_builder.rs11
-rw-r--r--compiler/rustc_errors/src/emitter.rs59
-rw-r--r--compiler/rustc_errors/src/lib.rs80
-rw-r--r--compiler/rustc_errors/src/lock.rs3
-rw-r--r--compiler/rustc_errors/src/tests.rs10
7 files changed, 104 insertions, 85 deletions
diff --git a/compiler/rustc_errors/Cargo.toml b/compiler/rustc_errors/Cargo.toml
index e1ead08ea..bd3033fcb 100644
--- a/compiler/rustc_errors/Cargo.toml
+++ b/compiler/rustc_errors/Cargo.toml
@@ -10,6 +10,7 @@ tracing = "0.1"
rustc_ast = { path = "../rustc_ast" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_error_messages = { path = "../rustc_error_messages" }
+rustc_fluent_macro = { path = "../rustc_fluent_macro" }
rustc_serialize = { path = "../rustc_serialize" }
rustc_span = { path = "../rustc_span" }
rustc_macros = { path = "../rustc_macros" }
@@ -26,12 +27,11 @@ serde = { version = "1.0.125", features = [ "derive" ] }
serde_json = "1.0.59"
[target.'cfg(windows)'.dependencies.windows]
-version = "0.46.0"
+version = "0.48.0"
features = [
"Win32_Foundation",
"Win32_Security",
"Win32_System_Threading",
- "Win32_System_WindowsProgramming",
]
[features]
diff --git a/compiler/rustc_errors/messages.ftl b/compiler/rustc_errors/messages.ftl
index dde1d6c0a..337097343 100644
--- a/compiler/rustc_errors/messages.ftl
+++ b/compiler/rustc_errors/messages.ftl
@@ -1,19 +1,19 @@
-errors_target_invalid_address_space =
- invalid address space `{$addr_space}` for `{$cause}` in "data-layout": {$err}
+errors_target_inconsistent_architecture =
+ inconsistent target specification: "data-layout" claims architecture is {$dl}-endian, while "target-endian" is `{$target}`
-errors_target_invalid_bits =
- invalid {$kind} `{$bit}` for `{$cause}` in "data-layout": {$err}
+errors_target_inconsistent_pointer_width =
+ inconsistent target specification: "data-layout" claims pointers are {$pointer_size}-bit, while "target-pointer-width" is `{$target}`
-errors_target_missing_alignment =
- missing alignment for `{$cause}` in "data-layout"
+errors_target_invalid_address_space =
+ invalid address space `{$addr_space}` for `{$cause}` in "data-layout": {$err}
errors_target_invalid_alignment =
invalid alignment for `{$cause}` in "data-layout": {$err}
-errors_target_inconsistent_architecture =
- inconsistent target specification: "data-layout" claims architecture is {$dl}-endian, while "target-endian" is `{$target}`
-
-errors_target_inconsistent_pointer_width =
- inconsistent target specification: "data-layout" claims pointers are {$pointer_size}-bit, while "target-pointer-width" is `{$target}`
+errors_target_invalid_bits =
+ invalid {$kind} `{$bit}` for `{$cause}` in "data-layout": {$err}
errors_target_invalid_bits_size = {$err}
+
+errors_target_missing_alignment =
+ missing alignment for `{$cause}` in "data-layout"
diff --git a/compiler/rustc_errors/src/diagnostic_builder.rs b/compiler/rustc_errors/src/diagnostic_builder.rs
index 3064d2bed..db97d96fc 100644
--- a/compiler/rustc_errors/src/diagnostic_builder.rs
+++ b/compiler/rustc_errors/src/diagnostic_builder.rs
@@ -192,6 +192,7 @@ impl EmissionGuarantee for ErrorGuaranteed {
became non-error ({:?}), after original `.emit()`",
db.inner.diagnostic.level,
);
+ #[allow(deprecated)]
ErrorGuaranteed::unchecked_claim_error_was_emitted()
}
}
@@ -570,6 +571,14 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
Some((diagnostic, handler))
}
+ /// Retrieves the [`Handler`] if available
+ pub fn handler(&self) -> Option<&Handler> {
+ match self.inner.state {
+ DiagnosticBuilderState::Emittable(handler) => Some(handler),
+ DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation => None,
+ }
+ }
+
/// Buffers the diagnostic for later emission,
/// unless handler has disabled such buffering.
pub fn buffer(self, buffered_diagnostics: &mut Vec<Diagnostic>) {
@@ -791,7 +800,7 @@ macro_rules! struct_span_err {
($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
$session.struct_span_err_with_code(
$span,
- &format!($($message)*),
+ format!($($message)*),
$crate::error_code!($code),
)
})
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs
index fe44799ef..e8cd7eaa6 100644
--- a/compiler/rustc_errors/src/emitter.rs
+++ b/compiler/rustc_errors/src/emitter.rs
@@ -285,15 +285,11 @@ pub trait Emitter: Translate {
format!(
"help: {}{}: `{}`",
&msg,
- if self
- .source_map()
- .map(|sm| is_case_difference(
- sm,
- substitution,
- sugg.substitutions[0].parts[0].span,
- ))
- .unwrap_or(false)
- {
+ if self.source_map().is_some_and(|sm| is_case_difference(
+ sm,
+ substitution,
+ sugg.substitutions[0].parts[0].span,
+ )) {
" (notice the capitalization)"
} else {
""
@@ -336,7 +332,7 @@ pub trait Emitter: Translate {
// Skip past non-macro entries, just in case there
// are some which do actually involve macros.
- ExpnKind::Inlined | ExpnKind::Desugaring(..) | ExpnKind::AstPass(..) => None,
+ ExpnKind::Desugaring(..) | ExpnKind::AstPass(..) => None,
ExpnKind::Macro(macro_kind, name) => Some((macro_kind, name)),
}
@@ -407,7 +403,7 @@ pub trait Emitter: Translate {
continue;
}
- if always_backtrace && !matches!(trace.kind, ExpnKind::Inlined) {
+ if always_backtrace {
new_labels.push((
trace.def_site,
format!(
@@ -446,7 +442,6 @@ pub trait Emitter: Translate {
"this derive macro expansion".into()
}
ExpnKind::Macro(MacroKind::Bang, _) => "this macro invocation".into(),
- ExpnKind::Inlined => "this inlined function call".into(),
ExpnKind::Root => "the crate root".into(),
ExpnKind::AstPass(kind) => kind.descr().into(),
ExpnKind::Desugaring(kind) => {
@@ -601,7 +596,7 @@ impl Emitter for SilentEmitter {
if d.level == Level::Fatal {
let mut d = d.clone();
if let Some(ref note) = self.fatal_note {
- d.note(note);
+ d.note(note.clone());
}
self.fatal_handler.emit_diagnostic(&mut d);
}
@@ -1336,6 +1331,7 @@ impl EmitterWriter {
// see?
for (text, style) in msg.iter() {
let text = self.translate_message(text, args).map_err(Report::new).unwrap();
+ let text = &normalize_whitespace(&text);
let lines = text.split('\n').collect::<Vec<_>>();
if lines.len() > 1 {
for (i, line) in lines.iter().enumerate() {
@@ -1980,7 +1976,7 @@ impl EmitterWriter {
}
if let DisplaySuggestion::Add = show_code_change && is_item_attribute {
// The suggestion adds an entire line of code, ending on a newline, so we'll also
- // print the *following* line, to provide context of what we're advicing people to
+ // print the *following* line, to provide context of what we're advising people to
// do. Otherwise you would only see contextless code that can be confused for
// already existing code, despite the colors and UI elements.
// We special case `#[derive(_)]\n` and other attribute suggestions, because those
@@ -2302,22 +2298,25 @@ impl EmitterWriter {
// Colorize addition/replacements with green.
for &SubstitutionHighlight { start, end } in highlight_parts {
- // Account for tabs when highlighting (#87972).
- let tabs: usize = line_to_add
- .chars()
- .take(start)
- .map(|ch| match ch {
- '\t' => 3,
- _ => 0,
- })
- .sum();
- buffer.set_style_range(
- *row_num,
- max_line_num_len + 3 + start + tabs,
- max_line_num_len + 3 + end + tabs,
- Style::Addition,
- true,
- );
+ // This is a no-op for empty ranges
+ if start != end {
+ // Account for tabs when highlighting (#87972).
+ let tabs: usize = line_to_add
+ .chars()
+ .take(start)
+ .map(|ch| match ch {
+ '\t' => 3,
+ _ => 0,
+ })
+ .sum();
+ buffer.set_style_range(
+ *row_num,
+ max_line_num_len + 3 + start + tabs,
+ max_line_num_len + 3 + end + tabs,
+ Style::Addition,
+ true,
+ );
+ }
}
*row_num += 1;
}
diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs
index d20b16890..3dec0d929 100644
--- a/compiler/rustc_errors/src/lib.rs
+++ b/compiler/rustc_errors/src/lib.rs
@@ -31,15 +31,15 @@ use Level::*;
use emitter::{is_case_difference, Emitter, EmitterWriter};
use registry::Registry;
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
-use rustc_data_structures::stable_hasher::StableHasher;
-use rustc_data_structures::sync::{self, Lock, Lrc};
+use rustc_data_structures::stable_hasher::{Hash128, StableHasher};
+use rustc_data_structures::sync::{self, IntoDynSyncSend, Lock, Lrc};
use rustc_data_structures::AtomicRef;
pub use rustc_error_messages::{
fallback_fluent_bundle, fluent_bundle, DelayDm, DiagnosticMessage, FluentBundle,
LanguageIdentifier, LazyFallbackBundle, MultiSpan, SpanLabel, SubdiagnosticMessage,
};
+use rustc_fluent_macro::fluent_messages;
pub use rustc_lint_defs::{pluralize, Applicability};
-use rustc_macros::fluent_messages;
use rustc_span::source_map::SourceMap;
pub use rustc_span::ErrorGuaranteed;
use rustc_span::{Loc, Span};
@@ -330,12 +330,11 @@ impl CodeSuggestion {
});
buf.push_str(&part.snippet);
let cur_hi = sm.lookup_char_pos(part.span.hi());
- if cur_hi.line == cur_lo.line && !part.snippet.is_empty() {
- // Account for the difference between the width of the current code and the
- // snippet being suggested, so that the *later* suggestions are correctly
- // aligned on the screen.
- acc += len - (cur_hi.col.0 - cur_lo.col.0) as isize;
- }
+ // Account for the difference between the width of the current code and the
+ // snippet being suggested, so that the *later* suggestions are correctly
+ // aligned on the screen. Note that cur_hi and cur_lo can be on different
+ // lines, so cur_hi.col can be smaller than cur_lo.col
+ acc += len - (cur_hi.col.0 as isize - cur_lo.col.0 as isize);
prev_hi = cur_hi;
prev_line = sf.get_line(prev_hi.line - 1);
for line in part.snippet.split('\n').skip(1) {
@@ -409,7 +408,7 @@ struct HandlerInner {
err_count: usize,
warn_count: usize,
deduplicated_err_count: usize,
- emitter: Box<dyn Emitter + sync::Send>,
+ emitter: IntoDynSyncSend<Box<dyn Emitter + sync::Send>>,
delayed_span_bugs: Vec<DelayedDiagnostic>,
delayed_good_path_bugs: Vec<DelayedDiagnostic>,
/// This flag indicates that an expected diagnostic was emitted and suppressed.
@@ -427,7 +426,7 @@ struct HandlerInner {
/// This set contains a hash of every diagnostic that has been emitted by
/// this handler. These hashes is used to avoid emitting the same error
/// twice.
- emitted_diagnostics: FxHashSet<u128>,
+ emitted_diagnostics: FxHashSet<Hash128>,
/// Stashed diagnostics emitted in one stage of the compiler that may be
/// stolen by other stages (e.g. to improve them and add more information).
@@ -478,6 +477,8 @@ pub enum StashKey {
/// FRU syntax
MaybeFruTypo,
CallAssocMethod,
+ TraitMissingMethod,
+ OpaqueHiddenTypeMismatch,
}
fn default_track_diagnostic(d: &mut Diagnostic, f: &mut dyn FnMut(&mut Diagnostic)) {
@@ -605,7 +606,7 @@ impl Handler {
warn_count: 0,
deduplicated_err_count: 0,
deduplicated_warn_count: 0,
- emitter,
+ emitter: IntoDynSyncSend(emitter),
delayed_span_bugs: Vec::new(),
delayed_good_path_bugs: Vec::new(),
suppressed_expected_diag: false,
@@ -1069,26 +1070,29 @@ impl Handler {
}
pub fn has_errors(&self) -> Option<ErrorGuaranteed> {
- self.inner.borrow().has_errors().then(ErrorGuaranteed::unchecked_claim_error_was_emitted)
+ self.inner.borrow().has_errors().then(|| {
+ #[allow(deprecated)]
+ ErrorGuaranteed::unchecked_claim_error_was_emitted()
+ })
}
pub fn has_errors_or_lint_errors(&self) -> Option<ErrorGuaranteed> {
- self.inner
- .borrow()
- .has_errors_or_lint_errors()
- .then(ErrorGuaranteed::unchecked_claim_error_was_emitted)
+ self.inner.borrow().has_errors_or_lint_errors().then(|| {
+ #[allow(deprecated)]
+ ErrorGuaranteed::unchecked_claim_error_was_emitted()
+ })
}
pub fn has_errors_or_delayed_span_bugs(&self) -> Option<ErrorGuaranteed> {
- self.inner
- .borrow()
- .has_errors_or_delayed_span_bugs()
- .then(ErrorGuaranteed::unchecked_claim_error_was_emitted)
+ self.inner.borrow().has_errors_or_delayed_span_bugs().then(|| {
+ #[allow(deprecated)]
+ ErrorGuaranteed::unchecked_claim_error_was_emitted()
+ })
}
pub fn is_compilation_going_to_fail(&self) -> Option<ErrorGuaranteed> {
- self.inner
- .borrow()
- .is_compilation_going_to_fail()
- .then(ErrorGuaranteed::unchecked_claim_error_was_emitted)
+ self.inner.borrow().is_compilation_going_to_fail().then(|| {
+ #[allow(deprecated)]
+ ErrorGuaranteed::unchecked_claim_error_was_emitted()
+ })
}
pub fn print_error_count(&self, registry: &Registry) {
@@ -1333,6 +1337,7 @@ impl HandlerInner {
.push(DelayedDiagnostic::with_backtrace(diagnostic.clone(), backtrace));
if !self.flags.report_delayed_bugs {
+ #[allow(deprecated)]
return Some(ErrorGuaranteed::unchecked_claim_error_was_emitted());
}
}
@@ -1411,7 +1416,10 @@ impl HandlerInner {
self.bump_err_count();
}
- guaranteed = Some(ErrorGuaranteed::unchecked_claim_error_was_emitted());
+ #[allow(deprecated)]
+ {
+ guaranteed = Some(ErrorGuaranteed::unchecked_claim_error_was_emitted());
+ }
} else {
self.bump_warn_count();
}
@@ -1429,7 +1437,7 @@ impl HandlerInner {
}
fn treat_err_as_bug(&self) -> bool {
- self.flags.treat_err_as_bug.map_or(false, |c| {
+ self.flags.treat_err_as_bug.is_some_and(|c| {
self.err_count() + self.lint_err_count + self.delayed_bug_count() >= c.get()
})
}
@@ -1462,10 +1470,10 @@ impl HandlerInner {
DiagnosticMessage::Str(warnings),
)),
(_, 0) => {
- let _ = self.fatal(&errors);
+ let _ = self.fatal(errors);
}
(_, _) => {
- let _ = self.fatal(&format!("{}; {}", &errors, &warnings));
+ let _ = self.fatal(format!("{}; {}", &errors, &warnings));
}
}
@@ -1486,18 +1494,18 @@ impl HandlerInner {
error_codes.sort();
if error_codes.len() > 1 {
let limit = if error_codes.len() > 9 { 9 } else { error_codes.len() };
- self.failure(&format!(
+ self.failure(format!(
"Some errors have detailed explanations: {}{}",
error_codes[..limit].join(", "),
if error_codes.len() > 9 { "..." } else { "." }
));
- self.failure(&format!(
+ self.failure(format!(
"For more information about an error, try \
`rustc --explain {}`.",
&error_codes[0]
));
} else {
- self.failure(&format!(
+ self.failure(format!(
"For more information about this error, try \
`rustc --explain {}`.",
&error_codes[0]
@@ -1595,7 +1603,7 @@ impl HandlerInner {
// This is technically `self.treat_err_as_bug()` but `delay_span_bug` is called before
// incrementing `err_count` by one, so we need to +1 the comparing.
// FIXME: Would be nice to increment err_count in a more coherent way.
- if self.flags.treat_err_as_bug.map_or(false, |c| {
+ if self.flags.treat_err_as_bug.is_some_and(|c| {
self.err_count() + self.lint_err_count + self.delayed_bug_count() + 1 >= c.get()
}) {
// FIXME: don't abort here if report_delayed_bugs is off
@@ -1663,7 +1671,7 @@ impl HandlerInner {
if bug.level != Level::DelayedBug {
// NOTE(eddyb) not panicking here because we're already producing
// an ICE, and the more information the merrier.
- bug.note(&format!(
+ bug.note(format!(
"`flushed_delayed` got diagnostic with level {:?}, \
instead of the expected `DelayedBug`",
bug.level,
@@ -1732,7 +1740,7 @@ impl DelayedDiagnostic {
}
fn decorate(mut self) -> Diagnostic {
- self.inner.note(&format!("delayed at {}", self.note));
+ self.inner.note(format!("delayed at {}\n{}", self.inner.emitted_at, self.note));
self.inner
}
}
@@ -1831,7 +1839,7 @@ pub fn add_elided_lifetime_in_path_suggestion(
if incl_angl_brckt { format!("<{}>", anon_lts) } else { format!("{}, ", anon_lts) };
diag.span_suggestion_verbose(
insertion_span.shrink_to_hi(),
- &format!("indicate the anonymous lifetime{}", pluralize!(n)),
+ format!("indicate the anonymous lifetime{}", pluralize!(n)),
suggestion,
Applicability::MachineApplicable,
);
diff --git a/compiler/rustc_errors/src/lock.rs b/compiler/rustc_errors/src/lock.rs
index 7db262abf..bd5cf49b5 100644
--- a/compiler/rustc_errors/src/lock.rs
+++ b/compiler/rustc_errors/src/lock.rs
@@ -19,8 +19,7 @@ pub fn acquire_global_lock(name: &str) -> Box<dyn Any> {
use windows::{
core::PCSTR,
Win32::Foundation::{CloseHandle, HANDLE, WAIT_ABANDONED, WAIT_OBJECT_0},
- Win32::System::Threading::{CreateMutexA, ReleaseMutex, WaitForSingleObject},
- Win32::System::WindowsProgramming::INFINITE,
+ Win32::System::Threading::{CreateMutexA, ReleaseMutex, WaitForSingleObject, INFINITE},
};
struct Handle(HANDLE);
diff --git a/compiler/rustc_errors/src/tests.rs b/compiler/rustc_errors/src/tests.rs
index 52103e460..0e729b716 100644
--- a/compiler/rustc_errors/src/tests.rs
+++ b/compiler/rustc_errors/src/tests.rs
@@ -2,7 +2,7 @@ use crate::error::{TranslateError, TranslateErrorKind};
use crate::fluent_bundle::*;
use crate::translation::Translate;
use crate::FluentBundle;
-use rustc_data_structures::sync::Lrc;
+use rustc_data_structures::sync::{IntoDynSyncSend, Lrc};
use rustc_error_messages::fluent_bundle::resolver::errors::{ReferenceKind, ResolverError};
use rustc_error_messages::langid;
use rustc_error_messages::DiagnosticMessage;
@@ -27,10 +27,14 @@ fn make_dummy(ftl: &'static str) -> Dummy {
let langid_en = langid!("en-US");
#[cfg(parallel_compiler)]
- let mut bundle = FluentBundle::new_concurrent(vec![langid_en]);
+ let mut bundle: FluentBundle =
+ IntoDynSyncSend(crate::fluent_bundle::bundle::FluentBundle::new_concurrent(vec![
+ langid_en,
+ ]));
#[cfg(not(parallel_compiler))]
- let mut bundle = FluentBundle::new(vec![langid_en]);
+ let mut bundle: FluentBundle =
+ IntoDynSyncSend(crate::fluent_bundle::bundle::FluentBundle::new(vec![langid_en]));
bundle.add_resource(resource).expect("Failed to add FTL resources to the bundle.");