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

std::io::Cursor::position behavior changed in the beta #47640

Closed
pietroalbini opened this issue Jan 21, 2018 · 5 comments
Closed

std::io::Cursor::position behavior changed in the beta #47640

pietroalbini opened this issue Jan 21, 2018 · 5 comments
Labels
regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Milestone

Comments

@pietroalbini
Copy link
Member

Seems like the behavior of std::io::Cursor::position changed, because the test suite of rmp now fails on beta and nightly while working fine on stable (crater log). One example of such an error:

#[test]
fn from_str32_read_str_len_eof() {
    let buf: &[u8] = &[0xdb, 0x00, 0x00, 0x00];
    let mut cur = Cursor::new(buf);

    read_str_len(&mut cur).err().unwrap();
    assert_eq!(4, cur.position());
}
---- func::decode::string::from_str32_read_str_len_eof stdout ----
        thread 'func::decode::string::from_str32_read_str_len_eof' panicked at 'assertion failed: `(left == right)`
  left: `4`,
 right: `1`', rmp/tests/func/decode/string.rs:120:5

My guess is this regression is related to #46485, which is the only pull request that changed the behavior for Cursor<&[u8]>.

cc @3Hren

@pietroalbini pietroalbini added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. regression-from-stable-to-beta Performance or correctness regression from stable to beta. labels Jan 21, 2018
@pietroalbini pietroalbini added this to the 1.24 milestone Jan 21, 2018
@3Hren
Copy link
Contributor

3Hren commented Jan 21, 2018

Not sure it's the Cursor's issue. The code is: https://github.com/3Hren/msgpack-rust/blob/master/rmp/src/decode/str.rs#L75

Seems like either byteorder can now read atomically, or Read::read_exact does the same. Both cases are valid, but forces me to rewrite test conditions.

@alexcrichton
Copy link
Member

Thanks for the report @pietroalbini! @3Hren will this be difficult to update for you? I do think I agree that both cases are the same here in terms of correctness, but if it's difficult to update we could consider reverting.

The issue here I think can be boiled down to:

use std::io::{Cursor, Read};

fn main() {
    let mut io = Cursor::new(&[1, 2][..]);
    assert!(io.read_exact(&mut [0; 4]).is_err());
    println!("{}", io.position());
}

This currently prints 2 on stable (1.23.0) and 0 on beta. A side effect of #46485 is that a call to read_exact will fail without conuming bytes if there's not enough space, while before the bytes were consumed eagerly.

@3Hren
Copy link
Contributor

3Hren commented Jan 22, 2018

It's okay for me, no need for reverting :)

@alexcrichton
Copy link
Member

Ok! I'll bring this up with @rust-lang/libs team soon as well, but we're pretty likely to close this.

3Hren added a commit to 3Hren/msgpack-rust that referenced this issue Jan 22, 2018
3Hren added a commit to 3Hren/msgpack-rust that referenced this issue Jan 22, 2018
@alexcrichton
Copy link
Member

The libs team discussed this today and concluded to close, but thanks regardless for the report @pietroalbini and the willingness to update @3Hren!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants