diff options
| author | bors <bors@rust-lang.org> | 2021-07-30 09:43:32 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-07-30 09:43:32 +0000 |
| commit | 1195bea5a7b73e079fa14b37ac7e375fc77d368a (patch) | |
| tree | a39e64e2b413b013cdf4889d73fa249343c49cc8 /library/alloc/src/string.rs | |
| parent | f739552870cdb23d433478739b371f22b155af8a (diff) | |
| parent | 84e18828d4450651cda6a6158cada7b503217a14 (diff) | |
| download | rust-1195bea5a7b73e079fa14b37ac7e375fc77d368a.tar.gz rust-1195bea5a7b73e079fa14b37ac7e375fc77d368a.zip | |
Auto merge of #87615 - JohnTitor:rollup-t5jpmrg, r=JohnTitor
Rollup of 10 pull requests Successful merges: - #87052 (Optimize fmt::PadAdapter::wrap) - #87522 (Fix assert in diy_float) - #87553 (Fix typo in rustc_driver::version) - #87554 (2229: Discr should be read when PatKind is Range) - #87564 (min_type_alias_impl_trait is going to be removed in 1.56) - #87574 (Update the examples in `String` and `VecDeque::retain`) - #87583 (Refactor compression cache in v0 symbol mangler) - #87585 (Add missing links for core::char types) - #87594 (fs File get_path procfs usage for netbsd same as linux.) - #87602 ([backtraces]: look for the `begin` symbol only after seeing `end`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library/alloc/src/string.rs')
| -rw-r--r-- | library/alloc/src/string.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index bc5ab3637ae..5411316f55a 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -1350,13 +1350,14 @@ impl String { /// assert_eq!(s, "foobar"); /// ``` /// - /// The exact order may be useful for tracking external state, like an index. + /// Because the elements are visited exactly once in the original order, + /// external state may be used to decide which elements to keep. /// /// ``` /// let mut s = String::from("abcde"); /// let keep = [false, true, true, false, true]; - /// let mut i = 0; - /// s.retain(|_| (keep[i], i += 1).0); + /// let mut iter = keep.iter(); + /// s.retain(|_| *iter.next().unwrap()); /// assert_eq!(s, "bce"); /// ``` #[inline] |
