Closed
Description
use std::path::Path;
// use std::ptr::{null, null_mut};
///Returns a function, which compares a &str against a name
fn cmp(name:&dyn ToString)
{}
fn cmp1(name:&dyn AsRef<Path>)
{}
fn main(){
cmp("test");
cmp1("test");
}
The current output is:
error[E0277]: the size for values of type `str` cannot be known at compilation time
--> src/main.rs:10:9
|
10 | cmp("test");
| --- ^^^^^^ doesn't have a size known at compile-time
| |
| required by a bound introduced by this call
|
= help: the trait `Sized` is not implemented for `str`
= note: required for the cast to the object type `dyn ToString`
error[E0277]: the size for values of type `str` cannot be known at compilation time
--> src/main.rs:11:10
|
11 | cmp1("test");
| ---- ^^^^^^ doesn't have a size known at compile-time
| |
| required by a bound introduced by this call
|
= help: the trait `Sized` is not implemented for `str`
= note: required for the cast to the object type `dyn AsRef<Path>`
For more information about this error, try `rustc --explain E0277`.
Stating, that &str does not have a known size at compile time is just wrong.
I think that rust sees, that the function parameter has a Borrowed type and that the function call also provides a borrowed type. So rust probably procedes to check the actual types 'behind' the borrow.
It is just, that here I would expect a message asking me if I would have liked to borrow here, since that would solve this error.