about summary refs log tree commit diff
path: root/compiler/rustc_mir
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2020-10-01 02:13:43 +0200
committerGitHub <noreply@github.com>2020-10-01 02:13:43 +0200
commit73258f87eaacd0b0b9dfbda5603119d425866801 (patch)
tree31aa5f750ef0946fafb3fce16da249e101382487 /compiler/rustc_mir
parent0044a9c08478d54047abc812a86220cd33f5f120 (diff)
parentc6107c53d72250d8c1d41f161ce54648bef4d9d2 (diff)
downloadrust-73258f87eaacd0b0b9dfbda5603119d425866801.tar.gz
rust-73258f87eaacd0b0b9dfbda5603119d425866801.zip
Rollup merge of #77324 - Aaron1011:fix/const-item-mutation-ptr, r=petrochenkov
Don't fire `const_item_mutation` lint on writes through a pointer

Fixes #77321
Diffstat (limited to 'compiler/rustc_mir')
-rw-r--r--compiler/rustc_mir/src/transform/check_const_item_mutation.rs14
1 files changed, 9 insertions, 5 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 70c1aed0957..0281c478a6c 100644
--- a/compiler/rustc_mir/src/transform/check_const_item_mutation.rs
+++ b/compiler/rustc_mir/src/transform/check_const_item_mutation.rs
@@ -60,11 +60,15 @@ impl<'a, 'tcx> Visitor<'tcx> for ConstMutationChecker<'a, 'tcx> {
             // so emitting a lint would be redundant.
             if !lhs.projection.is_empty() {
                 if let Some(def_id) = self.is_const_item(lhs.local) {
-                    self.lint_const_item_usage(def_id, loc, |lint| {
-                        let mut lint = lint.build("attempting to modify a `const` item");
-                        lint.note("each usage of a `const` item creates a new temporary - the original `const` item will not be modified");
-                        lint
-                    })
+                    // Don't lint on writes through a pointer
+                    // (e.g. `unsafe { *FOO = 0; *BAR.field = 1; }`)
+                    if !matches!(lhs.projection.last(), Some(PlaceElem::Deref)) {
+                        self.lint_const_item_usage(def_id, loc, |lint| {
+                            let mut lint = lint.build("attempting to modify a `const` item");
+                            lint.note("each usage of a `const` item creates a new temporary - the original `const` item will not be modified");
+                            lint
+                        })
+                    }
                 }
             }
             // We are looking for MIR of the form: