Skip to content

Commit 0dfe7b6

Browse files
committed
Add justification of the destructor filter
1 parent 17db1cb commit 0dfe7b6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

compiler/rustc_mir/src/transform/check_const_item_mutation.rs

+12
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ impl<'a, 'tcx> ConstMutationChecker<'a, 'tcx> {
3434

3535
fn is_const_item_without_destructor(&self, local: Local) -> Option<DefId> {
3636
let def_id = self.is_const_item(local)?;
37+
38+
// We avoid linting mutation of a const item if the const's type has a
39+
// Drop impl. The Drop logic observes the mutation which was performed.
40+
//
41+
// struct Log { msg: &'static str }
42+
// const LOG: Log = Log { msg: "" };
43+
// impl Drop for Log {
44+
// fn drop(&mut self) { println!("{}", self.msg); }
45+
// }
46+
//
47+
// LOG.msg = "wow"; // prints "wow"
48+
//
3749
match self.tcx.adt_def(def_id).destructor(self.tcx) {
3850
Some(_) => None,
3951
None => Some(def_id),

0 commit comments

Comments
 (0)