@@ -324,14 +324,6 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
324324 }
325325 }
326326
327- /// Emits an error at the given `span` if an expression cannot be evaluated in the current
328- /// context. This is meant for use in a post-const-checker pass such as the const precise
329- /// live drops lint.
330- pub fn check_op_spanned_post < O : NonConstOp < ' tcx > > ( mut self , op : O , span : Span ) {
331- self . check_op_spanned ( op, span) ;
332- assert ! ( self . secondary_errors. is_empty( ) ) ;
333- }
334-
335327 fn check_static ( & mut self , def_id : DefId , span : Span ) {
336328 if self . tcx . is_thread_local_static ( def_id) {
337329 self . tcx . dcx ( ) . span_bug ( span, "tls access is checked in `Rvalue::ThreadLocalRef`" ) ;
@@ -429,6 +421,43 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
429421
430422 true
431423 }
424+
425+ pub fn check_drop_terminator (
426+ & mut self ,
427+ dropped_place : Place < ' tcx > ,
428+ location : Location ,
429+ terminator_span : Span ,
430+ ) {
431+ let ty_of_dropped_place = dropped_place. ty ( self . body , self . tcx ) . ty ;
432+
433+ let needs_drop = if let Some ( local) = dropped_place. as_local ( ) {
434+ self . qualifs . needs_drop ( self . ccx , local, location)
435+ } else {
436+ qualifs:: NeedsDrop :: in_any_value_of_ty ( self . ccx , ty_of_dropped_place)
437+ } ;
438+ // If this type doesn't need a drop at all, then there's nothing to enforce.
439+ if !needs_drop {
440+ return ;
441+ }
442+
443+ let mut err_span = self . span ;
444+ let needs_non_const_drop = if let Some ( local) = dropped_place. as_local ( ) {
445+ // Use the span where the local was declared as the span of the drop error.
446+ err_span = self . body . local_decls [ local] . source_info . span ;
447+ self . qualifs . needs_non_const_drop ( self . ccx , local, location)
448+ } else {
449+ qualifs:: NeedsNonConstDrop :: in_any_value_of_ty ( self . ccx , ty_of_dropped_place)
450+ } ;
451+
452+ self . check_op_spanned (
453+ ops:: LiveDrop {
454+ dropped_at : terminator_span,
455+ dropped_ty : ty_of_dropped_place,
456+ needs_non_const_drop,
457+ } ,
458+ err_span,
459+ ) ;
460+ }
432461}
433462
434463impl < ' tcx > Visitor < ' tcx > for Checker < ' _ , ' tcx > {
@@ -874,35 +903,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
874903 return ;
875904 }
876905
877- let mut err_span = self . span ;
878- let ty_of_dropped_place = dropped_place. ty ( self . body , self . tcx ) . ty ;
879-
880- let needs_drop = if let Some ( local) = dropped_place. as_local ( ) {
881- self . qualifs . needs_drop ( self . ccx , local, location)
882- } else {
883- qualifs:: NeedsDrop :: in_any_value_of_ty ( self . ccx , ty_of_dropped_place)
884- } ;
885- // If this type doesn't need a drop at all, then there's nothing to enforce.
886- if !needs_drop {
887- return ;
888- }
889-
890- let needs_non_const_drop = if let Some ( local) = dropped_place. as_local ( ) {
891- // Use the span where the local was declared as the span of the drop error.
892- err_span = self . body . local_decls [ local] . source_info . span ;
893- self . qualifs . needs_non_const_drop ( self . ccx , local, location)
894- } else {
895- qualifs:: NeedsNonConstDrop :: in_any_value_of_ty ( self . ccx , ty_of_dropped_place)
896- } ;
897-
898- self . check_op_spanned (
899- ops:: LiveDrop {
900- dropped_at : Some ( terminator. source_info . span ) ,
901- dropped_ty : ty_of_dropped_place,
902- needs_non_const_drop,
903- } ,
904- err_span,
905- ) ;
906+ self . check_drop_terminator ( * dropped_place, location, terminator. source_info . span ) ;
906907 }
907908
908909 TerminatorKind :: InlineAsm { .. } => self . check_op ( ops:: InlineAsm ) ,
0 commit comments