-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Implement DerefMut for String #26241
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @aturon (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Is it also time to look at either deprecating or stabilizing |
Those casing ascii methods are pretty broken in unicode context, but I guess we could allow arbitrary ascii -> ascii mappings. Since a grapheme can be multiple codepoints, this also edits / transforms graphemes that use at least one ascii codepoint, for example é (depending on normalization). |
@bluss Agreed, the |
I would be more uncomfortable with stabilizing |
OK. |
I say we just land DerefMut and call it a day. Other stuff is easy to impl outside std. |
I don't want to complicate this issue, but we might want to add slicing of |
Added a commit:
|
a61076a
to
ef8ac71
Compare
I'm 👍 on this change in general, but are we OK landing this insta-stable? (Since it's just filling out APIs according to vetted/stable convention, seems fine to me, but I wanted to check.) |
|
Hm, I was also forgetting that implementations of stable traits are instantly stable regardless. I'm happy with the PR as it stands. |
This PR is now entering its final comment period. There was some discussion at triage today about this and there was some hesitation about the power that |
After seeing #9750 again I’ve been pondering on whether this PR introduces a way to break the UTF-8 invariant in safe code. I believe it does not:
|
☔ The latest upstream changes (presumably #26192) made this pull request unmergeable. Please resolve the merge conflicts. |
I’ll rebase once a decision is made on what to include or not. |
@@ -806,6 +814,12 @@ impl str { | |||
core_str::StrExt::split_at(self, mid) | |||
} | |||
|
|||
/// Divide one mutable string slice into two at an index. | |||
#[inline] | |||
pub fn split_at_mut(&mut self, mid: usize) -> (&mut str, &mut str) { |
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.
Can you tag this with an explicit unstable
tag?
The consensus of the libs team is to move ahead with this PR, with a rebase and a few nits addressed this should be good to go, thanks @SimonSapin! |
285feb6
to
28357e5
Compare
Rebased and added a commit to address comments. This commits also adds I’m getting an LLVM assertion error when building locally :( Could this be specific to stage1? I haven’t tried stage2 yet.
|
28357e5
to
23daca3
Compare
I’m still getting the same LLVM error after rebasing on today’s Rust master. Any suggestion what to do here? |
Unfortunately I don't know how to get past that error. |
`&mut str` is rarely useful, but it is for e.g. `AsciiExt::make_ascii_lowercase`.
... matching the existing Index impls. There is no reason not to if String implement DerefMut. The code removed in `src/librustc/middle/effect.rs` was added in rust-lang#9750 to prevent things like `s[0] = 0x80` where `s: String`, but I belive became unnecessary when the Index(Mut) traits were introduced.
After discussion with @SimonSapin I am interpreting this statement from @alexcrichton 👍
as an implicit |
@bors r=alexcrichton 0375d9c |
🙀 |
doener on IRC suggested that I might be hitting #26484. After running |
23daca3
to
eb99f0e
Compare
I just pushed a rebase. |
@bors r=alexcrichton eb99f0e |
⌛ Testing commit eb99f0e with merge 13aed07... |
💔 Test failed - auto-mac-64-opt |
88fe063
to
3226858
Compare
@alexcrichton With that last commit |
⌛ Testing commit 3226858 with merge dd46cf8... |
See rust-lang/rfcs#1157