Skip to content

Breaking change to ZipWriter::finish() in 1.2.0 release #124

@justin-formlogic

Description

@justin-formlogic

Describe the bug

PR #98 introduced a breaking change to the public ZipWriter::finish() method. It now consumes self rather than taking a mutable reference to self.

To Reproduce

Given something like the following, upgrading from 1.1.4 to 1.2.0 breaks the build.

struct Zipper {
    zip: ZipWriter<Cursor<Vec<u8>>>,
    // other stuff
}

impl Zipper {
    pub(super) fn finish(&mut self) -> Result<Cursor<Vec<u8>>, zip::result::ZipError> {
        self.zip.finish()
    }
}
error[E0507]: cannot move out of `self.zip` which is behind a mutable reference
    --> zipper.rs:58:9
     |
58   |         self.zip.finish()
     |         ^^^^^^^^ -------- `self.zip` moved due to this method call
     |         |
     |         move occurs because `self.zip` has type `ZipWriter<std::io::Cursor<Vec<u8>>>`, which does not implement the `Copy` trait
     |
note: `zip::write::<impl ZipWriter<W>>::finish` takes ownership of the receiver `self`, which moves `self.zip`
    --> /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zip-1.2.3/src/write.rs:1312:23
     |
1312 |     pub fn finish(mut self) -> ZipResult<W> {
     |                       ^^^^

Expected behavior

Semver compatible updates shouldn't fail the build.

Additional context

This was very easy to fix in my application, as I could just change the &mut self to self since nothing uses the encapsulating struct after calling finish. But other applications may be more difficult to refactor and this results in unexpected breakage when running cargo update against a codebase.

Ideally, this change would be deferred until a 2.0.0 release (reverting this change in a 1.2.4 release and/or yanking 1.2.0 through 1.2.3).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions