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

rustc: trait-level where clauses are mistakenly imposed when bounding by the trait #50792

Closed
aturon opened this issue May 16, 2018 · 6 comments
Closed
Labels
A-traits Area: Trait system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@aturon
Copy link
Member

aturon commented May 16, 2018

I'm trying to use a where clause to define one trait in terms of another, as applied to a wrapper type:

struct Wrapper<T>(T);

trait Base {}
trait Wrapped: Sized where Wrapper<Self>: Base {}

fn wat<F: Wrapped>() {}

But when I try to bound by the new trait, I get a strange error:

error[E0277]: the trait bound `Wrapper<F>: Base` is not satisfied
 --> src/main.rs:7:1
  |
7 | fn wat<F: Wrapped>() {}
  | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Base` is not implemented for `Wrapper<F>`
  |
note: required by `Wrapped`
 --> src/main.rs:5:1
  |
5 | trait Wrapped: Sized where Wrapper<Self>: Base {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@aturon aturon added A-traits Area: Trait system C-bug Category: This is a bug. labels May 16, 2018
@aturon
Copy link
Member Author

aturon commented May 16, 2018

cc @nikomatsakis @eddyb @cramertj

@aturon
Copy link
Member Author

aturon commented May 16, 2018

Note: affects 1.26 and the current nightly.

@leoyvens
Copy link
Contributor

You can get it to work by repeating the where clause:

struct Wrapper<T>(T);

trait Base {}
trait Wrapped: Sized where Wrapper<Self>: Base {}

fn wat<F: Wrapped>() where Wrapper<F>: Base {}

fn main() {}

I think what is desired here is the implied bounds feature.

@cuviper
Copy link
Member

cuviper commented May 16, 2018

This seems similar to #20671, though from a slightly different angle.

Rust 1.3 has no complaint with the example. Rust 1.4 starts E0277 as a warning that "will become a HARD ERROR in the next release. See RFC 1214 for details." Rust 1.7 is where it actually became an error.

@leoyvens
Copy link
Contributor

Yes, rust-lang/rfcs#1214 improved the well-formedness check, and it states that for a trait reference to be WF all where clauses on the trait must be satisified. The implied bounds RFC says that functions can now assume those where clauses to be satifsfied, but that RFC is still being implemented so this is a dupe of #44491. And it's not "just a bug".

@jonas-schievink jonas-schievink added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 22, 2020
@jonas-schievink
Copy link
Contributor

Closing in favor of #20671 / #44491

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-traits Area: Trait system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants