summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_errors/src
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_errors/src')
-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
4 files changed, 51 insertions, 29 deletions
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!(