error[E0308]: mismatched types
--> src/lib.rs:18:25
|
18 | type Borrowed<'a> = B::Borrowed<'a> where Self: 'a;
| ^^^^^^^^^^^^^^^ lifetime mismatch
|
= note: expected trait `<<B as Borrow>::Borrowed<'a> as Sized>`
found trait `<<B as Borrow>::Borrowed<'cow> as Sized>`
note: the lifetime `'a` as defined here...
--> src/lib.rs:18:19
|
18 | type Borrowed<'a> = B::Borrowed<'a> where Self: 'a;
| ^^
note: ...does not necessarily outlive the lifetime `'cow` as defined here
--> src/lib.rs:14:6
|
14 | impl<'cow, B: Borrow + 'cow> Borrow for Cow<'cow, B>
| ^^^^
where did it say about Sized ? It's all about the lifetimes.
Yes the error message doesn't say anything about Sized. I'm just wondering what's the difference here between Sized bound and std::fmt::Debug bound. After all, one code compiles and the other doesn't.
And it's not just about Sized and std::fmt::Debug. Clone and Copy doesn't compile. AsRef<u8> and 'static compiles. Seems like if the trait is not object safe, code doesn't compile. If the trait is object safe, code compiles.
trait Borrow {
type Borrowed<'a>;
}
impl<'cow, T: Borrow + 'cow> Borrow for (T,)
where
T::Borrowed<'cow>: Sized, // Add this line cause error
{
type Borrowed<'a> = T::Borrowed<'a>;
}
trait Trait {
type Associated<'a>;
}
impl<'t, T: Trait + 't> Trait for (T,)
where
T::Associated<'t>: Sized, // Add this line cause error
{
type Associated<'a> = T::Associated<'a>;
}