-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Copy all AsciiExt
methods to the primitive types directly in order to deprecate it later
#44042
Copy all AsciiExt
methods to the primitive types directly in order to deprecate it later
#44042
Conversation
I don't think the Travis-fail is my fault ... Right? 😕 |
I do not believe so, seems... strange? |
“The” |
|
@LukasKalbertodt Any error other than |
@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? |
A creative hack to work around // The existing impl block
#[lang = "slice"]
impl<T> [T] {
// ...
// New methods:
fn is_ascii(&self) where Self: AsRef<[u8]> {
let self_as_bytes = self.as_ref();
// ...
}
} Given the available impls of |
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 |
I believe it is not possible purely in library code, just like |
r? @sfackler since highfive flaked and this seems library related. Not sure if you'll need compiler team input though... |
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. |
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? |
@alexcrichton There’s still two issues to resolve:
|
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 |
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:
|
We do have the impl [T] {
fn foo() where Self: 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 |
The not-blocking on it solution would be to keep using the extension trait for [u8]. |
☔ The latest upstream changes (presumably #44678) made this pull request unmergeable. Please resolve the merge conflicts. |
ping @LukasKalbertodt would you be willing to keep up w/ this PR? |
I think we are still waiting for the team's decision on whether to introduce |
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 |
@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!
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 ^_^ |
@bors r=alexcrichton |
📌 Commit ea55596 has been approved by |
…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
☀️ Test successful - status-appveyor, status-travis |
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:
|
Step 1 will be done by a team member (e.g. #45285), so you don't need to submit that PR yourself. |
🎉🎉🎉🎉 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree this would be good to have, but it’s tricky. I’ve opened #45803.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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/296391447 https://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/303139434 https://travis-ci.org/exercism/rust/builds/306431846 As 1.23 is now stable and our repo disallows warnings on stable, we will need this.
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? 😕 |
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? |
I did consider changing it to |
@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
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:Does everyone agree that deprecating=> apparently yesAsciiExt
is 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: u8
instead ofother: &u8
. The latter was enforced by the trait. Since we're not bound to a trait anymore, we can drop the reference, ok?AsciiExt
interface 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