@@ -81,7 +81,34 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
81
81
err. span_label ( move_span, format ! ( "value moved{} here" , move_msg) ) ;
82
82
} ;
83
83
}
84
- //FIXME: add note for closure
84
+
85
+ if let Some ( ty) = self . retrieve_type_for_place ( place) {
86
+ let needs_note = match ty. sty {
87
+ ty:: TypeVariants :: TyClosure ( id, _) => {
88
+ let tables = self . tcx . typeck_tables_of ( id) ;
89
+ let node_id = self . tcx . hir . as_local_node_id ( id) . unwrap ( ) ;
90
+ let hir_id = self . tcx . hir . node_to_hir_id ( node_id) ;
91
+ if let Some ( _) = tables. closure_kind_origins ( ) . get ( hir_id) {
92
+ false
93
+ } else {
94
+ true
95
+ }
96
+ } ,
97
+ _ => true ,
98
+ } ;
99
+
100
+ if needs_note {
101
+ let note_msg = match self . describe_place ( place) {
102
+ Some ( name) => format ! ( "`{}`" , name) ,
103
+ None => "value" . to_owned ( ) ,
104
+ } ;
105
+
106
+ err. note ( & format ! ( "move occurs because {} has type `{}`, \
107
+ which does not implement the `Copy` trait",
108
+ note_msg, ty) ) ;
109
+ }
110
+ }
111
+
85
112
err. emit ( ) ;
86
113
}
87
114
}
@@ -655,4 +682,21 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
655
682
fn retrieve_borrow_span ( & self , borrow : & BorrowData ) -> Span {
656
683
self . mir . source_info ( borrow. location ) . span
657
684
}
685
+
686
+ // Retrieve type of a place for the current MIR representation
687
+ fn retrieve_type_for_place ( & self , place : & Place < ' tcx > ) -> Option < ty:: Ty > {
688
+ match place {
689
+ Place :: Local ( local) => {
690
+ let local = & self . mir . local_decls [ * local] ;
691
+ Some ( local. ty )
692
+ } ,
693
+ Place :: Static ( ref st) => Some ( st. ty ) ,
694
+ Place :: Projection ( ref proj) => {
695
+ match proj. elem {
696
+ ProjectionElem :: Field ( _, ty) => Some ( ty) ,
697
+ _ => None ,
698
+ }
699
+ } ,
700
+ }
701
+ }
658
702
}
0 commit comments