-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
impl From<&[T; N]> and From<&mut [T; N]> for Vec<T> #95098
Conversation
r? @dtolnay (rust-highfive has picked a reviewer for you, use r? to override) |
@rust-lang/libs-api: impl<T: Clone, const N: usize> From<&[T; N]> for Vec<T> {…}
impl<T: Clone, const N: usize> From<&mut [T; N]> for Vec<T> {…} These are array versions of the already-stable conversions from slice to vec. impl<T: Clone> From<&[T]> for Vec<T> {…} // since 1.0.0
impl<T: Clone> From<&mut [T]> for Vec<T> {…} // since 1.19.0 Array 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. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
@bors r+ |
📌 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#95098 rust-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: