@@ -275,30 +275,27 @@ pub fn check_trait_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
275
275
/// fn next<'a>(&'a mut self) -> Option<Self::Item<'a>>;
276
276
/// }
277
277
/// ```
278
- fn check_gat_where_clauses (
279
- tcx : TyCtxt < ' _ > ,
280
- trait_item : & hir:: TraitItem < ' _ > ,
281
- encl_trait_def_id : DefId ,
282
- ) {
283
- let item = tcx. associated_item ( trait_item. def_id ) ;
278
+ fn check_gat_where_clauses ( tcx : TyCtxt < ' _ > , gat_hir : & hir:: TraitItem < ' _ > , gat_def_id : DefId ) {
279
+ let gat_item = tcx. associated_item ( gat_def_id) ;
280
+ let gat_def_id = gat_hir. def_id ;
284
281
// If the current trait item isn't a type, it isn't a GAT
285
- if !matches ! ( item . kind, ty:: AssocKind :: Type ) {
282
+ if !matches ! ( gat_item . kind, ty:: AssocKind :: Type ) {
286
283
return ;
287
284
}
288
- let generics : & ty:: Generics = tcx. generics_of ( trait_item . def_id ) ;
285
+ let gat_generics : & ty:: Generics = tcx. generics_of ( gat_def_id ) ;
289
286
// If the current associated type doesn't have any (own) params, it's not a GAT
290
287
// FIXME(jackh726): we can also warn in the more general case
291
- if generics . params . len ( ) == 0 {
288
+ if gat_generics . params . len ( ) == 0 {
292
289
return ;
293
290
}
294
- let associated_items: & ty:: AssocItems < ' _ > = tcx. associated_items ( encl_trait_def_id ) ;
291
+ let associated_items: & ty:: AssocItems < ' _ > = tcx. associated_items ( gat_def_id ) ;
295
292
let mut clauses: Option < FxHashSet < ty:: Predicate < ' _ > > > = None ;
296
293
// For every function in this trait...
297
294
// In our example, this would be the `next` method
298
295
for item in
299
296
associated_items. in_definition_order ( ) . filter ( |item| matches ! ( item. kind, ty:: AssocKind :: Fn ) )
300
297
{
301
- let id = hir:: HirId :: make_owner ( item. def_id . expect_local ( ) ) ;
298
+ let item_hir_id = hir:: HirId :: make_owner ( item. def_id . expect_local ( ) ) ;
302
299
let param_env = tcx. param_env ( item. def_id . expect_local ( ) ) ;
303
300
304
301
// Get the signature using placeholders. In our example, this would
@@ -314,11 +311,11 @@ fn check_gat_where_clauses(
314
311
let function_clauses = gather_gat_bounds (
315
312
tcx,
316
313
param_env,
317
- id ,
314
+ item_hir_id ,
318
315
sig. output ( ) ,
319
316
& wf_tys,
320
- trait_item . def_id ,
321
- generics ,
317
+ gat_def_id ,
318
+ gat_generics ,
322
319
) ;
323
320
324
321
if let Some ( function_clauses) = function_clauses {
@@ -347,15 +344,15 @@ fn check_gat_where_clauses(
347
344
let clauses = clauses. unwrap_or_default ( ) ;
348
345
debug ! ( ?clauses) ;
349
346
if !clauses. is_empty ( ) {
350
- let param_env = tcx. param_env ( trait_item . def_id ) ;
347
+ let param_env = tcx. param_env ( gat_def_id ) ;
351
348
352
349
let mut clauses: Vec < _ > = clauses
353
350
. into_iter ( )
354
351
. filter ( |clause| match clause. kind ( ) . skip_binder ( ) {
355
352
ty:: PredicateKind :: RegionOutlives ( ty:: OutlivesPredicate ( a, b) ) => {
356
353
!region_known_to_outlive (
357
354
tcx,
358
- trait_item . hir_id ( ) ,
355
+ gat_hir . hir_id ( ) ,
359
356
param_env,
360
357
& FxHashSet :: default ( ) ,
361
358
a,
@@ -365,7 +362,7 @@ fn check_gat_where_clauses(
365
362
ty:: PredicateKind :: TypeOutlives ( ty:: OutlivesPredicate ( a, b) ) => {
366
363
!ty_known_to_outlive (
367
364
tcx,
368
- trait_item . hir_id ( ) ,
365
+ gat_hir . hir_id ( ) ,
369
366
param_env,
370
367
& FxHashSet :: default ( ) ,
371
368
a,
@@ -383,21 +380,17 @@ fn check_gat_where_clauses(
383
380
if !clauses. is_empty ( ) {
384
381
let plural = if clauses. len ( ) > 1 { "s" } else { "" } ;
385
382
let mut err = tcx. sess . struct_span_err (
386
- trait_item . span ,
387
- & format ! ( "missing required bound{} on `{}`" , plural, trait_item . ident) ,
383
+ gat_hir . span ,
384
+ & format ! ( "missing required bound{} on `{}`" , plural, gat_hir . ident) ,
388
385
) ;
389
386
390
387
let suggestion = format ! (
391
388
"{} {}" ,
392
- if !trait_item. generics. where_clause. predicates. is_empty( ) {
393
- ","
394
- } else {
395
- " where"
396
- } ,
389
+ if !gat_hir. generics. where_clause. predicates. is_empty( ) { "," } else { " where" } ,
397
390
clauses. join( ", " ) ,
398
391
) ;
399
392
err. span_suggestion (
400
- trait_item . generics . where_clause . tail_span_for_suggestion ( ) ,
393
+ gat_hir . generics . where_clause . tail_span_for_suggestion ( ) ,
401
394
& format ! ( "add the required where clause{}" , plural) ,
402
395
suggestion,
403
396
Applicability :: MachineApplicable ,
0 commit comments