@@ -390,14 +390,12 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
390390 {
391391 alias_ty
392392 } else {
393- return Err ( self . tcx ( ) . dcx ( ) . emit_err (
394- crate :: errors:: ReturnTypeNotationOnNonRpitit {
395- span : binding. span ,
396- ty : tcx. liberate_late_bound_regions ( assoc_item. def_id , output) ,
397- fn_span : tcx. hir ( ) . span_if_local ( assoc_item. def_id ) ,
398- note : ( ) ,
399- } ,
400- ) ) ;
393+ return Err ( tcx. dcx ( ) . emit_err ( crate :: errors:: ReturnTypeNotationOnNonRpitit {
394+ span : binding. span ,
395+ ty : tcx. liberate_late_bound_regions ( assoc_item. def_id , output) ,
396+ fn_span : tcx. hir ( ) . span_if_local ( assoc_item. def_id ) ,
397+ note : ( ) ,
398+ } ) ) ;
401399 } ;
402400
403401 // Finally, move the fn return type's bound vars over to account for the early bound
@@ -410,7 +408,9 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
410408 let bound_vars = tcx. late_bound_vars ( binding. hir_id ) ;
411409 ty:: Binder :: bind_with_vars ( instantiation_output, bound_vars)
412410 } else {
413- // Append the generic arguments of the associated type to the `trait_ref`.
411+ // Create the generic arguments for the associated type or constant by joining the
412+ // parent arguments (the arguments of the trait) and the own arguments (the ones of
413+ // the associated item itself) and construct an alias type using them.
414414 candidate. map_bound ( |trait_ref| {
415415 let ident = Ident :: new ( assoc_item. name , binding. item_name . span ) ;
416416 let item_segment = hir:: PathSegment {
@@ -421,16 +421,18 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
421421 infer_args : false ,
422422 } ;
423423
424- let args_trait_ref_and_assoc_item = self . create_args_for_associated_item (
424+ let alias_args = self . create_args_for_associated_item (
425425 path_span,
426426 assoc_item. def_id ,
427427 & item_segment,
428428 trait_ref. args ,
429429 ) ;
430+ debug ! ( ?alias_args) ;
430431
431- debug ! ( ?args_trait_ref_and_assoc_item) ;
432-
433- ty:: AliasTy :: new ( tcx, assoc_item. def_id , args_trait_ref_and_assoc_item)
432+ // Note that we're indeed also using `AliasTy` (alias *type*) for associated
433+ // *constants* to represent *const projections*. Alias *term* would be a more
434+ // appropriate name but alas.
435+ ty:: AliasTy :: new ( tcx, assoc_item. def_id , alias_args)
434436 } )
435437 } ;
436438
@@ -442,20 +444,22 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
442444 //
443445 // for<'a> <T as Iterator>::Item = &'a str // <-- 'a is bad
444446 // for<'a> <T as FnMut<(&'a u32,)>>::Output = &'a str // <-- 'a is ok
445- if let ConvertedBindingKind :: Equality ( ty ) = binding. kind {
446- let late_bound_in_trait_ref =
447+ if let ConvertedBindingKind :: Equality ( term ) = binding. kind {
448+ let late_bound_in_projection_ty =
447449 tcx. collect_constrained_late_bound_regions ( & projection_ty) ;
448- let late_bound_in_ty =
449- tcx. collect_referenced_late_bound_regions ( & trait_ref. rebind ( ty . node ) ) ;
450- debug ! ( ?late_bound_in_trait_ref ) ;
451- 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 ) ;
452454
455+ // NOTE(associated_const_equality): This error should be impossible to trigger
456+ // with associated const equality bounds.
453457 // FIXME: point at the type params that don't have appropriate lifetimes:
454458 // struct S1<F: for<'a> Fn(&i32, &i32) -> &'a i32>(F);
455459 // ---- ---- ^^^^^^^
456460 self . validate_late_bound_regions (
457- late_bound_in_trait_ref ,
458- late_bound_in_ty ,
461+ late_bound_in_projection_ty ,
462+ late_bound_in_term ,
459463 |br_name| {
460464 struct_span_code_err ! (
461465 tcx. dcx( ) ,
@@ -473,9 +477,9 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
473477
474478 match binding. kind {
475479 ConvertedBindingKind :: Equality ( ..) if let ty:: AssocKind :: Fn = assoc_kind => {
476- return Err ( self . tcx ( ) . dcx ( ) . emit_err (
477- crate :: errors :: ReturnTypeNotationEqualityBound { span : binding. span } ,
478- ) ) ;
480+ return Err ( tcx. dcx ( ) . emit_err ( crate :: errors :: ReturnTypeNotationEqualityBound {
481+ span : binding. span ,
482+ } ) ) ;
479483 }
480484 ConvertedBindingKind :: Equality ( term) => {
481485 // "Desugar" a constraint like `T: Iterator<Item = u32>` this to
0 commit comments