-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usage of pattern on lhs of assignment results in unsafety check for raw pointer deferences being skipped #107288
Comments
Looks like a duplicate of #79735 Edit: Maybe it isn't an exact duplicate, but the behavior is one that's sufficiently tracked in that other issue already. Edit2: Actually, it isn't sufficiently tracked in the other issue. The code here gives a warning claiming "undefined behavior", so in case the code is considered safe, we would still have a diagnostic issue. |
Ah, there's also #80059. But that discussion does not encounter the "this code causes undefined behavior" warning either. |
That warning feels like it's coming from const evaluation (rvalue promotion). I don't know if it actually is, but I would not be surprised if promotion/promotability is involved here somehow. |
This will be fixed by #102256. |
This is in fact fixed by #102256 on the latest stable:
|
I tried this code:
playground
I expected to see this happen: A compiler error, dereferencing pointers is unsafe, and no unsafe block is provided.
Instead, this happened:
As far as I can tell, this code erroneously compiles for any
Copy
type, so long as the pattern doesn't bind anything to an identifier. Calls to unsafe functions cause a compiler error as normal.Meta
Works on the playground when I tested with stable-1.66.1, beta-1.67.0-beta.10, and nightly-1.69.0 (2023-01-23)
The text was updated successfully, but these errors were encountered: