@@ -608,6 +608,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
608
608
* unified during the confirmation step.
609
609
*/
610
610
611
+ let tcx = self . tcx ( ) ;
612
+ let kind = if Some ( obligation. trait_ref . def_id ) == tcx. lang_items . fn_trait ( ) {
613
+ ty:: FnUnboxedClosureKind
614
+ } else if Some ( obligation. trait_ref . def_id ) == tcx. lang_items . fn_mut_trait ( ) {
615
+ ty:: FnMutUnboxedClosureKind
616
+ } else if Some ( obligation. trait_ref . def_id ) == tcx. lang_items . fn_once_trait ( ) {
617
+ ty:: FnOnceUnboxedClosureKind
618
+ } else {
619
+ return Ok ( ( ) ) ; // not a fn trait, ignore
620
+ } ;
621
+
611
622
let self_ty = self . infcx . shallow_resolve ( obligation. self_ty ( ) ) ;
612
623
let closure_def_id = match ty:: get ( self_ty) . sty {
613
624
ty:: ty_unboxed_closure( id, _) => id,
@@ -622,37 +633,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
622
633
self_ty. repr( self . tcx( ) ) ,
623
634
obligation. repr( self . tcx( ) ) ) ;
624
635
625
- let tcx = self . tcx ( ) ;
626
- let fn_traits = [
627
- ( ty:: FnUnboxedClosureKind , tcx. lang_items . fn_trait ( ) ) ,
628
- ( ty:: FnMutUnboxedClosureKind , tcx. lang_items . fn_mut_trait ( ) ) ,
629
- ( ty:: FnOnceUnboxedClosureKind , tcx. lang_items . fn_once_trait ( ) ) ,
630
- ] ;
631
- for tuple in fn_traits. iter ( ) {
632
- let kind = match tuple {
633
- & ( kind, Some ( ref fn_trait) )
634
- if * fn_trait == obligation. trait_ref . def_id =>
635
- {
636
- kind
637
- }
638
- _ => continue ,
639
- } ;
640
-
641
- // Check to see whether the argument and return types match.
642
- let closure_kind = match self . typer . unboxed_closures ( ) . borrow ( ) . find ( & closure_def_id) {
643
- Some ( closure) => closure. kind ,
644
- None => {
645
- self . tcx ( ) . sess . span_bug (
646
- obligation. cause . span ,
647
- format ! ( "No entry for unboxed closure: {}" ,
648
- closure_def_id. repr( self . tcx( ) ) ) . as_slice ( ) ) ;
649
- }
650
- } ;
651
-
652
- if closure_kind != kind {
653
- continue ;
636
+ let closure_kind = match self . typer . unboxed_closures ( ) . borrow ( ) . find ( & closure_def_id) {
637
+ Some ( closure) => closure. kind ,
638
+ None => {
639
+ self . tcx ( ) . sess . span_bug (
640
+ obligation. cause . span ,
641
+ format ! ( "No entry for unboxed closure: {}" ,
642
+ closure_def_id. repr( self . tcx( ) ) ) . as_slice ( ) ) ;
654
643
}
644
+ } ;
655
645
646
+ if closure_kind == kind {
656
647
candidates. vec . push ( UnboxedClosureCandidate ( closure_def_id) ) ;
657
648
}
658
649
0 commit comments