Skip to content

Primitive docs relevant - #48152

Merged
bors merged 5 commits into
rust-lang:masterfrom
antoyo:primitive-docs-relevant
Feb 17, 2018
Merged

Primitive docs relevant#48152
bors merged 5 commits into
rust-lang:masterfrom
antoyo:primitive-docs-relevant

Conversation

@antoyo

Copy link
Copy Markdown
Contributor

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

antoyo commented Feb 12, 2018

Copy link
Copy Markdown
ContributorAuthor

@rust-highfive

Copy link
Copy Markdown
Contributor

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.

Comment threadsrc/libcore/num/mod.rs Outdated
```
let n = 0b01001100", stringify!($SelfT), ";

assert_eq!(n.count_zeros(), 5);

Copy link
Copy Markdown
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would indeed!

Comment threadsrc/libcore/num/mod.rs Outdated
@@ -1436,33 +1446,35 @@ macro_rules! uint_impl {
unsafe { intrinsics::ctlz(self as $ActualT) as u32 }

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
Contributor

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.

@emilyalbiniemilyalbini 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
GuillaumeGomezforce-pushed the primitive-docs-relevant branch 3 times, most recently from 4f202bf to dcc9f74CompareFebruary 13, 2018 18:39
@GuillaumeGomez

Copy link
Copy Markdown
Member

Should be good now.

@GuillaumeGomezGuillaumeGomez changed the title [WIP] Primitive docs relevantPrimitive docs relevantFeb 14, 2018
@GuillaumeGomez

Copy link
Copy Markdown
Member

Tests passed!

@QuietMisdreavusQuietMisdreavus left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Contributor

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".

Comment threadsrc/libcore/num/mod.rs Outdated
@@ -1436,33 +1446,35 @@ macro_rules! uint_impl {
unsafe { intrinsics::ctlz(self as $ActualT) as u32 }

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor
[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
Copy Markdown
Contributor
[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
Copy Markdown
Contributor
[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
Copy Markdown
Contributor

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

@bors r+

@bors

bors commented Feb 15, 2018

Copy link
Copy Markdown
Collaborator

📌 Commit d692e94 has been approved by QuietMisdreavus

@borsbors 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
@borsbors 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
Copy Markdown
Member

@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] | ^^

@borsbors 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
Comment threadsrc/libcore/num/mod.rs Outdated
}

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Fixed.

@bors: r=QuietMisdreavus

@bors

bors commented Feb 16, 2018

Copy link
Copy Markdown
Collaborator

📌 Commit a58409d has been approved by QuietMisdreavus

@borsbors 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:masterFeb 17, 2018
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: 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

@antoyo@rust-highfive@GuillaumeGomez@QuietMisdreavus@bors@kennytm@joshtriplett@emilyalbini