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

Fix for #39596: sort Trait2 before Trait10. #40567

Merged
merged 1 commit into from
Mar 25, 2017

Conversation

clarfonthey
Copy link
Contributor

@clarfonthey clarfonthey commented Mar 16, 2017

This is a change discussed in #39596. Essentially, item names will be sorted as if they're (&str, u64) pairs instead of just &str, meaning that "Apple" < "Banana" and also "Fruit10" > "Fruit2".

Sample sorting:

  1. Apple
  2. Banana
  3. Fruit
  4. Fruit0
  5. Fruit00
  6. Fruit1
  7. Fruit01
  8. Fruit2
  9. Fruit02
  10. Fruit20
  11. Fruit100
  12. Pear

Examples of generated documentation:
https://docs.charr.xyz/before-doc/test_sorting/
https://docs.charr.xyz/after-doc/test_sorting/

Screenshots of generated documentation:
Before: http://imgur.com/Ktb10ti
After: http://imgur.com/CZJjqIN

@rust-highfive
Copy link
Collaborator

r? @steveklabnik

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

}

fn name_key(name: &str) -> (&str, u64) {
let split = s.bytes().rposition(|b| b < b'0' || b'9' < b).unwrap_or(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be unwrap_or(name.len())?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So we were actually both wrong on this one and I figured this out. The correct answer is map_or(0, |s| s + 1).

Because if the position of the last non-digit is nothing, then this should be 0. Otherwise, it should be the position + 1 to be the beginning of the digits.

// get rid of leading zeroes
let split = split + s[split..].bytes().position(|b| b != b'0').unwrap_or(0);
let strkey = &s[..split];
let intkey = s[split..].parse().unwrap_or(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

If parsing fails, shouldn't the ordering fall back to the full name for strkey?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The main thing I was thinking is that the only case where this could fail is if split == name.len(), in which case returning 0 for intkey is what's desired anyway. But I'll change it regardless for clarity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, you're right, overflowing a u64 can theoretically (but unlikely) happen. Fixed.

@clarfonthey clarfonthey force-pushed the rustdoc-sort branch 2 times, most recently from 7af0c0f to 15d35cd Compare March 20, 2017 01:44
@steveklabnik
Copy link
Member

r? @rust-lang/tools

@alexcrichton
Copy link
Member

@steveklabnik this seems like it's much more in the doc team's wheelhouse? (e.g. the presentation of the documentation, not the implementation)

@steveklabnik
Copy link
Member

Fine by me if that's fine by you :)

/cc @rust-lang/docs then

@GuillaumeGomez
Copy link
Member

Could provide screenshots of this (before and after would be very useful) please?

@clarfonthey
Copy link
Contributor Author

So I just picked out the errors in this, added a few tests, and I'll show a few screenshots once it's done compiling.

@clarfonthey clarfonthey force-pushed the rustdoc-sort branch 7 times, most recently from 5af9cd9 to 555223f Compare March 23, 2017 22:16
@clarfonthey
Copy link
Contributor Author

clarfonthey commented Mar 23, 2017

@clarfonthey
Copy link
Contributor Author

This is ready to merge whenever so let me know if the docs team is okay with this!

@clarfonthey clarfonthey changed the title Fix for #39596: sort Trait1 before Trait2. Fix for #39596: sort Trait2 before Trait10. Mar 24, 2017
@frewsxcv
Copy link
Member

LGTM, though going to double check it's alright with @GuillaumeGomez

@GuillaumeGomez
Copy link
Member

Fine by me. Thanks @clarcharr!

@bors: r=frewsxcv rollup

@bors
Copy link
Contributor

bors commented Mar 24, 2017

📌 Commit c09083c has been approved by frewsxcv

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Mar 24, 2017
Fix for rust-lang#39596: sort Trait2 before Trait10.

This is a change discussed in rust-lang#39596. Essentially, item names will be sorted as if they're (&str, u64) pairs instead of just `&str`, meaning that `"Apple" < "Banana"` and also `"Fruit10" > "Fruit2"`.

Sample sorting:

1. Apple
2. Banana
3. Fruit
4. Fruit0
5. Fruit00
6. Fruit1
7. Fruit01
8. Fruit2
9. Fruit02
10. Fruit20
11. Fruit100
12. Pear

Examples of generated documentation:
https://docs.charr.xyz/before-doc/test_sorting/
https://docs.charr.xyz/after-doc/test_sorting/

Screenshots of generated documentation:
Before: http://imgur.com/Ktb10ti
After: http://imgur.com/CZJjqIN
bors added a commit that referenced this pull request Mar 24, 2017
Rollup of 8 pull requests

- Successful merges: #40567, #40602, #40636, #40739, #40756, #40790, #40794, #40803
- Failed merges:
@bors bors merged commit c09083c into rust-lang:master Mar 25, 2017
@clarfonthey clarfonthey deleted the rustdoc-sort branch April 1, 2017 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants