@@ -549,57 +549,65 @@ fn check_existential_types<'a, 'fcx, 'gcx, 'tcx>(
549
549
fldop : |ty| {
550
550
if let ty:: TyAnon ( def_id, substs) = ty. sty {
551
551
trace ! ( "check_existential_types: anon_ty, {:?}, {:?}" , def_id, substs) ;
552
- let anon_node_id = tcx. hir . as_local_node_id ( def_id) . unwrap ( ) ;
553
- if may_define_existential_type ( tcx, fn_def_id, anon_node_id) {
554
- let generics = tcx. generics_of ( def_id) ;
555
- trace ! ( "check_existential_types may define. Generics: {:#?}" , generics) ;
556
- for ( subst, param) in substs. iter ( ) . zip ( & generics. params ) {
557
- if let ty:: subst:: UnpackedKind :: Type ( ty) = subst. unpack ( ) {
558
- match ty. sty {
559
- ty:: TyParam ( ..) => { } ,
560
- // prevent `fn foo() -> Foo<u32>` from being defining
561
- _ => {
562
- tcx
563
- . sess
564
- . struct_span_err (
565
- span,
566
- "non-defining existential type use in defining scope" ,
567
- )
568
- . span_note (
569
- tcx. def_span ( param. def_id ) ,
570
- & format ! (
571
- "used non-generic type {} for generic parameter" ,
572
- ty,
573
- ) ,
574
- )
575
- . emit ( ) ;
576
- return tcx. types . err ;
577
- } ,
578
- } // match ty
579
- } // if let Type = subst
580
- } // for (subst, param)
581
- } // if may_define_existential_type
582
-
583
- // now register the bounds on the parameters of the existential type
584
- // so the parameters given by the function need to fulfil them
585
- // ```rust
586
- // existential type Foo<T: Bar>: 'static;
587
- // fn foo<U>() -> Foo<U> { .. *}
588
- // ```
589
- // becomes
590
- // ```rust
591
- // existential type Foo<T: Bar>: 'static;
592
- // fn foo<U: Bar>() -> Foo<U> { .. *}
593
- // ```
594
- let predicates = tcx. predicates_of ( def_id) ;
595
- trace ! ( "check_existential_types may define. adding predicates: {:#?}" , predicates) ;
596
- for & pred in predicates. predicates . iter ( ) {
597
- let substituted_pred = pred. subst ( fcx. tcx , substs) ;
598
- // Avoid duplication of predicates that contain no parameters, for example.
599
- if !predicates. predicates . contains ( & substituted_pred) {
600
- substituted_predicates. push ( substituted_pred) ;
552
+ let generics = tcx. generics_of ( def_id) ;
553
+ // only check named existential types
554
+ if generics. parent . is_none ( ) {
555
+ let anon_node_id = tcx. hir . as_local_node_id ( def_id) . unwrap ( ) ;
556
+ if may_define_existential_type ( tcx, fn_def_id, anon_node_id) {
557
+ trace ! ( "check_existential_types may define. Generics: {:#?}" , generics) ;
558
+ for ( subst, param) in substs. iter ( ) . zip ( & generics. params ) {
559
+ if let ty:: subst:: UnpackedKind :: Type ( ty) = subst. unpack ( ) {
560
+ match ty. sty {
561
+ ty:: TyParam ( ..) => { } ,
562
+ // prevent `fn foo() -> Foo<u32>` from being defining
563
+ _ => {
564
+ tcx
565
+ . sess
566
+ . struct_span_err (
567
+ span,
568
+ "non-defining existential type use \
569
+ in defining scope",
570
+ )
571
+ . span_note (
572
+ tcx. def_span ( param. def_id ) ,
573
+ & format ! (
574
+ "used non-generic type {} for \
575
+ generic parameter",
576
+ ty,
577
+ ) ,
578
+ )
579
+ . emit ( ) ;
580
+ return tcx. types . err ;
581
+ } ,
582
+ } // match ty
583
+ } // if let Type = subst
584
+ } // for (subst, param)
585
+ } // if may_define_existential_type
586
+
587
+ // now register the bounds on the parameters of the existential type
588
+ // so the parameters given by the function need to fulfil them
589
+ // ```rust
590
+ // existential type Foo<T: Bar>: 'static;
591
+ // fn foo<U>() -> Foo<U> { .. *}
592
+ // ```
593
+ // becomes
594
+ // ```rust
595
+ // existential type Foo<T: Bar>: 'static;
596
+ // fn foo<U: Bar>() -> Foo<U> { .. *}
597
+ // ```
598
+ let predicates = tcx. predicates_of ( def_id) ;
599
+ trace ! (
600
+ "check_existential_types may define. adding predicates: {:#?}" ,
601
+ predicates,
602
+ ) ;
603
+ for & pred in predicates. predicates . iter ( ) {
604
+ let substituted_pred = pred. subst ( fcx. tcx , substs) ;
605
+ // Avoid duplication of predicates that contain no parameters, for example.
606
+ if !predicates. predicates . contains ( & substituted_pred) {
607
+ substituted_predicates. push ( substituted_pred) ;
608
+ }
601
609
}
602
- }
610
+ } // if is_named_existential_type
603
611
} // if let TyAnon
604
612
ty
605
613
} ,
0 commit comments