Skip to content

Stream borrowed after a move #370

Description

@faraplay

Try building a library with the following code:

use binrw::binread;

#[binread]
#[br(stream = reader)]
enum Foo {
    Bar {
        #[br(count = 1)]
        vec: Vec<u8>,
    },
}

I would expect this to compile, but it gives the following error:

error[E0382]: borrow of moved value                
    --> src\lib.rs:3:1
     |
   3 | #[binread]
     | ^^^^^^^^^^
     | |
     | value moved due to this method call
     | borrow occurs due to use in closure
     | value borrowed here after move
     | move occurs because value has type `&mut R`,which does not implement the `Copy` trait
     |
note: `stream_position` takes ownership of the receiver `self`, which moves value
    --> *omitted*/rust\library\std\src\io\mod.rs:2154:29
     |
2154 |     fn stream_position(&mut self) -> Resu...
     |                             ^^^^
     = note: this error originates in the attributemacro `binread` (in Nightly builds, run with -Z macro-backtrace for more info)
help: borrow this binding in the pattern to avoid moving the value
     |
   3 | ref #[binread]
     | +++

For more information about this error, try `rustc --explain E0382`.
error: could not compile `binrw_test` (lib) due to 1 previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions