Repository: rust
Issue: Inherent `impl` priority not respected for `FnMut`
Labels: A-trait-system,A-closures,T-compiler,C-bug

I am trying to implement something like `nvzqz`'s [`impls` trick](https://github.com/nvzqz/impls#how-it-works) for `FnMut`. What I see suggests that checking for this trait's implementation is not consistent with how other traits' implementations are checked for.

The way `nvzqz`'s trick works is to present the compiler with either (1) a trait `impl` or (2) a trait `impl` and an inherent `impl` where both have an item with the same signature. Case (2) applies when the inherent `impl`'s bounds are satisfied. In that case, Rust gives priority to the inherent `impl`.

However, when I try to apply his trick with `FnMut`, I get an error regarding the inherent `impl`'s bounds. It is as though this error is short-circuiting the process of finding the common item.

Specifically, I tried this code ([playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=15331910ad6216855aab4fec1d204758)):

```rust
use std::marker::PhantomData;

trait MyFnMut<U> {}
struct Foo<U>(pub PhantomData<U>);
impl<U> MyFnMut<U> for Foo<U> {}

trait NotFnMut {
    fn is_fn_mut(&self) -> bool;
}

impl<T, U> NotFnMut for IsFnMut<T, U>
where
    T: FnOnce() -> U,
{
    fn is_fn_mut(&self) -> bool { false }
}

struct IsFnMut<T, U>(pub T, pub PhantomData<U>);

impl<T, U> IsFnMut<T, U>
where
    T: FnMut() -> U,
    // T: MyFnMut<U>
{
    fn is_fn_mut(&self) -> bool { true }
}

fn main() {
    let x = String::from("x");
    let return_x = move || x;
    println!("return_x: {:?}", IsFnMut::<_, String>(return_x, PhantomData).is_fn_mut());
    
    let return_y = || String::from("y");
    println!("return_y: {:?}", IsFnMut::<_, String>(return_y, PhantomData).is_fn_mut());
    
    // let foo = Foo(PhantomData);
    // println!("foo: {:?}", IsFnMut::<_, String>(foo, PhantomData).is_fn_mut());
}
```

I expected to see this:
```
return_x: false
return_y: true
```

Instead, I saw this:
```
error[E0525]: expected a closure that implements the `FnMut` trait, but this closure only implements `FnOnce`
  --> src/main.rs:30:20
   |
30 |     let return_x = move || x;
   |                    ^^^^^^^^-
   |                    |       |
   |                    |       closure is `FnOnce` because it moves the variable `x` out of its environment
   |                    this closure implements `FnOnce`, not `FnMut`
31 |     println!("return_x: {:?}", IsFnMut::<_, String>(return_x, PhantomData).is_fn_mut());
   |                                                                            --------- the requirement to implement `FnMut` derives from here
```

* If, in the `IsFnMut` implementation, you change `is_fn_mut` to (say) `is_fn_mut_dont_find_me`, then the output becomes:
```
return_x: false
return_y: false
```
This demonstrates that the implementation of `NotFnMut` is available for the compiler to find ([playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=a8cccb8f9712fb16556731fca741fa36)).

* If you change the bound to `T: MyFnMut<U>` in the `IsFnMut` implementation, and uncomment the last two lines in `main`, then the output becomes:
```
return_x: false
return_y: false
foo: true
```
This demonstrates that the trick works for other traits (e.g., `MyFnMut`), and that `FnMut` is somehow "special" ([playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=86318678c856f1f959550255c766ab1f)).

Is `FnMut` intentionally special in this way, or is this a bug?