Repository: rust
Issue: "overflow evaluating the requirement" caused by a blanket impl with a wrapper on one of the trait's type parameters
Labels: A-associated-items,C-bug,T-types,fixed-by-next-solver

<!--
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.
-->

I tried this code:

```rust
// &self, &mut Target

pub trait ShowAt<Target, Style> {
    type Output;

    fn show_at(self, target: Target, style: Style) -> Self::Output;
}

struct Foo;
impl ShowAt<(), ()> for Foo {
    type Output = ();

    fn show_at(self, _target: (), _style: ()) -> Self::Output {}
}

struct Wrapper<T>(T);
impl<T, Target, Style> ShowAt<Target, Wrapper<Style>> for T
where
    T: ShowAt<Target, Style, Output = ()>,
{
    type Output = ();

    fn show_at(self, target: Target, style: Wrapper<Style>) -> Self::Output {
        self.show_at(target, style.0);
    }
}

fn main() {
    Foo.show_at((), ());
}
```

This code fails to compile with the following error at the `show_at` call in `main`:
```
error[E0275]: overflow evaluating the requirement `Foo: ShowAt<(), Wrapper<_>>`
  --> src\main.rs:29:9
   |
29 |     Foo.show_at((), ());
   |         ^^^^^^^
   |
   = help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`bug`)
   = note: required because of the requirements on the impl of `ShowAt<(), Wrapper<Wrapper<_>>>` for `Foo`
   = note: 126 redundant requirements hidden
   = note: required because of the requirements on the impl of `ShowAt<(), Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<_>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>` for `Foo`
```

I expected the code to compile, since `()` is not `Wrapper<_>`.

What I imagine is happening is that the trait resolution attempts to compute the set of possible `Style`s such that `Foo: ShowAt<(), Style>` even though, clearly, `Style = ()`. This leads to checking `Foo: ShowAt<_, Wrapper<_>>`, which recurses to checking `Foo: ShowAt<_, _>`.

While I can accept that the code above recurses, what causes me to think that this behavior might be a bug is that some slight modifications of the code, none of which remove the recursion, cause it to compile without errors. They are listed below:

1- Removing the `Output = ()` requirement in
```
impl<T, Target, Style> ShowAt<Target, Wrapper<Style>> for T
where
    T: ShowAt<Target, Style, Output = ()>,
```

2- Monomorphising `Target` to `()` by hand in the last `impl`:
```
impl<T, Style> ShowAt<(), Wrapper<Style>> for T
where
    T: ShowAt<(), Style, Output = ()>,
{
    type Output = ();

    fn show_at(self, target: (), style: Wrapper<Style>) -> Self::Output {
        self.show_at(target, style.0);
    }
}
```

3- Monomorphising `Target` to `()` everywhere. This is probably equivalent to the previous case.

### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc --version --verbose`:
```
rustc 1.53.0-nightly (07e0e2ec2 2021-03-24)
binary: rustc
commit-hash: 07e0e2ec268c140e607e1ac7f49f145612d0f597
commit-date: 2021-03-24
host: x86_64-pc-windows-msvc
release: 1.53.0-nightly
LLVM version: 12.0.0
```