1
Fork 0

Suppress CONST_ITEM_MUTATION lint if a dereference occurs anywhere

Fixes #79971
This commit is contained in:
Aaron Hill 2020-12-17 15:25:55 -05:00
parent d23e084483
commit dea13632a8
No known key found for this signature in database
GPG key ID: B4087E510E98B164
3 changed files with 21 additions and 11 deletions

View file

@ -66,12 +66,14 @@ impl<'a, 'tcx> ConstMutationChecker<'a, 'tcx> {
location: Location,
decorate: impl for<'b> FnOnce(LintDiagnosticBuilder<'b>) -> DiagnosticBuilder<'b>,
) {
// Don't lint on borrowing/assigning to a dereference
// e.g:
// Don't lint on borrowing/assigning when a dereference is involved.
// If we 'leave' the temporary via a dereference, we must
// be modifying something else
//
// `unsafe { *FOO = 0; *BAR.field = 1; }`
// `unsafe { &mut *FOO }`
if !matches!(place.projection.last(), Some(PlaceElem::Deref)) {
// `unsafe { (*ARRAY)[0] = val; }
if !place.projection.iter().any(|p| matches!(p, PlaceElem::Deref)) {
let source_info = self.body.source_info(location);
let lint_root = self.body.source_scopes[source_info.scope]
.local_data