-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-coercionsArea: implicit and explicit `expr as Type` coercionsArea: implicit and explicit `expr as Type` coercionsA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.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.T-langRelevant to the language teamRelevant to the language team
Description
Really weird example:
use std::path::Path;
fn main() {
let boxed_path: Box<Path> = Path::new("test").to_path_buf().into_boxed_path();
let as_ref_works: &Path = boxed_path.as_ref();
//let lots_of_question_marks: Box<dyn AsRef<Path>> = boxed_path;
}
Uncommenting the last line gives:
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> src/main.rs:5:56
|
5 | let lots_of_question_marks: Box<dyn AsRef<Path>> = boxed_path;
| ^^^^^^^^^^ borrow the `Path` instead
|
= help: within `std::path::Path`, the trait `std::marker::Sized` is not implemented for `[u8]`
= 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 because it appears within the type `std::path::Path`
= note: required for the cast to the object type `dyn std::convert::AsRef<std::path::Path>`
error: aborting due to previous error
I genuinely don't know what's going on here, but this seems to be a bug in both coercion and diagnostics.
This is on the latest nightly.
hr567mal0ki
Metadata
Metadata
Assignees
Labels
A-coercionsArea: implicit and explicit `expr as Type` coercionsArea: implicit and explicit `expr as Type` coercionsA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.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.T-langRelevant to the language teamRelevant to the language team