about summary refs log tree commit diff
path: root/library/core
AgeCommit message (Collapse)AuthorLines
2024-01-19Rollup merge of #118665 - dtolnay:signedness, r=NilstriebMatthias Krüger-1265/+1211
Consolidate all associated items on the NonZero integer types into a single impl block per type **Before:** ```rust #[repr(transparent)] #[rustc_layout_scalar_valid_range_start(1)] pub struct NonZeroI8(i8); impl NonZeroI8 { pub const fn new(n: i8) -> Option<Self> ... pub const fn get(self) -> i8 ... } impl NonZeroI8 { pub const fn leading_zeros(self) -> u32 ... pub const fn trailing_zeros(self) -> u32 ... } impl NonZeroI8 { pub const fn abs(self) -> NonZeroI8 ... } ... ``` **After:** ```rust #[repr(transparent)] #[rustc_layout_scalar_valid_range_start(1)] pub struct NonZeroI8(i8); impl NonZeroI8 { pub const fn new(n: i8) -> Option<Self> ... pub const fn get(self) -> i8 ... pub const fn leading_zeros(self) -> u32 ... pub const fn trailing_zeros(self) -> u32 ... pub const fn abs(self) -> NonZeroI8 ... ... } ``` Having 6-7 different impl blocks per type is not such a problem in today's implementation, but becomes awful upon the switch to a generic `NonZero<T>` type (context: https://github.com/rust-lang/rust/issues/82363#issuecomment-921513910). In the implementation from https://github.com/rust-lang/rust/pull/100428, there end up being **67** impl blocks on that type. <img src="https://github.com/rust-lang/rust/assets/1940490/5b68bd6f-8a36-4922-baa3-348e30dbfcc1" width="200"><img src="https://github.com/rust-lang/rust/assets/1940490/2cfec71e-c2cd-4361-a542-487f13f435d9" width="200"><img src="https://github.com/rust-lang/rust/assets/1940490/2fe00337-7307-405d-9036-6fe1e58b2627" width="200"> Without the refactor to a single impl block first, introducing `NonZero<T>` would be a usability regression compared to today's separate pages per type. With all those blocks expanded, Ctrl+F is obnoxious because you need to skip 12&times; past every match you don't care about. With all the blocks collapsed, Ctrl+F is useless. Getting to a state in which exactly one type's (e.g. `NonZero<u32>`) impl blocks are expanded while the rest are collapsed is annoying. After this refactor to a single impl block, we can move forward with making `NonZero<T>` a generic struct whose docs all go on the same rustdoc page. The rustdoc will have 12 impl blocks, one per choice of `T` supported by the standard library. The reader can expand a single one of those impl blocks e.g. `NonZero<u32>` to understand the entire API of that type. Note that moving the API into a generic `impl<T> NonZero<T> { ... }` is not going to be an option until after `NonZero<T>` has been stabilized, which may be months or years after its introduction. During the period while generic `NonZero` is unstable, it will be extra important to offer good documentation on all methods demonstrating the API being used through the stable aliases such as `NonZeroI8`. This PR follows a `key = $value` syntax for the macros which is similar to the macros we already use for producing a single large impl block on the integer primitives. https://github.com/rust-lang/rust/blob/1dd4db50620fb38a6382c22456a96ed7cddeff83/library/core/src/num/mod.rs#L288-L309 Best reviewed one commit at a time.
2024-01-17Remove unnecessary `let`s and borrowing from `Waker::noop()` usage.Kevin Reid-2/+1
`Waker::noop()` now returns a `&'static Waker` reference, so it can be passed directly to `Context` creation with no temporary lifetime issue.
2024-01-17Change return type of unstable `Waker::noop()` from `Waker` to `&Waker`.Kevin Reid-5/+12
The advantage of this is that it does not need to be assigned to a variable to be used in a `Context` creation, which is the most common thing to want to do with a noop waker. If an owned noop waker is desired, it can be created by cloning, but the reverse is harder. Alternatively, both versions could be provided, like `futures::task::noop_waker()` and `futures::task::noop_waker_ref()`, but that seems to me to be API clutter for a very small benefit, whereas having the `&'static` reference available is a large benefit. Previous discussion on the tracking issue starting here: https://github.com/rust-lang/rust/issues/98286#issuecomment-1862159766
2024-01-16Un-hide `iter::repeat_n`Scott McMurray-2/+0
2024-01-16Suggest less bug-prone construction of Duration in docsBen Wiederhake-0/+5
2024-01-16Rename `pointer` field on `Pin`LegionMammal978-20/+26
The internal, unstable field of `Pin` can conflict with fields from the inner type accessed via the `Deref` impl. Rename it from `pointer` to `__pointer`, to make it less likely to conflict with anything else.
2024-01-16Auto merge of #120025 - matthiaskrgr:rollup-e9ai06k, r=matthiaskrgrbors-15/+80
Rollup of 8 pull requests Successful merges: - #118361 (stabilise bound_map) - #119816 (Define hidden types in confirmation) - #119900 (Inline `check_closure`, simplify `deduce_sig_from_projection`) - #119969 (Simplify `closure_env_ty` and `closure_env_param`) - #119990 (Add private `NonZero<T>` type alias.) - #119998 (Update books) - #120002 (Lint `overlapping_ranges_endpoints` directly instead of collecting into a Vec) - #120018 (Don't allow `.html` files in `tests/mir-opt/`) r? `@ghost` `@rustbot` modify labels: rollup
2024-01-16Rollup merge of #119990 - reitermarkus:nonzero-type-alias, r=dtolnayMatthias Krüger-12/+79
Add private `NonZero<T>` type alias. According to step 2 suggested in https://github.com/rust-lang/rust/pull/100428#pullrequestreview-1767139731. This adds a private type alias for `NonZero<T>` so that some parts of the code can already start using `NonZero<T>` syntax. Using `NonZero<T>` for `convert` and other parts which implement `From` doesn't work while it is a type alias, since this results in conflicting implementations.
2024-01-16Rollup merge of #118361 - Dylan-DPC:80626/stab/bound-map, r=AmanieuMatthias Krüger-3/+1
stabilise bound_map Closes https://github.com/rust-lang/rust/issues/86026
2024-01-16Auto merge of #119954 - scottmcm:option-unwrap-failed, r=WaffleLapkinbors-2/+10
Split out `option::unwrap_failed` like we have `result::unwrap_failed` ...and like `option::expect_failed`
2024-01-15Revert unrelated changes from PR 119990David Tolnay-3/+3
2024-01-15Add private `NonZero<T>` type alias.Markus Reiter-15/+82
2024-01-15Auto merge of #119878 - scottmcm:inline-always-unwrap, r=workingjubileebors-1/+1
Tune the inlinability of `unwrap` Fixes #115463 cc `@thomcc` This tweaks `unwrap` on ~~`Option` &~~ `Result` to be two parts: - `#[inline(always)]` for checking the discriminant - `#[cold]` for actually panicking The idea here is that checking the discriminant on a `Result` ~~or `Option`~~ should always be trivial enough to be worth inlining, even in `opt-level=z`, especially compared to passing it to a function. As seen in the issue and codegen test, this will hopefully help particularly for things like `.try_into().unwrap()`s that are actually infallible, but in a way that's only visible with the inlining. EDIT: I've restricted this to `Result` to avoid combining effects
2024-01-14Unbreak tidy's feature parserDavid Tolnay-52/+31
tidy error: /git/rust/library/core/src/num/nonzero.rs:67: malformed stability attribute: missing `feature` key tidy error: /git/rust/library/core/src/num/nonzero.rs:82: malformed stability attribute: missing `feature` key tidy error: /git/rust/library/core/src/num/nonzero.rs:98: malformed stability attribute: missing the `since` key tidy error: /git/rust/library/core/src/num/nonzero.rs:112: malformed stability attribute: missing `feature` key tidy error: /git/rust/library/core/src/num/nonzero.rs:450: malformed stability attribute: missing `feature` key some tidy checks failed
2024-01-14Move BITS into omnibus impl blockDavid Tolnay-37/+14
2024-01-14Move signed MIN and MAX into signedness_dependent_methodsDavid Tolnay-52/+35
2024-01-14Move unsigned MIN and MAX into signedness_dependent_methodsDavid Tolnay-43/+26
2024-01-14Move is_power_of_two into unsigned part of signedness_dependent_methodsDavid Tolnay-40/+28
2024-01-14Move nonzero_unsigned_signed_operations methods into the omnibus impl blockDavid Tolnay-225/+201
2024-01-14Work around rustfmt doc attribute indentation bugDavid Tolnay-0/+1
2024-01-14Unindent nonzero_integer_signedness_dependent_methods macro bodyDavid Tolnay-589/+589
2024-01-14Move signedness dependent methods into the omnibus impl blockDavid Tolnay-35/+30
2024-01-14Move Neg impl into the macro that generates Div and RemDavid Tolnay-20/+20
2024-01-14Split out `option::unwrap_failed` like we have `result::unwrap_failed`Scott McMurray-2/+10
...and like `option::expect_failed`
2024-01-14Move leading_zeros and trailing_zeros methods into nonzero_integer macroDavid Tolnay-71/+75
2024-01-14Unindent nonzero_integer_impl_div_rem macro bodyDavid Tolnay-21/+21
2024-01-14Move impl Div and Rem into nonzero_integer macroDavid Tolnay-14/+9
2024-01-14Move 'impl FromStr for NonZero' into nonzero_integer macroDavid Tolnay-9/+2
2024-01-14Format nonzero_integer macro calls same way we do the primitive int implsDavid Tolnay-20/+59
The `key = $value` style will be beneficial as we introduce some more macro arguments here in later commits.
2024-01-14Unindent nonzero_integer macro bodyDavid Tolnay-139/+139
2024-01-14Define only a single NonZero type per macro callDavid Tolnay-6/+39
Later in this stack, as the nonzero_integers macro is going to be responsible for producing a larger fraction of the API for the NonZero integer types, it will need to receive a number of additional arguments beyond the ones currently seen here. Additional arguments, especially named arguments across multiple lines, will turn out clearer if everything in one macro call is for the same NonZero type. This commit adopts a similar arrangement to what we do for generating the API of the integer primitives (`impl u8` etc), which also generate a single type's API per top-level macro call, rather than generating all 12 impl blocks for the 12 types from one macro call.
2024-01-14Move nonzero_integers macro call to bottom of moduleDavid Tolnay-15/+15
This way all the other macros defined in this module, such as nonzero_leading_trailing_zeros, are available to call within the expansion of nonzero_integers. (Macros defined by macro_rules cannot be called from the same module above the location of the macro_rules.) In this commit the ability to call things like nonzero_leading_trailing_zeros is not immediately used, but later commits in this stack will be consolidating the entire API of NonZeroT to be generated through nonzero_integers, and will need to make use of some of the other macros to do that.
2024-01-14Add note on SpecOptionPartialEq to `newtype_index`clubby789-0/+1
2024-01-13libs: use `assert_unchecked` instead of intrinsicjoboet-9/+12
2024-01-13Rollup merge of #119902 - asquared31415:patch-1, r=the8472Matthias Krüger-3/+3
fix typo in `fn()` docs
2024-01-12update fn pointer trait impl docsasquared31415-8/+2
2024-01-12fix typo in `fn()` docsasquared31415-3/+3
2024-01-12Auto merge of #119452 - ↵bors-4/+18
AngelicosPhosphoros:make_nonzeroint_get_assume_nonzero, r=scottmcm Add assume into `NonZeroIntX::get` LLVM currently don't support range metadata for function arguments so it fails to optimize non zero integers using their invariant if they are provided using by-value function arguments. Related to https://github.com/rust-lang/rust/issues/119422 Related to https://github.com/llvm/llvm-project/issues/76628 Related to https://github.com/rust-lang/rust/issues/49572
2024-01-12Tune the inlinability of `Result::unwrap`Scott McMurray-1/+1
2024-01-12Auto merge of #119430 - NCGThompson:int-pow-bench, r=cuviperbors-0/+100
Add Benchmarks for int_pow Methods. There is quite a bit of room for improvement in performance of the `int_pow` family of methods. I added benchmarks for those functions. In particular, there are benchmarks for small compile-time bases to measure the effect of #114390. ~~I added a lot (245), but all but 22 of them are marked with `#[ignore]`. There are a lot of macros, and I would appreciate feedback on how to simplify them.~~ ~~To run benches relevant to #114390, use `./x bench core --stage 1 -- pow_base_const --include-ignored`.~~
2024-01-11Reduced amount of int_pow benchesNicholas Thompson-730/+43
Also simplified the macros
2024-01-11Rollup merge of #119853 - klensy:rustfmt-ignore, r=cuviperMatthias Krüger-75/+111
rustfmt.toml: don't ignore just any tests path, only root one Previously ignored any `tests` path, now only /tests at repo root. For reference, https://git-scm.com/docs/gitignore#_pattern_format
2024-01-11Waker::will_wake: Compare vtable address instead of its contentTomasz Miąsko-1/+3
Optimize will_wake implementation by comparing vtable address instead of its content. The existing best practice to avoid false negatives from will_wake is to define a waker vtable as a static item. That approach continues to works with the new implementation. While this potentially changes the observable behaviour, the function is documented to work on a best-effort basis. The PartialEq impl for RawWaker remains as it was.
2024-01-11Edited int_pow micro-benchmarksNicholas Thompson-103/+339
2024-01-11Added int_pow micro-benchmarksNicholas Thompson-0/+551
2024-01-11rint: further doc tweaksRalf Jung-4/+6
2024-01-11apply fmtklensy-75/+111
2024-01-11Make is_global/is_unicast_global special address handling completeJakub Stasiak-4/+22
IANA explicitly documents 192.0.0.9/32, 192.0.0.9/32 and 2001:30::/28 as globally reachable[1][2] and the is_global implementations declare following IANA so let's make this happen. In case of 2002::/16 IANA says N/A so I think it's safe to say we shouldn't return true there either. [1] https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml [2] https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml
2024-01-10Implement in-place iteratation markers for iter::{Copied, Cloned}The8472-4/+45
2024-01-10bench trustedrandomaccess specialization in zipThe8472-0/+13