Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upMiscompilation of mutable reference to const temporary #31234
Comments
This comment has been minimized.
This comment has been minimized.
|
@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 |
jethrogb
changed the title
Can call methods with &mut receiver on constants
Miscompilation of mutable reference to const temporary
Jan 27, 2016
This comment has been minimized.
This comment has been minimized.
|
Using |
This comment has been minimized.
This comment has been minimized.
|
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 |
dotdash
self-assigned this
Jan 27, 2016
This comment has been minimized.
This comment has been minimized.
|
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? |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis Yes, it's supposed to compile, and no, there is no temporary stack slot, |
This comment has been minimized.
This comment has been minimized.
But there ought to be one, right? The second call requires an autoref (it is an |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis There should be, but there isn't. That's the bug. |
dotdash
removed their assignment
Mar 4, 2016
This comment has been minimized.
This comment has been minimized.
|
Ping. Can someone at least assign some labels to this issue? |
sfackler
added
I-nominated
T-compiler
labels
Apr 2, 2016
This comment has been minimized.
This comment has been minimized.
|
In theory this is probably fixed with |
This comment has been minimized.
This comment has been minimized.
|
Given that this works with |
This comment has been minimized.
This comment has been minimized.
|
triage: P-low |
rust-highfive
added
P-low
and removed
I-nominated
labels
Apr 7, 2016
jethrogb
referenced this issue
Apr 23, 2016
Merged
Best practices for bug fixes in the compiler #1589
This comment has been minimized.
This comment has been minimized.
sanmai-NL
commented
Feb 19, 2017
|
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 |
This comment has been minimized.
This comment has been minimized.
|
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 comment has been minimized.
This comment has been minimized.
|
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 |
jethrogb
closed this
Feb 19, 2017
This comment has been minimized.
This comment has been minimized.
|
There are two issues about issuing warnings for this situation - rust-lang/rust-clippy#829 and rust-lang/rfcs#885. |
This comment has been minimized.
This comment has been minimized.
sanmai-NL
commented
Feb 20, 2017
•
|
@eddyb: In my understanding, the |
This comment has been minimized.
This comment has been minimized.
|
Every time you write |
This comment has been minimized.
This comment has been minimized.
sanmai-NL
commented
Feb 20, 2017
•
|
@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.) |
jethrogb commentedJan 27, 2016
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.