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

Remove str::is_whitespace and str::is_alphanumeric #49657

Closed
dtolnay opened this issue Apr 4, 2018 · 3 comments
Closed

Remove str::is_whitespace and str::is_alphanumeric #49657

dtolnay opened this issue Apr 4, 2018 · 3 comments
Labels
regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Milestone

Comments

@dtolnay
Copy link
Member

dtolnay commented Apr 4, 2018

These methods were added as stable in #49381 (currently in beta for 1.27.0) but we would prefer not to add them as discussed in #49381 (comment).

@dtolnay dtolnay added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. regression-from-stable-to-beta Performance or correctness regression from stable to beta. labels Apr 4, 2018
@withoutboats
Copy link
Contributor

withoutboats commented Apr 4, 2018

Strongly prefer to have this method (unsurprisngly). I assumed it was an oversight that it was missing; I've probably tried s.is_whitespace() a half dozen times and then been surprised it was nightly only.

@oli-obk
Copy link
Contributor

oli-obk commented Apr 5, 2018

We could add a system to be able to add suggestions to missing method errors. Thus the use of is_whitespace would suggest .chars().all(char::is_whitespace)

Deleting these methods should of course not be blocked on such a system being in place

@LukasKalbertodt
Copy link
Member

@oli-obk I like this idea a lot! (independently from this discussion)


About is_alphanumeric: I think I prefer to remove str::is_alphanumeric as it might lead to subtle Unicode bugs. Example:

println!("{}", "böb".chars().all(char::is_alphanumeric));    // true
println!("{}", "böb".chars().all(char::is_alphanumeric));    // false

The second string uses a Combining Diaeresis with an o instead of an ö. Sure, the explicit variant chars().all(...) also has this problem, but being explicit makes the bug a bit less subtle. Having is_alphanumeric on a string might suggest that the method "does the right thing" (whatever that is) instead of looking at characters individually.


I think str::is_whitespace doesn't have a problem with subtle Unicode bugs, but I don't quite like the name: is_whitespace sounds singular to me and thus doesn't translate perfectly to a string.

If you are interested, I did a bit of research how .chars().all(char::is_whitespace) is called in other languages (sometimes with libraries):

Maybe str::is_blank is a better name for Rust?

@alexcrichton alexcrichton added this to the 1.26 milestone Apr 5, 2018
alexcrichton added a commit to alexcrichton/rust that referenced this issue Apr 19, 2018
This commit tweaks a few stable APIs in the `beta` branch before they hit
stable. The `str::is_whitespace` and `str::is_alphanumeric` functions were
deleted (added in rust-lang#49381, issue at rust-lang#49657). The `and_modify` APIs added
in rust-lang#44734 were altered to take a `FnOnce` closure rather than a `FnMut` closure.

Closes rust-lang#49581
Closes rust-lang#49657
alexcrichton added a commit to alexcrichton/rust that referenced this issue Apr 19, 2018
This commit tweaks a few stable APIs in the `beta` branch before they hit
stable. The `str::is_whitespace` and `str::is_alphanumeric` functions were
deleted (added in rust-lang#49381, issue at rust-lang#49657). The `and_modify` APIs added
in rust-lang#44734 were altered to take a `FnOnce` closure rather than a `FnMut` closure.

Closes rust-lang#49581
Closes rust-lang#49657
bors added a commit that referenced this issue Apr 20, 2018
Tweak some stabilizations in libstd

This commit tweaks a few stable APIs in the `beta` branch before they hit
stable. The `str::is_whitespace` and `str::is_alphanumeric` functions were
deleted (added in #49381, issue at #49657). The `and_modify` APIs added
in #44734 were altered to take a `FnOnce` closure rather than a `FnMut` closure.

Closes #49581
Closes #49657
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants