about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2020-09-26 21:19:08 -0400
committerDavid Tolnay <dtolnay@gmail.com>2020-09-30 21:45:56 -0700
commit0dfe7b6434f6aabbe9673a891ba74c7c7922661d (patch)
tree27bdaaddc0d7657fc6bdb18299b606c39f21796a
parent17db1cb5d5a864d611e17d6e2466731c3b50a794 (diff)
downloadrust-0dfe7b6434f6aabbe9673a891ba74c7c7922661d.tar.gz
rust-0dfe7b6434f6aabbe9673a891ba74c7c7922661d.zip
Add justification of the destructor filter
-rw-r--r--compiler/rustc_mir/src/transform/check_const_item_mutation.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/compiler/rustc_mir/src/transform/check_const_item_mutation.rs b/compiler/rustc_mir/src/transform/check_const_item_mutation.rs
index b556e2d217d..aae67949945 100644
--- a/compiler/rustc_mir/src/transform/check_const_item_mutation.rs
+++ b/compiler/rustc_mir/src/transform/check_const_item_mutation.rs
@@ -34,6 +34,18 @@ impl<'a, 'tcx> ConstMutationChecker<'a, 'tcx> {
 
     fn is_const_item_without_destructor(&self, local: Local) -> Option<DefId> {
         let def_id = self.is_const_item(local)?;
+
+        // We avoid linting mutation of a const item if the const's type has a
+        // Drop impl. The Drop logic observes the mutation which was performed.
+        //
+        //     struct Log { msg: &'static str }
+        //     const LOG: Log = Log { msg: "" };
+        //     impl Drop for Log {
+        //         fn drop(&mut self) { println!("{}", self.msg); }
+        //     }
+        //
+        //     LOG.msg = "wow";  // prints "wow"
+        //
         match self.tcx.adt_def(def_id).destructor(self.tcx) {
             Some(_) => None,
             None => Some(def_id),