Uh oh!
There was an error while loading. Please reload this page.
Copy all AsciiExt methods to the primitive types directly in order to deprecate it later - #44042
Conversation
LukasKalbertodt
commented
Aug 22, 2017
I don't think the Travis-fail is my fault ... Right? 😕 |
steveklabnik
commented
Aug 22, 2017
I do not believe so, seems... strange? |
bluss
commented
Aug 23, 2017
“The” |
SimonSapin
commented
Aug 23, 2017
|
kennytm
commented
Aug 23, 2017
@LukasKalbertodt Any error other than |
LukasKalbertodt
commented
Aug 23, 2017
@kennytm Ok, thanks!
@bluss (and potentially everyone) I'm afraid I don't quite understand. There is this one impl-block in #[lang = "slice"]#[cfg(not(test))]impl<T>[T]{ ... }If I try to add If I add So... is that just impossible? Is that what you were saying, @bluss? |
SimonSapin
commented
Aug 23, 2017
A creative hack to work around // The existing impl block#[lang = "slice"]impl<T>[T]{// ...// New methods:fnis_ascii(&self)whereSelf:AsRef<[u8]>{let self_as_bytes = self.as_ref();// ...}}Given the available impls of |
LukasKalbertodt
commented
Aug 26, 2017
So am I right and it is indeed not possible to add methods to I see the following possibilities:
In 1b, 2b and 3 we assume that the possibility to add methods to |
SimonSapin
commented
Aug 26, 2017
I believe it is not possible purely in library code, just like |
aidanhs
commented
Aug 31, 2017
r? @sfackler since highfive flaked and this seems library related. Not sure if you'll need compiler team input though... |
sfackler
commented
Sep 2, 2017
This might be a bit tricky to land unstable since inherent methods override trait-provided methods. So every existing use of cc @rust-lang/libs. |
alexcrichton
commented
Sep 14, 2017
The libs team discussed this during triage the other day and the conclusion was that this is good to go, @sfackler do you know what specifically needs to be updated here? |
SimonSapin
commented
Sep 15, 2017
@alexcrichton There’s still two issues to resolve:
|
sfackler
commented
Sep 16, 2017
We're fine landing these as immediately stable since they're just being moved around. Not sure if we should block on figuring out the |
SimonSapin
commented
Sep 16, 2017
Am I missing something? I don’t see how we can just decide to not block on having a technical solution to get past this compilation error: |
LukasKalbertodt
commented
Sep 16, 2017
We do have the impl[T]{fnfoo()whereSelf:AsRef<[u8]>{}}solution. But as mentioned above, it has several disadvantages and really feels like a hack. Additionally, changing it to I could write the code to make |
sfackler
commented
Sep 16, 2017
The not-blocking on it solution would be to keep using the extension trait for [u8]. |
bors
commented
Sep 18, 2017
☔ The latest upstream changes (presumably #44678) made this pull request unmergeable. Please resolve the merge conflicts. |
alexcrichton
commented
Sep 21, 2017
ping @LukasKalbertodt would you be willing to keep up w/ this PR? |
kennytm
commented
Sep 21, 2017
I think we are still waiting for the team's decision on whether to introduce |
SimonSapin
commented
Sep 21, 2017
I’ll try to find a mentor in a couple weeks at the "impl days" after RustFest Zurich who could help with adding a lang item or something for |
LukasKalbertodt
commented
Sep 21, 2017
@alexcrichton Sure! I just wasn't sure if we decided already (what @kennytm said) ^_^ I'll rebase in the next couple of days and then move/copy the methods for |
Otherwise changes to the compiler are unable to introduce new warnings: some crates tested by cargotest deny all warnings and thus, the CI build fails. Thanks SimonSapin for the patch!
LukasKalbertodt
commented
Nov 5, 2017
Interesting, I didn't know that.
I just pushed the patch here; I guess it's easier ;-) Thanks a lot for quickly coming up with the patch and testing it! I tested locally again, too, and no issues so far. So I guess... this time, bors might actually return with a nice result ^_^ |
kennytm
commented
Nov 5, 2017
@bors r=alexcrichton |
bors
commented
Nov 5, 2017
📌 Commit ea55596 has been approved by |
bors
commented
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
bors
commented
Nov 5, 2017
☀️ Test successful - status-appveyor, status-travis |
LukasKalbertodt
commented
Nov 5, 2017
Yeah, finally :) My first non-tiny PR Thanks everyone for all the kind help! With this landed, I think there are the following related things:
|
kennytm
commented
Nov 5, 2017
Step 1 will be done by a team member (e.g. #45285), so you don't need to submit that PR yourself. |
SimonSapin
commented
Nov 5, 2017
🎉🎉🎉🎉 Thank you Lukas for pushing through all this, and sorry it took so much time and so many attempts. The deprecation warning should wait until the replacement reaches the stable channel. That is after 1.23.0 is released. #39658 (comment) says “stabilize these methods only on the u8 and char types” so I think it’s fine to send a PR doing that for the libs team to approve. |
| /// but without allocating and copying temporaries. | ||
| #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] | ||
| #[inline] | ||
| pub fn eq_ignore_ascii_case(&self, other: &[u8]) -> bool { |
There was a problem hiding this comment.
Any chance we can move this and similar non-alloc methods to libcore?
With to_*_lowercase()/_uppercase() methods missing in libcore, this is the only method available for case-insensitive string comparison, which is a common operation in many application, even embedded.
There was a problem hiding this comment.
I agree this would be good to have, but it’s tricky. I’ve opened #45803.
rustdoc: Include `impl [u8]` in the docs The impl was added in #44042 but wasn't visible in the docs.
In Rust 1.23, the `AsciiExt` methods are implemented directly on the concerned types, so attempting to import `AsciiExt` results in an unused import. Rust language PR: rust-lang/rust#44042 PSA: https://users.rust-lang.org/t/psa-dealing-with-warning-unused-import-std-ascii-asciiext-in-today-s-nightly/13726 This started warning as an unused import on nightly sometime between 2017-11-02 and 2017-11-09: https://travis-ci.org/exercism/rust/builds/296391447https://travis-ci.org/exercism/rust/builds/299770403 This started warning on beta exactly when 1.23.0 became Beta (it was accepted on 1.22.0): https://travis-ci.org/exercism/rust/builds/303139434https://travis-ci.org/exercism/rust/builds/306431846 As 1.23 is now stable and our repo disallows warnings on stable, we will need this.
albel727
commented
Mar 5, 2018
And so Not only this is inconsistent (and possibly has worse performance too, like in the Since it's of course the fault of But why nobody even considered changing this before stabilizing it in 1.24? 😕 |
Kimundi
commented
Mar 5, 2018
I think this was a unfortunate oversight. A lot of the discussion about those methods was about how to handle deprecating I'm not sure what we can do at this point outside of possibly changing it for the next epoch, but could you open an issue for this? |
LukasKalbertodt
commented
Mar 5, 2018
I did consider changing it to |
kennytm
commented
Mar 5, 2018
@Kimundi Epoch only affects syntax and doesn't allow breaking API compatibility, meaning this change requires a real Rust 2.0 unfortunately. |
EDIT:this PR is ready now. 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
AsciiExtand 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],charand&stris still missing) to get some feedback before I continue. Some questions possibly worth discussing:Does everyone agree that deprecating=> apparently yesAsciiExtis a good idea? Does everyone agree with the goal of this PR?Are my changes OK so far? Did I do something wrong?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?I tweaked=> I reverted this, because the interface has to match theeq_ignore_ascii_case(): it now takes the argumentother: u8instead ofother: &u8. The latter was enforced by the trait. Since we're not bound to a trait anymore, we can drop the reference, ok?AsciiExtinterface exactly.¹
Could it be that we can't write=> we couldn't at the time this PR was opened, but Simon made it possible.impl [u8] {}? This might be the reason forAsciiExt. If that is the case: is there a good reason we can't write such an impl block? What can we do instead?/cc @SimonSapin@zackw