-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
rustc: Remove &str
indexing from the language.
#15085
Conversation
It might be valuable to have an |
As a language change, this has no RFC corresponding with it, but it's small enough that it may be ok to discuss here instead. I personally would like to keep indexing. It is a fact that all our strings are utf-8 encoded, and that fact will never change. The type system will very quickly tell you you're getting a byte and not a char. |
@alexcrichton As @brson points out, you can get the utf-8 view from On the other hand, a bunch of the other methods on @brson Do you see these other methods as also encouraging poor hygiene? Or is there something that makes indexing particularly pernicious? |
It seems that we have a bit of a push-back from any byte-based methods on strings, but there are so many that I think it's ergonomically infeasible to remove all of them. It seems a little odd to remove half but leave the other half, leading to my opinion that this is a nice sugar that should stick around. |
@aturon I don't have a strong opinion about whether this is the correct thing to do or not. It has been previously-accepted as a milestone issue, so I implemented it. |
Per https://github.com/rust-lang/meeting-minutes/blob/master/weekly-meetings/2014-07-01.md, we're going to do this. |
r=me with a rebase |
Being able to index into the bytes of a string encourages poor UTF-8 hygiene. To get a view of `&[u8]` from either a `String` or `&str` slice, use the `as_bytes()` method. Closes rust-lang#12710. [breaking-change]
Being able to index into the bytes of a string encourages poor UTF-8 hygiene. To get a view of `&[u8]` from either a `String` or `&str` slice, use the `as_bytes()` method. Closes #12710. [breaking-change] If the diffstat is any indication this shouldn't have a huge impact but it will have some. Most changes in the `str` and `path` module. A lot of the existing usages were in tests where ascii is expected. There are a number of other legit uses where the characters are known to be ascii.
@cmr, the |
fix: ensure that ws loading error includes path to ws Should help with https://old.reddit.com/r/rust/comments/14cw5ts/newbie_confused_about_rustanalyzer/ `@bors` r+
Being able to index into the bytes of a string encourages
poor UTF-8 hygiene. To get a view of
&[u8]
from eithera
String
or&str
slice, use theas_bytes()
method.Closes #12710.
[breaking-change]
If the diffstat is any indication this shouldn't have a huge impact but it will have some. Most changes in the
str
andpath
module. A lot of the existing usages were in tests where ascii is expected. There are a number of other legit uses where the characters are known to be ascii.