@@ -39,6 +39,8 @@ use rustc::middle::free_region::RegionRelations;
39
39
use rustc:: ty:: { self , TyCtxt } ;
40
40
use rustc:: ty:: maps:: Providers ;
41
41
42
+ use syntax_pos:: DUMMY_SP ;
43
+
42
44
use std:: fmt;
43
45
use std:: rc:: Rc ;
44
46
use std:: hash:: { Hash , Hasher } ;
@@ -539,7 +541,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
539
541
MovedInCapture => ( "capture" , "captured" ) ,
540
542
} ;
541
543
542
- let ( _ol, _moved_lp_msg, mut err) = match the_move. kind {
544
+ let ( _ol, _moved_lp_msg, mut err, need_note ) = match the_move. kind {
543
545
move_data:: Declared => {
544
546
// If this is an uninitialized variable, just emit a simple warning
545
547
// and return.
@@ -586,11 +588,24 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
586
588
let msg = if !has_fork && partial { "partially " }
587
589
else if has_fork && !has_common { "collaterally " }
588
590
else { "" } ;
589
- let err = struct_span_err ! (
591
+ let mut err = struct_span_err ! (
590
592
self . tcx. sess, use_span, E0382 ,
591
593
"{} of {}moved value: `{}`" ,
592
594
verb, msg, nl) ;
593
- ( ol, moved_lp_msg, err) }
595
+ let need_note = match lp. ty . sty {
596
+ ty:: TypeVariants :: TyClosure ( id, _) => {
597
+ if let Ok ( ty:: ClosureKind :: FnOnce ) =
598
+ ty:: queries:: closure_kind:: try_get ( self . tcx , DUMMY_SP , id) {
599
+ err. help ( "closure was moved because it only implements `FnOnce`" ) ;
600
+ false
601
+ } else {
602
+ true
603
+ }
604
+ }
605
+ _ => true ,
606
+ } ;
607
+ ( ol, moved_lp_msg, err, need_note)
608
+ }
594
609
} ;
595
610
596
611
// Get type of value and span where it was previously
@@ -627,10 +642,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
627
642
err
628
643
} ;
629
644
630
- err. note ( & format ! ( "move occurs because `{}` has type `{}`, \
631
- which does not implement the `Copy` trait",
632
- self . loan_path_to_string( moved_lp) ,
633
- moved_lp. ty) ) ;
645
+ if need_note {
646
+ err. note ( & format ! ( "move occurs because `{}` has type `{}`, \
647
+ which does not implement the `Copy` trait",
648
+ self . loan_path_to_string( moved_lp) ,
649
+ moved_lp. ty) ) ;
650
+ }
634
651
635
652
// Note: we used to suggest adding a `ref binding` or calling
636
653
// `clone` but those suggestions have been removed because
0 commit comments