-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Fix ICE on using result of index on a constant to index into a constant #30714
Conversation
r? @arielb1 (rust_highfive has picked a reviewer for you, use r? to override) |
First time fixing an ICE so any feedback is greatly appreciated 😄 |
I'll squash those up later |
Good idea. We should probably report all other errors, too. It should only be a bug when it returns a non int ok value. |
const ARR: [usize; 5] = [5, 4, 3, 2, 1]; | ||
|
||
fn main() { | ||
assert_eq!(2, ARR[ARR[3]]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this require the feature gate to be turned on?
Ah nvrmind. This runs the normal eval then. Please add a second test with the feature gate enabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
3d4d377
to
11c16db
Compare
@oli-obk Done |
@bors r+ |
📌 Commit 11c16db has been approved by |
The issue was that the const evaluator was returning an error because the feature flag const_indexing wasn't turned on. The error was then reported as a bug. Fixes #29914
💔 Test failed - auto-mac-64-nopt-t |
|
I just retested this on OS X 10.11 and the test passes. Not sure what's going on |
So I tried merging again and retesting and it works on my machine:
|
@wesleywiser Signal 11 is SIGSEGV AFAIK, which is worrisome. |
@eddyb Agreed I'm just not sure where to go from here. I can't even repro the issue on my computer. |
AFAIR I also had SIGSEGV on buildbots once (a few months ago; also on OSX IIRC), which turned out to be “temporary” and not “reproducible” even on buildbots when retesting again. |
@bors: retry Looks like this was likely spurious |
⌛ Testing commit 11c16db with merge 97b0e0e... |
💔 Test failed - auto-win-gnu-64-nopt-t |
@bors: retry On Mon, Jan 11, 2016 at 3:44 PM, bors [email protected] wrote:
|
⌛ Testing commit 11c16db with merge cd251f8... |
Jup |
Got it. Thanks! |
38de158
to
f31cb44
Compare
It seems this PR also fixes #23513 and a similar ICE with const fn I got today:
The |
@@ -664,12 +662,19 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, | |||
adt::const_get_field(cx, &*brepr, bv, vinfo.discr, idx.node) | |||
}, | |||
hir::ExprIndex(ref base, ref index) => { | |||
//honor the const_indexing feature if this is in a CONST expression | |||
if !cx.sess().features.borrow().const_indexing && trueconst == TrueConst::Yes { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to add this check in order to get the compile-fail
test I added to pass. Maybe this is the wrong place to add the check though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Const indexing is allowed in statics, just not in true constants. So this check is wrong here.
@oli-obk When you get a minute, could you look at my changes? Thanks! |
With the change from |
Ok(ConstVal::Uint(u)) => u, | ||
_ => cx.sess().span_bug(index.span, | ||
"index is not an integer-constant expression") | ||
let iv = try!(const_expr(cx, &**index, param_substs, fn_args, trueconst)).0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trueconst
should probably be TrueConst::Yes
(definitely change this just to be on the safe side).
I think I'm missing something then. Isn't it supposed to fail because it's performing a constant index operation without using |
not quite: the |
Ah ok. That makes perfect sense now. Thanks! I'll fix this up tonight |
f31cb44
to
94cc410
Compare
@oli-obk Fixed |
_ => cx.sess().span_bug(index.span, | ||
"index is not an integer-constant expression") | ||
let (bv, bt) = try!(const_expr(cx, &**base, param_substs, fn_args, TrueConst::Yes)); | ||
let iv = try!(const_expr(cx, &**index, param_substs, fn_args, trueconst)).0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the TrueConst::Yes
should be on the index, not the array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks
94cc410
to
31fd057
Compare
lgtm |
☔ The latest upstream changes (presumably #31524) made this pull request unmergeable. Please resolve the merge conflicts. |
The issue was that the const evaluator was returning an error because the feature flag const_indexing wasn't turned on. The error was then reported as a bug. Fixes rust-lang#29914
31fd057
to
271777c
Compare
Rebased |
@arielb1 I think this is ready to go |
@bors r+ |
📌 Commit 271777c has been approved by |
The issue was that the const evaluator was returning an error because the feature flag const_indexing wasn't turned on. The error was then reported as a bug. Fixes #29914
The issue was that the const evaluator was returning an error because
the feature flag const_indexing wasn't turned on. The error was then
reported as a bug.
Fixes #29914