@@ -407,7 +407,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
407407 let bound_vars = tcx. late_bound_vars ( binding. hir_id ) ;
408408 ty:: Binder :: bind_with_vars ( subst_output, bound_vars)
409409 } else {
410- // Append the generic arguments of the associated type to the `trait_ref`.
410+ // Append the generic arguments of the associated type or const to the `trait_ref`.
411411 candidate. map_bound ( |trait_ref| {
412412 let ident = Ident :: new ( assoc_item. name , binding. item_name . span ) ;
413413 let item_segment = hir:: PathSegment {
@@ -418,19 +418,24 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
418418 infer_args : false ,
419419 } ;
420420
421- let args_trait_ref_and_assoc_item = self . create_args_for_associated_item (
421+ let alias_args = self . create_args_for_associated_item (
422422 path_span,
423423 assoc_item. def_id ,
424424 & item_segment,
425425 trait_ref. args ,
426426 ) ;
427+ debug ! ( ?alias_args) ;
427428
428- debug ! ( ?args_trait_ref_and_assoc_item) ;
429-
430- ty:: AliasTy :: new ( tcx, assoc_item. def_id , args_trait_ref_and_assoc_item)
429+ // Note that we're indeed also using `AliasTy` (alias *type*) for associated
430+ // *constants* to represent *const projections*. Alias *term* would be a more
431+ // appropriate name but alas.
432+ ty:: AliasTy :: new ( tcx, assoc_item. def_id , alias_args)
431433 } )
432434 } ;
433435
436+ // FIXME(fmease): This doesn't check actually seem to work for assoc consts.
437+ // We want to deny escaping late-bound vars in general anyways for assoc consts.
438+ // If the diagnostic *is* reachable, update it (“type” → “term” or similar).
434439 if !speculative {
435440 // Find any late-bound regions declared in `ty` that are not
436441 // declared in the trait-ref or assoc_item. These are not well-formed.
@@ -439,20 +444,20 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
439444 //
440445 // for<'a> <T as Iterator>::Item = &'a str // <-- 'a is bad
441446 // for<'a> <T as FnMut<(&'a u32,)>>::Output = &'a str // <-- 'a is ok
442- if let ConvertedBindingKind :: Equality ( ty ) = binding. kind {
443- let late_bound_in_trait_ref =
447+ if let ConvertedBindingKind :: Equality ( term ) = binding. kind {
448+ let late_bound_in_projection_ty =
444449 tcx. collect_constrained_late_bound_regions ( & projection_ty) ;
445- let late_bound_in_ty =
446- tcx. collect_referenced_late_bound_regions ( & trait_ref. rebind ( ty . node ) ) ;
447- debug ! ( ?late_bound_in_trait_ref ) ;
448- debug ! ( ?late_bound_in_ty ) ;
450+ let late_bound_in_term =
451+ tcx. collect_referenced_late_bound_regions ( & trait_ref. rebind ( term . node ) ) ;
452+ debug ! ( ?late_bound_in_projection_ty ) ;
453+ debug ! ( ?late_bound_in_term ) ;
449454
450455 // FIXME: point at the type params that don't have appropriate lifetimes:
451456 // struct S1<F: for<'a> Fn(&i32, &i32) -> &'a i32>(F);
452457 // ---- ---- ^^^^^^^
453458 self . validate_late_bound_regions (
454- late_bound_in_trait_ref ,
455- late_bound_in_ty ,
459+ late_bound_in_projection_ty ,
460+ late_bound_in_term ,
456461 |br_name| {
457462 struct_span_err ! (
458463 tcx. dcx( ) ,
0 commit comments