-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Closed
Copy link
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.