rust/library/core/src
bors 6672c16afc Auto merge of #121204 - cuviper:flatten-one-shot, r=the8472
Specialize flattening iterators with only one inner item

For iterators like `Once` and `option::IntoIter` that only ever have a
single item at most, the front and back iterator states in `FlatMap` and
`Flatten` are a waste, as they're always consumed already. We can use
specialization for these types to simplify the iterator methods.

It's a somewhat common pattern to use `flatten()` for options and
results, even recommended by [multiple][1] [clippy][2] [lints][3]. The
implementation is more efficient with `filter_map`, as mentioned in
[clippy#9377], but this new specialization should close some of that
gap for existing code that flattens.

[1]: https://rust-lang.github.io/rust-clippy/master/#filter_map_identity
[2]: https://rust-lang.github.io/rust-clippy/master/#option_filter_map
[3]: https://rust-lang.github.io/rust-clippy/master/#result_filter_map
[clippy#9377]: https://github.com/rust-lang/rust-clippy/issues/9377
2024-02-17 20:18:54 +00:00
..
alloc Add information about allocation lifetime to Allocator::allocate 2024-02-13 14:12:51 +00:00
array Replace NonZero::<_>::new with NonZero::new. 2024-02-15 08:09:42 +01:00
ascii implement Default for AsciiChar 2024-02-13 12:04:44 +01:00
async_iter Step all bootstrap cfgs forward 2024-02-08 07:44:34 -05:00
cell Add some optimizations 2023-10-13 14:54:33 +02:00
char Use generic NonZero internally. 2024-02-15 08:09:42 +01:00
cmp Use generic NonZero internally. 2024-02-15 08:09:42 +01:00
convert Add #[track_caller] to the "From implies Into" impl 2024-01-10 10:30:54 +01:00
ffi Rollup merge of #119449 - Nilstrieb:library-clippy, r=cuviper 2024-02-11 08:25:42 +01:00
fmt Remove dead codes in core 2023-12-12 07:03:37 +00:00
future Replace some usage of #[rustc_on_unimplemented] with 2024-01-05 15:23:09 +01:00
hash Add insta-stable std:#️⃣:{DefaultHasher, RandomState} exports 2023-11-02 20:35:20 -04:00
intrinsics various docs tweaks 2024-02-10 10:19:57 +01:00
io Auto merge of #120741 - a1phyr:safe_buffer_advance, r=m-ou-se 2024-02-17 00:23:15 +00:00
iter Clarify the flatten specialization comment 2024-02-16 16:08:01 -08:00
macros Rollup merge of #111106 - Stargateur:doc/format_args, r=m-ou-se 2024-02-15 09:20:16 +01:00
mem Auto merge of #116385 - kornelski:maybe-rename, r=Amanieu 2024-02-16 14:11:10 +00:00
net Auto merge of #116385 - kornelski:maybe-rename, r=Amanieu 2024-02-16 14:11:10 +00:00
num Auto merge of #120563 - reitermarkus:generic-nonzero-get, r=dtolnay 2024-02-17 02:30:53 +00:00
ops Replace NonZero::<_>::new with NonZero::new. 2024-02-15 08:09:42 +01:00
panic Replace some usage of #[rustc_on_unimplemented] with 2024-01-05 15:23:09 +01:00
prelude Revert "Remove #[alloc_error_handler] from the compiler and library" 2023-04-25 00:08:35 +02:00
ptr Replace NonZero::<_>::new with NonZero::new. 2024-02-15 08:09:42 +01:00
slice Add examples to document the return type of select_nth_unstable, select_nth_unstable_by, and select_nth_unstable_by_key. 2024-02-16 09:20:51 -05:00
str Auto merge of #120486 - reitermarkus:use-generic-nonzero, r=dtolnay 2024-02-16 07:46:31 +00:00
sync Clarified docs on non-atomic oprations on owned/mut refs to atomics 2024-02-14 20:14:45 +00:00
task Auto merge of #119863 - tmiasko:will-wake, r=m-ou-se 2024-02-15 14:43:29 +00:00
unicode Bump Unicode to version 15.1.0, regenerate tables 2024-02-09 17:35:46 +01:00
any.rs update version placeholders 2023-12-22 11:01:42 +01:00
arch.rs use visibility to check unused imports and delete some stmts 2023-10-22 21:27:46 +08:00
ascii.rs Use generic NonZero internally. 2024-02-15 08:09:42 +01:00
asserting.rs [RFC 2011] Library code 2022-05-22 07:18:32 -03:00
bool.rs core is now compilable 2023-04-16 07:20:26 +00:00
borrow.rs doc: replace wrong punctuation mark 2023-07-28 14:46:17 +02:00
cell.rs Cleanup around the new assert_unsafe_precondition 2024-02-11 12:35:44 -05:00
clone.rs remove redundant imports 2023-12-10 10:56:22 +08:00
cmp.rs Rollup merge of #115386 - RalfJung:partial-eq-chain, r=dtolnay 2024-02-05 11:07:25 +01:00
default.rs implement Default for AsciiChar 2024-02-13 12:04:44 +01:00
error.md Fix minor grammar typo 2023-09-06 09:47:22 -07:00
error.rs Spelling fix 2024-01-20 18:27:55 +00:00
escape.rs Use generic NonZero internally. 2024-02-15 08:09:42 +01:00
hint.rs Rewrite assert_unsafe_precondition around the new intrinsic 2024-02-08 11:52:14 -05:00
internal_macros.rs add track_caller for arith ops 2023-11-24 00:54:06 +08:00
intrinsics.rs Give the (un)likely intrinsics fallback bodies 2024-02-16 22:26:01 +00:00
lib.rs Step all bootstrap cfgs forward 2024-02-08 07:44:34 -05:00
marker.rs Step all bootstrap cfgs forward 2024-02-08 07:44:34 -05:00
option.rs Rollup merge of #119449 - Nilstrieb:library-clippy, r=cuviper 2024-02-11 08:25:42 +01:00
panic.rs merge core_panic feature into panic_internals 2023-12-09 14:49:00 +01:00
panicking.rs merge core_panic feature into panic_internals 2023-12-09 14:49:00 +01:00
pin.rs Rename pointer field on Pin 2024-01-16 14:58:42 -05:00
primitive.rs
primitive_docs.rs Rollup merge of #120880 - RalfJung:vtable-fnptr-partialeq, r=cuviper 2024-02-11 23:19:09 +01:00
result.rs Improve Option::inspect docs 2024-02-09 09:53:30 -06:00
time.rs Rollup merge of #120307 - djc:duration-constructors, r=Mark-Simulacrum 2024-02-11 08:25:42 +01:00
tuple.rs Rollup merge of #118307 - scottmcm:tuple-eq-simpler, r=joshtriplett 2024-02-11 08:25:41 +01:00
unit.rs Use implicit capture syntax in format_args 2022-03-10 10:23:40 -05:00