-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Promotion rules are surprising and insufficiently documented #105270
Comments
As unfortunately somewhat underdocumented, but pointed out here
whereas for normal function bodies
This means that the result of the call to On the other hand, in the So as a result, there is no bug here :-) |
Okay, maybe it is not a bug per se, but it just looks very weird when compile-time unsafe code has greater capabilities than the same runtime code. Besides the rules for const promotion are not properly documented and are subject to change over time, so the situation when miri accepts this code seems fragile to me. |
Yeah here's no Miri bug here, we just (unfortunately) desugar code differently in So if there is a bug here it is in documenting our promotion rules. I don't know where those docs would go. |
Cc @rust-lang/wg-const-eval |
Could you elaborate on the difference?
Is it just your guess? If so, it would be better to check it via crater run, I presume.
Both Reference and Nomicon seem fitting. |
Everything behaves as intended. And the part of the compiler that doesn't behave the way you expect it to isn't even in Miri, it is in rustc. Even without Miri, your code (the runtime version of this) has UB at runtime, it accesses dangling memory.
We did crater runs for this a few years ago. Also see #80619. |
The code in question (playground link):
When I run this code under miri, it complains about dangling reference on attempt to print
s_rt
:However, if I comment out this line and keep the line which prints
S_CONST
, miri runs this program just fine.Meta
I used the latest stable at the moment (1.65.0), but since miri requires nightly toolchain anyway I believe it used latest nightly (2022-12-03 2341517).
The text was updated successfully, but these errors were encountered: