diff options
| author | Aaron Hill <aa1ronham@gmail.com> | 2020-09-28 23:51:57 -0400 |
|---|---|---|
| committer | Aaron Hill <aa1ronham@gmail.com> | 2020-09-28 23:51:57 -0400 |
| commit | c6107c53d72250d8c1d41f161ce54648bef4d9d2 (patch) | |
| tree | d52ac4c22deb59568e9a25a746c9a8cef09af7c1 /compiler | |
| parent | fc2daaae610b5515438b551a2f3706196a997f35 (diff) | |
| download | rust-c6107c53d72250d8c1d41f161ce54648bef4d9d2.tar.gz rust-c6107c53d72250d8c1d41f161ce54648bef4d9d2.zip | |
Don't fire `const_item_mutation` lint on writes through a pointer
Fixes #77321
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_mir/src/transform/check_const_item_mutation.rs | 14 |
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: |
