@@ -5,11 +5,7 @@ use rustc_span::symbol::sym;
5
5
use tracing:: trace;
6
6
7
7
use super :: ConstCx ;
8
- use super :: check:: Qualifs ;
9
- use super :: ops:: { self } ;
10
- use super :: qualifs:: { NeedsNonConstDrop , Qualif } ;
11
8
use crate :: check_consts:: check:: Checker ;
12
- use crate :: check_consts:: qualifs:: NeedsDrop ;
13
9
use crate :: check_consts:: rustc_allow_const_fn_unstable;
14
10
15
11
/// 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>) {
46
42
return ;
47
43
}
48
44
49
- let mut visitor = CheckLiveDrops { ccx : & ccx , qualifs : Qualifs :: default ( ) } ;
45
+ let mut visitor = CheckLiveDrops { checker : Checker :: new ( & ccx ) } ;
50
46
51
47
visitor. visit_body ( body) ;
52
48
}
53
49
54
50
struct 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 > ,
66
52
}
67
53
68
54
impl < ' tcx > Visitor < ' tcx > for CheckLiveDrops < ' _ , ' tcx > {
@@ -82,38 +68,13 @@ impl<'tcx> Visitor<'tcx> for CheckLiveDrops<'_, 'tcx> {
82
68
83
69
match & terminator. kind {
84
70
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
-
107
71
// I know it's not great to be creating a new const checker, but I'd
108
72
// rather use it so we can deduplicate the error emitting logic that
109
73
// 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 ,
117
78
) ;
118
79
}
119
80
0 commit comments