Commit graph

948 commits

Author SHA1 Message Date
bors
7a3700c371 Auto merge of #68952 - faern:stabilize-assoc-int-consts, r=dtolnay
Stabilize assoc_int_consts associated int/float constants

The next step in RFC https://github.com/rust-lang/rfcs/pull/2700 (tracking issue #68490). Stabilizing the associated constants that were added in #68325.

* Stabilize all constants under the `assoc_int_consts` feature flag.
* Update documentation on old constants to say they are soft-deprecated and the new ones should be preferred.
* Update documentation examples to use new constants.
* Remove `uint_macro` and use `int_macro` for all integer types since the macros were identical anyway.

r? @LukasKalbertodt
2020-03-04 07:29:32 +00:00
Dylan DPC
e028f26e1d
Rollup merge of #69209 - Mark-Simulacrum:strip-unsafe, r=dtolnay
Miscellaneous cleanup to formatting

Each commit stands alone.

This pull request will also resolve #58320.
2020-02-26 15:34:30 +01:00
Dylan DPC
c261ff1a77
Rollup merge of #68984 - ecstatic-morse:const-u8-is-ascii, r=sfackler
Make `u8::is_ascii` a stable `const fn`

`char::is_ascii` was already stabilized as `const fn` in #55278, so there is no reason for `u8::is_ascii` to go through an unstable period.

cc @rust-lang/libs
2020-02-22 18:42:59 +05:30
Dylan DPC
d96951f554
Rollup merge of #68978 - ecstatic-morse:const-int-pow, r=oli-obk
Make integer exponentiation methods unstably const

cc #53718

This makes the following inherent methods on integer primitives into unstable `const fn`:
- `pow`
- `checked_pow`
- `wrapping_pow`
- `overflowing_pow`
- `saturating_pow`
- `next_power_of_two`
- `checked_next_power_of_two`
- `wrapping_next_power_of_two`

Only two changes were made to the implementation of these methods. First, I had to switch from the `?` operator, which is not yet implemented in a const context, to a `try_opt` macro. Second, `next_power_of_two` was using `ops::Add::add` (see the first commit) to "get overflow checks", so I switched to `#[rustc_inherit_overflow_checks]`. I'm not quite sure why the attribute wasn't used in the first place.
2020-02-20 10:49:12 +01:00
Mark Rousskov
6c45e4540b Drop unused argument to float functions 2020-02-17 09:18:33 -05:00
LeSeulArtichaut
2ae493a767 Stabilize {f32, f64}::{LOG2_10, LOG10_2} 2020-02-16 18:53:02 +01:00
Mark Rousskov
bd12cd3d2f Formatter::sign is &'static str
The contents were always UTF-8 anyway, and &str has an equivalent representation
to &[u8], so this should not affect performance while removing unsafety at
edges.

It may be worth exploring a further adjustment that stores a single byte
(instead of 16) as the contents are always "", "-", or "+".
2020-02-15 18:17:51 -05:00
Linus Färnstrand
b2dc618769 Add usage recommendation to old float constants 2020-02-12 20:20:56 +01:00
Linus Färnstrand
83191c2da6 Update float documentation to use associated consts 2020-02-12 20:20:56 +01:00
Linus Färnstrand
086927480b Add notice about using new consts in new code on int modules 2020-02-12 20:20:56 +01:00
Linus Färnstrand
c67de2570f Add notice about using new consts in new code on float modules 2020-02-12 20:20:56 +01:00
Linus Färnstrand
847a0dd845 Remove uint_macros that was identical to int_macros 2020-02-12 20:20:56 +01:00
Linus Färnstrand
5e17f31d94 Replace min/max_value() with MIN/MAX in integer docs 2020-02-12 20:20:56 +01:00
Linus Färnstrand
cf255c6dc1 Use new preferred consts in int docs 2020-02-12 20:20:56 +01:00
Linus Färnstrand
97bdd31b0e Add "soft deprecation" notice to old MIN/MAX docs 2020-02-12 20:20:55 +01:00
Linus Färnstrand
35298349c3 Add "soft deprecation" notice to old min/max_value() docs 2020-02-12 20:20:55 +01:00
Linus Färnstrand
271ba5a3ea Stabilize assoc_int_consts 2020-02-12 20:20:39 +01:00
Dylan DPC
6e1b75b7e1
Rollup merge of #68986 - ecstatic-morse:const-ascii-ctype, r=Centril
Make ASCII ctype functions unstably const

Makes the following inherent methods on `u8` and `char` unstable `const fn`:

 * `is_ascii_alphabetic`
 * `is_ascii_uppercase`
 * `is_ascii_lowercase`
 * `is_ascii_alphanumeric`
 * `is_ascii_digit`
 * `is_ascii_hexdigit`
 * `is_ascii_punctuation`
 * `is_ascii_graphic`
 * `is_ascii_whitespace`
 * `is_ascii_control`

cc #68983
2020-02-10 17:28:59 +01:00
Dylan MacKenzie
f6d4720f26 Make u8::is_ascii a stable const fn
`char::is_ascii` is already a stable `const fn`, so there is no reason
for `u8::is_ascii` to be unstable.
2020-02-08 21:29:32 -08:00
Dylan MacKenzie
a9212b8e93 Make the ASCII ctype inherent methods const 2020-02-08 21:29:25 -08:00
Dylan MacKenzie
269bf89865 Make integer power methods const 2020-02-08 17:19:09 -08:00
Dylan MacKenzie
2afa99379d Use bespoke macro instead of ? inside const fns 2020-02-08 17:18:13 -08:00
Dylan MacKenzie
c981d67b50 [!] Use rustc_inherit_overflow_checks in next_power_of_two
I believe the previous code was calling `ops::Add::add` instead of the
`+` operator to get this behavior.
2020-02-08 17:16:43 -08:00
Dylan MacKenzie
0b20ce97f7 Make num::NonZeroX::new an unstable const fn 2020-02-08 16:02:20 -08:00
Dylan MacKenzie
09160d1b84 Use consistent feature naming 2020-02-04 20:36:18 -08:00
Dylan MacKenzie
dda015aebc Make saturating arithmetic using intrinsics const 2020-02-04 11:04:04 -08:00
Dylan MacKenzie
526304da16 Make checked division const 2020-02-04 11:04:04 -08:00
Dylan MacKenzie
b46d1d2718 Make wrapping arithmetic const
Co-Authored-By: 9999years <rbt@sent.as>
2020-02-04 11:04:04 -08:00
Dylan MacKenzie
b422a19c43 Make saturating_mul a const fn
Co-Authored-By: 9999years <rbt@sent.as>
2020-02-04 11:04:04 -08:00
Dylan MacKenzie
de52a541d5 Make overflowing arithmetic const
Co-Authored-By: 9999years <rbt@sent.as>
2020-02-04 11:04:03 -08:00
Dylan MacKenzie
37c141885a Make checked arithmetic besides division const
Co-Authored-By: 9999years <rbt@sent.as>
2020-02-04 11:04:03 -08:00
Dylan MacKenzie
d9e3d2a531 Make euclidean division const
Co-Authored-By: 9999years <rbt@sent.as>
2020-02-04 11:04:03 -08:00
bors
c4071d0919 Auto merge of #68325 - faern:move-numeric-consts-to-associated-consts-step1, r=LukasKalbertodt
Move numeric consts to associated consts step1

A subset of #67913. Implements the first step of RFC https://github.com/rust-lang/rfcs/pull/2700

This PR adds the new constants as unstable constants and defines the old ones in terms of the new ones. Then fix a tiny bit of code that started having naming collisions because of the new assoc consts.

Removed a test that did not seem relevant any longer. Since doing just `u8::MIN` should now indeed be valid.
2020-01-30 08:55:07 +00:00
LeSeulArtichaut
684bd50148 Document From implementation for NonZero nums 2020-01-29 17:49:38 +01:00
Linus Färnstrand
002c7897a6 Unlock assoc_int_consts in documentation examples using it 2020-01-23 20:55:06 +01:00
Linus Färnstrand
9d257579fc Fix some float operations to work together with the assoc consts 2020-01-23 20:55:06 +01:00
Linus Färnstrand
22dcfa1d8d Add relevant associated constants to the float types 2020-01-23 20:55:06 +01:00
Linus Färnstrand
b5ff8064a4 Add MIN/MAX associated constants to the integer types 2020-01-23 20:55:06 +01:00
Thom Chiovoloni
783a7dc8ed Mark leading_trailing_ones with tracking issue 57969 2020-01-15 08:31:24 -08:00
Thom Chiovoloni
6a7a69bde9 Add {leading,trailing}_ones to primitive int types 2020-01-12 14:07:31 -08:00
Mazdak Farrokhzad
5ea69781f4
Rollup merge of #67966 - popzxc:core-std-matches, r=Centril
Use matches macro in libcore and libstd

This PR replaces matches like

```rust
match var {
    value => true,
    _ => false,
}
```

with use of `matches!` macro.

r? @Centril
2020-01-09 00:22:10 +01:00
Mazdak Farrokhzad
11f0013378
Rollup merge of #67884 - anp:allow-unused-const-attr, r=oli-obk
Fix incremental builds of core by allowing unused attribute.

I *think* that the same problem as in https://github.com/rust-lang/rust/issues/65023 was introduced by https://github.com/rust-lang/rust/pull/67657. This works around the current incrcomp issue with these attributes by allowing it here. This resolves the near-term issue for me, at least.
2020-01-09 00:22:08 +01:00
Igor Aleksanov
f720469fd0 Use matches macro in libcore and libstd 2020-01-08 07:10:28 +03:00
Lzu Tao
c7dbf5ad54 Use Self instead of $type 2020-01-06 04:33:31 +00:00
Adam Perry
3458aba0f9 Fix incremental builds of core by allowing unused attribute.
The same problem as in https://github.com/rust-lang/rust/issues/65023 was
introduced by https://github.com/rust-lang/rust/pull/67657. This works
around the current incrcomp issue with these attributes by allowing it
here.
2020-01-04 18:20:52 -08:00
jumbatm
525cd2d7c1 Re-add comment about behaviour of inline. 2020-01-05 08:01:32 +10:00
jumbatm
ae002c1d84 Also remove const-hack for abs 2020-01-04 08:42:22 +10:00
Dylan DPC
2c64475069
Rollup merge of #67430 - tspiteri:minus-inf, r=Dylan-DPC
doc: minus (U+2212) instead of dash (U+002D) for negative infinity

The documentation for [`f32::NEG_INFINITY`](https://doc.rust-lang.org/std/f32/constant.NEG_INFINITY.html) contains “-∞” with a dash instead of a minus sign, “−∞” with a proper minus sign looks better with the used Source Serif Pro font. Similarly for [`f64::NEG_INFINITY`](https://doc.rust-lang.org/std/f64/constant.NEG_INFINITY.html).
2019-12-31 18:14:01 +05:30
Yuki Okushi
047a4bb432
Rollup merge of #67657 - jumbatm:cleanup-const-hack, r=oli-obk
Clean up const-hack PRs now that const if / match exist.

Closes #67627.

Cleans up these merged PRs tagged with `const-hack`:

- #63810
- #63786
- #61635
- #58044

reverting their contents to have the match or if expressions they originally contained.

r? @oli-obk

There's one more PR in those tagged with `const-hack` that originally wasn't merged (#65107). Reading the thread, it looks like it was originally closed because the `const-hack` for the checked arithmetic non-negligibly hurt performance, and because there was no way to manipulate the returned Option at compile time anyway (with neither const if nor const match). Would you like me to add these changes to the changes from this PR here too, now that we have the necessary features?
2019-12-30 14:07:50 +09:00
jumbatm
91c2f78b50 Clean up const-hack from #58044 2019-12-27 23:21:32 +10:00