@@ -576,7 +576,11 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
576
576
577
577
match & stmt. kind {
578
578
StatementKind :: Assign ( box ( lhs, rhs) ) => {
579
- self . consume_rvalue ( location, ( rhs, span) , flow_state) ;
579
+ // FIXME: drop-elaboration checks the discriminant of an enum after it has been
580
+ // moved out. This is a known isses and should be fixed in the future.
581
+ if !matches ! ( rhs, Rvalue :: Discriminant ( _) ) {
582
+ self . consume_rvalue ( location, ( rhs, span) , flow_state) ;
583
+ }
580
584
581
585
self . mutate_place ( location, ( * lhs, span) , Shallow ( None ) , flow_state) ;
582
586
}
@@ -661,13 +665,12 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
661
665
) ;
662
666
}
663
667
TerminatorKind :: DropAndReplace {
664
- place : drop_place ,
665
- value : new_value ,
668
+ place : _drop_place ,
669
+ value : _new_value ,
666
670
target : _,
667
671
unwind : _,
668
672
} => {
669
- self . mutate_place ( loc, ( * drop_place, span) , Deep , flow_state) ;
670
- self . consume_operand ( loc, ( new_value, span) , flow_state) ;
673
+ bug ! ( "undesugared drop and replace in borrowck" )
671
674
}
672
675
TerminatorKind :: Call {
673
676
func,
@@ -678,11 +681,22 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
678
681
from_hir_call : _,
679
682
fn_span : _,
680
683
} => {
684
+ self . mutate_place ( loc, ( * destination, span) , Deep , flow_state) ;
681
685
self . consume_operand ( loc, ( func, span) , flow_state) ;
686
+
687
+ // drop glue for box does not pass borrowck
688
+ let func_ty = func. ty ( self . body , self . infcx . tcx ) ;
689
+ use rustc_hir:: lang_items:: LangItem ;
690
+ if let ty:: FnDef ( func_id, _) = func_ty. kind ( ) {
691
+ if Some ( func_id) == self . infcx . tcx . lang_items ( ) . get ( LangItem :: BoxFree ) . as_ref ( )
692
+ {
693
+ return ;
694
+ }
695
+ }
696
+
682
697
for arg in args {
683
698
self . consume_operand ( loc, ( arg, span) , flow_state) ;
684
699
}
685
- self . mutate_place ( loc, ( * destination, span) , Deep , flow_state) ;
686
700
}
687
701
TerminatorKind :: Assert { cond, expected : _, msg, target : _, cleanup : _ } => {
688
702
self . consume_operand ( loc, ( cond, span) , flow_state) ;
@@ -1100,13 +1114,23 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1100
1114
this. report_conflicting_borrow ( location, place_span, bk, borrow) ;
1101
1115
this. buffer_error ( err) ;
1102
1116
}
1103
- WriteKind :: StorageDeadOrDrop => this
1104
- . report_borrowed_value_does_not_live_long_enough (
1105
- location,
1106
- borrow,
1107
- place_span,
1108
- Some ( kind) ,
1109
- ) ,
1117
+ WriteKind :: StorageDeadOrDrop => {
1118
+ use rustc_span:: DesugaringKind ;
1119
+ if let Some ( DesugaringKind :: Replace ) = place_span. 1 . desugaring_kind ( ) {
1120
+ // If this is a drop triggered by a reassignment, it's more user friendly
1121
+ // to report a problem with the explicit assignment than the implicit drop.
1122
+ this. report_illegal_mutation_of_borrowed (
1123
+ location, place_span, borrow,
1124
+ )
1125
+ } else {
1126
+ this. report_borrowed_value_does_not_live_long_enough (
1127
+ location,
1128
+ borrow,
1129
+ place_span,
1130
+ Some ( kind) ,
1131
+ )
1132
+ }
1133
+ }
1110
1134
WriteKind :: Mutate => {
1111
1135
this. report_illegal_mutation_of_borrowed ( location, place_span, borrow)
1112
1136
}
0 commit comments