Why does this code fail to compile?
trait TFoo {}
fn foo<T: TFoo>(v: Box<T>) {}
fn bar(v: Box<TFoo>) {
foo(v);
}
fn main() {}
compilation error:
error[E0277]: the trait bound `TFoo: std::marker::Sized` is not satisfied
--> src/main.rs:6:5
|
6 | foo(v);
| ^^^ `TFoo` does not have a constant size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `TFoo`
= note: required by `foo`
This code compiles if the signature of foo
is fn foo(v: Box<TFoo>)
. Why can Box<T> where T: Trait
not be passed as a parameter, but Box<Trait>
can be passed?