rust-lang / futures-rs

Zero-cost asynchronous programming in Rust
https://rust-lang.github.io/futures-rs/
Apache License 2.0
5.38k stars 624 forks source link

(futures v0.1) Fix logic bug in stream::Stream::filter_map doctest #2765

Closed decathorpe closed 1 year ago

decathorpe commented 1 year ago

If you're wondering why I'm submitting a PR with a patch for the ancient v0.1 branch: We're running cargo test for Rust crates that we have packaged for Fedora Linux (where possible), and this issue started happening once we updated to Rust 1.71.0 a few days ago. We still have futures v0.1 packaged since quite a few things are sadly still depending on it (mostly via tokio 0.1).

The operator for the modulo and the test were swapped, and using "modulo zero" is undefined and results in an unconditional panic, which is now caught with Rust 1.71 (unconditional_panic lint).

---- src/stream/mod.rs - stream::Stream::filter_map (line 396) stdout ----
error: this operation will panic at runtime
  --> src/stream/mod.rs:403:8
   |
10 |     if x % 0 == 2 {
   |        ^^^^^ attempt to calculate the remainder of `_` with a divisor of zero
   |
   = note: `#[deny(unconditional_panic)]` on by default
error: aborting due to previous error
Couldn't compile the test.
failures:
    src/stream/mod.rs - stream::Stream::filter_map (line 396)

It's a simple fix for an unimportant thing in an ancient branch, but since I patched this for our futures v0.1 package already, I thought I'd submit it upstream, even if you might just say "we don't care about this any more" (which would be fine with me!).

taiki-e commented 1 year ago

Thanks.