@@ -52,15 +52,15 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
5252
5353 self . moved_error_reported . insert ( root_place. clone ( ) ) ;
5454
55- let item_msg = match self . describe_place ( place) {
55+ let item_msg = match self . describe_place_with_options ( place, IncludingDowncast ( true ) ) {
5656 Some ( name) => format ! ( "`{}`" , name) ,
5757 None => "value" . to_owned ( ) ,
5858 } ;
5959 self . tcx
6060 . cannot_act_on_uninitialized_variable (
6161 span,
6262 desired_action. as_noun ( ) ,
63- & self . describe_place ( place) . unwrap_or ( "_" . to_owned ( ) ) ,
63+ & self . describe_place_with_options ( place, IncludingDowncast ( true ) ) . unwrap_or ( "_" . to_owned ( ) ) ,
6464 Origin :: Mir ,
6565 )
6666 . span_label ( span, format ! ( "use of possibly uninitialized {}" , item_msg) )
@@ -72,14 +72,14 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
7272 span,
7373 desired_action. as_noun ( ) ,
7474 msg,
75- & self . describe_place ( place) . unwrap_or ( "_" . to_owned ( ) ) ,
75+ self . describe_place_with_options ( & place, IncludingDowncast ( true ) ) ,
7676 Origin :: Mir ,
7777 ) ;
7878
7979 let mut is_loop_move = false ;
80- for moi in mois {
80+ for moi in & mois {
8181 let move_msg = "" ; //FIXME: add " (into closure)"
82- let move_span = self . mir . source_info ( self . move_data . moves [ * moi] . source ) . span ;
82+ let move_span = self . mir . source_info ( self . move_data . moves [ * * moi] . source ) . span ;
8383 if span == move_span {
8484 err. span_label (
8585 span,
@@ -116,16 +116,21 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
116116 } ;
117117
118118 if needs_note {
119- let note_msg = match self . describe_place ( place) {
120- Some ( name) => format ! ( "`{}`" , name) ,
121- None => "value" . to_owned ( ) ,
122- } ;
119+ let mpi = self . move_data . moves [ * mois[ 0 ] ] . path ;
120+ let place = & self . move_data . move_paths [ mpi] . place ;
121+
122+ if let Some ( ty) = self . retrieve_type_for_place ( place) {
123+ let note_msg = match self . describe_place_with_options ( place, IncludingDowncast ( true ) ) {
124+ Some ( name) => format ! ( "`{}`" , name) ,
125+ None => "value" . to_owned ( ) ,
126+ } ;
123127
124- err. note ( & format ! (
125- "move occurs because {} has type `{}`, \
126- which does not implement the `Copy` trait",
127- note_msg, ty
128- ) ) ;
128+ err. note ( & format ! (
129+ "move occurs because {} has type `{}`, \
130+ which does not implement the `Copy` trait",
131+ note_msg, ty
132+ ) ) ;
133+ }
129134 }
130135 }
131136
@@ -654,12 +659,22 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
654659 }
655660}
656661
662+ pub ( super ) struct IncludingDowncast ( bool ) ;
663+
657664impl < ' cx , ' gcx , ' tcx > MirBorrowckCtxt < ' cx , ' gcx , ' tcx > {
658665 // End-user visible description of `place` if one can be found. If the
659666 // place is a temporary for instance, None will be returned.
660667 pub ( super ) fn describe_place ( & self , place : & Place < ' tcx > ) -> Option < String > {
668+ self . describe_place_with_options ( place, IncludingDowncast ( false ) )
669+ }
670+
671+ // End-user visible description of `place` if one can be found. If the
672+ // place is a temporary for instance, None will be returned.
673+ // `IncludingDowncast` parameter makes the function return `Err` if `ProjectionElem` is
674+ // `Downcast` and `IncludingDowncast` is true
675+ pub ( super ) fn describe_place_with_options ( & self , place : & Place < ' tcx > , including_downcast : IncludingDowncast ) -> Option < String > {
661676 let mut buf = String :: new ( ) ;
662- match self . append_place_to_string ( place, & mut buf, false ) {
677+ match self . append_place_to_string ( place, & mut buf, false , & including_downcast ) {
663678 Ok ( ( ) ) => Some ( buf) ,
664679 Err ( ( ) ) => None ,
665680 }
@@ -671,6 +686,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
671686 place : & Place < ' tcx > ,
672687 buf : & mut String ,
673688 mut autoderef : bool ,
689+ including_downcast : & IncludingDowncast ,
674690 ) -> Result < ( ) , ( ) > {
675691 match * place {
676692 Place :: Local ( local) => {
@@ -692,15 +708,18 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
692708 }
693709 } else {
694710 if autoderef {
695- self . append_place_to_string ( & proj. base , buf, autoderef) ?;
711+ self . append_place_to_string ( & proj. base , buf, autoderef, & including_downcast ) ?;
696712 } else {
697713 buf. push_str ( & "*" ) ;
698- self . append_place_to_string ( & proj. base , buf, autoderef) ?;
714+ self . append_place_to_string ( & proj. base , buf, autoderef, & including_downcast ) ?;
699715 }
700716 }
701717 }
702718 ProjectionElem :: Downcast ( ..) => {
703- self . append_place_to_string ( & proj. base , buf, autoderef) ?;
719+ self . append_place_to_string ( & proj. base , buf, autoderef, & including_downcast) ?;
720+ if including_downcast. 0 {
721+ return Err ( ( ) ) ;
722+ }
704723 }
705724 ProjectionElem :: Field ( field, _ty) => {
706725 autoderef = true ;
@@ -711,14 +730,14 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
711730 buf. push_str ( & name) ;
712731 } else {
713732 let field_name = self . describe_field ( & proj. base , field) ;
714- self . append_place_to_string ( & proj. base , buf, autoderef) ?;
733+ self . append_place_to_string ( & proj. base , buf, autoderef, & including_downcast ) ?;
715734 buf. push_str ( & format ! ( ".{}" , field_name) ) ;
716735 }
717736 }
718737 ProjectionElem :: Index ( index) => {
719738 autoderef = true ;
720739
721- self . append_place_to_string ( & proj. base , buf, autoderef) ?;
740+ self . append_place_to_string ( & proj. base , buf, autoderef, & including_downcast ) ?;
722741 buf. push_str ( "[" ) ;
723742 if let Err ( _) = self . append_local_to_string ( index, buf) {
724743 buf. push_str ( ".." ) ;
@@ -730,7 +749,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
730749 // Since it isn't possible to borrow an element on a particular index and
731750 // then use another while the borrow is held, don't output indices details
732751 // to avoid confusing the end-user
733- self . append_place_to_string ( & proj. base , buf, autoderef) ?;
752+ self . append_place_to_string ( & proj. base , buf, autoderef, & including_downcast ) ?;
734753 buf. push_str ( & "[..]" ) ;
735754 }
736755 } ;
0 commit comments