summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2021-03-22Expose str::SplitInclusiveMark Rousskov-1/+1
2021-02-06Rollup merge of #81580 - rodrimati1992:patch-2, r=dtolnayMara Bos-4/+35
Document how `MaybeUninit<Struct>` can be initialized.
2021-02-06Rollup merge of #80011 - Stupremee:stabilize-peekable-next-if, r=dtolnayMara Bos-5/+2
Stabilize `peekable_next_if` This PR stabilizes the `peekable_next_if` feature Resolves #72480
2021-02-05Bump peekable_next_if to rust 1.51.0David Tolnay-2/+2
2021-02-05Rollup merge of #81767 - exrook:layout-error-stability, r=Mark-SimulacrumMara Bos-4/+4
Update LayoutError/LayoutErr stability attributes `LayoutError` ended up not making it into 1.49.0, updating the stability attributes to reflect that. I also pushed `LayoutErr` deprecation back a release to allow 2 releases before the deprecation comes into effect. This change should be backported to beta.
2021-02-05Rollup merge of #81730 - RustyYato:object-safe-allocator, r=AmanieuMara Bos-1/+4
Make `Allocator` object-safe This allows rust-lang/wg-allocators#83: polymorphic allocators
2021-02-04Update LayoutError/LayoutErr stability attributesJacob Hughes-4/+4
2021-02-04Rollup merge of #81727 - m-ou-se:unstabilize-bits, r=Mark-SimulacrumMara Bos-2/+4
Revert stabilizing integer::BITS. We agreed in the libs meeting just now to revert stablization, since the [breakage](https://github.com/rust-lang/rust/issues/81654) is significant throughout the ecosystem, through `lexical-core`. cc https://github.com/rust-lang/rust/issues/76904 Fixes https://github.com/rust-lang/rust/issues/81654
2021-02-04Rollup merge of #81645 - m-ou-se:panic-lint, r=estebank,flip1995Mara Bos-7/+8
Add lint for `panic!(123)` which is not accepted in Rust 2021. This extends the `panic_fmt` lint to warn for all cases where the first argument cannot be interpreted as a format string, as will happen in Rust 2021. It suggests to add `"{}",` to format the message as a string. In the case of `std::panic!()`, it also suggests the recently stabilized `std::panic::panic_any()` function as an alternative. It renames the lint to `non_fmt_panic` to match the lint naming guidelines. ![image](https://user-images.githubusercontent.com/783247/106520928-675ea680-64d5-11eb-81f7-d8fa48b93a0b.png) This is part of #80162. r? ```@estebank```
2021-02-04Stabilize feature(iterator_fold_self): Iterator::reduceMara Bos-3/+1
2021-02-04Improve documentation of Iterator::{fold, reduce}.Mara Bos-5/+16
2021-02-04Rename Iterator::fold_first to reduce.Mara Bos-4/+4
2021-02-03make Allocator object-safeRustyYato-1/+4
add test to ensure object-safety This allows for runtime polymorphic allocators
2021-02-03Update panic!() documentation about non-string panics.Mara Bos-7/+8
2021-02-03Revert stabilizing integer::BITS.Mara Bos-2/+4
2021-02-03Rollup merge of #81573 - ehuss:cell-links, r=jackh726Guillaume Gomez-20/+24
Add some links to the cell docs. This adds a few links to the cell module docs to make it a little easier to navigate to the types and functions it references.
2021-02-03Rollup merge of #81144 - nhwn:typo-map-while, r=jackh726Guillaume Gomez-1/+1
Fixed formatting typo in map_while docs changes `` ` None` `` to ``[`None`]`` for consistency
2021-02-02Rollup merge of #81647 - m-ou-se:assert-2021-fix, r=petrochenkovJack Huey-1/+1
Fix bug with assert!() calling the wrong edition of panic!(). The span of `panic!` produced by the `assert` macro did not carry the right edition. This changes `assert` to call the right version. Also adds tests for the 2021 edition of panic and assert, that would've caught this.
2021-02-02Rollup merge of #81588 - xfix:delete-doc-alias, r=Mark-SimulacrumJack Huey-0/+1
Add doc aliases for "delete" This patch adds doc aliases for "delete". The added aliases are supposed to reference usages `delete` in other programming languages. - `HashMap::remove`, `BTreeMap::remove` -> `Map#delete` and `delete` keyword in JavaScript. - `HashSet::remove`, `BTreeSet::remove` -> `Set#delete` in JavaScript. - `mem::drop` -> `delete` keyword in C++. - `fs::remove_file`, `fs::remove_dir`, `fs::remove_dir_all`-> `File#delete` in Java, `File#delete` and `Dir#delete` in Ruby. Before this change, searching for "delete" in documentation returned no results.
2021-02-02Auto merge of #80843 - Mark-Simulacrum:fmt-bump, r=petrochenkovbors-2/+4
Bump rustfmt version
2021-02-02Bump rustfmt versionMark Rousskov-2/+4
Also switches on formatting of the mir build module
2021-02-02Rollup merge of #81599 - sdroege:fuse-trusted-len, r=m-ou-seJonas Schievink-1/+14
Implement `TrustedLen` for `Fuse<I: TrustedLen>` This looks like it was simply forgotten.
2021-02-01Fix bug with assert!() calling the wrong edition of panic!().Mara Bos-1/+1
The span of `panic!` produced by the `assert` macro did not carry the right edition. This changes `assert` to call the right version.
2021-02-01Auto merge of #80851 - m-ou-se:panic-2021, r=petrochenkovbors-1/+51
Implement Rust 2021 panic This implements the Rust 2021 versions of `panic!()`. See https://github.com/rust-lang/rust/issues/80162 and https://github.com/rust-lang/rfcs/pull/3007. It does so by replacing `{std, core}::panic!()` by a bulitin macro that expands to either `$crate::panic::panic_2015!(..)` or `$crate::panic::panic_2021!(..)` depending on the edition of the caller. This does not yet make std's panic an alias for core's panic on Rust 2021 as the RFC proposes. That will be a separate change: https://github.com/rust-lang/rust/pull/80879/commits/c5273bdfb266c35e8eab9413aa8d58d27fdbe114 That change is blocked on figuring out what to do with https://github.com/rust-lang/rust/issues/80846 first.
2021-02-01Implement `TrustedLen` for `iter::Fuse<I: TrustedLen>`Sebastian Dröge-1/+9
2021-02-01Add SAFETY comment for the `TrustedRandomAccess` impl of `iter::Fuse`Sebastian Dröge-0/+5
2021-01-31Update comment about leakingrodrimati1992-1/+1
2021-01-31stabilize int_bits_constAshley Mannix-4/+2
2021-01-31Add doc aliases for "delete"Konrad Borowski-0/+1
This patch adds doc aliases for "delete". The added aliases are supposed to reference usages `delete` in other programming languages. - `HashMap::remove`, `BTreeMap::remove` -> `Map#delete` and `delete` keyword in JavaScript. - `HashSet::remove`, `BTreeSet::remove` -> `Set#delete` in JavaScript. - `mem::drop` -> `delete` keyword in C++. - `fs::remove_file`, `fs::remove_dir`, `fs::remove_dir_all` -> `File#delete` in Java, `File#delete` and `Dir#delete` in Ruby. Before this change, searching for "delete" in documentation returned no results.
2021-01-31Update maybe_uninit.rsrodrimati1992-1/+1
2021-01-31Removed trailing whitespacerodrimati1992-7/+7
2021-01-31Document how `MaybeUninit<Struct>` can be initialized.rodrimati1992-4/+35
2021-01-31Rollup merge of #81562 - the8472:improve-inplaceiterable-docs, r=sfacklerJonas Schievink-3/+5
Clarify that InPlaceIterable guarantees extend to all advancing iterator methods. A documentation update that should answer a question that came up in [this zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Safety.20guarantees.20of.20InPlaceIterable/near/223743336) CC `@SkiFire13`
2021-01-31Rollup merge of #81484 - Kogia-sima:perf/optimize-udiv_1e19, r=nagisaJonas Schievink-19/+36
Optimize decimal formatting of 128-bit integers ## Description This PR optimizes the `udivmod_1e19` function, which is used for formatting 128-bit integers, based on the algorithm provided in \[1\]. This optimization improves performance of formatting 128-bit integers, especially on 64-bit architectures. It also slightly reduces the output binary size. ## Assembler comparison https://godbolt.org/z/YrG5zY ## Performance #### previous results ``` test fmt::write_u128_max ... bench: 552 ns/iter (+/- 4) test fmt::write_u128_min ... bench: 125 ns/iter (+/- 2) ``` #### new results ``` test fmt::write_u128_max ... bench: 205 ns/iter (+/- 13) test fmt::write_u128_min ... bench: 129 ns/iter (+/- 5) ``` ## Reference \[1\] T. Granlund and P. Montgomery, “Division by Invariant Integers Using Multiplication” in Proc. of the SIGPLAN94 Conference on Programming Language Design and Implementation, 1994, pp. 61–72
2021-01-31Rollup merge of #81198 - dtolnay:partialeq, r=m-ou-seJonas Schievink-6/+10
Remove requirement that forces symmetric and transitive PartialEq impls to exist ### Counterexample of symmetry: If you [have](https://docs.rs/proc-macro2/1.0.24/proc_macro2/struct.Ident.html#impl-PartialEq%3CT%3E) an impl like: ```rust impl<T> PartialEq<T> for Ident where T: ?Sized + AsRef<str> ``` then Rust will not even allow the symmetric impl to exist. ```console error[E0210]: type parameter `T` must be covered by another type when it appears before the first local type (`Ident`) --> src/main.rs:9:6 | 9 | impl<T> PartialEq<Ident> for T where T: ?Sized + AsRef<str> { | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Ident`) | = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type = note: in this case, 'before' refers to the following order: `impl<..> ForeignTrait<T1, ..., Tn> for T0`, where `T0` is the first and `Tn` is the last ``` <br> ### Counterexample of transitivity: Consider these two existing impls from `regex` and `clap`: ```rust // regex /// An inline representation of `Option<char>`. pub struct Char(u32); impl PartialEq<char> for Char { fn eq(&self, other: &char) -> bool { self.0 == *other as u32 } } ``` ```rust // clap pub(crate) enum KeyType { Short(char), Long(OsString), Position(u64), } impl PartialEq<char> for KeyType { fn eq(&self, rhs: &char) -> bool { match self { KeyType::Short(c) => c == rhs, _ => false, } } } ``` It's nice to be able to add `PartialEq<proc_macro::Punct> for char` in libproc_macro (https://github.com/rust-lang/rust/pull/80595), but it makes no sense to force an `impl PartialEq<Punct> for Char` and `impl PartialEq<Punct> for KeyType` in `regex` and `clap` in code that otherwise has nothing to do with proc macros. <br> `@rust-lang/libs`
2021-01-31Rollup merge of #81048 - yoshuawuyts:stabilize-core-slice-fill-with, r=m-ou-seJonas Schievink-3/+2
Stabilize `core::slice::fill_with` _Tracking issue: https://github.com/rust-lang/rust/issues/79221_ This stabilizes the `slice_fill_with` feature for Rust 1.51, following the stabilization of `slice_fill` in 1.50. This was requested by libs team members in https://github.com/rust-lang/rust/pull/79213. This PR also adds the "memset" alias for `slice::fill_with`, mirroring the alias set on the `slice::fill` sibling API. This will ensure someone looking for "memset" will find both variants. r? `@Amanieu`
2021-01-31Rollup merge of #80470 - SimonSapin:array-intoiter-type, r=m-ou-seJonas Schievink-8/+19
Stabilize by-value `[T; N]` iterator `core::array::IntoIter` Tracking issue: https://github.com/rust-lang/rust/issues/65798 This is unblocked now that `min_const_generics` has been stabilized in https://github.com/rust-lang/rust/pull/79135. This PR does *not* include the corresponding `IntoIterator` impl, which is https://github.com/rust-lang/rust/pull/65819. Instead, an iterator can be constructed through the `new` method. `new` would become unnecessary when `IntoIterator` is implemented and might be deprecated then, although it will stay stable.
2021-01-31Rollup merge of #80279 - Yaulendil:str-as-mut, r=m-ou-seJonas Schievink-0/+8
Implement missing `AsMut<str>` for `str` Allows `&mut str` to be taken by a Generic which requires `T` such that `T: AsMut<str>`. Motivating example: ```rust impl<'i, T> From<T> for StructImmut<'i> where T: AsRef<str> + 'i, { fn from(asref: T) -> Self { let string: &str = asref.as_ref(); // ... } } impl<'i, T> From<T> for StructMut<'i> where T: AsMut<str> + 'i, { fn from(mut asmut: T) -> Self { let string: &mut str = asmut.as_mut(); // ... } } ``` The Immutable form of this structure can be constructed by `StructImmut::from(s)` where `s` may be a `&String` or a `&str`, because `AsRef<str>` is implemented for `str`. However, the mutable form of the structure can be constructed in the same way **only** with a `&mut String`, and **not** with a `&mut str`. This change does have some precedent, because as can be seen in [the Implementors](https://doc.rust-lang.org/std/convert/trait.AsMut.html#implementors), `AsMut<[T]>` is implemented for `[T]` as well as for `Vec<T>`, but `AsMut<str>` is implemented only for `String`. This would complete the symmetry. As a trait implementation, this should be immediately stable.
2021-01-30Add some links to the cell docs.Eric Huss-20/+24
2021-01-30Bump as_mut_str_for_str stable version.Mara Bos-1/+1
2021-01-30Clarify that guarantees extend to other advancing iterator methods.The8472-3/+5
2021-01-30Rollup merge of #81409 - gilescope:chars_count, r=joshtriplettYuki Okushi-6/+1
Slight simplification of chars().count() Slight simplification: No need to call len(), we can just count the number of non continuation bytes. I can't see any reason not to do this, can you?
2021-01-30Rollup merge of #80959 - jhpratt:unsigned_abs-stabilization, r=m-ou-seYuki Okushi-3/+3
Stabilize `unsigned_abs` Resolves #74913. This PR stabilizes the `i*::unsigned_abs()` method, which returns the absolute value of an integer _as its unsigned equivalent_. This has the advantage that it does not overflow on `i*::MIN`. I have gone ahead and used this in a couple locations throughout the repository.
2021-01-30Rollup merge of #80886 - RalfJung:stable-raw-ref-macros, r=m-ou-seYuki Okushi-13/+10
Stabilize raw ref macros This stabilizes `raw_ref_macros` (https://github.com/rust-lang/rust/issues/73394), which is possible now that https://github.com/rust-lang/rust/issues/74355 is fixed. However, as I already said in https://github.com/rust-lang/rust/issues/73394#issuecomment-751342185, I am not particularly happy with the current names of the macros. So I propose we also change them, which means I am proposing to stabilize the following in `core::ptr`: ```rust pub macro const_addr_of($e:expr) { &raw const $e } pub macro mut_addr_of($e:expr) { &raw mut $e } ``` The macro name change means we need another round of FCP. Cc `````@rust-lang/libs````` Fixes #73394
2021-01-30Rollup merge of #79023 - yoshuawuyts:stream, r=KodrAusYuki Okushi-0/+239
Add `core::stream::Stream` [[Tracking issue: #79024](https://github.com/rust-lang/rust/issues/79024)] This patch adds the `core::stream` submodule and implements `core::stream::Stream` in accordance with [RFC2996](https://github.com/rust-lang/rfcs/pull/2996). The RFC hasn't been merged yet, but as requested by the libs team in https://github.com/rust-lang/rfcs/pull/2996#issuecomment-725696389 I'm filing this PR to get the ball rolling. ## Documentatation The docs in this PR have been adapted from [`std::iter`](https://doc.rust-lang.org/std/iter/index.html), [`async_std::stream`](https://docs.rs/async-std/1.7.0/async_std/stream/index.html), and [`futures::stream::Stream`](https://docs.rs/futures/0.3.8/futures/stream/trait.Stream.html). Once this PR lands my plan is to follow this up with PRs to add helper methods such as `stream::repeat` which can be used to document more of the concepts that are currently missing. That will allow us to cover concepts such as "infinite streams" and "laziness" in more depth. ## Feature gate The feature gate for `Stream` is `stream_trait`. This matches the `#[lang = "future_trait"]` attribute name. The intention is that only the APIs defined in RFC2996 will use this feature gate, with future additions such as `stream::repeat` using their own feature gates. This is so we can ensure a smooth path towards stabilizing the `Stream` trait without needing to stabilize all the APIs in `core::stream` at once. But also don't start expanding the API until _after_ stabilization, as was the case with `std::future`. __edit:__ the feature gate has been changed to `async_stream` to match the feature gate proposed in the RFC. ## Conclusion This PR introduces `core::stream::{Stream, Next}` and re-exports it from `std` as `std::stream::{Stream, Next}`. Landing `Stream` in the stdlib has been a mult-year process; and it's incredibly exciting for this to finally happen! --- r? `````@KodrAus````` cc/ `````@rust-lang/wg-async-foundations````` `````@rust-lang/libs`````
2021-01-29rename raw_const/mut -> const/mut_addr_of, and stabilize themRalf Jung-13/+10
2021-01-29Rollup merge of #81306 - SkiFire13:fuse-flatten, r=cuviperYuki Okushi-2/+14
Fuse inner iterator in FlattenCompat and improve related tests Fixes #81248
2021-01-29Optimize udiv_1e19() functionKogia-sima-19/+36
2021-01-28Rollup merge of #81277 - flip1995:from_diag_items, r=matthewjasperYuki Okushi-0/+3
Make more traits of the From/Into family diagnostic items Following traits are now diagnostic items: - `From` (unchanged) - `Into` - `TryFrom` - `TryInto` This also adds symbols for those items: - `into_trait` - `try_from_trait` - `try_into_trait` Related: https://github.com/rust-lang/rust-clippy/pull/6620#discussion_r562482587
2021-01-26Same instructions, but simpler.Giles Cope-1/+1