Skip to content

Conversation

@flodiebold
Copy link
Member

@flodiebold flodiebold commented Apr 13, 2020

E.g.

trait Trait {
    type Item: SomeOtherTrait;
}

Note that these don't simply desugar to where clauses; as I understand it, where clauses have to be proved by the user of the trait, but these bounds are proved by the implementor. (Also, where clauses on associated types are unstable.)

(Another one from my recursive solver branch...)

E.g.
```
trait Trait {
    type Item: SomeOtherTrait;
}
```
Note that these don't simply desugar to where clauses; as I understand it, where
clauses have to be proved by the *user* of the trait, but these bounds are proved
by the *implementor*. (Also, where clauses on associated types are unstable.)
@bjorn3
Copy link
Member

bjorn3 commented Apr 13, 2020

trait Trait {
    type Item: SomeOtherTrait;
}

is equivalent to the following, right?

trait Trait where Self::Item: SomeOtherTrait {
    type Item;
}

At least

trait B where Self::B: std::fmt::Display {
    type B;
}

impl B for () {
    type B = Vec<u8>;
}

gives an error:

error[E0277]: `std::vec::Vec<u8>` doesn't implement `std::fmt::Display`
  --> src/lib.rs:10:5
   |
5  | trait B where Self::B: std::fmt::Display {
   |               -------------------------- restricted in this bound
6  |     type B;
   |          - associated type defined here
...
9  | impl B for () {
   | ------------- in this `impl` item
10 |     type B = Vec<u8>;
   |     ^^^^^^^^^^^^^^^^^ `std::vec::Vec<u8>` cannot be formatted with the default formatter
   |
   = help: the trait `std::fmt::Display` is not implemented for `std::vec::Vec<u8>`
   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead

@flodiebold
Copy link
Member Author

That's true, they result in the same clauses in Chalk as well.

@matklad
Copy link
Contributor

matklad commented Apr 15, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented Apr 15, 2020

@bors bors bot merged commit 1e0ba04 into rust-lang:master Apr 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants