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

nightly rustc breaks stable code for some type inferences #26279

Closed
bombless opened this Issue Jun 13, 2015 · 8 comments

Comments

Projects
None yet
6 participants
@bombless
Copy link
Contributor

bombless commented Jun 13, 2015

use std::ops::Add;
trait Zero: Add<Self, Output=Self> {
    fn zero()->Self;
}

impl Zero for i32 {
    fn zero()->i32 {
        0
    }
}

fn main() {
    let mut x = Vec::<i32>::new();
    x.extend(vec![Zero::zero()].into_iter())
}

nightly (breaking) : http://is.gd/5Pl8DA
stable (compiles) : http://is.gd/ZLTyOv

@bombless bombless changed the title nightly rustc breaks stable code for some type inference nightly rustc breaks stable code for some type inferences Jun 13, 2015

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Jun 14, 2015

triage: I-nominated

@bluss

This comment has been minimized.

Copy link
Contributor

bluss commented Jun 14, 2015

There's a tag on PR #25989 already too.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Jun 17, 2015

triage: P-high

@rust-highfive rust-highfive added P-high and removed I-nominated labels Jun 17, 2015

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Jun 17, 2015

Gave P-high because this is a regression.

@bluss

This comment has been minimized.

Copy link
Contributor

bluss commented Jun 17, 2015

It's deliberate, due to new Extend impls in libstd, on for example Vec.

@jroesch

This comment has been minimized.

Copy link
Member

jroesch commented Jul 6, 2015

@bluss I'm out of the std loop could you elaborate?

@bluss

This comment has been minimized.

Copy link
Contributor

bluss commented Jul 6, 2015

Sure, Vec<T> and other collections used to implement only Extend<T> so x.extend(vec![Zero::zero()].into_iter()) would infer the type for the Zero uniquely, from the type of x.

Now, Vec<T> implements both Extend<T> and Extend<&T> where T: Copy, so it is ambiguous which type the Zero call should produce.

I said it was deliberate because we knew that this issue would exist, a new trait impl would make some code ambiguous. It is called minor change (but breaking change) in the rust policy on stability, and hence permitted. (RFC: Policy on semver and API evolution)

One convenient workaround is to just use the explict form: i32::zero() (hm that's silly, but I suspect the original case has a type parameter). With a type parameter it can be written T::zero().

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Jul 24, 2015

I'm going to close this issue, since we've decided that the breakage due to extend is acceptable.

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.