summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_error_messages/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_error_messages/src/lib.rs')
-rw-r--r--compiler/rustc_error_messages/src/lib.rs26
1 files changed, 21 insertions, 5 deletions
diff --git a/compiler/rustc_error_messages/src/lib.rs b/compiler/rustc_error_messages/src/lib.rs
index 51e1fe531..3bf155050 100644
--- a/compiler/rustc_error_messages/src/lib.rs
+++ b/compiler/rustc_error_messages/src/lib.rs
@@ -4,6 +4,7 @@
#![feature(type_alias_impl_trait)]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]
+#![cfg_attr(not(bootstrap), allow(internal_features))]
#[macro_use]
extern crate tracing;
@@ -71,17 +72,17 @@ pub enum TranslationBundleError {
impl fmt::Display for TranslationBundleError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
- TranslationBundleError::ReadFtl(e) => write!(f, "could not read ftl file: {}", e),
+ TranslationBundleError::ReadFtl(e) => write!(f, "could not read ftl file: {e}"),
TranslationBundleError::ParseFtl(e) => {
- write!(f, "could not parse ftl file: {}", e)
+ write!(f, "could not parse ftl file: {e}")
}
- TranslationBundleError::AddResource(e) => write!(f, "failed to add resource: {}", e),
+ TranslationBundleError::AddResource(e) => write!(f, "failed to add resource: {e}"),
TranslationBundleError::MissingLocale => write!(f, "missing locale directory"),
TranslationBundleError::ReadLocalesDir(e) => {
- write!(f, "could not read locales dir: {}", e)
+ write!(f, "could not read locales dir: {e}")
}
TranslationBundleError::ReadLocalesDirEntry(e) => {
- write!(f, "could not read locales dir entry: {}", e)
+ write!(f, "could not read locales dir entry: {e}")
}
TranslationBundleError::LocaleIsNotDir => {
write!(f, "`$sysroot/share/locales/$locale` is not a directory")
@@ -354,6 +355,13 @@ impl DiagnosticMessage {
}
}
}
+
+ pub fn as_str(&self) -> Option<&str> {
+ match self {
+ DiagnosticMessage::Eager(s) | DiagnosticMessage::Str(s) => Some(s),
+ DiagnosticMessage::FluentIdentifier(_, _) => None,
+ }
+ }
}
impl From<String> for DiagnosticMessage {
@@ -526,6 +534,14 @@ impl MultiSpan {
pub fn has_span_labels(&self) -> bool {
self.span_labels.iter().any(|(sp, _)| !sp.is_dummy())
}
+
+ /// Clone this `MultiSpan` without keeping any of the span labels - sometimes a `MultiSpan` is
+ /// to be re-used in another diagnostic, but includes `span_labels` which have translated
+ /// messages. These translated messages would fail to translate without their diagnostic
+ /// arguments which are unlikely to be cloned alongside the `Span`.
+ pub fn clone_ignoring_labels(&self) -> Self {
+ Self { primary_spans: self.primary_spans.clone(), ..MultiSpan::new() }
+ }
}
impl From<Span> for MultiSpan {