Repository: rust
Issue: Warn that trait implementation is gated by a feature flag
Labels: A-diagnostics,T-compiler

Given the following code: (Playground link not provided because this involves a crate not on playground)

```rust
use rayon::iter::IntoParallelIterator;
use dashmap::DashSet;

#[derive(PartialEq, Eq, PartialOrd, Ord, Hash)]
struct Foo;

let test = DashSet::<Foo>::new();
test.par_iter();
```

The current output is:

```
error[E0599]: the method `par_iter` exists for struct `DashSet<Foo>`, but its trait bounds were not satisfied
  --> src/lib.rs:74:14
   |
74 |         test.par_iter();
   |              ^^^^^^^^ method cannot be called on `DashSet<Foo>` due to unsatisfied trait bounds
   | 
  ::: /home/edward/.cargo/registry/src/github.com-1ecc6299db9ec823/dashmap-4.0.2/src/set.rs:19:1
   |
19 | pub struct DashSet<K, S = RandomState> {
   | -------------------------------------- doesn't satisfy `DashSet<Foo>: IntoParallelRefIterator`
   |
   = note: the following trait bounds were not satisfied:
           `&DashSet<Foo>: IntoParallelIterator`
           which is required by `DashSet<Foo>: IntoParallelRefIterator`
```

<!-- The following is not always necessary. -->
Ideally the output should look like:

```
error[E0599]: the method `par_iter` exists for struct `DashSet<Foo>`, but its trait bounds were not satisfied
  --> src/lib.rs:74:14
   |
74 |         test.par_iter();
   |              ^^^^^^^^ method cannot be called on `DashSet<Foo>` due to unsatisfied trait bounds
   | 
  ::: /home/edward/.cargo/registry/src/github.com-1ecc6299db9ec823/dashmap-4.0.2/src/set.rs:19:1
   |
19 | pub struct DashSet<K, S = RandomState> {
   | -------------------------------------- doesn't satisfy `DashSet<Foo>: IntoParallelRefIterator`
   |
   = note: the following trait bounds were not satisfied:
           `&DashSet<Foo>: IntoParallelIterator`
           which is required by `DashSet<Foo>: IntoParallelRefIterator`
   = note: `dashmap` has an optional feature `rayon` that is currently not enabled.
```

I was trying to call `par_iter()` on the following example, but was very confused with regards to the error message. Consider the following image, snapshotted from the [`dashmap::DashSet` docs](https://docs.rs/dashmap/4.0.2/dashmap/struct.DashSet.html#impl-FromParallelIterator%3CK%3E):
![image](https://user-images.githubusercontent.com/6173958/127957155-50fc0de4-dbcd-4189-96d1-3683f7ed0d09.png)

It looks like `Foo` satisfies all the trait bounds needed for `DashSet<Foo>` to fufill `InterParallelIterator`, yet the trait still isn't being satisfied! What's going on? The solution is a case of either confusing docs.rs or a perhaps unintuitive diagnostic: a missing feature flag (in this case, `rayon`).

As a quick concept, I would suggest a note indicating that the trait implementation _does_ exist for a struct but isn't enabled because the feature isn't enabled. As a layman on the rustc internals, I'm not sure how feasible this would be, but something like the following might be viable:
 1. On a failed trait bound check `Trait`,
 2. Check if struct `Foo` from crate `crate` implements `Trait` regardless of enabled features,
 3. If so, check if the `Trait` implementation or its parent mods is enabled through a feature, and that feature isn't enabled,
 4. If so, add a note saying that `Trait` is not satisfied because the trait implementation is gated by a feature flag.

I think this is worthwhile to implement, as I believe this is incredibly confusing to new Rust users. The compiler and docs make no indication that a trait implementation is gated, which means that a new user would be absolutely lost on next steps.
Heck, I would consider myself an intermediate or even an advanced user, and had to ask the community for help.