Skip to content
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

Remove unnecessary calls to Str::as_slice #22561

Merged
merged 2 commits into from
Mar 9, 2015
Merged

Conversation

richo
Copy link
Contributor

@richo richo commented Feb 20, 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.

@rust-highfive
Copy link
Collaborator

r? @gankro

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

@richo
Copy link
Contributor Author

richo commented Feb 20, 2015

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
Copy link
Contributor Author

richo commented Feb 20, 2015

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

@@ -443,6 +443,6 @@ mod tests {
#[test]
fn test_format() {
let s = fmt::format(format_args!("Hello, {}!", "world"));
assert_eq!(s.as_slice(), "Hello, world!");
assert_eq!(s.as_str(), "Hello, world!");
Copy link
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
Copy link
Contributor

Gankra commented Feb 20, 2015

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
Copy link
Contributor Author

richo commented Feb 20, 2015

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

@alexcrichton
Copy link
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
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
Copy link
Contributor Author

richo commented Mar 8, 2015

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
Copy link
Contributor Author

richo commented Mar 8, 2015

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
Copy link
Contributor Author

richo commented Mar 8, 2015

Aaaaaand all tests pass on linux \o/

@@ -96,11 +96,11 @@ impl<S: Str> SliceConcatExt<str, String> for [S] {
}

// `len` calculation may overflow but push_str will check boundaries
let len = s.iter().map(|s| s.as_slice().len()).sum();
let len = s.iter().map(|s| s.as_str().len()).sum();
Copy link
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
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
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
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
Copy link
Contributor Author

richo commented Mar 9, 2015

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
Member

Thanks @richo!

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

richo commented Mar 9, 2015

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
Member

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

@alexcrichton
Copy link
Member

@bors: r+ 5a930fd7ba381551a00f287c1506937ebb612d1f

@richo
Copy link
Contributor Author

richo commented Mar 9, 2015

Great catch, cheers!

@bors
Copy link
Contributor

bors commented Mar 9, 2015

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

@bors
Copy link
Contributor

bors commented Mar 9, 2015

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

@Manishearth
Copy link
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
Copy link
Contributor Author

richo commented Mar 9, 2015

Test fixed, r?

@Manishearth
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Mar 9, 2015

@bors r=Manishearth 7981aa6

@richo
Copy link
Contributor Author

richo commented Mar 9, 2015

@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
Member

(already was removed 😄 )

@richo
Copy link
Contributor Author

richo commented Mar 9, 2015

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
Copy link
Contributor

bors commented Mar 9, 2015

⌛ 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 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