Skip to content

Remove unnecessary calls to Str::as_slice#22561

Merged
bors merged 2 commits into
rust-lang:masterfrom
richo:as_slice-as_str
Mar 9, 2015
Merged

Remove unnecessary calls to Str::as_slice#22561
bors merged 2 commits into
rust-lang:masterfrom
richo:as_slice-as_str

Conversation

@richo

@richo richo commented Feb 20, 2015

Copy link
Copy Markdown
Contributor

This may not be quite ready to go out, I fixed some docs but suspect I missed a bunch.

I also wound up fixing a bunch of redundant [] suffixes, but on closer inspection I don't believe that can land until after a snapshot.

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @gankro

(rust_highfive has picked a reviewer for you, use r? to override)

@richo

richo commented Feb 20, 2015

Copy link
Copy Markdown
Contributor Author

Ok, I think I got everything, but no doubt I missed something in a test, on a platform I don't have to test on. A bors run would be helpful.

there were cases where Deref coercions would have worked, but I opted for as_str anyway, as it made the surrounding code more readable (eg, the fact that it was going to coerce to a str was not obvious)

@richo richo force-pushed the as_slice-as_str branch 2 times, most recently from 7829834 to dc54f08 Compare February 20, 2015 05:35
@richo

richo commented Feb 20, 2015

Copy link
Copy Markdown
Contributor Author

Following up from IRC, the places where I left .as_str(), eg the assertions were all places where it seemed that as a reader, explicitly taking the underlying str wasn't obvious.

More than happy to go back and fix them all

Comment thread src/libcollections/fmt.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Places like these I think should be fine to drop the as_str from, clarity-wise.

@Gankra

Gankra commented Feb 20, 2015

Copy link
Copy Markdown
Contributor

Yeah going over this the as_str's don't really seem to add anything outside of a generic context. I would just drop 'em where you can.

@richo

richo commented Feb 20, 2015

Copy link
Copy Markdown
Contributor Author

Thanks for all the feedback! I'll revise when I get a chance.

@alexcrichton

Copy link
Copy Markdown
Member

Could you also leave as_slice in-place but #[deprecated] for now? I suspect there is a lot of code to go clean up outside the repo still using .as_slice() :)

@nikomatsakis

Copy link
Copy Markdown
Contributor

(Sadly, needs a rebase.)

@richo richo force-pushed the as_slice-as_str branch 2 times, most recently from 4c81487 to 40e4262 Compare March 8, 2015 06:30
@richo

richo commented Mar 8, 2015

Copy link
Copy Markdown
Contributor Author

I redid this patch from scratch (I had some fairly lurky attempts to fix tests from the last time). Running make check now

@richo richo force-pushed the as_slice-as_str branch 2 times, most recently from 1f64c1f to f1357cd Compare March 8, 2015 20:27
@richo

richo commented Mar 8, 2015

Copy link
Copy Markdown
Contributor Author

r? @gankro I believe this is good to go out. the lldb tests are failing locally for me, but I believe it's because I have a wedged lldb install

(Error in case it's not something I've done is Fatal Python error: PyThreadState_Get: no current thread which then aborts python)

@richo

richo commented Mar 8, 2015

Copy link
Copy Markdown
Contributor Author

Aaaaaand all tests pass on linux \o/

Comment thread src/libcollections/str.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be replaced with &s[..]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a bunch of warnings about places I could use slice syntax, I figured I'd do this in two passes to make landing it feasible, although this was less churn than I expected.

I also wasn't sure if the syntax was dependant on a snapshot.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the slicing syntax should definitely be usable as-is today, thankfully it's been around for awhile!

@alexcrichton

Copy link
Copy Markdown
Member

It's still a little unclear to me whether we want to do this or not. I think that if generic conversion traits land then there's no real need for the Str trait or the as_str method as they're basically just specializations of that trait.

I think it'd be totally fine, however, to land as much removal of as_str as possible for now though!

@richo

richo commented Mar 9, 2015

Copy link
Copy Markdown
Contributor Author

Ok, I'll probably have a PR for that subset of this one in the next few days.

@richo richo force-pushed the as_slice-as_str branch from f1357cd to c94bf20 Compare March 9, 2015 05:25
@alexcrichton

Copy link
Copy Markdown
Member

Thanks @richo!

@richo richo force-pushed the as_slice-as_str branch from c94bf20 to 5a930fd Compare March 9, 2015 05:26
@richo

richo commented Mar 9, 2015

Copy link
Copy Markdown
Contributor Author

Thanks to totally unforeseen organisation on my part, the rebase to only remove as_slice()s was totally trivial. r? @alexcrichton

@rust-highfive rust-highfive assigned alexcrichton and unassigned Gankra Mar 9, 2015
@alexcrichton alexcrichton changed the title str: rename as_slice to as_str Remove unnecessary calls to Str::as_slice Mar 9, 2015
@alexcrichton

Copy link
Copy Markdown
Member

Nice! I updated the title and removed the Closes #xxxx in the title, otherwise looks great to me!

@alexcrichton

Copy link
Copy Markdown
Member

@bors: r+ 5a930fd7ba381551a00f287c1506937ebb612d1f

@richo

richo commented Mar 9, 2015

Copy link
Copy Markdown
Contributor Author

Great catch, cheers!

@bors

bors commented Mar 9, 2015

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 5a930fd with merge 3f61b5d...

@bors

bors commented Mar 9, 2015

Copy link
Copy Markdown
Collaborator

💔 Test failed - auto-linux-64-x-android-t

@Manishearth

Copy link
Copy Markdown
Member
/home/rustbuild/src/rust-buildbot/slave/auto-linux-64-x-android-t/build/src/libstd/process.rs:833:32: 835:53 error: the trait `core::ops::Fn<(char,)>` is not implemented for the type `collections::string::String` [E0277]
/home/rustbuild/src/rust-buildbot/slave/auto-linux-64-x-android-t/build/src/libstd/process.rs:833                 assert!(output.contains(format!("{}={}",
/home/rustbuild/src/rust-buildbot/slave/auto-linux-64-x-android-t/build/src/libstd/process.rs:834                                                 *k,
/home/rustbuild/src/rust-buildbot/slave/auto-linux-64-x-android-t/build/src/libstd/process.rs:835  

@richo richo force-pushed the as_slice-as_str branch from 5a930fd to 7981aa6 Compare March 9, 2015 14:54
@richo

richo commented Mar 9, 2015

Copy link
Copy Markdown
Contributor Author

Test fixed, r?

@Manishearth

Copy link
Copy Markdown
Member

@bors: r+

@bors

bors commented Mar 9, 2015

Copy link
Copy Markdown
Collaborator

@bors r=Manishearth 7981aa6

@richo

richo commented Mar 9, 2015

Copy link
Copy Markdown
Contributor Author

@Manishearth you might want to remove this from the rollup, I was just eyeballing it and spotted a few things that look off, I think it got mangled in the rebase. I have make check running here, but I don't want to toast another rollup :(

@Manishearth

Copy link
Copy Markdown
Member

(already was removed 😄 )

@richo

richo commented Mar 9, 2015

Copy link
Copy Markdown
Contributor Author

Ok, make check passes. I'm planning to hand hold this through bors, since I don't have access to an android test environment. (Fingers crossed I caught everything this time though)

@bors

bors commented Mar 9, 2015

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 7981aa6 with merge b83b26b...

bors added a commit that referenced this pull request Mar 9, 2015
This may not be quite ready to go out, I fixed some docs but suspect I missed a bunch.

I also wound up fixing a bunch of redundant `[]` suffixes, but on closer inspection I don't believe that can land until after a snapshot.
@bors

bors commented Mar 9, 2015

Copy link
Copy Markdown
Collaborator

@bors bors merged commit 7981aa6 into rust-lang:master Mar 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants