Skip to content

Commit f6c606c

Browse files
authored
Rollup merge of rust-lang#106923 - mejrs:fluent_err, r=davidtwco
Restore behavior when primary bundle is missing Fixes rust-lang#106755 by restoring some of the behavior prior to rust-lang#106427 Still, I have no idea how this debug assertion can even hit while using `en-US` as primary bundle. r? ``@davidtwco``
2 parents 07c993e + 4c13a21 commit f6c606c

File tree

4 files changed

+59
-6
lines changed

4 files changed

+59
-6
lines changed

compiler/rustc_error_messages/src/lib.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,10 @@ pub fn fluent_bundle(
135135

136136
let fallback_locale = langid!("en-US");
137137
let requested_fallback_locale = requested_locale.as_ref() == Some(&fallback_locale);
138-
138+
trace!(?requested_fallback_locale);
139+
if requested_fallback_locale && additional_ftl_path.is_none() {
140+
return Ok(None);
141+
}
139142
// If there is only `-Z additional-ftl-path`, assume locale is "en-US", otherwise use user
140143
// provided locale.
141144
let locale = requested_locale.clone().unwrap_or(fallback_locale);
@@ -153,7 +156,7 @@ pub fn fluent_bundle(
153156
bundle.set_use_isolating(with_directionality_markers);
154157

155158
// If the user requests the default locale then don't try to load anything.
156-
if !requested_fallback_locale && let Some(requested_locale) = requested_locale {
159+
if let Some(requested_locale) = requested_locale {
157160
let mut found_resources = false;
158161
for sysroot in user_provided_sysroot.iter_mut().chain(sysroot_candidates.iter_mut()) {
159162
sysroot.push("share");

compiler/rustc_errors/src/translation.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::error::TranslateError;
1+
use crate::error::{TranslateError, TranslateErrorKind};
22
use crate::snippet::Style;
33
use crate::{DiagnosticArg, DiagnosticMessage, FluentBundle};
44
use rustc_data_structures::sync::Lrc;
@@ -95,6 +95,16 @@ pub trait Translate {
9595
// The primary bundle was present and translation succeeded
9696
Some(Ok(t)) => t,
9797

98+
// If `translate_with_bundle` returns `Err` with the primary bundle, this is likely
99+
// just that the primary bundle doesn't contain the message being translated, so
100+
// proceed to the fallback bundle.
101+
Some(Err(
102+
primary @ TranslateError::One {
103+
kind: TranslateErrorKind::MessageMissing, ..
104+
},
105+
)) => translate_with_bundle(self.fallback_fluent_bundle())
106+
.map_err(|fallback| primary.and(fallback))?,
107+
98108
// Always yeet out for errors on debug (unless
99109
// `RUSTC_TRANSLATION_NO_DEBUG_ASSERT` is set in the environment - this allows
100110
// local runs of the test suites, of builds with debug assertions, to test the
@@ -106,9 +116,8 @@ pub trait Translate {
106116
do yeet primary
107117
}
108118

109-
// If `translate_with_bundle` returns `Err` with the primary bundle, this is likely
110-
// just that the primary bundle doesn't contain the message being translated or
111-
// something else went wrong) so proceed to the fallback bundle.
119+
// ..otherwise, for end users, an error about this wouldn't be useful or actionable, so
120+
// just hide it and try with the fallback bundle.
112121
Some(Err(primary)) => translate_with_bundle(self.fallback_fluent_bundle())
113122
.map_err(|fallback| primary.and(fallback))?,
114123

tests/ui/issues/issue-106755.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// compile-flags:-Ztranslate-lang=en_US
2+
3+
#![feature(negative_impls)]
4+
#![feature(marker_trait_attr)]
5+
6+
#[marker]
7+
trait MyTrait {}
8+
9+
struct TestType<T>(::std::marker::PhantomData<T>);
10+
11+
unsafe impl<T: MyTrait + 'static> Send for TestType<T> {}
12+
13+
impl<T: MyTrait> !Send for TestType<T> {} //~ ERROR found both positive and negative implementation
14+
15+
unsafe impl<T: 'static> Send for TestType<T> {} //~ ERROR conflicting implementations
16+
17+
impl !Send for TestType<i32> {}
18+
19+
fn main() {}

tests/ui/issues/issue-106755.stderr

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0751]: found both positive and negative implementation of trait `Send` for type `TestType<_>`:
2+
--> $DIR/issue-106755.rs:13:1
3+
|
4+
LL | unsafe impl<T: MyTrait + 'static> Send for TestType<T> {}
5+
| ------------------------------------------------------ positive implementation here
6+
LL |
7+
LL | impl<T: MyTrait> !Send for TestType<T> {}
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ negative implementation here
9+
10+
error[E0119]: conflicting implementations of trait `Send` for type `TestType<_>`
11+
--> $DIR/issue-106755.rs:15:1
12+
|
13+
LL | unsafe impl<T: MyTrait + 'static> Send for TestType<T> {}
14+
| ------------------------------------------------------ first implementation here
15+
...
16+
LL | unsafe impl<T: 'static> Send for TestType<T> {}
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `TestType<_>`
18+
19+
error: aborting due to 2 previous errors
20+
21+
Some errors have detailed explanations: E0119, E0751.
22+
For more information about an error, try `rustc --explain E0119`.

0 commit comments

Comments
 (0)