When a trait parameter depends upon Sized, the error message only referred to the full trait itself and didn't mention Sized. This makes the failure to implement Sized explicit. It also notes when the Sized trait bound is explicit or implicit.
50 lines
1.1 KiB
Rust
50 lines
1.1 KiB
Rust
use std::fmt::Display;
|
|
|
|
trait ImplicitTrait {
|
|
fn foo(&self);
|
|
}
|
|
|
|
trait ExplicitTrait {
|
|
fn foo(&self);
|
|
}
|
|
|
|
trait DisplayTrait {
|
|
fn foo(&self);
|
|
}
|
|
|
|
trait UnimplementedTrait {
|
|
fn foo(&self);
|
|
}
|
|
|
|
// Implicitly requires `T: Sized`.
|
|
impl<T> ImplicitTrait for T {
|
|
fn foo(&self) {}
|
|
}
|
|
|
|
// Explicitly requires `T: Sized`.
|
|
impl<T: Sized> ExplicitTrait for T {
|
|
fn foo(&self) {}
|
|
}
|
|
|
|
// Requires `T: Display`.
|
|
impl<T: Display> DisplayTrait for T {
|
|
fn foo(&self) {}
|
|
}
|
|
|
|
fn main() {
|
|
// `[u8]` does not implement `Sized`.
|
|
let x: &[u8] = &[];
|
|
ImplicitTrait::foo(x);
|
|
//~^ ERROR: the trait bound `[u8]: ImplicitTrait` is not satisfied [E0277]
|
|
ExplicitTrait::foo(x);
|
|
//~^ ERROR: the trait bound `[u8]: ExplicitTrait` is not satisfied [E0277]
|
|
|
|
// `UnimplementedTrait` has no implementations.
|
|
UnimplementedTrait::foo(x);
|
|
//~^ ERROR: the trait bound `[u8]: UnimplementedTrait` is not satisfied [E0277]
|
|
|
|
// `[u8; 0]` implements `Sized` but not `Display`.
|
|
let x: &[u8; 0] = &[];
|
|
DisplayTrait::foo(x);
|
|
//~^ ERROR: the trait bound `[u8; 0]: DisplayTrait` is not satisfied [E0277]
|
|
}
|