@@ -39,6 +39,8 @@ use rustc::middle::free_region::RegionRelations;
3939use rustc:: ty:: { self , TyCtxt } ;
4040use rustc:: ty:: maps:: Providers ;
4141
42+ use syntax_pos:: DUMMY_SP ;
43+
4244use std:: fmt;
4345use std:: rc:: Rc ;
4446use std:: hash:: { Hash , Hasher } ;
@@ -539,7 +541,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
539541 MovedInCapture => ( "capture" , "captured" ) ,
540542 } ;
541543
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 {
543545 move_data:: Declared => {
544546 // If this is an uninitialized variable, just emit a simple warning
545547 // and return.
@@ -586,11 +588,24 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
586588 let msg = if !has_fork && partial { "partially " }
587589 else if has_fork && !has_common { "collaterally " }
588590 else { "" } ;
589- let err = struct_span_err ! (
591+ let mut err = struct_span_err ! (
590592 self . tcx. sess, use_span, E0382 ,
591593 "{} of {}moved value: `{}`" ,
592594 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+ }
594609 } ;
595610
596611 // Get type of value and span where it was previously
@@ -627,10 +642,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
627642 err
628643 } ;
629644
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+ }
634651
635652 // Note: we used to suggest adding a `ref binding` or calling
636653 // `clone` but those suggestions have been removed because
0 commit comments