@@ -404,7 +404,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
404404 let bound_vars = tcx. late_bound_vars ( binding. hir_id ) ;
405405 ty:: Binder :: bind_with_vars ( subst_output, bound_vars)
406406 } else {
407- // Append the generic arguments of the associated type to the `trait_ref`.
407+ // Append the generic arguments of the associated type or const to the `trait_ref`.
408408 candidate. map_bound ( |trait_ref| {
409409 let ident = Ident :: new ( assoc_item. name , binding. item_name . span ) ;
410410 let item_segment = hir:: PathSegment {
@@ -415,19 +415,24 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
415415 infer_args : false ,
416416 } ;
417417
418- let args_trait_ref_and_assoc_item = self . create_args_for_associated_item (
418+ let alias_args = self . create_args_for_associated_item (
419419 path_span,
420420 assoc_item. def_id ,
421421 & item_segment,
422422 trait_ref. args ,
423423 ) ;
424+ debug ! ( ?alias_args) ;
424425
425- debug ! ( ?args_trait_ref_and_assoc_item) ;
426-
427- ty:: AliasTy :: new ( tcx, assoc_item. def_id , args_trait_ref_and_assoc_item)
426+ // Note that we're indeed also using `AliasTy` (alias *type*) for associated
427+ // *constants* to represent *const projections*. Alias *term* would be a more
428+ // appropriate name but alas.
429+ ty:: AliasTy :: new ( tcx, assoc_item. def_id , alias_args)
428430 } )
429431 } ;
430432
433+ // FIXME(fmease): This doesn't check actually seem to work for assoc consts.
434+ // We want to deny escaping late-bound vars in general anyways for assoc consts.
435+ // If the diagnostic *is* reachable, update it (“type” → “term” or similar).
431436 if !speculative {
432437 // Find any late-bound regions declared in `ty` that are not
433438 // declared in the trait-ref or assoc_item. These are not well-formed.
@@ -436,20 +441,20 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
436441 //
437442 // for<'a> <T as Iterator>::Item = &'a str // <-- 'a is bad
438443 // for<'a> <T as FnMut<(&'a u32,)>>::Output = &'a str // <-- 'a is ok
439- if let ConvertedBindingKind :: Equality ( ty ) = binding. kind {
440- let late_bound_in_trait_ref =
444+ if let ConvertedBindingKind :: Equality ( term ) = binding. kind {
445+ let late_bound_in_projection_ty =
441446 tcx. collect_constrained_late_bound_regions ( & projection_ty) ;
442- let late_bound_in_ty =
443- tcx. collect_referenced_late_bound_regions ( & trait_ref. rebind ( ty . node ) ) ;
444- debug ! ( ?late_bound_in_trait_ref ) ;
445- debug ! ( ?late_bound_in_ty ) ;
447+ let late_bound_in_term =
448+ tcx. collect_referenced_late_bound_regions ( & trait_ref. rebind ( term . node ) ) ;
449+ debug ! ( ?late_bound_in_projection_ty ) ;
450+ debug ! ( ?late_bound_in_term ) ;
446451
447452 // FIXME: point at the type params that don't have appropriate lifetimes:
448453 // struct S1<F: for<'a> Fn(&i32, &i32) -> &'a i32>(F);
449454 // ---- ---- ^^^^^^^
450455 self . validate_late_bound_regions (
451- late_bound_in_trait_ref ,
452- late_bound_in_ty ,
456+ late_bound_in_projection_ty ,
457+ late_bound_in_term ,
453458 |br_name| {
454459 struct_span_err ! (
455460 tcx. dcx( ) ,
0 commit comments