-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
std: Allow ?Sized parameters in std::io::copy #27531
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
r? @alexcrichton I think this is a sensible generalization |
Oh interesting! I thought we had already done this... We may actually want to take this in the opposite direction and instead change the signature to: fn copy<R: Read, W: Write>(r: R, w: W) -> io::Result<u64>; That's the generalization we've taken with a bunch of |
@alexcrichton That could be a breaking change. Currently the only way to call |
Yeah it's in theory a breaking change because the meaning of I'd want to run this through crater to make sure there's no regressions we know of, and if there is then we can stick with |
Oh, right. |
@alexcrichton I'd love to change it that way instead — it would be more consistent with other I/O API too. |
Updated, has [breaking-change] tag in commit log since we try to track everything that's technically breaking. This change is what I want to do too, I just didn't realize it would be possible. But all is fine, except for the type parameter change. |
I've kicked off a crater build to evaluate the impact |
Hm, looks like we may not be able to do this, the were three regressions, although I'm not sure why at least one of them hit an error... |
Oh that was unexpected, but it's good we tried that out in crater. All the cases seem to be that Back to the original plan, to just add |
PR is back to the original plan.. |
@@ -45,7 +45,8 @@ use io::{self, Read, Write, ErrorKind, BufRead}; | |||
/// # } | |||
/// ``` | |||
#[stable(feature = "rust1", since = "1.0.0")] | |||
pub fn copy<R: Read, W: Write>(reader: &mut R, writer: &mut W) -> io::Result<u64> { | |||
pub fn copy<R: ?Sized + Read, W: ?Sized + Write>(reader: &mut R, writer: &mut W) | |||
-> io::Result<u64> { |
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.
If you have time, what's our actual best style for wrapping function signatures?
libstd seems to want this:
A:
pub fn copy<R: ?Sized + Read, W: ?Sized + Write>(reader: &mut R,
writer: &mut W)
-> io::Result<u64> {
B:
pub fn copy<R: ?Sized, W: ?Sized>(reader: &mut R,
writer: &mut W)
-> io::Result<u64> where R: Read, W: Write {
I usually do this personally, dislike {
hanging so far to the right
C:
pub fn copy<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W) -> io::Result<u64>
where R: Read, W: Write
{
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.
Grepping around is dizzying. There are a few different styles active!
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.
I would personally vote for the ideal style of:
pub fn copy<R, W>(reader: &mut R, writer: &mut W) -> io::Result<u64>
where R: Read + ?Sized, W: Write + ?Sized
{
/* ... */
}
Unfortunately ?Sized
doesn't work in a where clause right now so that's not possible. Overall though I'd go with option (C). I do agree though that we're not consistent throughout the codebase on what style of where clauses we have.
Could you also add a test that calls this with trait objects? |
cc @gankro, mysterious travis failures (spurious) |
@alexcrichton That is mind boggling. 0.o |
PR updated with style & a test |
Thanks @tomaka for bringing this bug to attention |
|
||
#[test] | ||
fn copy_copies() { | ||
let mut r = repeat(4); |
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.
apparently I don't know how repeat works. Fixing this..
std::io::copy did not allow passing trait objects directly (only with an extra &mut wrapping).
Updated, test fixed, r? @alexcrichton |
std: Allow ?Sized parameters in std::io::copy
std: Allow ?Sized parameters in std::io::copy