@@ -560,7 +560,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
560
560
reasons
561
561
}
562
562
563
- fn ty_contains_trait (
563
+ /// Returns true if `ty` may implement `trait_def_id`
564
+ fn ty_impls_trait (
564
565
& self ,
565
566
ty : Ty < ' tcx > ,
566
567
cause : & ObligationCause < ' tcx > ,
@@ -615,32 +616,32 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
615
616
let clone_obligation_should_hold = tcx
616
617
. lang_items ( )
617
618
. clone_trait ( )
618
- . map ( |clone_trait| self . ty_contains_trait ( ty, & cause, clone_trait) )
619
+ . map ( |clone_trait| self . ty_impls_trait ( ty, & cause, clone_trait) )
619
620
. unwrap_or ( false ) ;
620
621
let sync_obligation_should_hold = tcx
621
622
. lang_items ( )
622
623
. sync_trait ( )
623
- . map ( |sync_trait| self . ty_contains_trait ( ty, & cause, sync_trait) )
624
+ . map ( |sync_trait| self . ty_impls_trait ( ty, & cause, sync_trait) )
624
625
. unwrap_or ( false ) ;
625
626
let send_obligation_should_hold = tcx
626
627
. lang_items ( )
627
628
. send_trait ( )
628
- . map ( |send_trait| self . ty_contains_trait ( ty, & cause, send_trait) )
629
+ . map ( |send_trait| self . ty_impls_trait ( ty, & cause, send_trait) )
629
630
. unwrap_or ( false ) ;
630
631
let unpin_obligation_should_hold = tcx
631
632
. lang_items ( )
632
633
. unpin_trait ( )
633
- . map ( |unpin_trait| self . ty_contains_trait ( ty, & cause, unpin_trait) )
634
+ . map ( |unpin_trait| self . ty_impls_trait ( ty, & cause, unpin_trait) )
634
635
. unwrap_or ( false ) ;
635
636
let unwind_safe_obligation_should_hold = tcx
636
637
. lang_items ( )
637
638
. unwind_safe_trait ( )
638
- . map ( |unwind_safe_trait| self . ty_contains_trait ( ty, & cause, unwind_safe_trait) )
639
+ . map ( |unwind_safe_trait| self . ty_impls_trait ( ty, & cause, unwind_safe_trait) )
639
640
. unwrap_or ( false ) ;
640
641
let ref_unwind_safe_obligation_should_hold = tcx
641
642
. lang_items ( )
642
643
. ref_unwind_safe_trait ( )
643
- . map ( |ref_unwind_safe_trait| self . ty_contains_trait ( ty, & cause, ref_unwind_safe_trait) )
644
+ . map ( |ref_unwind_safe_trait| self . ty_impls_trait ( ty, & cause, ref_unwind_safe_trait) )
644
645
. unwrap_or ( false ) ;
645
646
646
647
// Check whether catpured fields also implement the trait
@@ -652,34 +653,32 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
652
653
let clone_obligation_holds_for_capture = tcx
653
654
. lang_items ( )
654
655
. clone_trait ( )
655
- . map ( |clone_trait| self . ty_contains_trait ( ty, & cause, clone_trait) )
656
+ . map ( |clone_trait| self . ty_impls_trait ( ty, & cause, clone_trait) )
656
657
. unwrap_or ( false ) ;
657
658
let sync_obligation_holds_for_capture = tcx
658
659
. lang_items ( )
659
660
. sync_trait ( )
660
- . map ( |sync_trait| self . ty_contains_trait ( ty, & cause, sync_trait) )
661
+ . map ( |sync_trait| self . ty_impls_trait ( ty, & cause, sync_trait) )
661
662
. unwrap_or ( false ) ;
662
663
let send_obligation_holds_for_capture = tcx
663
664
. lang_items ( )
664
665
. send_trait ( )
665
- . map ( |send_trait| self . ty_contains_trait ( ty, & cause, send_trait) )
666
+ . map ( |send_trait| self . ty_impls_trait ( ty, & cause, send_trait) )
666
667
. unwrap_or ( false ) ;
667
668
let unpin_obligation_holds_for_capture = tcx
668
669
. lang_items ( )
669
670
. unpin_trait ( )
670
- . map ( |unpin_trait| self . ty_contains_trait ( ty, & cause, unpin_trait) )
671
+ . map ( |unpin_trait| self . ty_impls_trait ( ty, & cause, unpin_trait) )
671
672
. unwrap_or ( false ) ;
672
673
let unwind_safe_obligation_holds_for_capture = tcx
673
674
. lang_items ( )
674
675
. unwind_safe_trait ( )
675
- . map ( |unwind_safe| self . ty_contains_trait ( ty, & cause, unwind_safe) )
676
+ . map ( |unwind_safe| self . ty_impls_trait ( ty, & cause, unwind_safe) )
676
677
. unwrap_or ( false ) ;
677
678
let ref_unwind_safe_obligation_holds_for_capture = tcx
678
679
. lang_items ( )
679
680
. ref_unwind_safe_trait ( )
680
- . map ( |ref_unwind_safe_trait| {
681
- self . ty_contains_trait ( ty, & cause, ref_unwind_safe_trait)
682
- } )
681
+ . map ( |ref_unwind_safe_trait| self . ty_impls_trait ( ty, & cause, ref_unwind_safe_trait) )
683
682
. unwrap_or ( false ) ;
684
683
685
684
if !clone_obligation_holds_for_capture && clone_obligation_should_hold {
@@ -732,11 +731,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
732
731
min_captures : Option < & ty:: RootVariableMinCaptureList < ' tcx > > ,
733
732
closure_clause : hir:: CaptureBy ,
734
733
var_hir_id : hir:: HirId ,
735
- ) -> Option < ( ) > {
734
+ ) -> bool {
736
735
let ty = self . infcx . resolve_vars_if_possible ( self . node_ty ( var_hir_id) ) ;
737
736
738
737
if !ty. needs_drop ( self . tcx , self . tcx . param_env ( closure_def_id. expect_local ( ) ) ) {
739
- return None ;
738
+ return false ;
740
739
}
741
740
742
741
let root_var_min_capture_list = if let Some ( root_var_min_capture_list) =
@@ -749,11 +748,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
749
748
750
749
match closure_clause {
751
750
// Only migrate if closure is a move closure
752
- hir:: CaptureBy :: Value => return Some ( ( ) ) ,
751
+ hir:: CaptureBy :: Value => return true ,
753
752
hir:: CaptureBy :: Ref => { }
754
753
}
755
754
756
- return None ;
755
+ return false ;
757
756
} ;
758
757
759
758
let projections_list = root_var_min_capture_list
@@ -779,10 +778,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
779
778
projections_list,
780
779
)
781
780
{
782
- return Some ( ( ) ) ;
781
+ return true ;
783
782
}
784
783
785
- return None ;
784
+ return false ;
786
785
}
787
786
788
787
/// Figures out the list of root variables (and their types) that aren't completely
@@ -816,27 +815,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
816
815
817
816
// Perform auto-trait analysis
818
817
for ( & var_hir_id, _) in upvars. iter ( ) {
819
- // println!("CHeck auto traits");
820
- let mut need_some_migrations = false ;
818
+ let mut need_migration = false ;
821
819
if let Some ( trait_migration_cause) =
822
820
self . compute_2229_migrations_for_trait ( min_captures, closure_clause, var_hir_id)
823
821
{
824
- need_some_migrations = true ;
822
+ need_migration = true ;
825
823
auto_trait_reasons. extend ( trait_migration_cause) ;
826
824
}
827
825
828
- if let Some ( _ ) = self . compute_2229_migrations_for_drop (
826
+ if self . compute_2229_migrations_for_drop (
829
827
closure_def_id,
830
828
closure_span,
831
829
min_captures,
832
830
closure_clause,
833
831
var_hir_id,
834
832
) {
835
- need_some_migrations = true ;
833
+ need_migration = true ;
836
834
drop_reorder_reason = true ;
837
835
}
838
836
839
- if need_some_migrations {
837
+ if need_migration {
840
838
need_migrations. push ( var_hir_id) ;
841
839
}
842
840
}
0 commit comments