-
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
Miscompilation of mutable reference to const temporary #31234
Comments
@nikomatsakis I wish there was an easy way to dump the const qualifications as annotations on expressions. My guess is that we're missing the borrow somehow, or if const qualification is correct, then maybe the const handling code in |
Using |
Using @ref = constant i64 0
@const = constant i64* @ref
...
%1 = load i64**, i64*** bitcast (i64** @const to i64***)
%2 = call i64 @method(i64** %1) Which is roughly the same as: @ref = constant i64 0
...
%2 = call i64 @method(i64** bitcast (i64* @ref to i64**)) So cc @dotdash |
Just to be clear: the problem is in trans, right? That is, I expect this example to compile, but it seems like the temporary stack slot is being dropped too early? |
@nikomatsakis Yes, it's supposed to compile, and no, there is no temporary stack slot, |
But there ought to be one, right? The second call requires an autoref (it is an |
@nikomatsakis There should be, but there isn't. That's the bug. |
Ping. Can someone at least assign some labels to this issue? |
In theory this is probably fixed with |
Given that this works with |
triage: P-low |
It appears this issue is related to one I have. Why is it possible to make mutable references to const items but not to let-bound items? This is very counterintuitive (at least to a beginner) and seems hardly productive to me. See this playground: https://is.gd/6eVLzl |
You shouldn't be able to get a mutable reference that you can use to mutate the constant but instead a copy (e.g. just like you can do |
This issue has been fixed in the MIR rewrite. @sanmai-NL What you're seeing is not related and is also working as intended. A |
There are two issues about issuing warnings for this situation - https://github.com/Manishearth/rust-clippy/issues/829 and rust-lang/rfcs#885. |
@eddyb: In my understanding, the |
Every time you write |
@jethrogb: Thanks for explaining. From what I read in the Rust book:
, which is misleading if they practically always refer to a different address in memory. Your issue is not a docs issue, but I hope I may take the opportunity to point out another confusing or misleading sentence there:
They don't, they do not have a single lifetime at all, they have lifetimes corresponding to each scope in which they are written (not ‘used’). I really wonder what the use of (Okay now, I won't discuss this side issue further even in response.) |
This code compiles, but yields:
The second number may vary.
This used to lead to segfaults (in 1.5.0 and earlier) in code such as:
This doesn't segfault in 1.6.0 anymore, but that is due to an unrelated change.
The text was updated successfully, but these errors were encountered: