@@ -5,11 +5,7 @@ use rustc_span::symbol::sym;
55use tracing:: trace;
66
77use super :: ConstCx ;
8- use super :: check:: Qualifs ;
9- use super :: ops:: { self } ;
10- use super :: qualifs:: { NeedsNonConstDrop , Qualif } ;
118use crate :: check_consts:: check:: Checker ;
12- use crate :: check_consts:: qualifs:: NeedsDrop ;
139use crate :: check_consts:: rustc_allow_const_fn_unstable;
1410
1511/// Returns `true` if we should use the more precise live drop checker that runs after drop
@@ -46,23 +42,13 @@ pub fn check_live_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mir::Body<'tcx>) {
4642 return ;
4743 }
4844
49- let mut visitor = CheckLiveDrops { ccx : & ccx , qualifs : Qualifs :: default ( ) } ;
45+ let mut visitor = CheckLiveDrops { checker : Checker :: new ( & ccx ) } ;
5046
5147 visitor. visit_body ( body) ;
5248}
5349
5450struct CheckLiveDrops < ' mir , ' tcx > {
55- ccx : & ' mir ConstCx < ' mir , ' tcx > ,
56- qualifs : Qualifs < ' mir , ' tcx > ,
57- }
58-
59- // So we can access `body` and `tcx`.
60- impl < ' mir , ' tcx > std:: ops:: Deref for CheckLiveDrops < ' mir , ' tcx > {
61- type Target = ConstCx < ' mir , ' tcx > ;
62-
63- fn deref ( & self ) -> & Self :: Target {
64- self . ccx
65- }
51+ checker : Checker < ' mir , ' tcx > ,
6652}
6753
6854impl < ' tcx > Visitor < ' tcx > for CheckLiveDrops < ' _ , ' tcx > {
@@ -82,38 +68,13 @@ impl<'tcx> Visitor<'tcx> for CheckLiveDrops<'_, 'tcx> {
8268
8369 match & terminator. kind {
8470 mir:: TerminatorKind :: Drop { place : dropped_place, .. } => {
85- let ty_of_dropped_place = dropped_place. ty ( self . body , self . tcx ) . ty ;
86-
87- let needs_drop = if let Some ( local) = dropped_place. as_local ( ) {
88- self . qualifs . needs_drop ( self . ccx , local, location)
89- } else {
90- NeedsDrop :: in_any_value_of_ty ( self . ccx , ty_of_dropped_place)
91- } ;
92- // If this type doesn't need a drop at all, then there's nothing to enforce.
93- if !needs_drop {
94- return ;
95- }
96-
97- let mut err_span = terminator. source_info . span ;
98-
99- let needs_non_const_drop = if let Some ( local) = dropped_place. as_local ( ) {
100- // Use the span where the local was declared as the span of the drop error.
101- err_span = self . body . local_decls [ local] . source_info . span ;
102- self . qualifs . needs_non_const_drop ( self . ccx , local, location)
103- } else {
104- NeedsNonConstDrop :: in_any_value_of_ty ( self . ccx , ty_of_dropped_place)
105- } ;
106-
10771 // I know it's not great to be creating a new const checker, but I'd
10872 // rather use it so we can deduplicate the error emitting logic that
10973 // it contains.
110- Checker :: new ( self . ccx ) . check_op_spanned_post (
111- ops:: LiveDrop {
112- dropped_at : Some ( terminator. source_info . span ) ,
113- dropped_ty : ty_of_dropped_place,
114- needs_non_const_drop,
115- } ,
116- err_span,
74+ self . checker . check_drop_terminator (
75+ * dropped_place,
76+ location,
77+ terminator. source_info . span ,
11778 ) ;
11879 }
11980
0 commit comments