about summary refs log tree commit diff
path: root/library/core/src/num/nonzero.rs
AgeCommit message (Collapse)AuthorLines
2025-09-25add doc for `NonZero*` const creationTim 'Piepmatz' Hesse-0/+12
2025-09-12Constify Eq, Ord, PartialOrdEvgenii Zheltonozhskii-6/+11
2025-09-01Constify conversion traitsltdk-1/+1
2025-08-18Implement feature `int_lowest_highest_one` for integer and NonZero typesAlexandre Courbot-0/+48
Implement the accepted ACP for methods that find the index of the least significant (lowest) and most significant (highest) set bit in an integer for signed, unsigned, and NonZero types. Also add unit tests for all these types.
2025-08-10Constify remaining operatorsltdk-16/+27
2025-08-07Auto merge of #144997 - BoxyUwU:bootstrap_bump, r=Mark-Simulacrumbors-1/+1
bump bootstrap compiler to 1.90 beta There were significantly less `cfg(bootstrap)` and `cfg(not(bootstrap))` this release. Presumably due to the fact that we change the bootstrap stage orderings to reduce the need for them and it was successful :pray:
2025-08-06tidyBoxy-1/+1
2025-08-05Renamed `isolate_most_least_significant_one` functionsokaneco-4/+4
libs-api has agreed to rename these functions to `isolate_highest_one`/`isolate_lowest_one`
2025-07-21Constify Try, From, TryFromEvgenii Zheltonozhskii-1/+2
2025-07-17Make `NonZero` `const PartialEq`Oli Scherer-2/+3
2025-07-07doc(std): clarify `NonZero<T>` usage limitation in doc commentxizheyin-0/+9
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-06-07Make NonZero<char> possibleMarijn Schouten-0/+1
2025-06-06remove extraneous textTshepang Mbambo-33/+0
"Basic usage" implies there is an example that shows advanced usage
2025-05-21Add some track_caller info to precondition panicsBen Kimock-0/+2
2025-04-24Mention average in midpoint documentationsUrgau-1/+3
2025-04-09replace version placeholderBoxy-4/+4
2025-03-07Rollup merge of #134797 - spastorino:ergonomic-ref-counting-1, r=nikomatsakisMatthias Krüger-0/+4
Ergonomic ref counting This is an experimental first version of ergonomic ref counting. This first version implements most of the RFC but doesn't implement any of the optimizations. This was left for following iterations. RFC: https://github.com/rust-lang/rfcs/pull/3680 Tracking issue: https://github.com/rust-lang/rust/issues/132290 Project goal: https://github.com/rust-lang/rust-project-goals/issues/107 r? ```@nikomatsakis```
2025-03-06library: Use size_of from the prelude instead of importedThalia Archibald-4/+1
Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the prelude instead of importing or qualifying them. These functions were added to all preludes in Rust 1.80.
2025-03-06Add UseCloned trait related codeSantiago Pastorino-0/+4
2025-02-23Auto merge of #137237 - cuviper:stage0, r=Mark-Simulacrumbors-2/+2
Master bootstrap update https://forge.rust-lang.org/release/process.html#master-bootstrap-update-tuesday r? `@Mark-Simulacrum`
2025-02-22Rollup merge of #136910 - okaneco:sig_ones, r=thomccMatthias Krüger-0/+64
Implement feature `isolate_most_least_significant_one` for integer types Accepted ACP - https://github.com/rust-lang/libs-team/issues/467 Tracking issue - #136909 Implement ACP for functions that isolate the most significant set bit and least significant set bit on unsigned, signed, and `NonZero` integers. Add function `isolate_most_significant_one` Add function `isolate_least_significant_one` --- This PR adds the following impls ```rust impl {u8, u16, u32, u64, u128, usize} { const fn isolate_most_significant_one(self) -> Self; const fn isolate_least_significant_one(self) -> Self; } impl {i8, i16, i32, i64, i128, isize} { const fn isolate_most_significant_one(self) -> Self; const fn isolate_least_significant_one(self) -> Self; } impl NonZeroT { const fn isolate_most_significant_one(self) -> Self; const fn isolate_least_significant_one(self) -> Self; } ``` Example behavior ```rust assert_eq!(u8::isolate_most_significant_one(0b01100100), 0b01000000); assert_eq!(u8::isolate_least_significant_one(0b01100100), 0b00000100); ```
2025-02-20Implement feature `isolate_most_least_significant_one` for integer typesokaneco-0/+64
Implement accepted ACP for functions that isolate the most significant set bit and least significant set bit on unsigned, signed, and NonZero integers. Add function `isolate_most_significant_one` Add function `isolate_least_significant_one` Add tests
2025-02-18update version placeholdersJosh Stone-2/+2
(cherry picked from commit e4840ce59bdddb19394df008c5c26d9c493725f8)
2025-02-15Stabilize (and const-stabilize) `integer_sign_cast`Pavel Grigorenko-4/+4
2025-02-06stabilize `NonZero::count_ones`Waffle Lapkin-3/+2
2025-02-03Add `cast_signed` and `cast_unsigned` methods for `NonZero` typesJosh Triplett-0/+47
2025-02-03For NonZero impl macros, give unsigned impls access to the corresponding ↵Josh Triplett-2/+17
signed type There was a macro parameter giving signed impls access to the corresponding unsigned type, but not the other way around. This will allow implementing methods converting in both directions.
2025-01-26Rollup merge of #136019 - scottmcm:alias-unchecked-div, r=Mark-SimulacrumJacob Pratt-0/+7
Add an `unchecked_div` alias to the `Div<NonZero<_>>` impls Inspired by https://github.com/rust-lang/libs-team/issues/526, if people are looking for `unchecked_div`, point them to `u32: Div<NonZero<u32>>` and friends which do no runtime checks -- and are safe! -- rather than today's behaviour of [the intrinsic being the top result](https://doc.rust-lang.org/std/?search=unchecked_div). ![image](https://github.com/user-attachments/assets/cf2a3c06-4876-49c1-8e33-64cd431c772a)
2025-01-24Add an `unchecked_div` alias to the `Div<NonZero<_>>` implsScott McMurray-0/+7
2025-01-24Update library/core/src/num/nonzero.rs Carl Sverre-1/+1
Tweak language Co-authored-by: Jonas Böttiger <jonasboettiger@icloud.com>
2025-01-23Add memory layout documentation to generic NonZero<T>Carl Sverre-0/+20
2025-01-09Update a bunch of library types for MCP807Scott McMurray-30/+1
This greatly reduces the number of places that actually use the `rustc_layout_scalar_valid_range_*` attributes down to just 3: ``` library/core\src\ptr\non_null.rs 68:#[rustc_layout_scalar_valid_range_start(1)] library/core\src\num\niche_types.rs 19: #[rustc_layout_scalar_valid_range_start($low)] 20: #[rustc_layout_scalar_valid_range_end($high)] ``` Everything else -- PAL Nanoseconds, alloc's `Cap`, niched FDs, etc -- all just wrap those `niche_types` types.
2025-01-08update version placeholdersPietro Albini-2/+2
2024-12-04Rollup merge of #133651 - scottmcm:nonnull-nonzero-no-field-projection, ↵Matthias Krüger-6/+28
r=oli-obk Update `NonZero` and `NonNull` to not field-project (per MCP#807) https://github.com/rust-lang/compiler-team/issues/807#issuecomment-2506098540 was accepted, so this is the first PR towards moving the library to not using field projections into `[rustc_layout_scalar_valid_range_*]` types. `NonZero` was already using `transmute` nearly everywhere, so there are very few changes to it. `NonNull` needed more changes, but they're mostly simple, changing `.pointer` to `.as_ptr()`. r? libs cc #133324, which will tidy up some of the MIR from this a bit more, but isn't a blocker.
2024-12-03Update `NonZero` and `NonNull` to not field-project (per MCP807)Scott McMurray-6/+28
2024-12-02Auto merge of #133728 - jhpratt:rollup-k1i60pg, r=jhprattbors-1/+0
Rollup of 4 pull requests Successful merges: - #133589 (Remove `hir::ArrayLen`) - #133672 (Remove a bunch of unnecessary const stability noise) - #133678 (Stabilize `ptr::fn_addr_eq`) - #133727 (Update mailmap) r? `@ghost` `@rustbot` modify labels: rollup
2024-12-01Rollup merge of #131784 - Urgau:stabilize-midpoint, r=dtolnayJacob Pratt-3/+2
Stabilize unsigned and float variants of `num_midpoint` feature This PR proposes that we stabilize the unsigned variants of the [`num_midpoint`](https://github.com/rust-lang/rust/issues/110840#issue-1684506201) feature as well as the floats variants, since they are not subject to any unresolved questions, which is equivalent to doing `(a + b) / 2` (and `(a + b) >> 1`) in a sufficiently large number. The stabilized API surface would be: ```rust /// Calculates the middle point of `self` and `rhs`. /// /// `midpoint(a, b)` is `(a + b) / 2` as if it were performed in a sufficiently-large unsigned integral type. /// This implies that the result is always rounded towards negative infinity and that no overflow will ever occur. impl u{8,16,32,64,128,size} { pub const fn midpoint(self, rhs: Self) -> Self; } impl NonZeroU{8,16,32,64,size} { pub const fn midpoint(self, rhs: Self) -> Self; } impl f{32,64} { pub const fn midpoint(self, rhs: Self) -> Self; } ``` The signed variants `u{8,16,32,64,128,size}` would remain gated, until a decision is made about the rounding mode, in other words that the [unresolved questions](https://github.com/rust-lang/rust/issues/110840#issue-1684506201) are resolved. cc `@rust-lang/libs-api` cc `@scottmcm` r? libs-api
2024-12-01Stabilize unsigned `num_midpoint` featureUrgau-3/+2
2024-11-30get rid of a bunch of unnecessary rustc_const_unstableRalf Jung-1/+0
2024-11-27replace placeholder versionBoxy-4/+4
2024-11-12Add tracking issue number to unsigned_nonzero_div_ceil featureAsger Hautop Drewsen-1/+1
2024-11-05Implement div_ceil for NonZero<unsigned>Asger Hautop Drewsen-0/+29
2024-11-03Rollup merge of #132563 - frectonz:master, r=AmanieuJubilee-1/+9
Modify `NonZero` documentation to reference the underlying integer type This change updates the documentation for `NonZero` integer types to explicitly reference the underlying integer type each `NonZero` variant wraps, instead of using a general "integer" term. **Before** ![image](https://github.com/user-attachments/assets/b13bda82-007b-459c-8b22-e27d79005271) **After** ![image](https://github.com/user-attachments/assets/1d7fadc7-dce3-4b84-9b8f-d2bb81c05eb7)
2024-11-03Modify `NonZero` documentation to reference the underlying integer typefrectonz-1/+9
This change updates the documentation for `NonZero` integer types to explicitly reference the underlying integer type each `NonZero` variant wraps, instead of using a general "integer" term.
2024-11-03Rollup merge of #131377 - rick-de-water:nonzero-exp, r=dtolnayMatthias Krüger-16/+30
Add LowerExp and UpperExp implementations to NonZero Adds `LowerExp` and `UpperExp` trait implementations to `NonZero`, as discussed in rust-lang/libs-team#458. I had to modify the macro to mark the new impls with a different rust version. Let me know if this is the right way to do it (first timer here!)
2024-11-02get rid of a whole bunch of unnecessary rustc_const_unstable attributesRalf Jung-1/+0
2024-11-01remove some unnecessary rustc_allow_const_fn_unstableRalf Jung-1/+0
2024-10-28Rollup merge of #131391 - ChaiTRex:isqrt, r=scottmcm,tgross35Matthias Krüger-3/+2
Stabilize `isqrt` feature Stabilizes the `isqrt` feature. FCP is incomplete. Closes #116226
2024-10-25library: consistently use American spelling for 'behavior'Ralf Jung-8/+8
2024-10-08Stabilize `isqrt` featureChai T. Rex-3/+2