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 regression with zipped iterators #29278

Closed
larsluthman opened this Issue Oct 24, 2015 · 5 comments

Comments

Projects
None yet
7 participants
@larsluthman
Copy link

larsluthman commented Oct 24, 2015

The following code compiles with Stable and Beta but not with Nightly on https://play.rust-lang.org/ as of 2015-10-24:

fn main() {
    let mut output = vec![Vec::<i32>::new(); 5];
    let input = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
    for chunk in input.chunks(5) {
        for (i, o) in chunk.iter().zip(output.as_mut()) {
            o.push(*i);
        }
    }
    println!("{:?}", output);
}

With Stable and Beta I get the correct output:

[[0, 5, 10], [1, 6, 11], [2, 7, 12], [3, 8, 13], [4, 9]]

With Nightly I get the error message

<anon>:6:13: 6:23 error: the type of this value must be known in this context
<anon>:6             o.push(*i);
@eefriedman

This comment has been minimized.

Copy link
Contributor

eefriedman commented Oct 24, 2015

This isn't a type inference regression; the problem is that Vec acquired a couple implementations of AsMut, and they're impossible to distinguish based on only the information "the result must implement IntoIter".

@bluss

This comment has been minimized.

Copy link
Contributor

bluss commented Oct 24, 2015

AsMut added in #28663. Unfortunately the smallest new trait impls cause issues like this 😞

I don't want to shift the blame, but AsMut is a conversion trait, used for generics. It shouldn't have been in the prelude, because it's not intended to be called like this IMO.

More idiomatic would be to write chunk.iter().zip(&mut output), which continues to compile.

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Oct 25, 2015

triage: I-nominated

@brson

This comment has been minimized.

Copy link
Contributor

brson commented Oct 28, 2015

This is on beta now.

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Oct 29, 2015

The libs team discussed this during triage today, and the conclusion was to close this for now. This is indeed breakage with the addition of AsMut for Vec<T>, but it is covered under our API evolution policy which is to say that a local elaboration (e.g. type annotations) will fix this. If this becomes a widespread problem we will consider reverting, but for now it seems minor enough to not warrant that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.