about summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2023-09-18Stabilize `{IpAddr, Ipv6Addr}::to_canonical`Trevor Gross-10/+13
Make `IpAddr::to_canonical` and `IpV6Addr::to_canonical` stable, as well as const stabilize `Ipv6Addr::to_ipv4_mapped`. Newly stable API: impl IpAddr { // Now stable under `ip_to_canonical` const fn to_canonical(&self) -> IpAddr; } impl Ipv6Addr { // Now stable under `ip_to_canonical` const fn to_canonical(&self) -> IpAddr; // Already stable, this makes it const stable under // `const_ipv6_to_ipv4_mapped` const fn to_ipv4_mapped(&self) -> Option<Ipv4Addr> } These stabilize a subset of the following tracking issues: - https://github.com/rust-lang/rust/issues/27709 - https://github.com/rust-lang/rust/issues/76205
2023-09-18Rollup merge of #115494 - RalfJung:primitive_docs, r=Mark-SimulacrumMatthias Krüger-14/+11
get rid of duplicate primitive_docs Having this duplicate makes editing that file very annoying. And at least locally the generated docs still look perfectly fine...
2023-09-18Rollup merge of #109409 - WaffleLapkin:progamer, r=dtolnayMatthias Krüger-0/+85
Add `minmax{,_by,_by_key}` functions to `core::cmp` This PR adds the following functions: ```rust // mod core::cmp #![unstable(feature = "cmp_minmax")] pub fn minmax<T>(v1: T, v2: T) -> [T; 2] where T: Ord; pub fn minmax_by<T, F>(v1: T, v2: T, compare: F) -> [T; 2] where F: FnOnce(&T, &T) -> Ordering; pub fn minmax_by_key<T, F, K>(v1: T, v2: T, mut f: F) -> [T; 2] where F: FnMut(&T) -> K, K: Ord; ``` (they are also `const` under `#[feature(const_cmp)]`, I've omitted `const` stuff for simplicity/readability) ---- Semantically these functions are equivalent to `{ let mut arr = [v1, v2]; arr.sort(); arr }`, but since they operate on 2 elements only, they are implemented as a single comparison. Even though that's basically a sort, I think "sort 2 elements" operation is useful on it's own in many cases. Namely, it's a common pattern when you have 2 things, and need to know which one is smaller/bigger to operate on them differently. I've wanted such functions countless times, most recently in #109402, so I thought I'd propose them. ---- r? libs-api
2023-09-18Fill-in tracking issue for `feature(cmp_minmax)`Maybe Waffle-3/+3
2023-09-18Add `minmax*` functions to `core::cmp`Maybe Waffle-0/+85
2023-09-18get rid of duplicate primitive_docsRalf Jung-14/+11
2023-09-18Auto merge of #108043 - a1phyr:string_write_fmt, r=workingjubileebors-2/+22
Small wins for formatting-related code This PR does two small wins in fmt code: - Override `write_char` for `PadAdapter` to use inner buffer's `write_char` - Override some `write_fmt` implementations to avoid avoid the additional indirection and vtable generated by the default impl.
2023-09-18Auto merge of #115547 - WaffleLapkin:spin_looping, r=Mark-Simulacrumbors-24/+17
Simplify `core::hint::spin_loop` The grouping was inconsistent and not really helpful. r? t-libs
2023-09-17Specialize `fmt::Write::write_fmt` for `Sized` typesBenoît du Garreau-2/+22
2023-09-17Rollup merge of #115477 - kellerkindt:stabilized_int_impl, r=dtolnayDylan DPC-222/+218
Stabilize the `Saturating` type Closes #87920 Closes #92354 Stabilization report https://github.com/rust-lang/rust/issues/87920#issuecomment-1652346124 FCP https://github.com/rust-lang/rust/issues/87920#issuecomment-1676438885
2023-09-17Rollup merge of #115434 - soqb:ascii-char-manual-debug, r=dtolnayDylan DPC-2/+39
make `Debug` impl for `ascii::Char` match that of `char` # Objective use a more recognisable format for the `Debug` impl on `ascii::Char` than the derived one based off the enum variants. The alogorithm used is the following: - escape `ascii::Char::{Null, CharacterTabulation, CarraigeReturn, LineFeed, ReverseSolidus, Apostrophe}` to `'\0'`, `'\t'`, `'\r'`, `'\n'`, `'\\'` and `'\''` respectively. these are the same escape codes as `<char as Debug>::fmt` uses. - if `u8::is_ascii_control` is false, print the character wrapped in single quotes. - otherwise, print in the format `'\xAB'` where `A` and `B` are the hex nibbles of the byte. (`char` uses unicode escapes and this seems like the corresponding ascii format). Tracking issue: https://github.com/rust-lang/rust/issues/110998
2023-09-17Auto merge of #113748 - clarfonthey:ip-step, r=dtolnaybors-1/+66
impl Step for IP addresses ACP: rust-lang/libs-team#235 Note: since this is insta-stable, it requires an FCP. Separating out from the bit operations PR since it feels logically disjoint, and so their FCPs can be separate.
2023-09-17Auto merge of #115782 - a1phyr:improve_pad_adapter, r=dtolnaybors-0/+8
Improve `PadAdapter::write_char` Split from #108043
2023-09-16Rollup merge of #115560 - ShE3py:format-results, r=dtolnayMatthias Krüger-1/+1
Update doc for `alloc::format!` and `core::concat!` Closes #115551. Used comments instead of `assert!`s as [`std::fmt`](https://doc.rust-lang.org/std/fmt/index.html#usage) uses comments. Should all the str-related macros (`format!`, `format_args!`, `concat!`, `stringify!`, `println!`, `writeln!`, etc.) references each others? For instance, [`concat!`](https://doc.rust-lang.org/core/macro.concat.html) mentions that integers are stringified, but don't link to `stringify!`. `@rustbot` label +A-docs +A-fmt
2023-09-16Rollup merge of #115329 - xzmeng:fix-std-doc, r=dtolnayMatthias Krüger-3/+3
fix std::primitive doc: homogenous -> homogeneous replace "homogenous" with the more commonly used "homogeneous".
2023-09-16Auto merge of #112229 - clarfonthey:range-iter-count, r=dtolnaybors-0/+20
Specialize count for range iterators Since `size_hint` is already specialized, it feels apt to specialize `count` as well. Without any specialized version of `ExactSizeIterator::len` or `Step::steps_between`, this feels like a more reliable way of accessing this without having to rely on knowing that `size_hint` is correct. In my case, this is particularly useful to access the `steps_between` implementation for `char` from the standard library without having to compute it manually. I didn't think it was worth modifying the `Step` trait to add a version of `steps_between` that used native overflow checks since this is just doing one subtraction in most cases anyway, and so I decided to make the inclusive version use `checked_add` so it didn't have this lopsided overflow-checks-but-only-sometimes logic.
2023-09-16Rollup merge of #115607 - RalfJung:safe-traits-unsafe-code, r=dtolnayMatthias Krüger-0/+35
clarify that unsafe code must not rely on our safe traits This adds a disclaimer to PartialEq, Eq, PartialOrd, Ord, Hash, Deref, DerefMut. We already have a similar disclaimer in ExactSizeIterator (worded a bit differently): ``` /// Note that this trait is a safe trait and as such does *not* and *cannot* /// guarantee that the returned length is correct. This means that `unsafe` /// code **must not** rely on the correctness of [`Iterator::size_hint`]. The /// unstable and unsafe [`TrustedLen`](super::marker::TrustedLen) trait gives /// this additional guarantee. ``` If there are any other traits that should carry such a disclaimer, please let me know. Fixes https://github.com/rust-lang/rust/issues/73682
2023-09-16fix a comment about assert_receiver_is_total_eqRalf Jung-3/+3
2023-09-16Specialize count for range iteratorsltdk-0/+20
2023-09-16impl Step for IP addressesltdk-1/+66
2023-09-16Auto merge of #114494 - est31:extend_useless_ptr_null_checks, r=jackh726bors-1/+16
Make useless_ptr_null_checks smarter about some std functions This teaches the `useless_ptr_null_checks` lint that some std functions can't ever return null pointers, because they need to point to valid data, get references as input, etc. This is achieved by introducing an `#[rustc_never_returns_null_ptr]` attribute and adding it to these std functions (gated behind bootstrap `cfg_attr`). Later on, the attribute could maybe be used to tell LLVM that the returned pointer is never null. I don't expect much impact of that though, as the functions are pretty shallow and usually the input data is already never null. Follow-up of PR #113657 Fixes #114442
2023-09-16Auto merge of #115520 - Finomnis:const_transmute_copy, r=dtolnaybors-2/+1
Stabilize const_transmute_copy Closes #83165
2023-09-14Auto merge of #114656 - bossmc:rework-no-coverage-attr, r=oli-obkbors-3/+7
Rework `no_coverage` to `coverage(off)` As discussed at the tail of https://github.com/rust-lang/rust/issues/84605 this replaces the `no_coverage` attribute with a `coverage` attribute that takes sub-parameters (currently `off` and `on`) to control the coverage instrumentation. Allows future-proofing for things like `coverage(off, reason="Tested live", issue="#12345")` or similar.
2023-09-12Improve `PadAdapter::write_char`Benoît du Garreau-0/+8
2023-09-08Rollup merge of #115201 - notriddle:notriddle/type-alias-impl-list, ↵Guillaume Gomez-9/+9
r=GuillaumeGomez rustdoc: list matching impls on type aliases Fixes https://github.com/rust-lang/rust/issues/32077 Fixes #99952 Remake of https://github.com/rust-lang/rust/pull/112429 Partially reverts https://github.com/rust-lang/rust/pull/112543, but keeps the test case. This version of the PR avoids the infinite loop by structurally matching types instead of using full unification. This version does not support type alias trait bounds, but the compiler does not enforce those anyway (https://github.com/rust-lang/rust/issues/21903). r? `@GuillaumeGomez` CC `@lcnr`
2023-09-08Rollup merge of #104299 - mkrasnitski:discriminant-transmute-docs, r=oli-obkGuillaume Gomez-0/+5
Clarify stability guarantee for lifetimes in enum discriminants Since `std::mem::Discriminant` erases lifetimes, it should be clarified that changing the concrete value of a lifetime parameter does not change the value of an enum discriminant for a given variant. This is useful as it guarantees that it is safe to transmute `Discriminant<Foo<'a>>` to `Discriminant<Foo<'b>>` for any combination of `'a` and `'b`. This also holds for type-generics as long as the type parameters do not change, e.g. `Discriminant<Foo<T, 'a>>` can be transmuted to `Discriminant<Foo<T, 'b>>`. Side note: Is what I've written actually enough to imply soundness (or rather codify it), or should it specifically be spelled out that it's OK to transmute in the above way?
2023-09-08Partially outline code inside the panic! macroJohn Kåre Alsaker-1/+56
2023-09-08Rename the feature, but not the attribute, to `coverage_attribute`Andy Caldwell-2/+2
2023-09-08Rework no_coverage to coverage(off)Andy Caldwell-3/+7
2023-09-08Auto merge of #114299 - clarfonthey:char-min, r=dtolnay,BurntSushibors-1/+51
Add char::MIN ACP: rust-lang/libs-team#252 Tracking issue: #114298 r? `@rust-lang/libs-api`
2023-09-07Guarantee that Layout::align returns a non-zero power of twoJoshua Liebow-Feeser-0/+2
2023-09-07Auto merge of #115166 - Urgau:invalid_ref_casting-invalid-unsafecell-usage, ↵bors-0/+1
r=est31 Lint on invalid usage of `UnsafeCell::raw_get` in reference casting This PR proposes to take into account `UnsafeCell::raw_get` method call for non-Freeze types for the `invalid_reference_casting` lint. The goal of this is to catch those kind of invalid reference casting: ```rust fn as_mut<T>(x: &T) -> &mut T { unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *const _) } //~^ ERROR casting `&T` to `&mut T` is undefined behavior } ``` r? `@est31`
2023-09-06Fix minor grammar typoDarius Wiles-1/+1
2023-09-06clarify that unsafe code must not rely on our safe traitsRalf Jung-0/+35
2023-09-06Update doc for `alloc::format!` and `core::concat!`ShE3py-1/+1
2023-09-05Rollup merge of #114794 - RalfJung:swap-safety, r=m-ou-seMatthias Krüger-3/+9
clarify safety documentation of ptr::swap and ptr::copy Closes https://github.com/rust-lang/rust/issues/81005
2023-09-05fix a comment in std::iter::successorsJuly Tikhonov-1/+1
The `unfold` function have since been renamed to `from_fn`.
2023-09-05if -> whenRalf Jung-3/+3
2023-09-05Rollup merge of #115540 - cjgillot:custom-debuginfo, r=oli-obkMatthias Krüger-12/+27
Support debuginfo for custom MIR.
2023-09-05Rollup merge of #114813 - RalfJung:fpu-control, r=AmanieuMatthias Krüger-0/+12
explain why we can mutate the FPU control word This is usually not allowed (see https://github.com/rust-lang/stdarch/pull/1454), but here we have a special case.
2023-09-05Rollup merge of #114412 - RalfJung:libc-symbols, r=pnkfelixMatthias Krüger-5/+13
document our assumptions about symbols provided by the libc LLVM makes assumptions about `memcmp`, `memmove`, and `memset` that go beyond what the C standard guarantees -- see https://reviews.llvm.org/D86993. Since we use LLVM, we are inheriting these assumptions. With https://github.com/rust-lang/rust/pull/114382 we are also making a similar assumption about `memcmp`, so I added that to the list. Fixes https://github.com/rust-lang/unsafe-code-guidelines/issues/426.
2023-09-05Rollup merge of #113510 - ink-feather-org:const_ptr_transmute_docs, r=RalfJungMatthias Krüger-1/+4
Document soundness of Integer -> Pointer -> Integer conversions in `const` contexts. see this [zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/Soundness.20of.20Integer.20-.3E.20Pointer.20-.3E.20Integer.20conversions) r? `@RalfJung` With this slice `Iterator`'s should be able to be made const once the const Trait reimplementation is done.
2023-09-04Simplify `core::hint::spin_loop`Maybe Waffle-24/+17
2023-09-03Clarify ManuallyDrop bit validityJoshua Liebow-Feeser-6/+6
Clarify that `ManuallyDrop<T>` has the same bit validity as `T`.
2023-09-03Auto merge of #115491 - Zoxc:refcell-tweak, r=Mark-Simulacrumbors-2/+24
Outline panicking code for `RefCell::borrow` and `RefCell::borrow_mut` This outlines panicking code for `RefCell::borrow` and `RefCell::borrow_mut` to reduce code size.
2023-09-03Stabilize const_transmute_copyFinomnis-2/+1
2023-09-03Rollup merge of #115279 - schuelermine:patch/doc/RangeFull/remote-parens, ↵Matthias Krüger-1/+1
r=Mark-Simulacrum RangeFull: Remove parens around .. in documentation snippet I’ve removed unnecessary parentheses in a documentation snippet documenting `RangeFull`. It could’ve lead people to believe the parentheses were necessary.
2023-09-03support in-place collecting additional FlatMap shapesThe 8472-15/+59
2023-09-03Expand in-place iteration specialization to Flatten, FlatMap and ArrayChunksThe 8472-40/+272
2023-09-03Outline panicking code for `RefCell::borrow` and `RefCell::borrow_mut`John Kåre Alsaker-2/+24