summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_errors
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:42 +0000
commitcec1877e180393eba0f6ddb0cf97bf3a791631c7 (patch)
tree47b4dac2a9dd9a40c30c251b4d4a72d7ccf77e9f /compiler/rustc_errors
parentAdding debian version 1.74.1+dfsg1-1. (diff)
downloadrustc-cec1877e180393eba0f6ddb0cf97bf3a791631c7.tar.xz
rustc-cec1877e180393eba0f6ddb0cf97bf3a791631c7.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_errors')
-rw-r--r--compiler/rustc_errors/Cargo.toml26
-rw-r--r--compiler/rustc_errors/src/diagnostic_builder.rs1
-rw-r--r--compiler/rustc_errors/src/emitter.rs31
-rw-r--r--compiler/rustc_errors/src/lib.rs24
-rw-r--r--compiler/rustc_errors/src/tests.rs24
5 files changed, 65 insertions, 41 deletions
diff --git a/compiler/rustc_errors/Cargo.toml b/compiler/rustc_errors/Cargo.toml
index faab9f09d..fc3ff835a 100644
--- a/compiler/rustc_errors/Cargo.toml
+++ b/compiler/rustc_errors/Cargo.toml
@@ -3,29 +3,29 @@ name = "rustc_errors"
version = "0.0.0"
edition = "2021"
-[lib]
-
[dependencies]
-tracing = "0.1"
+# tidy-alphabetical-start
+annotate-snippets = "0.9"
+derive_setters = "0.1.6"
rustc_ast = { path = "../rustc_ast" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
+rustc_data_structures = { path = "../rustc_data_structures" }
rustc_error_messages = { path = "../rustc_error_messages" }
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
+rustc_hir = { path = "../rustc_hir" }
+rustc_lint_defs = { path = "../rustc_lint_defs" }
+rustc_macros = { path = "../rustc_macros" }
rustc_serialize = { path = "../rustc_serialize" }
rustc_span = { path = "../rustc_span" }
-rustc_macros = { path = "../rustc_macros" }
-rustc_data_structures = { path = "../rustc_data_structures" }
rustc_target = { path = "../rustc_target" }
-rustc_hir = { path = "../rustc_hir" }
-rustc_lint_defs = { path = "../rustc_lint_defs" }
rustc_type_ir = { path = "../rustc_type_ir" }
-unicode-width = "0.1.4"
-termcolor = "1.2.0"
-annotate-snippets = "0.9"
-termize = "0.1.1"
serde = { version = "1.0.125", features = [ "derive" ] }
serde_json = "1.0.59"
-derive_setters = "0.1.6"
+termcolor = "1.2.0"
+termize = "0.1.1"
+tracing = "0.1"
+unicode-width = "0.1.4"
+# tidy-alphabetical-end
[target.'cfg(windows)'.dependencies.windows]
version = "0.48.0"
@@ -36,4 +36,6 @@ features = [
]
[features]
+# tidy-alphabetical-start
rustc_use_parallel_compiler = ['rustc_error_messages/rustc_use_parallel_compiler']
+# tidy-alphabetical-end
diff --git a/compiler/rustc_errors/src/diagnostic_builder.rs b/compiler/rustc_errors/src/diagnostic_builder.rs
index 5e23ae655..85acf8ab5 100644
--- a/compiler/rustc_errors/src/diagnostic_builder.rs
+++ b/compiler/rustc_errors/src/diagnostic_builder.rs
@@ -659,6 +659,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
msg: impl Into<SubdiagnosticMessage>,
) -> &mut Self);
forward!(pub fn help(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self);
+ forward!(pub fn help_once(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self);
forward!(pub fn span_help(
&mut self,
sp: impl Into<MultiSpan>,
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs
index d322cbe9d..68dba8602 100644
--- a/compiler/rustc_errors/src/emitter.rs
+++ b/compiler/rustc_errors/src/emitter.rs
@@ -23,7 +23,7 @@ use crate::{
use rustc_lint_defs::pluralize;
use derive_setters::Setters;
-use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
+use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
use rustc_data_structures::sync::{DynSend, IntoDynSyncSend, Lrc};
use rustc_error_messages::{FluentArgs, SpanLabel};
use rustc_span::hygiene::{ExpnKind, MacroKind};
@@ -337,9 +337,7 @@ pub trait Emitter: Translate {
&& last_name != name
{
let descr = macro_kind.descr();
- format!(
- " which comes from the expansion of the {descr} `{last_name}`",
- )
+ format!(" which comes from the expansion of the {descr} `{last_name}`",)
} else {
"".to_string()
};
@@ -372,7 +370,7 @@ pub trait Emitter: Translate {
}
fn render_multispan_macro_backtrace(&self, span: &mut MultiSpan, always_backtrace: bool) {
- let mut new_labels: Vec<(Span, String)> = vec![];
+ let mut new_labels = FxIndexSet::default();
for &sp in span.primary_spans() {
if sp.is_dummy() {
@@ -389,7 +387,7 @@ pub trait Emitter: Translate {
}
if always_backtrace {
- new_labels.push((
+ new_labels.insert((
trace.def_site,
format!(
"in this expansion of `{}`{}",
@@ -433,7 +431,7 @@ pub trait Emitter: Translate {
format!("this {} desugaring", kind.descr()).into()
}
};
- new_labels.push((
+ new_labels.insert((
trace.call_site,
format!(
"in {}{}",
@@ -1350,7 +1348,14 @@ impl EmitterWriter {
buffer.append(0, "]", Style::Level(*level));
label_width += 2 + code.len();
}
- let header_style = if is_secondary { Style::HeaderMsg } else { Style::MainHeaderMsg };
+ let header_style = if is_secondary {
+ Style::HeaderMsg
+ } else if self.short_message {
+ // For short messages avoid bolding the message, as it doesn't look great (#63835).
+ Style::NoStyle
+ } else {
+ Style::MainHeaderMsg
+ };
if *level != Level::FailureNote {
buffer.append(0, ": ", header_style);
label_width += 2;
@@ -1935,7 +1940,9 @@ impl EmitterWriter {
is_multiline,
)
}
- if let DisplaySuggestion::Add = show_code_change && is_item_attribute {
+ 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 advising people to
// do. Otherwise you would only see contextless code that can be confused for
@@ -2355,11 +2362,7 @@ impl FileWithAnnotatedLines {
let label = label.as_ref().map(|m| {
normalize_whitespace(
- &emitter
- .translate_message(m, &args)
- .map_err(Report::new)
- .unwrap()
- .to_string(),
+ &emitter.translate_message(m, &args).map_err(Report::new).unwrap(),
)
});
diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs
index b747a62b8..dd462cc64 100644
--- a/compiler/rustc_errors/src/lib.rs
+++ b/compiler/rustc_errors/src/lib.rs
@@ -3,6 +3,8 @@
//! This module contains the code for creating and emitting diagnostics.
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
+#![cfg_attr(not(bootstrap), doc(rust_logo))]
+#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![feature(array_windows)]
#![feature(extract_if)]
#![feature(if_let_guard)]
@@ -505,6 +507,9 @@ pub enum StashKey {
CallAssocMethod,
TraitMissingMethod,
OpaqueHiddenTypeMismatch,
+ MaybeForgetReturn,
+ /// Query cycle detected, stashing in favor of a better error.
+ Cycle,
}
fn default_track_diagnostic(d: &mut Diagnostic, f: &mut dyn FnMut(&mut Diagnostic)) {
@@ -551,7 +556,7 @@ impl Drop for HandlerInner {
// instead of "require some error happened". Sadly that isn't ideal, as
// lints can be `#[allow]`'d, potentially leading to this triggering.
// Also, "good path" should be replaced with a better naming.
- if !self.has_any_message() && !self.suppressed_expected_diag {
+ if !self.has_any_message() && !self.suppressed_expected_diag && !std::thread::panicking() {
let bugs = std::mem::replace(&mut self.delayed_good_path_bugs, Vec::new());
self.flush_delayed(
bugs,
@@ -1376,16 +1381,16 @@ impl HandlerInner {
self.emitted_diagnostic_codes.insert(code.clone());
}
- let already_emitted = |this: &mut Self| {
+ let already_emitted = {
let mut hasher = StableHasher::new();
diagnostic.hash(&mut hasher);
let diagnostic_hash = hasher.finish();
- !this.emitted_diagnostics.insert(diagnostic_hash)
+ !self.emitted_diagnostics.insert(diagnostic_hash)
};
// Only emit the diagnostic if we've been asked to deduplicate or
// haven't already emitted an equivalent diagnostic.
- if !(self.flags.deduplicate_diagnostics && already_emitted(self)) {
+ if !(self.flags.deduplicate_diagnostics && already_emitted) {
debug!(?diagnostic);
debug!(?self.emitted_diagnostics);
let already_emitted_sub = |sub: &mut SubDiagnostic| {
@@ -1401,6 +1406,11 @@ impl HandlerInner {
};
diagnostic.children.extract_if(already_emitted_sub).for_each(|_| {});
+ if already_emitted {
+ diagnostic.note(
+ "duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`",
+ );
+ }
self.emitter.emit_diagnostic(diagnostic);
if diagnostic.is_error() {
@@ -1666,7 +1676,11 @@ impl HandlerInner {
let _ = write!(
&mut out,
"delayed span bug: {}\n{}\n",
- bug.inner.styled_message().iter().filter_map(|(msg, _)| msg.as_str()).collect::<String>(),
+ bug.inner
+ .styled_message()
+ .iter()
+ .filter_map(|(msg, _)| msg.as_str())
+ .collect::<String>(),
&bug.note
);
}
diff --git a/compiler/rustc_errors/src/tests.rs b/compiler/rustc_errors/src/tests.rs
index 0e729b716..79a2af7f3 100644
--- a/compiler/rustc_errors/src/tests.rs
+++ b/compiler/rustc_errors/src/tests.rs
@@ -151,12 +151,14 @@ fn misformed_fluent() {
primary: box TranslateError::One { kind: TranslateErrorKind::PrimaryBundleMissing, .. },
fallback: box TranslateError::One { kind: TranslateErrorKind::Fluent { errs }, .. },
} = &err
- && let [FluentError::ResolverError(ResolverError::Reference(
- ReferenceKind::Message { id, .. }
- | ReferenceKind::Variable { id, .. },
- ))] = &**errs
+ && let [
+ FluentError::ResolverError(ResolverError::Reference(
+ ReferenceKind::Message { id, .. } | ReferenceKind::Variable { id, .. },
+ )),
+ ] = &**errs
&& id == "name"
- {} else {
+ {
+ } else {
panic!("{err:#?}")
};
assert_eq!(
@@ -176,12 +178,14 @@ fn misformed_fluent() {
primary: box TranslateError::One { kind: TranslateErrorKind::PrimaryBundleMissing, .. },
fallback: box TranslateError::One { kind: TranslateErrorKind::Fluent { errs }, .. },
} = &err
- && let [FluentError::ResolverError(ResolverError::Reference(
- ReferenceKind::Message { id, .. }
- | ReferenceKind::Variable { id, .. },
- ))] = &**errs
+ && let [
+ FluentError::ResolverError(ResolverError::Reference(
+ ReferenceKind::Message { id, .. } | ReferenceKind::Variable { id, .. },
+ )),
+ ] = &**errs
&& id == "oops"
- {} else {
+ {
+ } else {
panic!("{err:#?}")
};
assert_eq!(