Skip to content
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

ICE with cast in fixed-length vector #10618

Closed
Ms2ger opened this issue Nov 23, 2013 · 5 comments
Closed

ICE with cast in fixed-length vector #10618

Ms2ger opened this issue Nov 23, 2013 · 5 comments
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@Ms2ger
Copy link
Contributor

Ms2ger commented Nov 23, 2013

The following code:

fn main() {
    let x: [bool, ..1 as uint];
}

causes:

error: internal compiler error: node_id_to_type: no type for node `expr 1 as uint (id=16)`
This message reflects a bug in the Rust compiler. 
We would appreciate a bug report: https://github.com/mozilla/rust/wiki/HOWTO-submit-a-Rust-bug-report
task 'rustc' failed at 'explicit failure', /build/buildd/rust-nightly-201311220805~747213a~precise/src/libsyntax/diagnostic.rs:101
task '<main>' failed at 'explicit failure', /build/buildd/rust-nightly-201311220805~747213a~precise/src/librustc/lib.rs:396

in the latest nightly from https://launchpad.net/~hansjorg/+archive/rust.

@Ms2ger
Copy link
Contributor Author

Ms2ger commented Nov 23, 2013

klutzy suggests this might be related to #9942.

@jfager
Copy link
Contributor

jfager commented Nov 23, 2013

I was looking into #5900 and this looks like a somewhat similar problem. The issue is that middle::const_eval::eval_const_expr_partial's ExprCast arm, which gets hit as a part of the call to check_item (here, specifically, check_fn), wants the ExprCast's parent id to already be in the type context but nothing has put it there yet. In #5900 this is because the enum doesn't get checked before the struct; here, it doesn't look like its order dependent, there's just nothing pushing that expression into the context.

@jfager
Copy link
Contributor

jfager commented Nov 23, 2013

This gets to the ICE through a more direct code path:

static x: &'static [bool, ..1 as uint] = &'static [true, ..1];

bors added a commit that referenced this issue Jan 31, 2014
I tried a couple of different ways to squash this, and still don't think this is ideal, but I wanted to get it out for feedback.

Closes #5900
Closes #9942

There are a few scenarios where the compiler tries to evaluate CastExprs without the corresponding types being available yet in the type context:  #10618, #5900, #9942

This PR takes the approach of having eval_const_expr_partial's CastExpr arm fall back to a limited ast_ty_to_ty call that only checks for (a subset of) valid const types, when the direct type lookup fails.  It's kind of hacky, so I understand if you don't want to take this as is.  I'd need a little mentoring to get this into better shape, as figuring out the proper fix has been a little daunting. I'm also happy if someone else wants to pick this up and run with it.

This closes 5900 and 9942, but only moves the goalposts a little on 10618, which now falls over in a later phase of the compiler.
@eminence
Copy link
Contributor

Visiting for triage. This issue still exists in the latest master (e2273d9). However @jfager's example doesn't ICE (just gives a syntax error)

@alexcrichton
Copy link
Member

Flagging as needstest (seems to work now)

bors added a commit that referenced this issue Aug 23, 2014
bors added a commit that referenced this issue Aug 24, 2014
@bors bors closed this as completed in ed18bae Aug 24, 2014
flip1995 pushed a commit to flip1995/rust that referenced this issue Apr 11, 2023
[missing_const_for_fn] fix rust-lang#7121

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: [`missing_const_for_fn`] note about removing const may break compatibility

fix rust-lang#7121
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants