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 equivalents of C's <ctype.h> functions to AsciiExt. #39659

Merged
merged 3 commits into from
Feb 15, 2017

Conversation

zackw
Copy link
Contributor

@zackw zackw commented Feb 8, 2017

  • is_ascii_alphabetic
  • is_ascii_uppercase
  • is_ascii_lowercase
  • is_ascii_alphanumeric
  • is_ascii_digit
  • is_ascii_hexdigit
  • is_ascii_punctuation
  • is_ascii_graphic
  • is_ascii_whitespace
  • is_ascii_control

This addresses issue #39658.

Lightly tested on x86-64-linux. tidy complains about the URLs in the documentation making lines too long, I don't know what to do about that.

 * `is_ascii_alphabetic`
 * `is_ascii_uppercase`
 * `is_ascii_lowercase`
 * `is_ascii_alphanumeric`
 * `is_ascii_digit`
 * `is_ascii_hexdigit`
 * `is_ascii_punctuation`
 * `is_ascii_graphic`
 * `is_ascii_whitespace`
 * `is_ascii_control`

This addresses issue rust-lang#39658.
@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 @sfackler (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.

@sfackler sfackler added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Feb 8, 2017
@sfackler
Copy link
Member

sfackler commented Feb 8, 2017

cc @rust-lang/libs

I've always been a bit annoyed this is a separate trait at all. Might be worth inlining these while we're at it.

@zackw
Copy link
Contributor Author

zackw commented Feb 8, 2017

I've always been a bit annoyed this is a separate trait at all. Might be worth inlining these while we're at it.

I assume by that you mean folding the entire AsciiExt trait into the types it extends. I don't disagree, but can that be done compatibly? There's already a compatibility kludge (the unimplemented!s) in here...

@sfackler
Copy link
Member

sfackler commented Feb 8, 2017

The idea would be that we deprecate this entire module and just move to inherent methods.

@aturon
Copy link
Member

aturon commented Feb 8, 2017

@sfackler

I've always been a bit annoyed this is a separate trait at all. Might be worth inlining these while we're at it.

Interesting -- I don't think there's a good rationale for them being extension methods right now. (Maybe there was at some point, pre-DST). Given that all the methods include ascii in their name, this seems reasonable to me.

I'm also 👍 on this PR.

@zackw
Copy link
Contributor Author

zackw commented Feb 9, 2017

I don't mind doing the work to turn AsciiExt into inherent methods, but I don't understand how libstd, libcore, and libcollections are organized well enough to know where to put the inherent methods. I'm going to need some help with that.

@aturon
Copy link
Member

aturon commented Feb 12, 2017

@japaric, any chance you'd be willing to help @zackw here, given that it may require some more inherent method magic around primitive types?

@alexcrichton
Copy link
Member

Looks good to me as well!

I believe the intention of the trait was to add the method to [u8] and u8 as well, as opposed to just char and str.

I'd be tempted to punt the migration to inherent methods (if at all) to a future PR though and go ahead and land this. Thoughts?

@alexcrichton
Copy link
Member

@zackw it also looks like tidy may be failing on travis?

@aturon
Copy link
Member

aturon commented Feb 13, 2017

I'd be tempted to punt the migration to inherent methods (if at all) to a future PR though and go ahead and land this. Thoughts?

Yeah, that probably makes sense. I do think it'd be a nice change, but it's orthogonal.

@zackw
Copy link
Contributor Author

zackw commented Feb 13, 2017

@alexcrichton

tidy may be failing on travis

Yeah, that's because the added documentation contains two very long URLs. I have just pushed a change to squeeze those lines in under the limit (by shortening the [foo]: tag for them).

@alexcrichton
Copy link
Member

Shame on you for writing thorough documentation!

:)

@zackw
Copy link
Contributor Author

zackw commented Feb 13, 2017

Okay, now the problem is that the doc tests for the new unstable feature aren't properly annotated to say that they use the new unstable feature. 😝 And the reason I didn't notice this before is that I don't know how to run stdlib doc tests locally. 🤦‍♂️

Can one of you please tell me how to do that?

@alexcrichton
Copy link
Member

Oh you can just prefix the tests with #![feature(...)] to allow them to pass. There should be a few other examples of this throughout the standard library as well

@zackw
Copy link
Contributor Author

zackw commented Feb 13, 2017

Oh you can just prefix the tests with #![feature(...)] to allow them to pass

That part I know. What I don't know is how to run the doc tests locally, so that I can verify that I did it right before pushing. rustdoc --test src/libstd/ascii.rs doesn't work, because it tries to process ascii.rs as a standalone crate.

@alexcrichton
Copy link
Member

Oh for that you can use ./x.py src/libstd --test-args $name

@aturon
Copy link
Member

aturon commented Feb 13, 2017

We discussed this is the libs team meeting, and we're all in favor of merging as-is. Feel free to open a separate PR to move to inherent methods as well!

r=me once the travis failure is addressed.

@zackw
Copy link
Contributor Author

zackw commented Feb 13, 2017

@alexcrichton Oh, I see now. x.py test src/libstd does run the doctests, but only If all of the #[test] tests succeed. And my computer can't do IPv6, which makes the #[test] tests always have some failures, so I thought the doctests were under a separate x.py invocation. Thanks for the hint.

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Feb 14, 2017

📌 Commit 162240c has been approved by alexcrichton

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Feb 14, 2017
Add equivalents of C's <ctype.h> functions to AsciiExt.

 * `is_ascii_alphabetic`
 * `is_ascii_uppercase`
 * `is_ascii_lowercase`
 * `is_ascii_alphanumeric`
 * `is_ascii_digit`
 * `is_ascii_hexdigit`
 * `is_ascii_punctuation`
 * `is_ascii_graphic`
 * `is_ascii_whitespace`
 * `is_ascii_control`

