@@ -31,6 +31,15 @@ impl<'a, 'tcx> ConstMutationChecker<'a, 'tcx> {
31
31
None
32
32
}
33
33
}
34
+
35
+ fn is_const_item_without_destructor ( & self , local : Local ) -> Option < DefId > {
36
+ let def_id = self . is_const_item ( local) ?;
37
+ match self . tcx . adt_def ( def_id) . destructor ( self . tcx ) {
38
+ Some ( _) => None ,
39
+ None => Some ( def_id) ,
40
+ }
41
+ }
42
+
34
43
fn lint_const_item_usage (
35
44
& self ,
36
45
const_item : DefId ,
@@ -59,7 +68,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ConstMutationChecker<'a, 'tcx> {
59
68
// Assigning directly to a constant (e.g. `FOO = true;`) is a hard error,
60
69
// so emitting a lint would be redundant.
61
70
if !lhs. projection . is_empty ( ) {
62
- if let Some ( def_id) = self . is_const_item ( lhs. local ) {
71
+ if let Some ( def_id) = self . is_const_item_without_destructor ( lhs. local ) {
63
72
// Don't lint on writes through a pointer
64
73
// (e.g. `unsafe { *FOO = 0; *BAR.field = 1; }`)
65
74
if !matches ! ( lhs. projection. last( ) , Some ( PlaceElem :: Deref ) ) {
@@ -89,7 +98,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ConstMutationChecker<'a, 'tcx> {
89
98
fn visit_rvalue ( & mut self , rvalue : & Rvalue < ' tcx > , loc : Location ) {
90
99
if let Rvalue :: Ref ( _, BorrowKind :: Mut { .. } , place) = rvalue {
91
100
let local = place. local ;
92
- if let Some ( def_id) = self . is_const_item ( local) {
101
+ if let Some ( def_id) = self . is_const_item_without_destructor ( local) {
93
102
// If this Rvalue is being used as the right-hand side of a
94
103
// `StatementKind::Assign`, see if it ends up getting used as
95
104
// the `self` parameter of a method call (as the terminator of our current
0 commit comments