@@ -575,7 +575,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
575
575
// generators don't take arguments.
576
576
}
577
577
578
- ty:: Closure ( _ , substs) => {
578
+ ty:: Closure ( did , substs) => {
579
579
// Only check the upvar types for WF, not the rest
580
580
// of the types within. This is needed because we
581
581
// capture the signature and it may not be WF
@@ -596,18 +596,26 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
596
596
// probably always be WF, because it should be
597
597
// shorthand for something like `where(T: 'a) {
598
598
// fn(&'a T) }`, as discussed in #25860.
599
- //
600
- // Note that we are also skipping the generic
601
- // types. This is consistent with the `outlives`
602
- // code, but anyway doesn't matter: within the fn
599
+ walker. skip_current_subtree ( ) ; // subtree handled below
600
+ // FIXME(eddyb) add the type to `walker` instead of recursing.
601
+ self . compute ( substs. as_closure ( ) . tupled_upvars_ty ( ) . into ( ) ) ;
602
+ // Note that we cannot skip the generic types
603
+ // types. Normally, within the fn
603
604
// body where they are created, the generics will
604
605
// always be WF, and outside of that fn body we
605
606
// are not directly inspecting closure types
606
607
// anyway, except via auto trait matching (which
607
608
// only inspects the upvar types).
608
- walker. skip_current_subtree ( ) ; // subtree handled below
609
- // FIXME(eddyb) add the type to `walker` instead of recursing.
610
- self . compute ( substs. as_closure ( ) . tupled_upvars_ty ( ) . into ( ) ) ;
609
+ // But when a closure is part of a type-alias-impl-trait
610
+ // then the function that created the defining site may
611
+ // have had more bounds available than the type alias
612
+ // specifies. This may cause us to have a closure in the
613
+ // hidden type that is not actually well formed and
614
+ // can cause compiler crashes when the user abuses unsafe
615
+ // code to procure such a closure.
616
+ // See src/test/ui/type-alias-impl-trait/wf_check_closures.rs
617
+ let obligations = self . nominal_obligations ( did, substs) ;
618
+ self . out . extend ( obligations) ;
611
619
}
612
620
613
621
ty:: FnPtr ( _) => {
0 commit comments