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
Closed

nightly rustc breaks stable code for some type inferences #26279

bombless opened this issue Jun 13, 2015 · 8 comments
Labels
P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@bombless
Copy link
Contributor

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

triage: I-nominated

@alexcrichton alexcrichton added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Jun 14, 2015
@bluss
Copy link
Member

bluss commented Jun 14, 2015

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

@nikomatsakis nikomatsakis added the regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. label Jun 17, 2015
@nikomatsakis
Copy link
Contributor

triage: P-high

@rust-highfive rust-highfive added P-high High priority and removed I-nominated labels Jun 17, 2015
@nikomatsakis
Copy link
Contributor

Gave P-high because this is a regression.

@bluss
Copy link
Member

bluss commented Jun 17, 2015

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

@jroesch
Copy link
Member

jroesch commented Jul 6, 2015

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

@bluss
Copy link
Member

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

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
Labels
P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants