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

Regression: Using T: Bound in method impl and where T: Bound in method declaration yields an error #20107

Closed
japaric opened this issue Dec 21, 2014 · 3 comments
Labels
A-typesystem Area: The type system

Comments

@japaric
Copy link
Member

japaric commented Dec 21, 2014

STR

#![crate_type = "lib"]

trait Bound {}

trait Trait {
    fn a<T>(&self, T) where T: Bound;
    fn b<T>(&self, T) where T: Bound;
    fn c<T: Bound>(&self, T);
    fn d<T: Bound>(&self, T);
}

impl Trait for bool {
    fn a<T: Bound>(&self, _: T) {}  //~ This gets rejected but should be accepted
    fn b<T>(&self, _: T) where T: Bound {}
    fn c<T: Bound>(&self, _: T) {}
    fn d<T>(&self, _: T) where T: Bound {}
}

Output

where.rs:13:5: 13:35 error: in method `a`, type parameter 0 requires bound `Bound`, which is not required by the corresponding type parameter in the trait declaration [E0052]
where.rs:13     fn a<T: Bound>(&self, _: T) {}
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error

Version

Doesn't compile on:

rustc 0.13.0-nightly (cc19e3380 2014-12-20 20:00:36 +0000)

This used to compile in:

rustc 0.13.0-nightly (99d6956c3 2014-12-18 20:32:07 +0000)

These 4 formms are equivalent and should continue to be accepted. Some changes to the where clause parser landed yesterday (#20073), perhaps that caused the regression?

cc @nikomatsakis @jroesch

@nikomatsakis
Copy link
Contributor

Yes, I didn't anticipate this, but it's basically a dup of #20020. Not quite a dup, but cleaning up the code that #20020 says we ought to cleanup will fix this too. (In particular, #20020 is more about cases that should be rejected but will be accepted, but I didn't realize there would be the opposite too.)

@jroesch
Copy link
Member

jroesch commented Dec 22, 2014

I added this as a test case on my working branch for #20020.

bors added a commit that referenced this issue Jan 15, 2015
…sakis

This should fix both #20020 and #20107. This moves out the code into its own file.

I have a couple concerns that can either be addressed in this PR or in a future one.

- The error reporting for the fulfillment context should be span aware because currently it is attached to the top
  of the file which is less then desirable.
- There is a failure in the test file: run-pass/issue-2611-3.rs, this seems like it should be a failure to me, but I am not sure.

As a nit I'm not enthused about the file name, and am open to better suggestions. 

r? @nikomatsakis
@tomjakubowski
Copy link
Contributor

Should be closed now by #20290

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

No branches or pull requests

6 participants