Skip to content

Commit dee71b6

Browse files
authored
Rollup merge of rust-lang#106971 - oli-obk:tait_error, r=davidtwco
Handle diagnostics customization on the fluent side (for one specific diagnostic) r? ``@davidtwco``
2 parents e328198 + 64e5f91 commit dee71b6

File tree

8 files changed

+24
-19
lines changed

8 files changed

+24
-19
lines changed

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

-12
Original file line numberDiff line numberDiff line change
@@ -367,18 +367,6 @@ fn check_opaque_type_parameter_valid(
367367
for (i, arg) in opaque_type_key.substs.iter().enumerate() {
368368
let arg_is_param = match arg.unpack() {
369369
GenericArgKind::Type(ty) => matches!(ty.kind(), ty::Param(_)),
370-
GenericArgKind::Lifetime(lt) if lt.is_static() => {
371-
tcx.sess
372-
.struct_span_err(span, "non-defining opaque type use in defining scope")
373-
.span_label(
374-
tcx.def_span(opaque_generics.param_at(i, tcx).def_id),
375-
"cannot use static lifetime; use a bound lifetime \
376-
instead or remove the lifetime parameter from the \
377-
opaque type",
378-
)
379-
.emit();
380-
return false;
381-
}
382370
GenericArgKind::Lifetime(lt) => {
383371
matches!(*lt, ty::ReEarlyBound(_) | ty::ReFree(_))
384372
}

compiler/rustc_error_messages/locales/en-US/borrowck.ftl

+4-1
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,7 @@ borrowck_cannot_move_when_borrowed =
123123
124124
borrowck_opaque_type_non_generic_param =
125125
expected generic {$kind} parameter, found `{$ty}`
126-
.label = this generic parameter must be used with a generic {$kind} parameter
126+
.label = {STREQ($ty, "'static") ->
127+
[true] cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type
128+
*[other] this generic parameter must be used with a generic {$kind} parameter
129+
}

compiler/rustc_error_messages/locales/en-US/infer.ftl

-2
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ infer_region_explanation = {$pref_kind ->
147147
}{$desc_kind ->
148148
*[should_not_happen] [{$desc_kind}]
149149
[restatic] the static lifetime
150-
[reempty] the empty lifetime
151-
[reemptyuni] the empty lifetime in universe {$desc_arg}
152150
[revar] lifetime {$desc_arg}
153151
154152
[as_defined] the lifetime `{$desc_arg}` as defined here

compiler/rustc_error_messages/src/lib.rs

+15
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ pub fn fluent_bundle(
182182
trace!(?locale);
183183
let mut bundle = new_bundle(vec![locale]);
184184

185+
// Add convenience functions available to ftl authors.
186+
register_functions(&mut bundle);
187+
185188
// Fluent diagnostics can insert directionality isolation markers around interpolated variables
186189
// indicating that there may be a shift from right-to-left to left-to-right text (or
187190
// vice-versa). These are disabled because they are sometimes visible in the error output, but
@@ -244,6 +247,15 @@ pub fn fluent_bundle(
244247
Ok(Some(bundle))
245248
}
246249

250+
fn register_functions(bundle: &mut FluentBundle) {
251+
bundle
252+
.add_function("STREQ", |positional, _named| match positional {
253+
[FluentValue::String(a), FluentValue::String(b)] => format!("{}", (a == b)).into(),
254+
_ => FluentValue::Error,
255+
})
256+
.expect("Failed to add a function to the bundle.");
257+
}
258+
247259
/// Type alias for the result of `fallback_fluent_bundle` - a reference-counted pointer to a lazily
248260
/// evaluated fluent bundle.
249261
pub type LazyFallbackBundle = Lrc<Lazy<FluentBundle, impl FnOnce() -> FluentBundle>>;
@@ -256,6 +268,9 @@ pub fn fallback_fluent_bundle(
256268
) -> LazyFallbackBundle {
257269
Lrc::new(Lazy::new(move || {
258270
let mut fallback_bundle = new_bundle(vec![langid!("en-US")]);
271+
272+
register_functions(&mut fallback_bundle);
273+
259274
// See comment in `fluent_bundle`.
260275
fallback_bundle.set_use_isolating(with_directionality_markers);
261276

tests/ui/type-alias-impl-trait/bounds-are-checked.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type X<'a> = impl Into<&'static str> + From<&'a str>;
88
fn f<'a: 'static>(t: &'a str) -> X<'a> {
99
//~^ WARNING unnecessary lifetime parameter
1010
t
11-
//~^ ERROR non-defining opaque type use
11+
//~^ ERROR expected generic lifetime parameter, found `'static`
1212
}
1313

1414
fn extend_lt<'a>(o: &'a str) -> &'static str {

tests/ui/type-alias-impl-trait/bounds-are-checked.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | fn f<'a: 'static>(t: &'a str) -> X<'a> {
66
|
77
= help: you can use the `'static` lifetime directly, in place of `'a`
88

9-
error: non-defining opaque type use in defining scope
9+
error[E0792]: expected generic lifetime parameter, found `'static`
1010
--> $DIR/bounds-are-checked.rs:10:5
1111
|
1212
LL | type X<'a> = impl Into<&'static str> + From<&'a str>;
@@ -17,3 +17,4 @@ LL | t
1717

1818
error: aborting due to previous error; 1 warning emitted
1919

20+
For more information about this error, try `rustc --explain E0792`.

tests/ui/type-alias-impl-trait/generic_nondefining_use.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn concrete_ty() -> OneTy<u32> {
1919

2020
fn concrete_lifetime() -> OneLifetime<'static> {
2121
6u32
22-
//~^ ERROR non-defining opaque type use in defining scope
22+
//~^ ERROR expected generic lifetime parameter, found `'static`
2323
}
2424

2525
fn concrete_const() -> OneConst<{ 123 }> {

tests/ui/type-alias-impl-trait/generic_nondefining_use.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | type OneTy<T> = impl Debug;
77
LL | 5u32
88
| ^^^^
99

10-
error: non-defining opaque type use in defining scope
10+
error[E0792]: expected generic lifetime parameter, found `'static`
1111
--> $DIR/generic_nondefining_use.rs:21:5
1212
|
1313
LL | type OneLifetime<'a> = impl Debug;

0 commit comments

Comments
 (0)