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

Add FromStr impl for NonZero types #58717

Open
wants to merge 5 commits into
base: master
from

Conversation

@hellow554
Copy link
Contributor

hellow554 commented Feb 25, 2019

This is a WIP implementation because I do have some questions regarding the solution.

Somebody should ping the lang team on this I guess.
Please see the annotations on the code for more details.

Closes #58604

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Feb 25, 2019

r? @withoutboats

(rust_highfive has picked a reviewer for you, use r? to override)

@Centril

This comment has been minimized.

Copy link
Contributor

Centril commented Feb 25, 2019

@hellow554

This comment has been minimized.

Copy link
Contributor Author

hellow554 commented Feb 26, 2019

Just as a note: I'm on vacation the next two weeks, so I would really love to see some feedback soon @SimonSapin

@SimonSapin

This comment has been minimized.

Copy link
Contributor

SimonSapin commented Feb 26, 2019

#[unstable] unfortunately doesn’t work on trait impls. Since both the type and trait are stable, the impl will be immediately usable.

@rfcbot fcp merge

Please see the annotations on the code for more details.

I couldn’t find those.

@SimonSapin SimonSapin added the T-libs label Feb 26, 2019

@SimonSapin

This comment has been minimized.

Copy link
Contributor

SimonSapin commented Feb 26, 2019

@rfcbot fcp merge

@rfcbot

This comment has been minimized.

Copy link

rfcbot commented Feb 26, 2019

Team member @SimonSapin 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.

Show resolved Hide resolved src/libcore/num/mod.rs Outdated
@rfcbot

This comment has been minimized.

Copy link

rfcbot commented Feb 26, 2019

🔔 This is now entering its final comment period, as per the review above. 🔔

@hellow554

This comment has been minimized.

Copy link
Contributor Author

hellow554 commented Feb 26, 2019

@SimonSapin I mean the github review thing regarding the unstable thing and from_str_radix.

So for the unstable attribute, I can change that to stable with version 1.34?
What about from_str_radix?

@SimonSapin

This comment has been minimized.

Copy link
Contributor

SimonSapin commented Feb 26, 2019

I don’t seem to find any review or comment about from_str_radix except this one 7 minutes ago. Maybe you still need to submit it?

I think that Beta 1.34 was or will be branched this week, so this should likely be 1.35. And yes, changed to stable.

Show resolved Hide resolved src/libcore/num/mod.rs Outdated
Show resolved Hide resolved src/libcore/num/mod.rs Outdated
Show resolved Hide resolved src/libcore/num/mod.rs
Show resolved Hide resolved src/libcore/num/mod.rs Outdated
@hellow554

This comment has been minimized.

Copy link
Contributor Author

hellow554 commented Feb 27, 2019

TIL: you don't see that rewiew until I hit that button ^^ Sorry!

@SimonSapin

This comment has been minimized.

Copy link
Contributor

SimonSapin commented Feb 27, 2019

@rust-lang/libs What do you think of adding a Zero variant to IntErrorKind (which is #[non_exhaustive] and unstable) and reuse it and ParseIntError for these conversions, rather than introducing new types?

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Feb 27, 2019

@SimonSapin that strategy sounds plausible to me!

@hellow554 hellow554 marked this pull request as ready for review Feb 27, 2019

@SimonSapin

This comment has been minimized.

Copy link
Contributor

SimonSapin commented Feb 27, 2019

Alright, diff look good. r+ when FCP finishes.

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Feb 27, 2019

The job x86_64-gnu-llvm-6.0 of your PR failed on Travis (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.
travis_time:end:00185549:start=1551289234908168486,finish=1551289321843955148,duration=86935786662
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-6.0
---
travis_time:start:test_debuginfo
Check compiletest suite=debuginfo mode=debuginfo-both (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:14:09] 
[01:14:09] running 119 tests
[01:14:34] .iiiii...i.....i..i...i..i.i..i.ii...i.....i..i....i..........iiii..........i...ii...i.......ii.i.i. 100/119
[01:14:38] i......iii.i.....ii
[01:14:38] 
[01:14:38]  finished in 28.896
[01:14:38] travis_fold:end:test_debuginfo

---
[01:24:05]    Compiling core v0.0.0 (/checkout/src/libcore)
[01:24:07] error[E0433]: failed to resolve: use of undeclared type or module `NonZeroU8`
[01:24:07]    --> src/libcore/../libcore/tests/nonzero.rs:132:47
[01:24:07]     |
[01:24:07] 132 |     assert_eq!("123".parse::<NonZeroU8>(), Ok(NonZeroU8::new(123).unwrap()));
[01:24:07]     |                                               ^^^^^^^^^ use of undeclared type or module `NonZeroU8`
[01:24:07] error[E0433]: failed to resolve: use of undeclared type or module `IntErrorKind`
[01:24:07]    --> src/libcore/../libcore/tests/nonzero.rs:136:19
[01:24:07]     |
[01:24:07] 136 |             kind: IntErrorKind::Zero
---
[01:24:07]     |
[01:24:07] 148 |             kind: IntErrorKind::Overflow
[01:24:07]     |                   ^^^^^^^^^^^^ use of undeclared type or module `IntErrorKind`
[01:24:07] 
[01:24:07] error[E0412]: cannot find type `NonZeroU8` in this scope
[01:24:07]    --> src/libcore/../libcore/tests/nonzero.rs:132:30
[01:24:07]     |
[01:24:07] 132 |     assert_eq!("123".parse::<NonZeroU8>(), Ok(NonZeroU8::new(123).unwrap()));
[01:24:07] help: a struct with a similar name exists
[01:24:07]     |
[01:24:07]     |
[01:24:07] 132 |     assert_eq!("123".parse::<NonZeroU32>(), Ok(NonZeroU8::new(123).unwrap()));
[01:24:07] help: possible candidates are found in other modules, you can import them into scope
[01:24:07]     |
[01:24:07] 1   | use core::num::NonZeroU8;
[01:24:07]     |
[01:24:07]     |
[01:24:07] 1   | use std::num::NonZeroU8;
[01:24:07]     |
[01:24:07] 
[01:24:07] error[E0412]: cannot find type `NonZeroU8` in this scope
[01:24:07]    --> src/libcore/../libcore/tests/nonzero.rs:134:21
[01:24:07]     |
[01:24:07] 134 |         "0".parse::<NonZeroU8>(),
[01:24:07] help: a struct with a similar name exists
[01:24:07]     |
[01:24:07]     |
[01:24:07] 134 |         "0".parse::<NonZeroU32>(),
[01:24:07] help: possible candidates are found in other modules, you can import them into scope
[01:24:07]     |
[01:24:07] 1   | use core::num::NonZeroU8;
[01:24:07]     |
---
[01:24:07] help: possible candidates are found in other modules, you can import them into scope
[01:24:07]     |
[01:24:07] 1   | use core::num::ParseIntError;
[01:24:07]     |
[01:24:07] 1   | use std::num::ParseIntError;
[01:24:07] 
[01:24:07] 
[01:24:07] error[E0412]: cannot find type `NonZeroU8` in this scope
[01:24:07]    --> src/libcore/../libcore/tests/nonzero.rs:140:22
[01:24:07]     |
[01:24:07] 140 |         "-1".parse::<NonZeroU8>(),
[01:24:07] help: a struct with a similar name exists
[01:24:07]     |
[01:24:07]     |
[01:24:07] 140 |         "-1".parse::<NonZeroU32>(),
[01:24:07] help: possible candidates are found in other modules, you can import them into scope
[01:24:07]     |
[01:24:07] 1   | use core::num::NonZeroU8;
[01:24:07]     |
---
[01:24:07] help: possible candidates are found in other modules, you can import them into scope
[01:24:07]     |
[01:24:07] 1   | use core::num::ParseIntError;
[01:24:07]     |
[01:24:07] 1   | use std::num::ParseIntError;
[01:24:07] 
[01:24:07] 
[01:24:07] error[E0412]: cannot find type `NonZeroU8` in this scope
[01:24:07]    --> src/libcore/../libcore/tests/nonzero.rs:146:23
[01:24:07]     |
[01:24:07] 146 |         "129".parse::<NonZeroU8>(),
[01:24:07] help: a struct with a similar name exists
[01:24:07]     |
[01:24:07]     |
[01:24:07] 146 |         "129".parse::<NonZeroU32>(),
[01:24:07] help: possible candidates are found in other modules, you can import them into scope
[01:24:07]     |
[01:24:07] 1   | use core::num::NonZeroU8;
[01:24:07]     |
---
[01:24:07] help: possible candidates are found in other modules, you can import them into scope
[01:24:07]     |
[01:24:07] 1   | use core::num::ParseIntError;
[01:24:07]     |
[01:24:07] 1   | use std::num::ParseIntError;
[01:24:07] 
[01:24:18] error: aborting due to 11 previous errors
[01:24:18] 
[01:24:18] Some errors occurred: E0412, E0422, E0433.
[01:24:18] Some errors occurred: E0412, E0422, E0433.
[01:24:18] For more information about an error, try `rustc --explain E0412`.
[01:24:18] error: Could not compile `core`.
[01:24:18] 
[01:24:18] To learn more, run the command again with --verbose.
[01:24:18] 
[01:24:18] 
[01:24:18] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "test" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" "panic-unwind backtrace" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "-p" "core" "--" "--quiet"
[01:24:18] 
[01:24:18] 
[01:24:18] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:24:18] Build completed unsuccessfully in 0:21:43
[01:24:18] Build completed unsuccessfully in 0:21:43
[01:24:18] Makefile:48: recipe for target 'check' failed
[01:24:18] make: *** [check] Error 1
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:2058aab0
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Wed Feb 27 19:06:29 UTC 2019
---
travis_time:end:052843e4:start=1551294391340574520,finish=1551294391346558537,duration=5984017
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:061bb880
$ ln -s . checkout && for CORE i

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 @TimNN. (Feature Requests)

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Feb 28, 2019

The job x86_64-gnu-llvm-6.0 of your PR failed on Travis (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.
travis_time:end:1dd7a369:start=1551336453136325981,finish=1551336529044450194,duration=75908124213
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-6.0
---
travis_time:start:test_debuginfo
Check compiletest suite=debuginfo mode=debuginfo-both (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:15:26] 
[01:15:26] running 119 tests
[01:15:53] .iiiii...i.....i..i...i..i.i..i.ii...i.....i..i....i..........iiii..........i...ii...i.......ii.i.i. 100/119
[01:15:58] i......iii.i.....ii
[01:15:58] 
[01:15:58]  finished in 31.575
[01:15:58] travis_fold:end:test_debuginfo

---
[01:25:11] travis_fold:start:test_stage1-core
travis_time:start:test_stage1-core
Testing core stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:25:11]    Compiling core v0.0.0 (/checkout/src/libcore)
[01:25:14] error[E0658]: use of unstable library feature 'int_error_matching': it can be useful to match errors when making error messages for integer parsing (see issue #22639)
[01:25:14]  --> src/libcore/../libcore/tests/nonzero.rs:1:17
[01:25:14]   |
[01:25:14] 1 | use core::num::{IntErrorKind, NonZeroU8, NonZeroU32, NonZeroI32, ParseIntError};
[01:25:14]   |
[01:25:14]   = help: add #![feature(int_error_matching)] to the crate attributes to enable
[01:25:14] 
[01:25:14] 
[01:25:14] error[E0658]: use of unstable library feature 'int_error_matching': it can be useful to match errors when making error messages for integer parsing (see issue #22639)
[01:25:14]    --> src/libcore/../libcore/tests/nonzero.rs:135:19
[01:25:14] 135 |             kind: IntErrorKind::Zero
[01:25:14]     |                   ^^^^^^^^^^^^^^^^^^
[01:25:14]     |
[01:25:14]     = help: add #![feature(int_error_matching)] to the crate attributes to enable
[01:25:14]     = help: add #![feature(int_error_matching)] to the crate attributes to enable
[01:25:14] 
[01:25:14] error[E0658]: use of unstable library feature 'int_error_matching': it can be useful to match errors when making error messages for integer parsing (see issue #22639)
[01:25:14]    --> src/libcore/../libcore/tests/nonzero.rs:141:19
[01:25:14] 141 |             kind: IntErrorKind::Underflow
[01:25:14]     |                   ^^^^^^^^^^^^^^^^^^^^^^^
[01:25:14]     |
[01:25:14]     = help: add #![feature(int_error_matching)] to the crate attributes to enable
[01:25:14]     = help: add #![feature(int_error_matching)] to the crate attributes to enable
[01:25:14] 
[01:25:14] error[E0658]: use of unstable library feature 'int_error_matching': it can be useful to match errors when making error messages for integer parsing (see issue #22639)
[01:25:14]    --> src/libcore/../libcore/tests/nonzero.rs:147:19
[01:25:14] 147 |             kind: IntErrorKind::Overflow
[01:25:14]     |                   ^^^^^^^^^^^^^^^^^^^^^^
[01:25:14]     |
[01:25:14]     = help: add #![feature(int_error_matching)] to the crate attributes to enable
---
[01:25:24] 
[01:25:24] To learn more, run the command again with --verbose.
[01:25:24] 
[01:25:24] 
[01:25:24] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "test" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" "panic-unwind backtrace" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "-p" "core" "--" "--quiet"
[01:25:24] 
[01:25:24] 
[01:25:24] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:25:24] Build completed unsuccessfully in 0:21:56
[01:25:24] Build completed unsuccessfully in 0:21:56
[01:25:24] Makefile:48: recipe for target 'check' failed
[01:25:24] make: *** [check] Error 1
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:080c14aa
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Thu Feb 28 08:14:21 UTC 2019
---
travis_time:end:0568bf28:start=1551341663882453381,finish=1551341663887550940,duration=5097559
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:020398ea
$ ln -s . checkout && for CORE i

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 @TimNN. (Feature Requests)

@hellow554

This comment has been minimized.

Copy link
Contributor Author

hellow554 commented Feb 28, 2019

[01:25:14] error[E0658]: use of unstable library feature 'int_error_matching': it can be useful to match errors when making error messages for integer parsing (see issue #22639)
[01:25:14]  --> src/libcore/../libcore/tests/nonzero.rs:1:17
[01:25:14]   |
[01:25:14] 1 | use core::num::{IntErrorKind, NonZeroU8, NonZeroU32, NonZeroI32, ParseIntError};
[01:25:14]   |
[01:25:14]   = help: add #![feature(int_error_matching)] to the crate attributes to enable

How should I deal with this? Should I add the feature to the test or should I do it like https://github.com/rust-lang/rust/blob/master/src/libcore/tests/num/int_macros.rs#L158-L160 and completly ignore the error and just check if it's Some or None?

@SimonSapin

This comment has been minimized.

Copy link
Contributor

SimonSapin commented Feb 28, 2019

I think the tests you linked were written before the kind method was added. So it’s not to avoid the feature gate that they are written this way. It’s fine to add whatever unstable feature gate to tests in this repository, as needed to write tests that you think are appropriate.

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Feb 28, 2019

The job x86_64-gnu-llvm-6.0 of your PR failed on Travis (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.
travis_time:end:27dbf610:start=1551361726383829793,finish=1551361884356879772,duration=157973049979
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-6.0
---
travis_time:start:test_debuginfo
Check compiletest suite=debuginfo mode=debuginfo-both (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:15:00] 
[01:15:00] running 119 tests
[01:15:25] .iiiii...i.....i..i...i..i.i..i.ii...i.....i..i....i..........iiii..........i...ii...i.......ii.i.i. 100/119
[01:15:29] i......iii.i.....ii
[01:15:29] 
[01:15:29]  finished in 29.047
[01:15:29] travis_fold:end:test_debuginfo

---
[01:24:50] travis_fold:start:test_stage1-core
travis_time:start:test_stage1-core
Testing core stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:24:50]    Compiling core v0.0.0 (/checkout/src/libcore)
[01:25:09] error[E0451]: field `kind` of struct `std::num::ParseIntError` is private
[01:25:09]    --> src/libcore/../libcore/tests/nonzero.rs:135:13
[01:25:09] 135 |             kind: IntErrorKind::Zero
[01:25:09]     |             ^^^^^^^^^^^^^^^^^^^^^^^^ field `kind` is private
[01:25:09] 
[01:25:09] 
[01:25:09] error[E0451]: field `kind` of struct `std::num::ParseIntError` is private
[01:25:09]    --> src/libcore/../libcore/tests/nonzero.rs:141:13
[01:25:09] 141 |             kind: IntErrorKind::Underflow
[01:25:09]     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ field `kind` is private
[01:25:09] 
[01:25:09] 
[01:25:09] error[E0451]: field `kind` of struct `std::num::ParseIntError` is private
[01:25:09]    --> src/libcore/../libcore/tests/nonzero.rs:147:13
[01:25:09] 147 |             kind: IntErrorKind::Overflow
[01:25:09]     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ field `kind` is private
[01:25:09] 
[01:25:10] error: aborting due to 3 previous errors
[01:25:10] error: aborting due to 3 previous errors
[01:25:10] 
[01:25:10] For more information about this error, try `rustc --explain E0451`.
[01:25:10] error: Could not compile `core`.
[01:25:10] 
[01:25:10] To learn more, run the command again with --verbose.
[01:25:10] 
[01:25:10] 
[01:25:10] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "test" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" "panic-unwind backtrace" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "-p" "core" "--" "--quiet"
[01:25:10] 
[01:25:10] 
[01:25:10] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:25:10] Build completed unsuccessfully in 0:21:38
[01:25:10] Build completed unsuccessfully in 0:21:38
[01:25:10] make: *** [check] Error 1
[01:25:10] Makefile:48: recipe for target 'check' failed
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:0017aaca
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Thu Feb 28 15:16:43 UTC 2019
---
travis_time:end:000834e0:start=1551367005579610717,finish=1551367005585463281,duration=5852564
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:203d394e
$ ln -s . checkout && for CORE 

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 @TimNN. (Feature Requests)

@hellow554 hellow554 changed the title WIP: Add FromStr impl for NonZero types Add FromStr impl for NonZero types Feb 28, 2019

@hellow554

This comment has been minimized.

Copy link
Contributor Author

hellow554 commented Feb 28, 2019

Finally (!) fixed my local rust environment so I could run the tests again sucesfully. Cross your fingers!

@rfcbot

This comment has been minimized.

Copy link

rfcbot commented Mar 8, 2019

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

The RFC will be merged soon.

@Centril Centril added this to the 1.35 milestone Mar 8, 2019

@hellow554

This comment has been minimized.

Copy link
Contributor Author

hellow554 commented Mar 13, 2019

@SimonSapin merge is done. Can you do a r+?

@TimNN

This comment has been minimized.

Copy link
Contributor

TimNN commented Mar 19, 2019

Ping from triage @SimonSapin: This PR is waiting for your review / approval!

@Centril

This comment has been minimized.

Copy link
Contributor

Centril commented Mar 26, 2019

Randomly reassigning; r? @Amanieu

@rust-highfive rust-highfive assigned Amanieu and unassigned SimonSapin Mar 26, 2019

@Amanieu

This comment has been minimized.

Copy link
Contributor

Amanieu commented Mar 26, 2019

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Mar 26, 2019

📌 Commit 7330525 has been approved by Amanieu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.