@@ -203,22 +203,36 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
203
203
fn suggest_static_lifetime_for_gat_from_hrtb (
204
204
& self ,
205
205
diag : & mut Diag < ' _ > ,
206
- _lower_bound : RegionVid ,
207
- ) {
206
+ lower_bound : RegionVid ,
207
+ ) -> Option < ( ) > {
208
208
let mut suggestions = vec ! [ ] ;
209
209
let hir = self . infcx . tcx . hir ( ) ;
210
210
211
211
// find higher-ranked trait bounds bounded to the generic associated types
212
- let hrtb_bounds = vec ! [ ] ;
213
- /*
214
- // FIXME: the best we can do is look at the representative, using something like:
215
212
let scc = self . regioncx . constraint_sccs ( ) . scc ( lower_bound) ;
216
- let Some(representative) =
217
- self.regioncx.constraint_sccs().annotation(scc).placeholder_representative()
218
- else {
219
- return;
220
- };
221
- */
213
+ let placeholder: ty:: PlaceholderRegion = self . regioncx . placeholder_representative ( scc) ?;
214
+ let placeholder_id = placeholder. bound . kind . get_id ( ) ?. as_local ( ) ?;
215
+ let gat_hir_id = self . infcx . tcx . local_def_id_to_hir_id ( placeholder_id) ;
216
+ let generics_impl =
217
+ self . infcx . tcx . parent_hir_node ( self . infcx . tcx . parent_hir_id ( gat_hir_id) ) . generics ( ) ?;
218
+
219
+ let mut hrtb_bounds = vec ! [ ] ;
220
+
221
+ for pred in generics_impl. predicates {
222
+ let BoundPredicate ( WhereBoundPredicate { bound_generic_params, bounds, .. } ) = pred
223
+ else {
224
+ continue ;
225
+ } ;
226
+ if bound_generic_params
227
+ . iter ( )
228
+ . rfind ( |bgp| self . infcx . tcx . local_def_id_to_hir_id ( bgp. def_id ) == gat_hir_id)
229
+ . is_some ( )
230
+ {
231
+ for bound in * bounds {
232
+ hrtb_bounds. push ( bound) ;
233
+ }
234
+ }
235
+ }
222
236
223
237
hrtb_bounds. iter ( ) . for_each ( |bound| {
224
238
let Trait ( PolyTraitRef { trait_ref, span : trait_span, .. } , _) = bound else {
@@ -267,6 +281,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
267
281
Applicability :: MaybeIncorrect ,
268
282
) ;
269
283
}
284
+ Some ( ( ) )
270
285
}
271
286
272
287
/// Produces nice borrowck error diagnostics for all the errors collected in `nll_errors`.
0 commit comments