@@ -52,15 +52,15 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
52
52
53
53
self . moved_error_reported . insert ( root_place. clone ( ) ) ;
54
54
55
- let item_msg = match self . describe_place ( place) {
55
+ let item_msg = match self . describe_place_with_options ( place, IncludingDowncast ( true ) ) {
56
56
Some ( name) => format ! ( "`{}`" , name) ,
57
57
None => "value" . to_owned ( ) ,
58
58
} ;
59
59
self . tcx
60
60
. cannot_act_on_uninitialized_variable (
61
61
span,
62
62
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 ( ) ) ,
64
64
Origin :: Mir ,
65
65
)
66
66
. span_label ( span, format ! ( "use of possibly uninitialized {}" , item_msg) )
@@ -72,14 +72,14 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
72
72
span,
73
73
desired_action. as_noun ( ) ,
74
74
msg,
75
- & self . describe_place ( place) . unwrap_or ( "_" . to_owned ( ) ) ,
75
+ self . describe_place_with_options ( & place, IncludingDowncast ( true ) ) ,
76
76
Origin :: Mir ,
77
77
) ;
78
78
79
79
let mut is_loop_move = false ;
80
- for moi in mois {
80
+ for moi in & mois {
81
81
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 ;
83
83
if span == move_span {
84
84
err. span_label (
85
85
span,
@@ -116,16 +116,21 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
116
116
} ;
117
117
118
118
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
+ } ;
123
127
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
+ }
129
134
}
130
135
}
131
136
@@ -654,12 +659,22 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
654
659
}
655
660
}
656
661
662
+ pub ( super ) struct IncludingDowncast ( bool ) ;
663
+
657
664
impl < ' cx , ' gcx , ' tcx > MirBorrowckCtxt < ' cx , ' gcx , ' tcx > {
658
665
// End-user visible description of `place` if one can be found. If the
659
666
// place is a temporary for instance, None will be returned.
660
667
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 > {
661
676
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 ) {
663
678
Ok ( ( ) ) => Some ( buf) ,
664
679
Err ( ( ) ) => None ,
665
680
}
@@ -671,6 +686,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
671
686
place : & Place < ' tcx > ,
672
687
buf : & mut String ,
673
688
mut autoderef : bool ,
689
+ including_downcast : & IncludingDowncast ,
674
690
) -> Result < ( ) , ( ) > {
675
691
match * place {
676
692
Place :: Local ( local) => {
@@ -692,15 +708,18 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
692
708
}
693
709
} else {
694
710
if autoderef {
695
- self . append_place_to_string ( & proj. base , buf, autoderef) ?;
711
+ self . append_place_to_string ( & proj. base , buf, autoderef, & including_downcast ) ?;
696
712
} else {
697
713
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 ) ?;
699
715
}
700
716
}
701
717
}
702
718
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
+ }
704
723
}
705
724
ProjectionElem :: Field ( field, _ty) => {
706
725
autoderef = true ;
@@ -711,14 +730,14 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
711
730
buf. push_str ( & name) ;
712
731
} else {
713
732
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 ) ?;
715
734
buf. push_str ( & format ! ( ".{}" , field_name) ) ;
716
735
}
717
736
}
718
737
ProjectionElem :: Index ( index) => {
719
738
autoderef = true ;
720
739
721
- self . append_place_to_string ( & proj. base , buf, autoderef) ?;
740
+ self . append_place_to_string ( & proj. base , buf, autoderef, & including_downcast ) ?;
722
741
buf. push_str ( "[" ) ;
723
742
if let Err ( _) = self . append_local_to_string ( index, buf) {
724
743
buf. push_str ( ".." ) ;
@@ -730,7 +749,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
730
749
// Since it isn't possible to borrow an element on a particular index and
731
750
// then use another while the borrow is held, don't output indices details
732
751
// 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 ) ?;
734
753
buf. push_str ( & "[..]" ) ;
735
754
}
736
755
} ;
0 commit comments