Repository: rust
Issue: Nightly (2021): trait bound error for missing use
Labels: A-diagnostics,T-compiler

<!--
Thank you for filing a bug report! 🐛 Please provide a short summary of the bug,
along with any information you feel relevant to replicating the bug.

If you cannot produce a minimal reproduction case (something that would work in
isolation), please provide the steps or even link to a repository that causes
the problematic output to occur.
-->
Using this rust version:

```bash
$ cargo --version
cargo 1.56.0-nightly (cc17afbb0 2021-08-02)
```

Given the following code: <!-- Please provide a link to play.rust-lang.org -->

```rust
use lazy_static::lazy_static;
use rand::distributions::{Distribution, Uniform};
use signal_hook::consts::signal::*;
use signal_hook_tokio::Signals;
use std::io::Error;
use std::time::Duration;
use tokio::time::{sleep, Instant};

lazy_static! {
    static ref START_TIME: Instant = Instant::now();
}

async fn handle_signals(signals: Signals) {
    let mut signals = signals.fuse();
    while let Some(signal) = signals.next().await {
        match signal {
            SIGTERM | SIGINT | SIGQUIT => {
                // Lets get out of here...
                std::process::exit(1);
            }
            _ => unreachable!(),
        }
    }
}

#[tokio::main]
async fn main() -> Result<(), Error> {
    let signals = Signals::new(&[SIGHUP, SIGTERM, SIGINT, SIGQUIT])?;
    let handle = signals.handle();
    let signals_task = tokio::spawn(handle_signals(signals));

    let page = get_page(42).await;
    println!("Page #42: {:?}", page);

    // Terminate the signal stream.
    handle.close();
    signals_task.await?;
    Ok(())
}

async fn get_page(i: usize) -> Vec<usize> {
    let millis = Uniform::from(5_000..6_000).sample(&mut rand::thread_rng());
    println!(
        "[{}] # get_page({}) will complete in {} ms on {:?}",
        START_TIME.elapsed().as_millis(),
        i,
        millis,
        std::thread::current().id()
    );

    sleep(Duration::from_millis(millis)).await;
    println!(
        "[{}] # get_page({}) completed",
        START_TIME.elapsed().as_millis(),
        i
    );

    (10 * i..10 * (i + 1)).collect()
}
```

The current output is:

```
error[E0599]: the method `fuse` exists for struct `signal_hook_tokio::SignalsInfo`, but its trait bounds were not satisfied
  --> regatta/examples/01-pages-hello-ok-int-c.rs:15:31
   |
15 |     let mut signals = signals.fuse();
   |                               ^^^^ method cannot be called on `signal_hook_tokio::SignalsInfo` due to unsatisfied trait bounds
   |
  ...
   |
92 | pub struct SignalsInfo<E: Exfiltrator = SignalOnly>(OwningSignalIterator<UnixStream, E>);
   | ----------------------------------------------------------------------------------------- doesn't satisfy `signal_hook_tokio::SignalsInfo: Iterator`
   |
   = note: the following trait bounds were not satisfied:
           `signal_hook_tokio::SignalsInfo: Iterator`
           which is required by `&mut signal_hook_tokio::SignalsInfo: Iterator`

For more information about this error, try `rustc --explain E0599`.
```

<!-- The following is not always necessary. -->
~~Ideally the output should be as shown in [this comment](https://github.com/rust-lang/rust/issues/36513#issuecomment-590658684) in issue #36513  (via PR #69255)and [this comment (Feb 2020)](https://github.com/rust-lang/rust/issues/40375#issuecomment-542337409) in issue #40375 (which seems to have changed back to uninformative [per this comment (Jun 2020)](https://github.com/rust-lang/rust/issues/40375#issuecomment-644328820))~~
Actually the output we should see is the same as in the [comment below](https://github.com/rust-lang/rust/issues/87857#issuecomment-894745313) (a subtle variation of this code) where helpful and correct messages are produced:

```
   ...
   = help: items from traits can only be used if the trait is in scope
   = note: the following trait is implemented but not in scope; perhaps add a `use` for it:
           `use futures::StreamExt;`
```

To fix, add `use futures::stream::{StreamExt};`

This issue has tripped, at least two (new) [users](https://github.com/vorner/signal-hook/issues/96).
A question to Discord #beginners about the likely root cause of this error wasn't responded to so its a subtle issue.