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