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

Unexpected trait bound not satisfied related to std::io::Write #125235

Open
sorairolake opened this issue May 18, 2024 · 1 comment
Open

Unexpected trait bound not satisfied related to std::io::Write #125235

sorairolake opened this issue May 18, 2024 · 1 comment
Labels
C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@sorairolake
Copy link
Contributor

sorairolake commented May 18, 2024

When I tried to build the documentation for zip crate v1.3.0 (cargo doc), it failed with unexpected errors (see zopfli-rs/zopfli#42). There seems to be no problem up to Rust 1.74.0, but the error occurs with Rust 1.75.0 or later.

Code

I tried this code:

https://github.com/zopfli-rs/zopfli/blob/5cea5a62d791e16440e8556feb663cffd3e888cf/src/deflate.rs#L23-L156
https://github.com/zopfli-rs/zopfli/blob/5cea5a62d791e16440e8556feb663cffd3e888cf/src/gzip.rs#L3-L97
https://github.com/zopfli-rs/zopfli/blob/5cea5a62d791e16440e8556feb663cffd3e888cf/src/zlib.rs#L3-L90

I expected to see this happen: Successfully build the documentation.

Instead, this happened:

error[E0277]: the trait bound `deflate::DeflateEncoder<W>: std::io::Write` is not satisfied
  --> zopfli-0.8.0/src/deflate.rs:63:73
   |
63 |     pub fn new_buffered(options: Options, btype: BlockType, sink: W) -> std::io::BufWriter<Self> {
   |                                                                         ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::io::Write` is not implemented for `deflate::DeflateEncoder<W>`
   |
note: required by a bound in `std::io::BufWriter`
  --> library/std/src/io/buffered/bufwriter.rs:69:1

error[E0277]: the trait bound `gzip::GzipEncoder<W>: std::io::Write` is not satisfied
  --> zopfli-0.8.0/src/gzip.rs:48:17
   |
48 |     ) -> Result<std::io::BufWriter<Self>, Error> {
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::io::Write` is not implemented for `gzip::GzipEncoder<W>`
   |
note: required by a bound in `std::io::BufWriter`
  --> library/std/src/io/buffered/bufwriter.rs:69:1

error[E0277]: the trait bound `zlib::ZlibEncoder<W>: std::io::Write` is not satisfied
  --> zopfli-0.8.0/src/zlib.rs:43:17
   |
43 |     ) -> Result<std::io::BufWriter<Self>, Error> {
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::io::Write` is not implemented for `zlib::ZlibEncoder<W>`
   |
note: required by a bound in `std::io::BufWriter`
  --> library/std/src/io/buffered/bufwriter.rs:69:1

For more information about this error, try `rustc --explain E0277`.
error: could not document `zopfli`
warning: build failed, waiting for other jobs to finish...

The trait std::io::Write seems to be implemented for deflate::DeflateEncoder<W>, so I think it satisfies the trait bound.

Version it worked on

It most recently worked on: Rust 1.74.0

Version with regression

rustc --version --verbose:

rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: x86_64-unknown-linux-gnu
release: 1.78.0
LLVM version: 18.1.2
@sorairolake sorairolake added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels May 18, 2024
@rustbot rustbot added I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 18, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 18, 2024
@lukas-code
Copy link
Member

lukas-code commented May 18, 2024

The error looks correct to me. Your crate contains this cfg(doc):

#[cfg(all(not(doc), feature = "std"))]
use std::io::{Error, Write};

#[cfg(any(doc, not(feature = "std")))]
pub use io::{Error, ErrorKind, Write};

So when you run cargo doc, DeflateEncoder actually implements your own copy of the Write trait, rather than the one from the standard library, but std::io::BufWriter requires the one from the standard library.

Prior to 1.75.0, this code was incorrectly accepted by rustdoc due to a bug, which got fixed in #117450.

@rustbot label T-rustdoc

@rustbot rustbot added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label May 18, 2024
@apiraino apiraino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants