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