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

Primitive docs relevant #48152

Merged
merged 5 commits into from
Feb 17, 2018
Merged

Primitive docs relevant #48152

merged 5 commits into from
Feb 17, 2018

Conversation

antoyo
Copy link
Contributor

@antoyo antoyo commented Feb 12, 2018

This fixes the documentation to show the right types in the examples for many integer methods.

I need to check if the result is correct before we merge.

@antoyo
Copy link
Contributor Author

antoyo commented Feb 12, 2018

r? @QuietMisdreavus
cc @GuillaumeGomez

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @joshtriplett (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

```
let n = 0b01001100", stringify!($SelfT), ";

assert_eq!(n.count_zeros(), 5);
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't seem right; wouldn't the number of zeroes depend on the size of the type? It should be the number of bits in the type minus 3.

Copy link
Member

Choose a reason for hiding this comment

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

It would indeed!

@@ -1436,33 +1446,35 @@ macro_rules! uint_impl {
unsafe { intrinsics::ctlz(self as $ActualT) as u32 }
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't the example of leading_zeroes get the same treatment, rather than hardcoding u16?

Copy link
Member

Choose a reason for hiding this comment

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

(And ditto for other methods here whose docs still list specific types in their examples.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some methods were left as is because it was hard to make the example generic.

Copy link
Member

Choose a reason for hiding this comment

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

If you can't convert all the examples, I would like to see the "examples are shared between primitive integer types" notice kept on the primitive docs, since it still applies.

@pietroalbini pietroalbini added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Feb 12, 2018
@GuillaumeGomez GuillaumeGomez force-pushed the primitive-docs-relevant branch 3 times, most recently from 4f202bf to dcc9f74 Compare February 13, 2018 18:39
@GuillaumeGomez
Copy link
Member

Should be good now.

@GuillaumeGomez GuillaumeGomez changed the title [WIP] Primitive docs relevant Primitive docs relevant Feb 14, 2018
@GuillaumeGomez
Copy link
Member

Tests passed!

Copy link
Member

@QuietMisdreavus QuietMisdreavus left a comment

Choose a reason for hiding this comment

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

Just a couple notes. Thanks so much for doing this!

int_impl! { i128, i128, u128, 128, -170141183460469231731687303715884105728,
170141183460469231731687303715884105727, "#![feature(i128_type)]
#![feature(i128)]
# fn main() {
Copy link
Member

Choose a reason for hiding this comment

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

Wait, does this actually need the manual fn main? Rustdoc should move those feature flags outside its generated main function.

Copy link
Member

Choose a reason for hiding this comment

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

Apparently it fails otherwise. I was quite surprised as well...

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it has to do with line breaks. Did your previous attempt have a line break after the feature flags? I think rustdoc doesn't do anything fancier than "if the line starts with #![, splice out the whole line".

@@ -1436,33 +1446,35 @@ macro_rules! uint_impl {
unsafe { intrinsics::ctlz(self as $ActualT) as u32 }
Copy link
Member

Choose a reason for hiding this comment

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

If you can't convert all the examples, I would like to see the "examples are shared between primitive integer types" notice kept on the primitive docs, since it still applies.

@QuietMisdreavus
Copy link
Member

[00:03:47] error: this file contains an un-closed delimiter
[00:03:47]     --> libcore/num/mod.rs:3756:4
[00:03:47]      |
[00:03:47] 3756 | ];
[00:03:47]      |    ^
[00:03:47]      |
[00:03:47] help: did you mean to close this delimiter?
[00:03:47]     --> libcore/num/mod.rs:1390:24
[00:03:47]      |
[00:03:47] 1390 | macro_rules! uint_impl {
[00:03:47]      |                        ^
[00:03:47] 
[00:03:47] error: no rules expected the token `#`
[00:03:47]     --> libcore/num/mod.rs:2481:1
[00:03:47]      |
[00:03:47] 2481 | #[lang = "u8"]
[00:03:47]      | ^
[00:03:47] 
[00:03:47] error: Could not compile `core`.

@QuietMisdreavus
Copy link
Member

[01:12:33]    Doc-tests core
[01:12:36] 
[01:12:36] running 1324 tests
<snip>
[01:14:46] failures:
[01:14:46] 
[01:14:46] ---- num/mod.rs - num::u128::leading_zeros (line 107) stdout ----
[01:14:46] 	error[E0658]: 128-bit type is unstable (see issue #35118)
[01:14:46]  --> num/mod.rs:108:9
[01:14:46]   |
[01:14:46] 4 | let n = u128::max_value() >> 2;
[01:14:46]   |         ^^^^^^^^^^^^^^^
[01:14:46]   |
[01:14:46]   = help: add #![feature(i128_type)] to the crate attributes to enable
[01:14:46] 
[01:14:46] thread 'rustc' panicked at 'couldn't compile the test', librustdoc/test.rs:298:13
[01:14:46] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[01:14:46] 
[01:14:46] 
[01:14:46] failures:
[01:14:46]     num/mod.rs - num::u128::leading_zeros (line 107)

@QuietMisdreavus
Copy link
Member

[01:19:36]    Doc-tests core
[01:19:40] 
[01:19:40] running 1324 tests
<snip>
[01:22:06] failures:
[01:22:06] 
[01:22:06] ---- num/mod.rs - num::u128::leading_zeros (line 107) stdout ----
[01:22:06] 	error: this file contains an un-closed delimiter
[01:22:06]  --> num/mod.rs:114:35
[01:22:06]   |
[01:22:06] 9 | assert_eq!(n.leading_zeros(), 2);
[01:22:06]   |                                   ^
[01:22:06]   |
[01:22:06] help: did you mean to close this delimiter?
[01:22:06]  --> num/mod.rs:111:11
[01:22:06]   |
[01:22:06] 6 | fn main() {
[01:22:06]   |           ^
[01:22:06] 
[01:22:06] thread 'rustc' panicked at 'couldn't compile the test', librustdoc/test.rs:298:13
[01:22:06] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[01:22:06] 
[01:22:06] 
[01:22:06] failures:
[01:22:06]     num/mod.rs - num::u128::leading_zeros (line 107)

@QuietMisdreavus
Copy link
Member

Looks like we're all set! Thanks so much!

@bors r+

@bors
Copy link
Contributor

bors commented Feb 15, 2018

📌 Commit d692e94 has been approved by QuietMisdreavus

@bors bors removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Feb 15, 2018
@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Feb 15, 2018
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Feb 16, 2018
…uietMisdreavus

Primitive docs relevant

This fixes the documentation to show the right types in the examples for many integer methods.

I need to check if the result is correct before we merge.
@kennytm
Copy link
Member

kennytm commented Feb 16, 2018

@bors r-

Unfortunately this PR failed on 32-bit platforms.

[00:03:20] error: unexpected end of macro invocation
[00:03:20]     --> src/libcore/num/mod.rs:1380:42
[00:03:20]      |
[00:03:20] 1380 |     int_impl! { isize, i32, u32, 32, "", "" }
[00:03:20]      |                                          ^^

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 16, 2018
}

#[cfg(target_pointer_width = "32")]
#[lang = "isize"]
impl isize {
int_impl! { isize, i32, u32, 32 }
int_impl! { isize, i32, u32, 32, "", "" }
Copy link
Member

Choose a reason for hiding this comment

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

You are missing -2147483648, 2147483647 here. Similar for the 16-bit code at line 1374 above.

Copy link
Member

Choose a reason for hiding this comment

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

Indeed, thanks!

@GuillaumeGomez
Copy link
Member

Fixed.

@bors: r=QuietMisdreavus

@bors
Copy link
Contributor

bors commented Feb 16, 2018

📌 Commit a58409d has been approved by QuietMisdreavus

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 16, 2018
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Feb 17, 2018
…uietMisdreavus

Primitive docs relevant

This fixes the documentation to show the right types in the examples for many integer methods.

I need to check if the result is correct before we merge.
bors added a commit that referenced this pull request Feb 17, 2018
Rollup of 8 pull requests

- Successful merges: #48095, #48152, #48234, #48239, #48243, #48260, #48284, #48286
- Failed merges:
@bors bors merged commit a58409d into rust-lang:master Feb 17, 2018
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.

8 participants