@@ -275,30 +275,27 @@ pub fn check_trait_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
275275/// fn next<'a>(&'a mut self) -> Option<Self::Item<'a>>;
276276/// }
277277/// ```
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 ;
284281 // 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 ) {
286283 return ;
287284 }
288- let generics : & ty:: Generics = tcx. generics_of ( trait_item . def_id ) ;
285+ let gat_generics : & ty:: Generics = tcx. generics_of ( gat_def_id ) ;
289286 // If the current associated type doesn't have any (own) params, it's not a GAT
290287 // FIXME(jackh726): we can also warn in the more general case
291- if generics . params . len ( ) == 0 {
288+ if gat_generics . params . len ( ) == 0 {
292289 return ;
293290 }
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 ) ;
295292 let mut clauses: Option < FxHashSet < ty:: Predicate < ' _ > > > = None ;
296293 // For every function in this trait...
297294 // In our example, this would be the `next` method
298295 for item in
299296 associated_items. in_definition_order ( ) . filter ( |item| matches ! ( item. kind, ty:: AssocKind :: Fn ) )
300297 {
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 ( ) ) ;
302299 let param_env = tcx. param_env ( item. def_id . expect_local ( ) ) ;
303300
304301 // Get the signature using placeholders. In our example, this would
@@ -314,11 +311,11 @@ fn check_gat_where_clauses(
314311 let function_clauses = gather_gat_bounds (
315312 tcx,
316313 param_env,
317- id ,
314+ item_hir_id ,
318315 sig. output ( ) ,
319316 & wf_tys,
320- trait_item . def_id ,
321- generics ,
317+ gat_def_id ,
318+ gat_generics ,
322319 ) ;
323320
324321 if let Some ( function_clauses) = function_clauses {
@@ -347,15 +344,15 @@ fn check_gat_where_clauses(
347344 let clauses = clauses. unwrap_or_default ( ) ;
348345 debug ! ( ?clauses) ;
349346 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 ) ;
351348
352349 let mut clauses: Vec < _ > = clauses
353350 . into_iter ( )
354351 . filter ( |clause| match clause. kind ( ) . skip_binder ( ) {
355352 ty:: PredicateKind :: RegionOutlives ( ty:: OutlivesPredicate ( a, b) ) => {
356353 !region_known_to_outlive (
357354 tcx,
358- trait_item . hir_id ( ) ,
355+ gat_hir . hir_id ( ) ,
359356 param_env,
360357 & FxHashSet :: default ( ) ,
361358 a,
@@ -365,7 +362,7 @@ fn check_gat_where_clauses(
365362 ty:: PredicateKind :: TypeOutlives ( ty:: OutlivesPredicate ( a, b) ) => {
366363 !ty_known_to_outlive (
367364 tcx,
368- trait_item . hir_id ( ) ,
365+ gat_hir . hir_id ( ) ,
369366 param_env,
370367 & FxHashSet :: default ( ) ,
371368 a,
@@ -383,21 +380,17 @@ fn check_gat_where_clauses(
383380 if !clauses. is_empty ( ) {
384381 let plural = if clauses. len ( ) > 1 { "s" } else { "" } ;
385382 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) ,
388385 ) ;
389386
390387 let suggestion = format ! (
391388 "{} {}" ,
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" } ,
397390 clauses. join( ", " ) ,
398391 ) ;
399392 err. span_suggestion (
400- trait_item . generics . where_clause . tail_span_for_suggestion ( ) ,
393+ gat_hir . generics . where_clause . tail_span_for_suggestion ( ) ,
401394 & format ! ( "add the required where clause{}" , plural) ,
402395 suggestion,
403396 Applicability :: MachineApplicable ,
0 commit comments