Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upstr's trim_left and trim_right implicitly assume LTR text #30459
Comments
huonw
added
I-nominated
T-libs
labels
Dec 18, 2015
This comment has been minimized.
This comment has been minimized.
|
I seem to recall Android adding |
This comment has been minimized.
This comment has been minimized.
|
+1 for How does the libs team feel about deprecating stable APIs? |
This comment has been minimized.
This comment has been minimized.
|
Can confirm: I don't think we need to deprecate these methods. A documentation tweak could clarify the current implications on their behavior. Do we even have a way to detect an RTL configuration anyways? Perhaps this is best left to an external crate to implement these methods as a precursor to a more general localization framework. |
This comment has been minimized.
This comment has been minimized.
No we don't.
Also, I don't really understand what you mean by an external crate doing this: there is absolutely no intention for these functions to change so to have |
This comment has been minimized.
This comment has been minimized.
|
I don’t think anything in the standard library should behave differently based on text direction. This stuff is more complex than you might think: http://www.unicode.org/reports/tr9/ (If you really want to do proper text layout, it’s a job for https://github.com/servo/unicode-bidi and other crates.) Left and right in Methods with an |
This comment has been minimized.
This comment has been minimized.
|
Okay, I see now. The text gets reversed during rendering--in memory the start of the string is at index As for the |
This comment has been minimized.
This comment has been minimized.
|
Yes, http://www.unicode.org/reports/tr9/#Introduction explains that memory representation of Unicode text is in "logical order" and gives some more details. Ok, |
aturon
removed
the
I-nominated
label
Jan 8, 2016
This comment has been minimized.
This comment has been minimized.
|
Libs team consensus: for now, we should make sure the documentation is clear about exactly what's happening here. In the long run, we'd be interested in a deprecation/renaming, but we'd like to have some better tools in place to do so. The problem is that if we just deprecate it normally, all crates using the functionality have to choose between deprecation messages and upping the version of Rust they require. Neither choice is great. The core team has discussed the idea of regular "long term support" releases, or otherwise some way to flag releases in a coarser-grained way. That can be useful for deprecations like this -- they would give something more like a small "epoch of Rust" to attach things like deprecations to, rather than forcing lib authors to just arbitrarily require Rust v1.7+ or whatever. More broadly, we'd like to establish a policy for this kind of minor cleanup -- where the change makes things more clear, but doesn't close any fundamental holes or anything. |
This comment has been minimized.
This comment has been minimized.
|
This is a very valid concern. Has a more fine-grained |
steveklabnik
added
the
A-docs
label
Jan 8, 2016
This comment has been minimized.
This comment has been minimized.
|
@SimonSapin yes, that idea has come up from time to time, and would definitely be helpful here. The main drawback is that it loses some of the point of deprecation -- if it's easy to opt out of the deprecation, there's little incentive to actually improve your code. Of course, in this particular case the use of deprecation is more about discoverability/documentation/API clarity than improving existing code per se. |
This comment has been minimized.
This comment has been minimized.
|
Other random idea: add the new name and deprecate the new one in a way that’s visible in the documentation but doesn’t emit a warning yet. (At least until the new name hits the stable channel.) |
This comment has been minimized.
This comment has been minimized.
|
@SimonSapin Yes, that's a feature we absolutely want -- basically, the ability to say "deprecated since Rust 1.8" or some other future release, and have the compiler/rustdoc do the right things. I'll open an issue for it. |
This comment has been minimized.
This comment has been minimized.
|
cc #30785 |
This comment has been minimized.
This comment has been minimized.
|
A possible alternative to |
This comment has been minimized.
This comment has been minimized.
|
Oh, and another idea we've talked about: the ability to |
steveklabnik
added a commit
to steveklabnik/rust
that referenced
this issue
Jan 26, 2016
steveklabnik
added a commit
to steveklabnik/rust
that referenced
this issue
Jan 26, 2016
steveklabnik
removed
the
A-docs
label
Jan 26, 2016
This comment has been minimized.
This comment has been minimized.
|
Removing docs since my PR is in, now just a libs question if we want new versions. |
steveklabnik
added a commit
to steveklabnik/rust
that referenced
this issue
Feb 1, 2016
steveklabnik
added a commit
to steveklabnik/rust
that referenced
this issue
Feb 2, 2016
bors
closed this
in
#31202
Feb 2, 2016
This comment has been minimized.
This comment has been minimized.
|
I believe #31202 closed this accidentally. At least, I can't see any documented decision from the libs team. |
huonw
reopened this
May 27, 2016
steveklabnik
added
the
A-libs
label
Aug 10, 2016
alexcrichton
referenced this issue
Feb 3, 2017
Closed
`str::trim_left` and `str::trim_right` method names are misleading #39499
steveklabnik
removed
the
A-libs
label
Mar 24, 2017
Mark-Simulacrum
added
the
C-enhancement
label
Jul 24, 2017
ollie27
referenced this issue
Dec 27, 2017
Merged
Deprecate [T]::rotate in favor of [T]::rotate_{left,right}. #46777
kennytm
added a commit
to kennytm/rust
that referenced
this issue
Apr 3, 2018
kennytm
added a commit
to kennytm/rust
that referenced
this issue
Apr 4, 2018
This comment has been minimized.
This comment has been minimized.
|
Now that #30785 is merged, it would be feasible to add unstable |
huonw commentedDec 18, 2015
These functions and their
_matchesvariants operate on the start and end of the string, which are only the left and right (respectively) of the displayed text when rendered left-to-right like English. For (readers/users of) RTL languages,trim_rightis hinting that it will be trimming the prefix, but this is of course not the case (and similarly for_left).These are stable and there is precedent in other languages for left/right e.g. Python (there's also significant precedent for start/end), so we may not be able/want to do anything here, but it seems worth noting.