rust-lang / rust-lang/rust

Unexpected trait bound not satisfied related to `std::io::Write`

Open
#125,235 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug regression-untriaged T-rustdoc
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with cargo doc on the linked zopfli-rs files, comparing Rust 1.74.0 with 1.75.0 or later. Start from the reported E0277 errors in deflate.rs, gzip.rs, and zlib.rs and investigate the regression between those compiler versions. Done means documentation builds successfully and a regression test covers the affected trait bounds.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.