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

Stop importing the float modules in documentation #70782

Merged
merged 3 commits into from
Apr 6, 2020

Conversation

faern
Copy link
Contributor

@faern faern commented Apr 4, 2020

Follow up to #69860. I realized I had not searched for and fixed this for the float values. So with this PR they also use the associated constants instead of the module level constants.

For the documentation where it also was using the consts submodule I opted to change it to import that directly. This becomes more in line with how other docs that use the consts submodule looks. And it also makes it so there are not two f32 or f64 things in the current namespace (both the module and the primitive type) and then hopefully confusing documentation readers less.

r? @dtolnay

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 4, 2020
@faern faern changed the title Stop importing the float modules. Use assoc consts Stop importing the float modules in documentation Apr 4, 2020
@rust-highfive
Copy link
Collaborator

The job mingw-check of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2020-04-04T18:10:10.4690901Z ========================== Starting Command Output ===========================
2020-04-04T18:10:10.4693548Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/aa96d745-e636-4877-a7fc-e7c7c377b5b0.sh
2020-04-04T18:10:10.4693863Z 
2020-04-04T18:10:10.4697933Z ##[section]Finishing: Disable git automatic line ending conversion
2020-04-04T18:10:10.4717114Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/70782/merge to s
2020-04-04T18:10:10.4720359Z Task         : Get sources
2020-04-04T18:10:10.4720628Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-04-04T18:10:10.4720883Z Version      : 1.0.0
2020-04-04T18:10:10.4721055Z Author       : Microsoft
---
2020-04-04T18:10:11.4650093Z ##[command]git remote add origin https://github.com/rust-lang/rust
2020-04-04T18:10:11.4659168Z ##[command]git config gc.auto 0
2020-04-04T18:10:11.4668667Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2020-04-04T18:10:11.4676376Z ##[command]git config --get-all http.proxy
2020-04-04T18:10:11.4681911Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/70782/merge:refs/remotes/pull/70782/merge
---
2020-04-04T18:12:44.4338976Z  ---> 3fc1b512c57b
2020-04-04T18:12:44.4339182Z Step 6/7 : ENV RUN_CHECK_WITH_PARALLEL_QUERIES 1
2020-04-04T18:12:44.4339531Z  ---> Using cache
2020-04-04T18:12:44.4339823Z  ---> 5ee4295733f4
2020-04-04T18:12:44.4415430Z Step 7/7 : ENV SCRIPT python2.7 ../x.py test src/tools/expand-yaml-anchors &&            python2.7 ../x.py check --target=i686-pc-windows-gnu --host=i686-pc-windows-gnu &&            python2.7 ../x.py build --stage 0 src/tools/build-manifest &&            python2.7 ../x.py test --stage 0 src/tools/compiletest &&            python2.7 ../x.py test src/tools/tidy &&            /scripts/validate-toolstate.sh
2020-04-04T18:12:44.4417194Z  ---> 3d07a0fa42fe
2020-04-04T18:12:44.4417456Z Successfully built 3d07a0fa42fe
2020-04-04T18:12:44.4463382Z Successfully tagged rust-ci:latest
2020-04-04T18:12:44.4963914Z Built container sha256:3d07a0fa42feb5754fc13bb2f7010ebe13e4b8b8cdbebed0c75d8da320c8c8ad
2020-04-04T18:12:44.4963914Z Built container sha256:3d07a0fa42feb5754fc13bb2f7010ebe13e4b8b8cdbebed0c75d8da320c8c8ad
2020-04-04T18:12:44.4978253Z Looks like docker image is the same as before, not uploading
2020-04-04T18:12:49.9257919Z [CI_JOB_NAME=mingw-check]
2020-04-04T18:12:49.9508910Z [CI_JOB_NAME=mingw-check]
2020-04-04T18:12:49.9529287Z == clock drift check ==
2020-04-04T18:12:49.9537240Z   local time: Sat Apr  4 18:12:49 UTC 2020
2020-04-04T18:12:50.2174602Z   network time: Sat, 04 Apr 2020 18:12:50 GMT
2020-04-04T18:12:50.2197337Z Starting sccache server...
2020-04-04T18:12:50.3066359Z configure: processing command line
2020-04-04T18:12:50.3067139Z configure: 
2020-04-04T18:12:50.3068044Z configure: rust.parallel-compiler := True
---
2020-04-04T18:16:26.1118501Z     Checking rustc_feature v0.0.0 (/checkout/src/librustc_feature)
2020-04-04T18:16:26.1494155Z     Checking fmt_macros v0.0.0 (/checkout/src/libfmt_macros)
2020-04-04T18:16:26.3580840Z     Checking rustc_ast_pretty v0.0.0 (/checkout/src/librustc_ast_pretty)
2020-04-04T18:16:26.5404071Z     Checking rustc_hir v0.0.0 (/checkout/src/librustc_hir)
2020-04-04T18:16:26.9996301Z     Checking rustc_query_system v0.0.0 (/checkout/src/librustc_query_system)
2020-04-04T18:16:29.3754522Z     Checking rustc_attr v0.0.0 (/checkout/src/librustc_attr)
2020-04-04T18:16:29.8704673Z     Checking rustc_parse v0.0.0 (/checkout/src/librustc_parse)
2020-04-04T18:16:31.9579164Z     Checking rustc_hir_pretty v0.0.0 (/checkout/src/librustc_hir_pretty)
2020-04-04T18:16:32.4139178Z     Checking rustc_ast_lowering v0.0.0 (/checkout/src/librustc_ast_lowering)
---
2020-04-04T18:18:19.1984738Z configure: build.locked-deps    := True
2020-04-04T18:18:19.1985215Z configure: llvm.ccache          := sccache
2020-04-04T18:18:19.1985829Z configure: build.cargo-native-static := True
2020-04-04T18:18:19.1986674Z configure: dist.missing-tools   := True
2020-04-04T18:18:19.1988321Z configure: build.configure-args := ['--enable-sccache', '--disable-manage-submodu ...
2020-04-04T18:18:19.1989396Z configure: writing `config.toml` in current directory
2020-04-04T18:18:19.1989916Z configure: 
2020-04-04T18:18:19.1991593Z configure: run `python /checkout/x.py --help`
2020-04-04T18:18:19.1991841Z configure: 
---
2020-04-04T18:19:40.3326370Z Hugepagesize:       2048 kB
2020-04-04T18:19:40.3326581Z DirectMap4k:       96192 kB
2020-04-04T18:19:40.3326774Z DirectMap2M:     4098048 kB
2020-04-04T18:19:40.3326967Z DirectMap1G:     5242880 kB
2020-04-04T18:19:40.3327580Z + python2.7 ../x.py test src/tools/expand-yaml-anchors
2020-04-04T18:19:41.6791856Z Ensuring the YAML anchors in the GitHub Actions config were expanded
2020-04-04T18:19:41.6791856Z Ensuring the YAML anchors in the GitHub Actions config were expanded
2020-04-04T18:19:41.6799818Z Building stage0 tool expand-yaml-anchors (x86_64-unknown-linux-gnu)
2020-04-04T18:19:41.9118797Z    Compiling unicode-xid v0.2.0
2020-04-04T18:19:42.0482416Z    Compiling syn v1.0.11
2020-04-04T18:19:42.9193298Z    Compiling linked-hash-map v0.5.2
2020-04-04T18:19:42.9415995Z    Compiling lazy_static v1.4.0
2020-04-04T18:19:42.9415995Z    Compiling lazy_static v1.4.0
2020-04-04T18:19:43.1585089Z    Compiling yaml-rust v0.4.3
2020-04-04T18:19:47.5189018Z    Compiling quote v1.0.2
2020-04-04T18:20:02.6113186Z    Compiling thiserror-impl v1.0.5
2020-04-04T18:20:07.1952889Z    Compiling thiserror v1.0.5
2020-04-04T18:20:07.2601534Z    Compiling yaml-merge-keys v0.4.0
2020-04-04T18:20:08.4441973Z    Compiling expand-yaml-anchors v0.1.0 (/checkout/src/tools/expand-yaml-anchors)
2020-04-04T18:20:10.0647909Z Build completed successfully in 0:00:29
2020-04-04T18:20:10.0658414Z + python2.7 ../x.py check --target=i686-pc-windows-gnu --host=i686-pc-windows-gnu
2020-04-04T18:20:10.3106302Z     Finished dev [unoptimized] target(s) in 0.18s
2020-04-04T18:20:11.3741376Z Checking rustdoc artifacts (x86_64-unknown-linux-gnu -> i686-pc-windows-gnu)
---
2020-04-04T18:22:19.9875224Z     Checking rustc_feature v0.0.0 (/checkout/src/librustc_feature)
2020-04-04T18:22:20.1370669Z     Checking fmt_macros v0.0.0 (/checkout/src/libfmt_macros)
2020-04-04T18:22:20.3426783Z     Checking rustc_ast_pretty v0.0.0 (/checkout/src/librustc_ast_pretty)
2020-04-04T18:22:20.3990923Z     Checking rustc_hir v0.0.0 (/checkout/src/librustc_hir)
2020-04-04T18:22:20.9896887Z     Checking rustc_query_system v0.0.0 (/checkout/src/librustc_query_system)
2020-04-04T18:22:23.3498992Z     Checking rustc_attr v0.0.0 (/checkout/src/librustc_attr)
2020-04-04T18:22:23.8458860Z     Checking rustc_parse v0.0.0 (/checkout/src/librustc_parse)
2020-04-04T18:22:25.9987763Z     Checking rustc_hir_pretty v0.0.0 (/checkout/src/librustc_hir_pretty)
2020-04-04T18:22:26.4578609Z     Checking rustc_ast_lowering v0.0.0 (/checkout/src/librustc_ast_lowering)
---
2020-04-04T18:26:38.7942846Z Build completed successfully in 0:00:43
2020-04-04T18:26:38.7951267Z + /scripts/validate-toolstate.sh
2020-04-04T18:26:38.7995377Z Cloning into 'rust-toolstate'...
2020-04-04T18:26:39.4292797Z Traceback (most recent call last):
2020-04-04T18:26:39.4293138Z   File "../../src/tools/publish_toolstate.py", line 305, in <module>
2020-04-04T18:26:39.4293429Z     cur_datetime
2020-04-04T18:26:39.4293680Z   File "../../src/tools/publish_toolstate.py", line 205, in update_latest
2020-04-04T18:26:39.4294812Z     maintainers = ' '.join('@'+name for name in MAINTAINERS[tool])
2020-04-04T18:26:39.4295252Z KeyError: u'rustc-dev-guide'
2020-04-04T18:26:39.4336832Z   local time: Sat Apr  4 18:26:39 UTC 2020
2020-04-04T18:26:39.4336832Z   local time: Sat Apr  4 18:26:39 UTC 2020
2020-04-04T18:26:39.6221473Z   network time: Sat, 04 Apr 2020 18:26:39 GMT
2020-04-04T18:26:40.9596547Z 
2020-04-04T18:26:40.9596547Z 
2020-04-04T18:26:40.9664614Z ##[error]Bash exited with code '1'.
2020-04-04T18:26:40.9678252Z ##[section]Finishing: Run build
2020-04-04T18:26:40.9726411Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/70782/merge to s
2020-04-04T18:26:40.9731249Z Task         : Get sources
2020-04-04T18:26:40.9731576Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-04-04T18:26:40.9731852Z Version      : 1.0.0
2020-04-04T18:26:40.9732046Z Author       : Microsoft
2020-04-04T18:26:40.9732046Z Author       : Microsoft
2020-04-04T18:26:40.9732377Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
2020-04-04T18:26:40.9732732Z ==============================================================================
2020-04-04T18:26:41.3095266Z Cleaning any cached credential from repository: rust-lang/rust (GitHub)
2020-04-04T18:26:41.3151304Z ##[section]Finishing: Checkout rust-lang/rust@refs/pull/70782/merge to s
2020-04-04T18:26:41.3242349Z Cleaning up task key
2020-04-04T18:26:41.3243501Z Start cleaning up orphan processes.
2020-04-04T18:26:41.3467397Z Terminate orphan process: pid (3762) (python)
2020-04-04T18:26:41.3705627Z ##[section]Finishing: Finalize Job

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @rust-lang/infra. (Feature Requests)

src/libstd/f32.rs Outdated Show resolved Hide resolved
@dtolnay
Copy link
Member

dtolnay commented Apr 5, 2020

@bors r+

@bors
Copy link
Contributor

bors commented Apr 5, 2020

📌 Commit 28c9231 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 Apr 5, 2020
@dtolnay
Copy link
Member

dtolnay commented Apr 5, 2020

Is it possible we could make f32::consts::FRAC_PI_2 work without having to import std::f32?

@faern
Copy link
Contributor Author

faern commented Apr 5, 2020

Is it possible we could make f32::consts::FRAC_PI_2 work without having to import std::f32?

Not that I know of. And probably not currently. But someone with better compiler knowledge can probably give a better answer.

Associated constant "modules" would be great. Having f32::math::PI would be awesome (where f32 is the primitive type, not the module). I think the module name consts is a bit strange, but I have not read the PR/RFC where it was introduced, maybe there is a good reason it's not called math. The docs on the module even say they are "mathematical constants".

@faern
Copy link
Contributor Author

faern commented Apr 5, 2020

Btw. Are not all the FRAC_* constants pointless now? PI / 2.0 generates identical assembly code according to godbolt. I assume they were needed because the constant evaluation at compile time was worse many versions ago(?). But do these constants have any value when using newer Rust?

I see there have been previous arguments about the naming of these constants. So given that the names are not perfect and have a hard time conveying exactly what they mean, I personally think PI / 2.0 is more clear and readable than FRAC_PI_2 for example. And it's shorter 🤷‍♂

This is of course not really relevant to this PR. But my point is that if these constants are indeed pointless it means that the only mathematical constants with any value are PI and E (and possibly TAU, but it's still experimental). And since there are only two of them they can easily become associated constants on the primitive types directly without clogging up the namespace much and we can soft deprecate all of std::fxx::consts 🎉

bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 5, 2020
Rollup of 7 pull requests

Successful merges:

 - rust-lang#70553 (move OS constants to platform crate)
 - rust-lang#70665 (Do not lose or reorder user-provided linker arguments)
 - rust-lang#70750 (Match options directly in the Fuse implementation)
 - rust-lang#70782 (Stop importing the float modules in documentation)
 - rust-lang#70798 ("cannot resolve" → "cannot satisfy")
 - rust-lang#70808 (Simplify dtor registration for HermitCore by using a list of destructors)
 - rust-lang#70824 (Remove marker comments in libstd/lib.rs macro imports)

Failed merges:

r? @ghost
@bors bors merged commit 269eeea into rust-lang:master Apr 6, 2020
@faern faern deleted the use-assoc-float-consts branch April 6, 2020 07:10
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants