Skip to content

Commit 0bbfcd0

Browse files
committed
Auto merge of rust-lang#79994 - JohnTitor:rollup-43wl2uj, r=JohnTitor
Rollup of 12 pull requests Successful merges: - rust-lang#79360 (std::iter: document iteration over `&T` and `&mut T`) - rust-lang#79398 (Link loop/for keyword) - rust-lang#79834 (Remove deprecated linked_list_extras methods.) - rust-lang#79845 (Fix rustup support in default_build_triple for python3) - rust-lang#79940 (fix more clippy::complexity findings) - rust-lang#79942 (Add post-init hook for static memory for miri.) - rust-lang#79954 (Fix building compiler docs with stage 0) - rust-lang#79963 (Fix typo in `DebruijnIndex` documentation) - rust-lang#79970 (Misc rustbuild improvements when the LLVM backend isn't used) - rust-lang#79973 (rustdoc light theme: Fix CSS for selected buttons) - rust-lang#79984 (Remove an unused dependency that made `rustdoc` crash) - rust-lang#79985 (Fixes submit event of the search input) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 13ce500 + 8bb951c commit 0bbfcd0

File tree

3 files changed

+55
-62
lines changed

3 files changed

+55
-62
lines changed

alloc/src/collections/linked_list.rs

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,68 +1099,6 @@ impl<T> ExactSizeIterator for IterMut<'_, T> {}
10991099
#[stable(feature = "fused", since = "1.26.0")]
11001100
impl<T> FusedIterator for IterMut<'_, T> {}
11011101

1102-
impl<T> IterMut<'_, T> {
1103-
/// Inserts the given element just after the element most recently returned by `.next()`.
1104-
/// The inserted element does not appear in the iteration.
1105-
///
1106-
/// This method will be removed soon.
1107-
#[inline]
1108-
#[unstable(
1109-
feature = "linked_list_extras",
1110-
reason = "this is probably better handled by a cursor type -- we'll see",
1111-
issue = "27794"
1112-
)]
1113-
#[rustc_deprecated(
1114-
reason = "Deprecated in favor of CursorMut methods. This method will be removed soon.",
1115-
since = "1.47.0"
1116-
)]
1117-
pub fn insert_next(&mut self, element: T) {
1118-
match self.head {
1119-
// `push_back` is okay with aliasing `element` references
1120-
None => self.list.push_back(element),
1121-
Some(head) => unsafe {
1122-
let prev = match head.as_ref().prev {
1123-
// `push_front` is okay with aliasing nodes
1124-
None => return self.list.push_front(element),
1125-
Some(prev) => prev,
1126-
};
1127-
1128-
let node = Some(
1129-
Box::leak(box Node { next: Some(head), prev: Some(prev), element }).into(),
1130-
);
1131-
1132-
// Not creating references to entire nodes to not invalidate the
1133-
// reference to `element` we handed to the user.
1134-
(*prev.as_ptr()).next = node;
1135-
(*head.as_ptr()).prev = node;
1136-
1137-
self.list.len += 1;
1138-
},
1139-
}
1140-
}
1141-
1142-
/// Provides a reference to the next element, without changing the iterator.
1143-
///
1144-
/// This method will be removed soon.
1145-
#[inline]
1146-
#[unstable(
1147-
feature = "linked_list_extras",
1148-
reason = "this is probably better handled by a cursor type -- we'll see",
1149-
issue = "27794"
1150-
)]
1151-
#[rustc_deprecated(
1152-
reason = "Deprecated in favor of CursorMut methods. This method will be removed soon.",
1153-
since = "1.47.0"
1154-
)]
1155-
pub fn peek_next(&mut self) -> Option<&mut T> {
1156-
if self.len == 0 {
1157-
None
1158-
} else {
1159-
unsafe { self.head.as_mut().map(|node| &mut node.as_mut().element) }
1160-
}
1161-
}
1162-
}
1163-
11641102
/// A cursor over a `LinkedList`.
11651103
///
11661104
/// A `Cursor` is like an iterator, except that it can freely seek back-and-forth.

core/src/iter/mod.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,51 @@
206206
//! 2. If you're creating a collection, implementing [`IntoIterator`] for it
207207
//! will allow your collection to be used with the `for` loop.
208208
//!
209+
//! # Iterating by reference
210+
//!
211+
//! Since [`into_iter()`] takes `self` by value, using a `for` loop to iterate
212+
//! over a collection consumes that collection. Often, you may want to iterate
213+
//! over a collection without consuming it. Many collections offer methods that
214+
//! provide iterators over references, conventionally called `iter()` and
215+
//! `iter_mut()` respectively:
216+
//!
217+
//! ```
218+
//! let mut values = vec![41];
219+
//! for x in values.iter_mut() {
220+
//! *x += 1;
221+
//! }
222+
//! for x in values.iter() {
223+
//! assert_eq!(*x, 42);
224+
//! }
225+
//! assert_eq!(values.len(), 1); // `values` is still owned by this function.
226+
//! ```
227+
//!
228+
//! If a collection type `C` provides `iter()`, it usually also implements
229+
//! `IntoIterator` for `&C`, with an implementation that just calls `iter()`.
230+
//! Likewise, a collection `C` that provides `iter_mut()` generally implements
231+
//! `IntoIterator` for `&mut C` by delegating to `iter_mut()`. This enables a
232+
//! convenient shorthand:
233+
//!
234+
//! ```
235+
//! let mut values = vec![41];
236+
//! for x in &mut values { // same as `values.iter_mut()`
237+
//! *x += 1;
238+
//! }
239+
//! for x in &values { // same as `values.iter()`
240+
//! assert_eq!(*x, 42);
241+
//! }
242+
//! assert_eq!(values.len(), 1);
243+
//! ```
244+
//!
245+
//! While many collections offer `iter()`, not all offer `iter_mut()`. For
246+
//! example, mutating the keys of a [`HashSet<T>`] or [`HashMap<K, V>`] could
247+
//! put the collection into an inconsistent state if the key hashes change, so
248+
//! these collections only offer `iter()`.
249+
//!
250+
//! [`into_iter()`]: IntoIterator::into_iter
251+
//! [`HashSet<T>`]: ../../std/collections/struct.HashSet.html
252+
//! [`HashMap<K, V>`]: ../../std/collections/struct.HashMap.html
253+
//!
209254
//! # Adapters
210255
//!
211256
//! Functions which take an [`Iterator`] and return another [`Iterator`] are

std/src/keyword_docs.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,12 @@ mod fn_keyword {}
565565
///
566566
/// For more information on for-loops, see the [Rust book] or the [Reference].
567567
///
568+
/// See also, [`loop`], [`while`].
569+
///
568570
/// [`in`]: keyword.in.html
569571
/// [`impl`]: keyword.impl.html
572+
/// [`loop`]: keyword.loop.html
573+
/// [`while`]: keyword.while.html
570574
/// [higher-ranked trait bounds]: ../reference/trait-bounds.html#higher-ranked-trait-bounds
571575
/// [Rust book]:
572576
/// ../book/ch03-05-control-flow.html#looping-through-a-collection-with-for
@@ -842,6 +846,8 @@ mod let_keyword {}
842846
///
843847
/// For more information on `while` and loops in general, see the [reference].
844848
///
849+
/// See also, [`for`], [`loop`].
850+
///
845851
/// [`for`]: keyword.for.html
846852
/// [`loop`]: keyword.loop.html
847853
/// [reference]: ../reference/expressions/loop-expr.html#predicate-loops
@@ -890,6 +896,10 @@ mod while_keyword {}
890896
///
891897
/// For more information on `loop` and loops in general, see the [Reference].
892898
///
899+
/// See also, [`for`], [`while`].
900+
///
901+
/// [`for`]: keyword.for.html
902+
/// [`while`]: keyword.while.html
893903
/// [Reference]: ../reference/expressions/loop-expr.html
894904
mod loop_keyword {}
895905

0 commit comments

Comments
 (0)