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

Type inference for indexing #21649

Closed
Zoxc opened this issue Jan 26, 2015 · 3 comments · Fixed by #21806
Closed

Type inference for indexing #21649

Zoxc opened this issue Jan 26, 2015 · 3 comments · Fixed by #21806
Labels
A-typesystem Area: The type system

Comments

@Zoxc
Copy link
Contributor

Zoxc commented Jan 26, 2015

This example used to work:

fn main() {
    let array = [true, false];

    for i in 0..1 { 
        println!("{}", array[i]);
    }
}

Recently you'll get the error: error: the trait``core::ops::Index<i32>``is not implemented for the type``[bool]``[E0277]

@huonw huonw added the A-typesystem Area: The type system label Jan 26, 2015
@edwardw
Copy link
Contributor

edwardw commented Jan 27, 2015

The following works:

fn main() {
    let array = [true, false];

    for i in range(0, 1) { // you mean range(0, 2) right?
        println!("{}", array[i]);
    }
}

So this could be a dup of #21672.

@kornelski
Copy link
Contributor

I think I've ran into this as well:

pub fn main() {
    let mut x = [[0f64; 3]; 3];

    for i in 0..3 {
        x[i][0] = 1.0; // the type of this value must be known in this context
    }
}

@edwardw
Copy link
Contributor

edwardw commented Jan 31, 2015

Should have been fixed in #21806.

edwardw added a commit to edwardw/rust that referenced this issue Feb 1, 2015
The new `::ops::Range` has separated implementations for each of the
numeric types, while the old `::iter::Range` has one for type `Int`.
However, we do not take output bindings into account when selecting
traits. So it confuses `typeck` and makes the new range does not work as
good as the old one when it comes to type inference.

This patch implements `Iterator` for the new range for one type `Int`.
This limitation could be lifted, however, if we ever reconsider the
output types' role in type inference.

Closes rust-lang#21595
Closes rust-lang#21649
Closes rust-lang#21672
bors added a commit that referenced this issue Feb 1, 2015
The new `::ops::Range` has separated implementations for each of the
numeric types, while the old `::iter::Range` has one for type `Int`.
However, we do not take output bindings into account when selecting
traits. So it confuses `typeck` and makes the new range does not work as
good as the old one when it comes to type inference.

This patch implements `Iterator` for the new range for one type `Int`.
This limitation could be lifted, however, if we ever reconsider the
output types' role in type inference.

Closes #21595
Closes #21649
Closes #21672
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-typesystem Area: The type system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants