-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Vec::extend_from_slice
’s documentation forgot about the difference of T: Clone
vs. T: Copy
bounds.
#97119
Comments
Vec::extend_from_slice
forgot about the difference of T: Clone
vs. T: Copy
bounds.Vec::extend_from_slice
’s documentation forgot about the difference of T: Clone
vs. T: Copy
bounds.
FWIW, rust-lang/rfcs#839 debated whether |
Interesting discussion to read, thanks for the link. I agree with your observation that the supposedly backwards compatible change that it ended on would be breaking; |
I thought we have a policy that adding new impls isn't considered a breaking change? I guess relaxing a bound is technically not the same as adding an impl but it seems effectively the same ... |
There's a difference between adding new impls for concrete types, which can't conflict downstream but may cause call ambiguity, versus adding or expanding a generic impl that could conflict with downstream impls. |
The following program demonstrated the difference: #[derive(Clone, Copy)]
struct Copyable;
#[derive(Clone)]
struct Clonable;
fn main() {
let mut vec = Vec::<Copyable>::new();
let array = [Copyable; 3];
let slice = &array[..];
vec.extend_from_slice(slice);
vec.extend(array);
vec.extend(slice);
let mut vec = Vec::<Clonable>::new();
let array = [const {Clonable}; 3];
let slice = &array[..];
vec.extend_from_slice(slice);
vec.extend(array);
// this will not work, because it expects an iterator that yields Clonable,
// but the iterator from this slice will yield &Clonable.
vec.extend(slice);
}
I suppose we could say something about extend not working with slices that are not Copyable.. |
Doc difference between extend and extend_from_slice fixes rust-lang#97119
Doc difference between extend and extend_from_slice fixes rust-lang#97119
Doc difference between extend and extend_from_slice fixes rust-lang#97119
Rollup merge of rust-lang#135983 - hkBst:patch-13, r=jhpratt Doc difference between extend and extend_from_slice fixes rust-lang#97119
Quoting from https://doc.rust-lang.org/nightly/std/vec/struct.Vec.html#method.extend_from_slice
But
Vec::extend_from_slice
supports&[T]
forT: Clone
, whereasVec::extend
only supportsimpl Iterator<Item = &T>
ifT: Copy
, so it’s not the same.The text was updated successfully, but these errors were encountered: