-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-collectionsArea: `std::collections`Area: `std::collections`C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Description
I would like the following code to compile:
fn f<S: Into<Vec<u8>> + Clone>(subscripts: &[S]) -> Vec<Vec<u8>> {
subscripts.iter().cloned().map(|s| s.into()).collect()
}
fn main() {
f(&[&b"hi"[..]]); // this works
f(&[b"hi"]); // error: `From<&[u8; 2]>` is not satisfied
}
The first call in main is hard to get right, since leaving out any part of the syntax gives confusing errors (without [..], gives From<&&[u8; 2]>
is not satisfied, without & gives doesn't have a size known at compile-time
).
The second call seems to be the same idea, but doesn't compile since From isn't implemented for array literals.
This can be implemented without trouble on nightly Rust except for the orphan rule: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=21632f9784745afa98663d5e6e471cbb
If someone is willing to mentor I'm happy to turn that playground into a PR :)
Metadata
Metadata
Assignees
Labels
A-collectionsArea: `std::collections`Area: `std::collections`C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.