I was recently surprised to discovered that ?Sized
doesn't work in a where
clause.
impl<'a, T> Foo<'a> for &'a T where T: std::borrow::Borrow<str> + ?Sized {}
Instead, ?Sized
belongs in a <>
trait bound, like so:
impl<'a, T: std::borrow::Borrow<str> + ?Sized> Foo<'a> for &'a T {}
(Here's a full program showing the difference: Rust Playground)
Why does Rust have this restriction against ?Sized
?