Uh oh!
There was an error while loading. Please reload this page.
impl From<&[T; N]> and From<&mut [T; N]> for Vec<T> - #95098
Conversation
rust-highfive
commented
Mar 19, 2022
r? @dtolnay (rust-highfive has picked a reviewer for you, use r? to override) |
dtolnay
commented
Mar 19, 2022
@rust-lang/libs-api: impl<T:Clone,constN:usize>From<&[T;N]>forVec<T>{…}impl<T:Clone,constN:usize>From<&mut[T;N]>forVec<T>{…}These are array versions of the already-stable conversions from slice to vec. impl<T:Clone>From<&[T]>forVec<T>{…}// since 1.0.0impl<T:Clone>From<&mut[T]>forVec<T>{…}// since 1.19.0Array support is useful for methods that use error[E0277]: the trait bound `Vec<u8>: From<&[u8; 3]>` is not satisfied --> src/main.rs:2:36 |2 | let _ = std::ffi::CString::new(b"+\xff+"); | ---------------------- ^^^^^^^^^ the trait `From<&[u8; 3]>` is not implemented for `Vec<u8>` | | | required by a bound introduced by this call | = help: the following implementations were found: <Vec<u8> as From<&str>> <Vec<u8> as From<CString>> <Vec<u8> as From<String>> <Vec<T, A> as From<Box<[T], A>>> and 6 others = note: required because of the requirements on the impl of `Into<Vec<u8>>` for `&[u8; 3]`note: required by a bound in `CString::new` |
Team member @dtolnay has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
rfcbot
commented
Mar 21, 2022
🔔 This is now entering its final comment period, as per the review above. 🔔 |
dtolnay
commented
Mar 28, 2022
@bors r+ |
bors
commented
Mar 28, 2022
📌 Commit 5dd7027 has been approved by |
…olnay
impl From<&[T; N]> and From<&mut [T; N]> for Vec<T>
I really wanted to write:
```rust
fn example(a: impl Into<Vec<u8>>) {}
fn main() {
example(b"raw");
}
```Rollup of 4 pull requests Successful merges: - rust-lang#88375 (Clarify that ManuallyDrop<T> has same layout as T) - rust-lang#93755 (Allow comparing `Vec`s with different allocators using `==`) - rust-lang#95016 (Docs: make Vec::from_raw_parts documentation less strict) - rust-lang#95098 (impl From<&[T; N]> and From<&mut [T; N]> for Vec<T>) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
…e without reverting rust-lang#95098rust-lang#95098 introduces new `From` impls for `Vec`, which can break existing code that relies on inference when calling `.as_ref()`. This change explicitly carves out a bias in the inference machinery to keep existing code compiling, while still maintaining the new `From` impls. Reported in rust-lang#96074.
I really wanted to write: