@@ -390,14 +390,12 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
390
390
{
391
391
alias_ty
392
392
} 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
+ } ) ) ;
401
399
} ;
402
400
403
401
// 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> + '_ {
410
408
let bound_vars = tcx. late_bound_vars ( binding. hir_id ) ;
411
409
ty:: Binder :: bind_with_vars ( instantiation_output, bound_vars)
412
410
} 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.
414
414
candidate. map_bound ( |trait_ref| {
415
415
let ident = Ident :: new ( assoc_item. name , binding. item_name . span ) ;
416
416
let item_segment = hir:: PathSegment {
@@ -421,16 +421,18 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
421
421
infer_args : false ,
422
422
} ;
423
423
424
- let args_trait_ref_and_assoc_item = self . create_args_for_associated_item (
424
+ let alias_args = self . create_args_for_associated_item (
425
425
path_span,
426
426
assoc_item. def_id ,
427
427
& item_segment,
428
428
trait_ref. args ,
429
429
) ;
430
+ debug ! ( ?alias_args) ;
430
431
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)
434
436
} )
435
437
} ;
436
438
@@ -442,20 +444,22 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
442
444
//
443
445
// for<'a> <T as Iterator>::Item = &'a str // <-- 'a is bad
444
446
// 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 =
447
449
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 ) ;
452
454
455
+ // NOTE(associated_const_equality): This error should be impossible to trigger
456
+ // with associated const equality bounds.
453
457
// FIXME: point at the type params that don't have appropriate lifetimes:
454
458
// struct S1<F: for<'a> Fn(&i32, &i32) -> &'a i32>(F);
455
459
// ---- ---- ^^^^^^^
456
460
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 ,
459
463
|br_name| {
460
464
struct_span_code_err ! (
461
465
tcx. dcx( ) ,
@@ -473,9 +477,9 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
473
477
474
478
match binding. kind {
475
479
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
+ } ) ) ;
479
483
}
480
484
ConvertedBindingKind :: Equality ( term) => {
481
485
// "Desugar" a constraint like `T: Iterator<Item = u32>` this to
0 commit comments