@@ -398,14 +398,12 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
398
398
{
399
399
alias_ty
400
400
} else {
401
- return Err ( self . tcx ( ) . dcx ( ) . emit_err (
402
- crate :: errors:: ReturnTypeNotationOnNonRpitit {
403
- span : binding. span ,
404
- ty : tcx. liberate_late_bound_regions ( assoc_item. def_id , output) ,
405
- fn_span : tcx. hir ( ) . span_if_local ( assoc_item. def_id ) ,
406
- note : ( ) ,
407
- } ,
408
- ) ) ;
401
+ return Err ( tcx. dcx ( ) . emit_err ( crate :: errors:: ReturnTypeNotationOnNonRpitit {
402
+ span : binding. span ,
403
+ ty : tcx. liberate_late_bound_regions ( assoc_item. def_id , output) ,
404
+ fn_span : tcx. hir ( ) . span_if_local ( assoc_item. def_id ) ,
405
+ note : ( ) ,
406
+ } ) ) ;
409
407
} ;
410
408
411
409
// Finally, move the fn return type's bound vars over to account for the early bound
@@ -417,7 +415,9 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
417
415
let bound_vars = tcx. late_bound_vars ( binding. hir_id ) ;
418
416
ty:: Binder :: bind_with_vars ( subst_output, bound_vars)
419
417
} else {
420
- // Append the generic arguments of the associated type to the `trait_ref`.
418
+ // Create the generic arguments for the associated type or constant by joining the
419
+ // parent arguments (the arguments of the trait) and the own arguments (the ones of
420
+ // the associated item itself) and construct an alias type using them.
421
421
candidate. map_bound ( |trait_ref| {
422
422
let ident = Ident :: new ( assoc_item. name , binding. item_name . span ) ;
423
423
let item_segment = hir:: PathSegment {
@@ -428,19 +428,22 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
428
428
infer_args : false ,
429
429
} ;
430
430
431
- let args_trait_ref_and_assoc_item = self . create_args_for_associated_item (
431
+ let alias_args = self . create_args_for_associated_item (
432
432
path_span,
433
433
assoc_item. def_id ,
434
434
& item_segment,
435
435
trait_ref. args ,
436
436
) ;
437
+ debug ! ( ?alias_args) ;
437
438
438
- debug ! ( ?args_trait_ref_and_assoc_item) ;
439
-
440
- ty:: AliasTy :: new ( tcx, assoc_item. def_id , args_trait_ref_and_assoc_item)
439
+ // Note that we're indeed also using `AliasTy` (alias *type*) for associated
440
+ // *constants* to represent *const projections*. Alias *term* would be a more
441
+ // appropriate name but alas.
442
+ ty:: AliasTy :: new ( tcx, assoc_item. def_id , alias_args)
441
443
} )
442
444
} ;
443
445
446
+ // FIXME(associated_const_equality): Can this actually ever fail with assoc consts?
444
447
if !speculative {
445
448
// Find any late-bound regions declared in `ty` that are not
446
449
// declared in the trait-ref or assoc_item. These are not well-formed.
@@ -449,20 +452,20 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
449
452
//
450
453
// for<'a> <T as Iterator>::Item = &'a str // <-- 'a is bad
451
454
// for<'a> <T as FnMut<(&'a u32,)>>::Output = &'a str // <-- 'a is ok
452
- if let ConvertedBindingKind :: Equality ( ty ) = binding. kind {
453
- let late_bound_in_trait_ref =
455
+ if let ConvertedBindingKind :: Equality ( term ) = binding. kind {
456
+ let late_bound_in_projection_ty =
454
457
tcx. collect_constrained_late_bound_regions ( & projection_ty) ;
455
- let late_bound_in_ty =
456
- tcx. collect_referenced_late_bound_regions ( & trait_ref. rebind ( ty . node ) ) ;
457
- debug ! ( ?late_bound_in_trait_ref ) ;
458
- debug ! ( ?late_bound_in_ty ) ;
458
+ let late_bound_in_term =
459
+ tcx. collect_referenced_late_bound_regions ( & trait_ref. rebind ( term . node ) ) ;
460
+ debug ! ( ?late_bound_in_projection_ty ) ;
461
+ debug ! ( ?late_bound_in_term ) ;
459
462
460
463
// FIXME: point at the type params that don't have appropriate lifetimes:
461
464
// struct S1<F: for<'a> Fn(&i32, &i32) -> &'a i32>(F);
462
465
// ---- ---- ^^^^^^^
463
466
self . validate_late_bound_regions (
464
- late_bound_in_trait_ref ,
465
- late_bound_in_ty ,
467
+ late_bound_in_projection_ty ,
468
+ late_bound_in_term ,
466
469
|br_name| {
467
470
struct_span_code_err ! (
468
471
tcx. dcx( ) ,
@@ -480,9 +483,9 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
480
483
481
484
match binding. kind {
482
485
ConvertedBindingKind :: Equality ( ..) if let ty:: AssocKind :: Fn = assoc_kind => {
483
- return Err ( self . tcx ( ) . dcx ( ) . emit_err (
484
- crate :: errors :: ReturnTypeNotationEqualityBound { span : binding. span } ,
485
- ) ) ;
486
+ return Err ( tcx. dcx ( ) . emit_err ( crate :: errors :: ReturnTypeNotationEqualityBound {
487
+ span : binding. span ,
488
+ } ) ) ;
486
489
}
487
490
ConvertedBindingKind :: Equality ( term) => {
488
491
// "Desugar" a constraint like `T: Iterator<Item = u32>` this to
0 commit comments