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

index is not an integer constant expression when using const fn argument #29798

Closed
oli-obk opened this issue Nov 12, 2015 · 4 comments
Closed
Labels
A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. C-bug Category: This is a bug. E-needs-test Call for participation: Writing correctness tests. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Nov 12, 2015

#![feature(const_fn)]
const fn test(x: usize) -> i32 {
    [42;5][x]
}
fn main () {
    let _ = test(5);
}

I guess we cannot const evaluate the index anymore but must translate it with llvm's constant evaluator, because it might only be available as a value we got from a static. But then I'm not sure how to do the range check.

Nope, that's not a problem. Is there any reason not to thin out trans/consts down to the point where it's just a thin wrapper around const_eval + translation of ConstVal to ValueRef?

I mean after #25570 (const indexing), since after that I think the const_eval is feature-equivalent with the const translator.

@eefriedman
Copy link
Contributor

const_eval currently can't return an address as a result (needed to evaluate e.g. const I: &'static u32 = &1).

Granted, that isn't a fundamental issue.

@oli-obk
Copy link
Contributor Author

oli-obk commented Nov 13, 2015

right. That would be solvable by adding a ConstVal::Ref variant.

@steveklabnik steveklabnik added the A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. label Mar 11, 2016
@oli-obk
Copy link
Contributor Author

oli-obk commented Jan 26, 2017

This now ices with thread 'main' panicked at 'index out of bounds: the len is 5 but the index is 5'

@steveklabnik steveklabnik added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jan 26, 2017
@Mark-Simulacrum
Copy link
Member

No longer ICEs or errors. E-needstest.

@Mark-Simulacrum Mark-Simulacrum added the E-needs-test Call for participation: Writing correctness tests. label May 20, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 22, 2017
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Jul 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. C-bug Category: This is a bug. E-needs-test Call for participation: Writing correctness tests. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

4 participants