Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize assoc_int_consts associated int/float constants #68952

Merged
merged 11 commits into from
Mar 4, 2020

Conversation

faern
Copy link
Contributor

@faern faern commented Feb 8, 2020

The next step in RFC rust-lang/rfcs#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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 8, 2020
@jonas-schievink jonas-schievink added relnotes Marks issues that should be documented in the release notes of the next release. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Feb 8, 2020
@jonas-schievink jonas-schievink added this to the 1.43 milestone Feb 8, 2020
Copy link
Member

@LukasKalbertodt LukasKalbertodt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, thanks!

(If you are comfortable with git rebase/squash/fixup you could improve the git history a bit by squashing your three "Fix ..." commits with the respective commits that is being fixed. That makes it a bit easier for commit-by-commit reviewing. However, that's really not important.)

@LukasKalbertodt
Copy link
Member

The code changes are good. However, as I mentioned in chat, I am not really a fan of stabilizing these constants only a few weeks after they have been added. @Mark-Simulacrum disagreed. To get another opinion and since I can't start FCP merges anyway, reassigning:

r? @dtolnay

@faern
Copy link
Contributor Author

faern commented Feb 9, 2020

Git history fixed :) I usually do that, but must have been lazy this time. Thanks.

With regards to when to stabilize. My two cents is that things sit around as unstable because we are evaluating if the naming is good, the API has a usable/ergonomic design, it's properly implemented, people actually seem to use/want this etc. But we basically already know all those things for this feature. It just moves an existing feature.

