@@ -576,7 +576,11 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
576576
577577 match & stmt. kind {
578578 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+ }
580584
581585 self . mutate_place ( location, ( * lhs, span) , Shallow ( None ) , flow_state) ;
582586 }
@@ -661,13 +665,12 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
661665 ) ;
662666 }
663667 TerminatorKind :: DropAndReplace {
664- place : drop_place ,
665- value : new_value ,
668+ place : _drop_place ,
669+ value : _new_value ,
666670 target : _,
667671 unwind : _,
668672 } => {
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" )
671674 }
672675 TerminatorKind :: Call {
673676 func,
@@ -678,11 +681,22 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
678681 from_hir_call : _,
679682 fn_span : _,
680683 } => {
684+ self . mutate_place ( loc, ( * destination, span) , Deep , flow_state) ;
681685 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+
682697 for arg in args {
683698 self . consume_operand ( loc, ( arg, span) , flow_state) ;
684699 }
685- self . mutate_place ( loc, ( * destination, span) , Deep , flow_state) ;
686700 }
687701 TerminatorKind :: Assert { cond, expected : _, msg, target : _, cleanup : _ } => {
688702 self . consume_operand ( loc, ( cond, span) , flow_state) ;
@@ -1100,13 +1114,23 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11001114 this. report_conflicting_borrow ( location, place_span, bk, borrow) ;
11011115 this. buffer_error ( err) ;
11021116 }
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+ }
11101134 WriteKind :: Mutate => {
11111135 this. report_illegal_mutation_of_borrowed ( location, place_span, borrow)
11121136 }
0 commit comments