Closed
Description
The following code produces a confusing error message:
use std::convert::AsRef;
use std::path::Path;
fn main() {
foo("bar", &"baz");
// ^^^^^^ doesn't have a size known at compile-time???
// Error message will clearly show that the second argument is the problem,
// but the first argument is the problem.
}
fn foo(_bar: &dyn AsRef<Path>, _baz: &str) {}
The confusing error when compiling the above code will be:
error[E0277]: the size for values of type `str` cannot be known at compilation time
--> src/main.rs:5:16
|
5 | foo("bar", &"baz");
| ^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `str`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= note: required for the cast to the object type `dyn std::convert::AsRef<std::path::Path>`
I first observed this error message behavior with Rust 1.39.