@@ -35,7 +35,7 @@ use crate::session_diagnostics::{
35
35
LifetimeReturnCategoryErr , RequireStaticErr , VarHereDenote ,
36
36
} ;
37
37
use crate :: universal_regions:: DefiningTy ;
38
- use crate :: { borrowck_errors, MirBorrowckCtxt } ;
38
+ use crate :: { borrowck_errors, fluent_generated as fluent , MirBorrowckCtxt } ;
39
39
40
40
impl < ' tcx > ConstraintDescription for ConstraintCategory < ' tcx > {
41
41
fn description ( & self ) -> & ' static str {
@@ -198,7 +198,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
198
198
// from higher-ranked trait bounds (HRTB). Try to locate span of the trait
199
199
// and the span which bounded to the trait for adding 'static lifetime suggestion
200
200
#[ allow( rustc:: diagnostic_outside_of_impl) ]
201
- #[ allow( rustc:: untranslatable_diagnostic) ] // FIXME: make this translatable
202
201
fn suggest_static_lifetime_for_gat_from_hrtb (
203
202
& self ,
204
203
diag : & mut Diag < ' _ > ,
@@ -251,23 +250,28 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
251
250
debug ! ( ?hrtb_bounds) ;
252
251
253
252
hrtb_bounds. iter ( ) . for_each ( |bound| {
254
- let Trait ( PolyTraitRef { trait_ref, span : trait_span, .. } , _) = bound else { return ; } ;
255
- diag. span_note (
256
- * trait_span,
257
- "due to current limitations in the borrow checker, this implies a `'static` lifetime"
258
- ) ;
259
- let Some ( generics_fn) = hir. get_generics ( self . body . source . def_id ( ) . expect_local ( ) ) else { return ; } ;
260
- let Def ( _, trait_res_defid) = trait_ref. path . res else { return ; } ;
253
+ let Trait ( PolyTraitRef { trait_ref, span : trait_span, .. } , _) = bound else {
254
+ return ;
255
+ } ;
256
+ diag. span_note ( * trait_span, fluent:: borrowck_limitations_implies_static) ;
257
+ let Some ( generics_fn) = hir. get_generics ( self . body . source . def_id ( ) . expect_local ( ) )
258
+ else {
259
+ return ;
260
+ } ;
261
+ let Def ( _, trait_res_defid) = trait_ref. path . res else {
262
+ return ;
263
+ } ;
261
264
debug ! ( ?generics_fn) ;
262
265
generics_fn. predicates . iter ( ) . for_each ( |predicate| {
263
- let BoundPredicate (
264
- WhereBoundPredicate {
265
- span : bounded_span,
266
- bounded_ty,
267
- bounds,
268
- ..
269
- }
270
- ) = predicate else { return ; } ;
266
+ let BoundPredicate ( WhereBoundPredicate {
267
+ span : bounded_span,
268
+ bounded_ty,
269
+ bounds,
270
+ ..
271
+ } ) = predicate
272
+ else {
273
+ return ;
274
+ } ;
271
275
bounds. iter ( ) . for_each ( |bd| {
272
276
if let Trait ( PolyTraitRef { trait_ref : tr_ref, .. } , _) = bd
273
277
&& let Def ( _, res_defid) = tr_ref. path . res
@@ -277,16 +281,17 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
277
281
&& generics_fn. params
278
282
. iter ( )
279
283
. rfind ( |param| param. def_id . to_def_id ( ) == defid)
280
- . is_some ( ) {
281
- suggestions. push ( ( bounded_span. shrink_to_hi ( ) , " + 'static" . to_string ( ) ) ) ;
282
- }
284
+ . is_some ( )
285
+ {
286
+ suggestions. push ( ( bounded_span. shrink_to_hi ( ) , " + 'static" . to_string ( ) ) ) ;
287
+ }
283
288
} ) ;
284
289
} ) ;
285
290
} ) ;
286
291
if suggestions. len ( ) > 0 {
287
292
suggestions. dedup ( ) ;
288
293
diag. multipart_suggestion_verbose (
289
- "consider restricting the type parameter to the `'static` lifetime" ,
294
+ fluent :: borrowck_restrict_to_static ,
290
295
suggestions,
291
296
Applicability :: MaybeIncorrect ,
292
297
) ;
@@ -976,7 +981,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
976
981
}
977
982
978
983
#[ allow( rustc:: diagnostic_outside_of_impl) ]
979
- #[ allow( rustc:: untranslatable_diagnostic) ] // FIXME: make this translatable
980
984
#[ instrument( skip( self , err) , level = "debug" ) ]
981
985
fn suggest_constrain_dyn_trait_in_impl (
982
986
& self ,
@@ -994,16 +998,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
994
998
debug ! ( "trait spans found: {:?}" , traits) ;
995
999
for span in & traits {
996
1000
let mut multi_span: MultiSpan = vec ! [ * span] . into ( ) ;
997
- multi_span
998
- . push_span_label ( * span, "this has an implicit `'static` lifetime requirement" ) ;
999
- multi_span. push_span_label (
1000
- ident. span ,
1001
- "calling this method introduces the `impl`'s `'static` requirement" ,
1002
- ) ;
1001
+ multi_span. push_span_label ( * span, fluent:: borrowck_implicit_static) ;
1002
+ multi_span. push_span_label ( ident. span , fluent:: borrowck_implicit_static_introduced) ;
1003
1003
err. subdiagnostic ( RequireStaticErr :: UsedImpl { multi_span } ) ;
1004
1004
err. span_suggestion_verbose (
1005
1005
span. shrink_to_hi ( ) ,
1006
- "consider relaxing the implicit `'static` requirement" ,
1006
+ fluent :: borrowck_implicit_static_relax ,
1007
1007
" + '_" ,
1008
1008
Applicability :: MaybeIncorrect ,
1009
1009
) ;
@@ -1045,7 +1045,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
1045
1045
}
1046
1046
1047
1047
#[ allow( rustc:: diagnostic_outside_of_impl) ]
1048
- #[ allow( rustc:: untranslatable_diagnostic) ] // FIXME: make this translatable
1049
1048
/// When encountering a lifetime error caused by the return type of a closure, check the
1050
1049
/// corresponding trait bound and see if dereferencing the closure return value would satisfy
1051
1050
/// them. If so, we produce a structured suggestion.
@@ -1166,15 +1165,14 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
1166
1165
if ocx. select_all_or_error ( ) . is_empty ( ) && count > 0 {
1167
1166
diag. span_suggestion_verbose (
1168
1167
tcx. hir ( ) . body ( * body) . value . peel_blocks ( ) . span . shrink_to_lo ( ) ,
1169
- "dereference the return value" ,
1168
+ fluent :: borrowck_dereference_suggestion ,
1170
1169
"*" . repeat ( count) ,
1171
1170
Applicability :: MachineApplicable ,
1172
1171
) ;
1173
1172
}
1174
1173
}
1175
1174
1176
1175
#[ allow( rustc:: diagnostic_outside_of_impl) ]
1177
- #[ allow( rustc:: untranslatable_diagnostic) ] // FIXME: make this translatable
1178
1176
fn suggest_move_on_borrowing_closure ( & self , diag : & mut Diag < ' _ > ) {
1179
1177
let map = self . infcx . tcx . hir ( ) ;
1180
1178
let body = map. body_owned_by ( self . mir_def_id ( ) ) ;
@@ -1213,7 +1211,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
1213
1211
if let Some ( closure_span) = closure_span {
1214
1212
diag. span_suggestion_verbose (
1215
1213
closure_span,
1216
- "consider adding 'move' keyword before the nested closure" ,
1214
+ fluent :: borrowck_move_closure_suggestion ,
1217
1215
"move " ,
1218
1216
Applicability :: MaybeIncorrect ,
1219
1217
) ;
0 commit comments