Skip to content

Clarify Vec::extend_from_slice doc#151057

Open
tbu- wants to merge 1 commit intorust-lang:mainfrom
tbu-:pr_doc_vec_extendfromslice
Open

Clarify Vec::extend_from_slice doc#151057
tbu- wants to merge 1 commit intorust-lang:mainfrom
tbu-:pr_doc_vec_extendfromslice

Conversation

@tbu-
Copy link
Copy Markdown
Contributor

@tbu- tbu- commented Jan 13, 2026

Calling vec.extend(slice.iter().cloned()) calls the same code thanks to specialization.

I don't know of any plans to deprecate this method.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 13, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Jan 13, 2026

r? @joboet

rustbot has assigned @joboet.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@JayanAXHF JayanAXHF added the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label Jan 13, 2026
@tbu- tbu- force-pushed the pr_doc_vec_extendfromslice branch from 74bc6c2 to 77a2782 Compare January 13, 2026 17:09
@JayanAXHF JayanAXHF added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jan 13, 2026
Calling `vec.extend(slice.iter())` calls the same code thanks
to specialization.

I don't know of any plans to deprecate this method.
@tbu- tbu- force-pushed the pr_doc_vec_extendfromslice branch from 77a2782 to e82cec8 Compare January 22, 2026 14:03
@rust-log-analyzer
Copy link
Copy Markdown
Collaborator

The job aarch64-gnu-llvm-20-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[RUSTC-TIMING] panic_abort test:false 0.044
   Compiling cfg-if v1.0.4
[RUSTC-TIMING] cfg_if test:false 0.030
   Compiling rustc-demangle v0.1.26
error[E0271]: type mismatch resolving `<Iter<'_, T> as IntoIterator>::Item == T`
    --> library/alloc/src/vec/mod.rs:3436:21
     |
3371 | impl<T: Clone, A: Allocator> Vec<T, A> {
     |      - expected this type parameter
...
3436 |         self.extend(other.iter())
     |              ------ ^^^^^^^^^^^^ expected type parameter `T`, found `&T`
     |              |
     |              required by a bound introduced by this call
     |
     = note: expected type parameter `_`
                     found reference `&_`
note: the method call chain might not have had the expected associated types
    --> library/alloc/src/vec/mod.rs:3435:48
     |
3435 |     pub fn extend_from_slice(&mut self, other: &[T]) {
     |                                                ^^^^ `IntoIterator::Item` is `&T` here
3436 |         self.extend(other.iter())
     |                           ------ `IntoIterator::Item` remains `&T` here
note: required by a bound in `extend`
    --> library/core/src/iter/traits/collect.rs:413:31
     |
 413 |     fn extend<T: IntoIterator<Item = A>>(&mut self, iter: T);
     |                               ^^^^^^^^ required by this bound in `Extend::extend`

[RUSTC-TIMING] memchr test:false 1.338
   Compiling rustc-literal-escaper v0.0.7
[RUSTC-TIMING] rustc_literal_escaper test:false 0.190

@tbu-
Copy link
Copy Markdown
Contributor Author

tbu- commented Jan 22, 2026

Hmm, that fails the run. I guess I have to investigate a little more.

@joboet
Copy link
Copy Markdown
Member

joboet commented Feb 7, 2026

@rustbot author

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 7, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Feb 7, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Feb 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants