rust/tests/ui/error-codes/E0277-4.rs
Daniel Smith 291d0a9a4b diagnostics: make implicit Sized bounds explicit in E0277
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.
2026-01-08 16:07:18 -05:00

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]
}