This addresses issue rust-lang#39658.

Lightly tested on x86-64-linux.  tidy complains about the URLs in the documentation making lines too long, I don't know what to do about that.
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Feb 14, 2017
Add equivalents of C's <ctype.h> functions to AsciiExt.

 * `is_ascii_alphabetic`
 * `is_ascii_uppercase`
 * `is_ascii_lowercase`
 * `is_ascii_alphanumeric`
 * `is_ascii_digit`
 * `is_ascii_hexdigit`
 * `is_ascii_punctuation`
 * `is_ascii_graphic`
 * `is_ascii_whitespace`
 * `is_ascii_control`

This addresses issue rust-lang#39658.

Lightly tested on x86-64-linux.  tidy complains about the URLs in the documentation making lines too long, I don't know what to do about that.
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Feb 14, 2017
Add equivalents of C's <ctype.h> functions to AsciiExt.

 * `is_ascii_alphabetic`
 * `is_ascii_uppercase`
 * `is_ascii_lowercase`
 * `is_ascii_alphanumeric`
 * `is_ascii_digit`
 * `is_ascii_hexdigit`
 * `is_ascii_punctuation`
 * `is_ascii_graphic`
 * `is_ascii_whitespace`
 * `is_ascii_control`

This addresses issue rust-lang#39658.

Lightly tested on x86-64-linux.  tidy complains about the URLs in the documentation making lines too long, I don't know what to do about that.
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Feb 14, 2017
Add equivalents of C's <ctype.h> functions to AsciiExt.

 * `is_ascii_alphabetic`
 * `is_ascii_uppercase`
 * `is_ascii_lowercase`
 * `is_ascii_alphanumeric`
 * `is_ascii_digit`
 * `is_ascii_hexdigit`
 * `is_ascii_punctuation`
 * `is_ascii_graphic`
 * `is_ascii_whitespace`
 * `is_ascii_control`

This addresses issue rust-lang#39658.

Lightly tested on x86-64-linux.  tidy complains about the URLs in the documentation making lines too long, I don't know what to do about that.
bors added a commit that referenced this pull request Feb 14, 2017
Rollup of 8 pull requests

- Successful merges: #39659, #39730, #39754, #39772, #39785, #39788, #39790, #39813
- Failed merges:
@bors bors merged commit 162240c into rust-lang:master Feb 15, 2017
@japaric
Copy link
Member

japaric commented Feb 15, 2017

@aturon

@japaric, any chance you'd be willing to help @zackw here, given that it may require some more inherent method magic around primitive types?

Sure!

@zackw For char, u8 and str, I believe the implementations can simply be moved into the inherent impl blocks:

For [u8], we'll have add a new u8_slice lang time to allow an inherent impl [u8] alongside the generic impl<T> [T] block. The magic for that is around here but I'm not sure if the change will be straightforward. I can look into that part.

@sfackler
Copy link
Member

sfackler commented Feb 15, 2017

Might be simpler to just stick it in the impl<T> [T] block with a where T: u8 bound on the methods.

@japaric
Copy link
Member

japaric commented Feb 15, 2017

with a where T: u8 bound on the methods.

But u8 is a type, not a trait. Or are you suggesting a "double dispatch" approach?

@sfackler
Copy link
Member

Oh duh, never mind me.

/// Checks if the value is an ASCII graphic character:
/// U+0021 '@' ... U+007E '~'.
/// For strings, true if all characters in the string are
/// ASCII punctuation.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/punctuation/graphic/ here.

@SimonSapin
Copy link
Contributor

When doing this, please make sure that [u8] methods show up in rustdoc output.

bors added a commit that referenced this pull request Nov 5, 2017
…r=alexcrichton

Copy all `AsciiExt` methods to the primitive types directly in order to deprecate it later

**EDIT:** [this PR is ready now](#44042 (comment)). I edited this post to reflect the current status of discussion, which is (apart from code review) pretty much settled.

---

This is my current progress in order to prepare stabilization of #39658. As discussed there (and in #39659), the idea is to deprecated `AsciiExt` and copy all methods to the type directly. Apparently there isn't really a reason to have those methods in an extension trait¹.

~~This is **work in progress**: copy&pasting code while slightly modifying the documentation isn't the most exciting thing to do. Therefore I wanted to already open this WIP PR after doing basically 1/4 of the job (copying methods to `&[u8]`, `char` and `&str` is still missing) to get some feedback before I continue. Some questions possibly worth discussing:~~

1. ~~Does everyone agree that deprecating `AsciiExt` is a good idea? Does everyone agree with the goal of this PR?~~ => apparently yes
2. ~~Are my changes OK so far? Did I do something wrong?~~
3. ~~The issue of the unstable-attribute is currently set to 0. I would wait until you say "Ok" to the whole thing, then create a tracking issue and then insert the correct issue id. Is that ok?~~
4. ~~I tweaked `eq_ignore_ascii_case()`: it now takes the argument `other: u8` instead of `other: &u8`. The latter was enforced by the trait. Since we're not bound to a trait anymore, we can drop the reference, ok?~~ => I reverted this, because the interface has to match the `AsciiExt` interface exactly.

¹ ~~Could it be that we can't write `impl [u8] {}`? This might be the reason for `AsciiExt`. If that is the case: is there a good reason we can't write such an impl block? What can we do instead?~~ => we couldn't at the time this PR was opened, but Simon made it possible.

/cc @SimonSapin @zackw
@zackw zackw deleted the asciiext-ctype branch November 17, 2017 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants