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
Closed

Type inference regression with zipped iterators #29278

larsluthman opened this issue Oct 24, 2015 · 5 comments
Labels
regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@larsluthman
Copy link

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);
@sfackler sfackler added the regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. label Oct 24, 2015
@eefriedman
Copy link
Contributor

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
Copy link
Member

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
Copy link
Member

triage: I-nominated

@alexcrichton alexcrichton added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Oct 25, 2015
@brson brson added the regression-from-stable-to-beta Performance or correctness regression from stable to beta. label Oct 28, 2015
@brson
Copy link
Contributor

brson commented Oct 28, 2015

This is on beta now.

@brson brson removed the regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. label Oct 28, 2015
@alexcrichton
Copy link
Member

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
Labels
regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants