Skip to content

Improve range docs #77874

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

Merged
merged 1 commit into from
Oct 19, 2020
Merged

Improve range docs #77874

merged 1 commit into from
Oct 19, 2020

Conversation

camelid
Copy link
Member

@camelid camelid commented Oct 12, 2020

  • Improve code formatting and legibility
  • Various other readability improvements

@camelid camelid added C-cleanup Category: PRs that clean code up or issues documenting cleanup. A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools labels Oct 12, 2020
@rust-highfive
Copy link
Contributor

r? @dtolnay

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 12, 2020
/// assert_eq!(arr[ .. 3], [0,1,2 ]);
/// assert_eq!(arr[ ..=3], [0,1,2,3 ]);
/// assert_eq!(arr[1.. ], [ 1,2,3,4]);
/// assert_eq!(arr[1.. 3], [ 1,2 ]); // Range
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure why the comment // Range was here; it didn't make sense to me, so I removed it.

Copy link
Member

Choose a reason for hiding this comment

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

It looks like these must have been copy-pasted to all the Range* types? So the comment is probably to emphasize that that particular line is the one for this type.

Seems like this example should be maybe somewhere where we reference it from all the types, and call-out Range, RangeTo, etc on every line. I guess there's not a core::range module to put it on...

Maybe this example could go on RangeBounds, and all the Range* types could link over there as a way to jump between them?

Copy link
Member Author

Choose a reason for hiding this comment

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

So the comment is probably to emphasize that that particular line is the one for this type.

Ah, I see; thanks for clearing that up :)

Copy link
Member Author

Choose a reason for hiding this comment

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

For now I just updated all the examples to make them consistent.

@camelid camelid force-pushed the range-docs-readability branch 2 times, most recently from 59543ff to 8778fdc Compare October 18, 2020 21:39
@camelid
Copy link
Member Author

camelid commented Oct 18, 2020

Ready for a final review!

@@ -6,6 +6,9 @@ use crate::hash::Hash;
/// `RangeFull` is primarily used as a [slicing index], its shorthand is `..`.
/// It cannot serve as an [`Iterator`] because it doesn't have a starting point.
///
/// `RangeFull` is a [*zero-sized type*][ZST], which means it is a singleton –
/// there is only one instance of the `RangeFull` type.
Copy link
Member

@scottmcm scottmcm Oct 18, 2020

Choose a reason for hiding this comment

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

suggestion: I would avoid the "singleton" and "instance" language here, since one can have (.., 4, ..) and such which could easily be argued to be two instances. (Just because something is a ZST doesn't mean that their addresses are always ptr::eq, which is demonstrated most clearly by the slice iterators.)

Maybe just leave the mention off? It's defined as pub struct RangeFull;, so I don't think we need to say this on every such type -- people can look it up in the book if they're curious. (For example, fmt::Error doesn't say it's a ZST.) Especially since I don't think there's a case where it being a ZST actually semantically affects safe code.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense. I think I added this because I say "This is the RangeFull" later on, and I thought this might make it clearer to people why I say "the": that there's only one possible value. But I can remove it :)

* Mention that `RangeFull` is a ZST and thus a singleton
* Improve code formatting and legibility
* Various other readability improvements
@camelid camelid force-pushed the range-docs-readability branch from 8778fdc to a885c50 Compare October 18, 2020 23:06
@scottmcm
Copy link
Member

r? @scottmcm
@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Oct 18, 2020

📌 Commit a885c50 has been approved by scottmcm

@rust-highfive rust-highfive assigned scottmcm and unassigned dtolnay Oct 18, 2020
@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 Oct 18, 2020
@camelid camelid changed the title Improve readability of range docs Improve range docs Oct 18, 2020
@bors
Copy link
Collaborator

bors commented Oct 19, 2020

⌛ Testing commit a885c50 with merge e42cbe8...

@bors
Copy link
Collaborator

bors commented Oct 19, 2020

☀️ Test successful - checks-actions, checks-azure
Approved by: scottmcm
Pushing e42cbe8 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Oct 19, 2020
@bors bors merged commit e42cbe8 into rust-lang:master Oct 19, 2020
@rustbot rustbot added this to the 1.49.0 milestone Oct 19, 2020
@camelid camelid deleted the range-docs-readability branch October 19, 2020 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools C-cleanup Category: PRs that clean code up or issues documenting cleanup. merged-by-bors This PR was explicitly merged by bors. 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