-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
False positive warning from dereference-assignment of const pointer to mutable data #77321
Copy link
Copy link
Closed
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
I have quite a lot of MMIO in an embedded project, defined and used like this:
(see a playground link)
When I
cargo build, I'm getting a whole host of warnings of the type:I expect no warnings, because I'm not assigning to a
const, I'm assigning to a dereferenced*mut u32, aka a mutable u32.I couldn't figure out a playground example that would show the value actually mutating, but by hitting hardware registers I can prove that the value does get mutated, and it makes sense that it would: The pointer is
const, but it's pointing to amutableu32. Dereferencing shouldn't care whether the pointer variable isconst.Meta
rustc --version --verbose:No backtrace for this bug; it's a warning.