Repository: rust
Issue: Unexpected trait bound not satisfied related to `std::io::Write`
Labels: T-rustdoc,C-bug,regression-untriaged

<!--
Thank you for filing a regression report! 🐛 A regression is something that changed between versions of Rust but was not supposed to.

Please provide a short summary of the regression, along with any information you feel is relevant to replicate it.
-->

When I tried to build the documentation for [`zip`](https://crates.io/crates/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:

```text
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

<!--
Provide the most recent version this worked on, for example:

It most recently worked on: Rust 1.47
-->

It most recently worked on: Rust 1.74.0

### Version with regression

<!--
Provide the version you are using that has the 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
```

<!--
Did the compiler crash? If so, please provide a backtrace.
-->

<!--
### Backtrace
-->
<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<!--
<details><summary>Backtrace</summary>
<p>

```
<backtrace>
```

</p>
</details>
-->

<!--
If you know when this regression occurred, please add a line like below, replacing `{channel}` with one of stable, beta, or nightly.

@rustbot modify labels: +regression-from-stable-to-{channel} -regression-untriaged
-->