For reference, moving the std::time::UNIX_EPOCH to SystemTime::UNIX_EPOCH assoc const (#49502) took two months from unstable to stable. But that included the RFC process, since it was added as unstable before any RFC was even posted. So not a fair comparison. These constants here have already been debated for nine months already :)

Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I think it's pretty clear that we want these so I am on board with moving forward.

I think the deprecation notice on the integer modules is too aggressive for now.

Could you remove the bold second sentences? I think this is not among the most important information to feature in the module index, especially not with emphasis. I think the links inside the module showing what to use instead are sufficient.

Could you also restore the "See also the i16 primitive type." links exactly how it existed before? Anyone who lands on the module's documentation is much more likely looking for the type and its methods, not the associated constants. So the way you've put the type link at the end of a paragraph about deprecation warnings and associated constants is not as good.

@faern
Copy link
Contributor Author

faern commented Feb 10, 2020

Could you remove the bold second sentences?

Sure. Add it to a new line so it ends up in the module docs, but not in the first-line summary like now? Or remove This module is soft-deprecated completely and just keep the paragraph on how using these constants won't cause compilation warnings (for now) but new users should prefer the associated constants?

Could you also restore the "See also the i16 primitive type."

Will do.

@faern
Copy link
Contributor Author

faern commented Feb 10, 2020

Done.

@dtolnay dtolnay added the needs-fcp This change is insta-stable, so needs a completed FCP to proceed. label Feb 10, 2020
@dtolnay
Copy link
Member

dtolnay commented Feb 10, 2020

@rfcbot fcp merge

@rust-lang/libs: This stabilizes associated constants on the primitive integer and float types to make e.g. i64::MAX work the way we've always liked for them to work, without importing std::i64.

The constants involved are:

  • On all the integers: MIN and MAX
  • On the floats: RADIX, MANTISSA_DIGITS, DIGITS, EPSILON, MIN, MIN_POSITIVE, MAX, MIN_EXP, MAX_EXP, MIN_10_EXP, MAX_10_EXP, NAN, INFINITY, NEG_INFINITY

The existing module-level constants' documentation will now link to the associated constants, but we don't trigger any new deprecation warnings. We can navigate deprecation at some (far) later time.

@rfcbot
Copy link

rfcbot commented Feb 10, 2020

Team member @dtolnay has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Feb 10, 2020
@bors
Copy link
Contributor

bors commented Feb 11, 2020

☔ The latest upstream changes (presumably #68491) made this pull request unmergeable. Please resolve the merge conflicts.

@bors
Copy link
Contributor

bors commented Mar 4, 2020

📌 Commit b2dc618 has been approved by dtolnay

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 4, 2020
@bors
Copy link
Contributor

bors commented Mar 4, 2020

⌛ Testing commit b2dc618 with merge 7a3700c...

@bors
Copy link
Contributor

bors commented Mar 4, 2020

☀️ Test successful - checks-azure
Approved by: dtolnay
Pushing 7a3700c to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 4, 2020
@bors bors merged commit 7a3700c into rust-lang:master Mar 4, 2020
bors added a commit to rust-lang/miri that referenced this pull request Mar 4, 2020
finally stop using min/max_value and the integer modules

rust-lang/rust#68952 landed, so we can finally do this :)
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Mar 4, 2020
Use associated constants of integer types

Take advantage of rust-lang#68952 in the interpreter and some nearby modules :)
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Mar 4, 2020
Use associated constants of integer types

Take advantage of rust-lang#68952 in the interpreter and some nearby modules :)
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Mar 5, 2020
Use associated constants of integer types

Take advantage of rust-lang#68952 in the interpreter and some nearby modules :)
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Mar 5, 2020
Use associated constants of integer types

Take advantage of rust-lang#68952 in the interpreter and some nearby modules :)
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Mar 5, 2020
Use associated constants of integer types

Take advantage of rust-lang#68952 in the interpreter and some nearby modules :)
@faern faern deleted the stabilize-assoc-int-consts branch March 8, 2020 21:06
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Apr 3, 2020
Use associated numeric consts in documentation

Now when the associated constants on int/float types are stabilized and the recommended way of accessing said constants (rust-lang#68952). We can start using it in this repository, and recommend it via documentation example code.

This PR is the reincarnation of rust-lang#67913 minus the actual adding + stabilization of said constants. (EDIT: Now it's only changing the documentation. So users will see the new consts, but we don't yet update the internal code)

Because of how fast bit rot happens to PRs that touch this many files, it does not try to replace 100% of the old usage of the constants in the entire repo, but a good chunk of them.
Centril added a commit to Centril/rust that referenced this pull request Apr 3, 2020
Use associated numeric consts in documentation

Now when the associated constants on int/float types are stabilized and the recommended way of accessing said constants (rust-lang#68952). We can start using it in this repository, and recommend it via documentation example code.

This PR is the reincarnation of rust-lang#67913 minus the actual adding + stabilization of said constants. (EDIT: Now it's only changing the documentation. So users will see the new consts, but we don't yet update the internal code)

Because of how fast bit rot happens to PRs that touch this many files, it does not try to replace 100% of the old usage of the constants in the entire repo, but a good chunk of them.
bors added a commit to rust-lang/rust-clippy that referenced this pull request Apr 8, 2020
Use assoc int and float consts instead of module level ones

changelog: Recommend primitive type associated constants instead of module level constants

In Rust 1.43 integer and float primitive types will have a number of new associated constants. For example `MAX`, `MIN` and a number of constants related to the machine representation of floats. rust-lang/rust#68952

These new constants are preferred over the module level constants in `{core,std}::{f*, u*, i*}`. I have in the last few days made sure that the documentation in the main rust repository uses the new constants in every place I could find (rust-lang/rust#69860, rust-lang/rust#70782). So the next step is naturally to make the linter recommend the new constants as well.

This PR only changes two lints. There are more. But I did not want the PR to be too big. And since I have not contributed to clippy before it felt saner to start with a small PR so I see if there are any quirks. More will come later.
@steveklabnik steveklabnik mentioned this pull request May 3, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request May 4, 2020
…dtolnay

Add const examples

I only added them to `std::f32` to get feedback on this approach before adding the other constants.

When looking at rust-lang#68952, I found the docs a little confusing. Unless you're intimately aware of what's going on here, I don't think it's super clear what is deprecated and what you're supposed to do instead. I think short examples really clarify what's meant here, so that's what I did.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request May 4, 2020
…dtolnay

Add const examples

I only added them to `std::f32` to get feedback on this approach before adding the other constants.

When looking at rust-lang#68952, I found the docs a little confusing. Unless you're intimately aware of what's going on here, I don't think it's super clear what is deprecated and what you're supposed to do instead. I think short examples really clarify what's meant here, so that's what I did.
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request May 16, 2020
Pkgsrc changes:
 * Bump rust bootstrap version to 1.42.0, except for Darwin/i686 where the
   bootstrap is not (yet?) available.

Upstream changes:

Version 1.43.0 (2020-04-23)
==========================

Language
--------
- [Fixed using binary operations with `&{number}` (e.g. `&1.0`) not having
  the type inferred correctly.][68129]
- [Attributes such as `#[cfg()]` can now be used on `if` expressions.][69201]

**Syntax only changes**
- [Allow `type Foo: Ord` syntactically.][69361]
- [Fuse associated and extern items up to defaultness.][69194]
- [Syntactically allow `self` in all `fn` contexts.][68764]
- [Merge `fn` syntax + cleanup item parsing.][68728]
- [`item` macro fragments can be interpolated into `trait`s, `impl`s,
  and `extern` blocks.][69366]
  For example, you may now write:
  ```rust
  macro_rules! mac_trait {
      ($i:item) => {
          trait T { $i }
      }
  }
  mac_trait! {
      fn foo() {}
  }
  ```
These are still rejected *semantically*, so you will likely receive an error but
these changes can be seen and parsed by macros and
conditional compilation.


Compiler
--------
- [You can now pass multiple lint flags to rustc to override the previous
  flags.][67885] For example; `rustc -D unused -A unused-variables` denies
  everything in the `unused` lint group except `unused-variables` which
  is explicitly allowed. However, passing `rustc -A unused-variables -D unused` denies
  everything in the `unused` lint group **including** `unused-variables` since
  the allow flag is specified before the deny flag (and therefore overridden).
- [rustc will now prefer your system MinGW libraries over its bundled libraries
  if they are available on `windows-gnu`.][67429]
- [rustc now buffers errors/warnings printed in JSON.][69227]

Libraries
---------
- [`Arc<[T; N]>`, `Box<[T; N]>`, and `Rc<[T; N]>`, now implement
  `TryFrom<Arc<[T]>>`,`TryFrom<Box<[T]>>`, and `TryFrom<Rc<[T]>>`
  respectively.][69538] **Note** These conversions are only available when `N`
  is `0..=32`.
- [You can now use associated constants on floats and integers directly, rather
  than having to import the module.][68952] e.g. You can now write `u32::MAX` or
  `f32::NAN` with no imports.
- [`u8::is_ascii` is now `const`.][68984]
- [`String` now implements `AsMut<str>`.][68742]
- [Added the `primitive` module to `std` and `core`.][67637] This module
  reexports Rust's primitive types. This is mainly useful in macros
  where you want avoid these types being shadowed.
- [Relaxed some of the trait bounds on `HashMap` and `HashSet`.][67642]
- [`string::FromUtf8Error` now implements `Clone + Eq`.][68738]

Stabilized APIs
---------------
- [`Once::is_completed`]
- [`f32::LOG10_2`]
- [`f32::LOG2_10`]
- [`f64::LOG10_2`]
- [`f64::LOG2_10`]
- [`iter::once_with`]

Cargo
-----
- [You can now set config `[profile]`s in your `.cargo/config`, or through
  your environment.][cargo/7823]
- [Cargo will now set `CARGO_BIN_EXE_<name>` pointing to a binary's
  executable path when running integration tests or benchmarks.][cargo/7697]
  `<name>` is the name of your binary as-is e.g. If you wanted the executable
  path for a binary named `my-program`you would use
  `env!("CARGO_BIN_EXE_my-program")`.

Misc
----
- [Certain checks in the `const_err` lint were deemed unrelated to const
  evaluation][69185], and have been moved to the `unconditional_panic` and
  `arithmetic_overflow` lints.

Compatibility Notes
-------------------

- [Having trailing syntax in the `assert!` macro is now a hard error.][69548]
  This has been a warning since 1.36.0.
- [Fixed `Self` not having the correctly inferred type.][69340] This incorrectly
  led to some instances being accepted, and now correctly emits a hard error.

[69340]: rust-lang/rust#69340

Internal Only
-------------
These changes provide no direct user facing benefits, but represent significant
improvements to the internals and overall performance of `rustc` and
related tools.

- [All components are now built with `opt-level=3` instead of `2`.][67878]
- [Improved how rustc generates drop code.][67332]
- [Improved performance from `#[inline]`-ing certain hot functions.][69256]
- [traits: preallocate 2 Vecs of known initial size][69022]
- [Avoid exponential behaviour when relating types][68772]
- [Skip `Drop` terminators for enum variants without drop glue][68943]
- [Improve performance of coherence checks][68966]
- [Deduplicate types in the generator witness][68672]
- [Invert control in struct_lint_level.][68725]

[67332]: rust-lang/rust#67332
[67429]: rust-lang/rust#67429
[67637]: rust-lang/rust#67637
[67642]: rust-lang/rust#67642
[67878]: rust-lang/rust#67878
[67885]: rust-lang/rust#67885
[68129]: rust-lang/rust#68129
[68672]: rust-lang/rust#68672
[68725]: rust-lang/rust#68725
[68728]: rust-lang/rust#68728
[68738]: rust-lang/rust#68738
[68742]: rust-lang/rust#68742
[68764]: rust-lang/rust#68764
[68772]: rust-lang/rust#68772
[68943]: rust-lang/rust#68943
[68952]: rust-lang/rust#68952
[68966]: rust-lang/rust#68966
[68984]: rust-lang/rust#68984
[69022]: rust-lang/rust#69022
[69185]: rust-lang/rust#69185
[69194]: rust-lang/rust#69194
[69201]: rust-lang/rust#69201
[69227]: rust-lang/rust#69227
[69548]: rust-lang/rust#69548
[69256]: rust-lang/rust#69256
[69361]: rust-lang/rust#69361
[69366]: rust-lang/rust#69366
[69538]: rust-lang/rust#69538
[cargo/7823]: rust-lang/cargo#7823
[cargo/7697]: rust-lang/cargo#7697
[`Once::is_completed`]: https://doc.rust-lang.org/std/sync/struct.Once.html#method.is_completed
[`f32::LOG10_2`]: https://doc.rust-lang.org/std/f32/consts/constant.LOG10_2.html
[`f32::LOG2_10`]: https://doc.rust-lang.org/std/f32/consts/constant.LOG2_10.html
[`f64::LOG10_2`]: https://doc.rust-lang.org/std/f64/consts/constant.LOG10_2.html
[`f64::LOG2_10`]: https://doc.rust-lang.org/std/f64/consts/constant.LOG2_10.html
[`iter::once_with`]: https://doc.rust-lang.org/std/iter/fn.once_with.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. merged-by-bors This PR was explicitly merged by bors. needs-fcp This change is insta-stable, so needs a completed FCP to proceed. relnotes Marks issues that should be documented in the release notes of the next release. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants