summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_error_messages
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /compiler/rustc_error_messages
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_error_messages')
-rw-r--r--compiler/rustc_error_messages/src/lib.rs39
1 files changed, 19 insertions, 20 deletions
diff --git a/compiler/rustc_error_messages/src/lib.rs b/compiler/rustc_error_messages/src/lib.rs
index 0accb4ab9..51e1fe531 100644
--- a/compiler/rustc_error_messages/src/lib.rs
+++ b/compiler/rustc_error_messages/src/lib.rs
@@ -226,7 +226,7 @@ fn register_functions(bundle: &mut FluentBundle) {
pub type LazyFallbackBundle = Lrc<Lazy<FluentBundle, impl FnOnce() -> FluentBundle>>;
/// Return the default `FluentBundle` with standard "en-US" diagnostic messages.
-#[instrument(level = "trace")]
+#[instrument(level = "trace", skip(resources))]
pub fn fallback_fluent_bundle(
resources: Vec<&'static str>,
with_directionality_markers: bool,
@@ -242,7 +242,6 @@ pub fn fallback_fluent_bundle(
for resource in resources {
let resource = FluentResource::try_new(resource.to_string())
.expect("failed to parse fallback fluent resource");
- trace!(?resource);
fallback_bundle.add_resource_overriding(resource);
}
@@ -263,8 +262,7 @@ type FluentId = Cow<'static, str>;
#[rustc_diagnostic_item = "SubdiagnosticMessage"]
pub enum SubdiagnosticMessage {
/// Non-translatable diagnostic message.
- // FIXME(davidtwco): can a `Cow<'static, str>` be used here?
- Str(String),
+ Str(Cow<'static, str>),
/// Translatable message which has already been translated eagerly.
///
/// Some diagnostics have repeated subdiagnostics where the same interpolated variables would
@@ -275,8 +273,7 @@ pub enum SubdiagnosticMessage {
/// incorrect diagnostics. Eager translation results in translation for a subdiagnostic
/// happening immediately after the subdiagnostic derive's logic has been run. This variant
/// stores messages which have been translated eagerly.
- // FIXME(#100717): can a `Cow<'static, str>` be used here?
- Eager(String),
+ Eager(Cow<'static, str>),
/// Identifier of a Fluent message. Instances of this variant are generated by the
/// `Subdiagnostic` derive.
FluentIdentifier(FluentId),
@@ -290,17 +287,17 @@ pub enum SubdiagnosticMessage {
impl From<String> for SubdiagnosticMessage {
fn from(s: String) -> Self {
- SubdiagnosticMessage::Str(s)
+ SubdiagnosticMessage::Str(Cow::Owned(s))
}
}
-impl<'a> From<&'a str> for SubdiagnosticMessage {
- fn from(s: &'a str) -> Self {
- SubdiagnosticMessage::Str(s.to_string())
+impl From<&'static str> for SubdiagnosticMessage {
+ fn from(s: &'static str) -> Self {
+ SubdiagnosticMessage::Str(Cow::Borrowed(s))
}
}
impl From<Cow<'static, str>> for SubdiagnosticMessage {
fn from(s: Cow<'static, str>) -> Self {
- SubdiagnosticMessage::Str(s.to_string())
+ SubdiagnosticMessage::Str(s)
}
}
@@ -312,8 +309,7 @@ impl From<Cow<'static, str>> for SubdiagnosticMessage {
#[rustc_diagnostic_item = "DiagnosticMessage"]
pub enum DiagnosticMessage {
/// Non-translatable diagnostic message.
- // FIXME(#100717): can a `Cow<'static, str>` be used here?
- Str(String),
+ Str(Cow<'static, str>),
/// Translatable message which has already been translated eagerly.
///
/// Some diagnostics have repeated subdiagnostics where the same interpolated variables would
@@ -324,8 +320,7 @@ pub enum DiagnosticMessage {
/// incorrect diagnostics. Eager translation results in translation for a subdiagnostic
/// happening immediately after the subdiagnostic derive's logic has been run. This variant
/// stores messages which have been translated eagerly.
- // FIXME(#100717): can a `Cow<'static, str>` be used here?
- Eager(String),
+ Eager(Cow<'static, str>),
/// Identifier for a Fluent message (with optional attribute) corresponding to the diagnostic
/// message.
///
@@ -363,17 +358,17 @@ impl DiagnosticMessage {
impl From<String> for DiagnosticMessage {
fn from(s: String) -> Self {
- DiagnosticMessage::Str(s)
+ DiagnosticMessage::Str(Cow::Owned(s))
}
}
-impl<'a> From<&'a str> for DiagnosticMessage {
- fn from(s: &'a str) -> Self {
- DiagnosticMessage::Str(s.to_string())
+impl From<&'static str> for DiagnosticMessage {
+ fn from(s: &'static str) -> Self {
+ DiagnosticMessage::Str(Cow::Borrowed(s))
}
}
impl From<Cow<'static, str>> for DiagnosticMessage {
fn from(s: Cow<'static, str>) -> Self {
- DiagnosticMessage::Str(s.to_string())
+ DiagnosticMessage::Str(s)
}
}
@@ -496,6 +491,10 @@ impl MultiSpan {
replacements_occurred
}
+ pub fn pop_span_label(&mut self) -> Option<(Span, DiagnosticMessage)> {
+ self.span_labels.pop()
+ }
+
/// Returns the strings to highlight. We always ensure that there
/// is an entry for each of the primary spans -- for each primary
/// span `P`, if there is at least one label with span `P`, we return