Open
Description
Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=277b0605705776743255b4aa99055334
use core::fmt::Display;
struct S<T: ?Sized> {
inner: Box<T>,
}
impl<T> S<T> {
fn foo(&self) {}
}
fn main() {
let x: S<dyn Display> = S { inner: Box::new(0) as _ };
x.foo();
}
The current output is:
error[E0599]: the method `foo` exists for struct `S<dyn std::fmt::Display>`, but its trait bounds were not satisfied
--> src/main.rs:12:7
|
2 | struct S<T: ?Sized> {
| ------------------- method `foo` not found for this
...
12 | x.foo();
| ^^^ method cannot be called on `S<dyn std::fmt::Display>` due to unsatisfied trait bounds
|
= note: the following trait bounds were not satisfied:
`dyn std::fmt::Display: Sized`
Ideally the output should look like:
error[E0599]: the method `foo` exists for struct `S<dyn std::fmt::Display>`, but its trait bounds were not satisfied
--> src/main.rs:12:7
|
2 | struct S<T: ?Sized> {
| ------------------- method `foo` not found for this
...
12 | x.foo();
| ^^^ method cannot be called on `S<dyn std::fmt::Display>` due to unsatisfied trait bounds
|
= note: the following trait bounds were not satisfied:
`dyn std::fmt::Display: Sized`
note: implicitly required by the following `impl` block:
7 | impl<T> S<T> {
= help: consider relaxing the implicit `Sized` restriction
7 | impl<T: ?Sized> S<T> {
++++++++
This already exists for free functions; not sure why it's broken above. https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=4c7a6a69f9678c4ea5b410431e201c8c