Repository: rust
Issue: When call from out of crate, E0275 occurs
Labels: A-trait-system,C-bug,E-needs-mcve,T-types

<!--
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:
```terminal
$ tree
.
├── Cargo.toml
└── src
    ├── bin
    │   └── a.rs
    └── lib.rs

2 directories, 3 files
```

`Cargo.toml`
```toml
[package]
name = "baz"
version = "0.1.0"
authors = []
edition = "2018"

[dependencies]

[features]
default = []
bar = []
```

`src/lib.rs`
```rust
use std::ops::Add;

#[derive(Clone, Debug)]
pub struct S<T>(pub T);

// If comment outed, no error
impl<T> Add<&S<T>> for &S<T>
where
    T: for<'x> From<<&'x T as Add>::Output>,
    for<'x> &'x T: Add,
{
    type Output = S<T>;
    fn add(self, _: &S<T>) -> Self::Output {
        unimplemented!()
    }
}

// If comment outed, no error
impl<T> Add<&S<T>> for S<T>
where
    T: for<'x> From<<&'x T as Add>::Output>,
    for<'x> &'x T: Add,
{
    type Output = Self;
    fn add(self, _: &S<T>) -> Self::Output {
        unimplemented!()
    }
}

impl<T> Add<S<T>> for S<T>
where
    T: for<'x> From<<&'x T as Add>::Output>,
    for<'x> &'x T: Add,
{
    type Output = Self;
    fn add(self, _: S<T>) -> Self::Output {
        unimplemented!()
    }
}

pub fn foo() {
    dbg!(S(2i32) + S(3i32)); // OK
}
```

`src/bin/a.rs`
```rust
fn main() {
    #[cfg(not(feature = "bar"))]
    {
        use baz::S;
        use std::ops::Add;
        dbg!(S(2i32) + S(3i32)); // E0275
        dbg!(S(2i32).add(S(3i32))); // E0275
        dbg!(std::ops::Add::<S<i32>>::add(S(2i32), S(3i32))); // OK
    }
    #[cfg(feature = "bar")]
    {
        use baz::foo;
        // suppress optimize
        let v = std::env::args().collect::<Vec<_>>();
        if v.len() == 42 {
            foo();
        }
        println!("Hello, world!");
    }
}
```

I expected to see this happen: no compile error

Instead, this happened: E0275

### 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.67.0-nightly (b3bc6bf31 2022-11-24)
binary: rustc
commit-hash: b3bc6bf31265ac10946a0832092dbcedf9b26805
commit-date: 2022-11-24
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4
```

```
rustc 1.66.0-beta.2 (0040709e3 2022-11-20)
binary: rustc
commit-hash: 0040709e39bfa159d099ee14628ad4ac72f91406
commit-date: 2022-11-20
host: x86_64-unknown-linux-gnu
release: 1.66.0-beta.2
LLVM version: 15.0.2
```

```
rustc 1.65.0 (897e37553 2022-11-02)
binary: rustc
commit-hash: 897e37553bba8b42751c67658967889d11ecd120
commit-date: 2022-11-02
host: x86_64-unknown-linux-gnu
release: 1.65.0
LLVM version: 15.0.0
```

<details><summary>log nightly</summary>
<p>

```terminal
$ rustc --version --verbose
rustc 1.67.0-nightly (b3bc6bf31 2022-11-24)
binary: rustc
commit-hash: b3bc6bf31265ac10946a0832092dbcedf9b26805
commit-date: 2022-11-24
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4
$ cargo clean
$ cargo run --bin a
   Compiling baz v0.1.0 (/home/Toru3/polynomial-ring2)
error[E0275]: overflow evaluating the requirement `for<'x> &'x Simd<_, _>: Add`
  |
  = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`a`)
  = note: required for `&'x S<Simd<_, _>>` to implement `for<'x> Add`
  = note: 127 redundant requirements hidden
  = note: required for `&'x S<S<S<S<S<...>>>>>` to implement `for<'x> Add`
  = note: the full type name has been written to '/home/Toru3/polynomial-ring2/target/debug/deps/a-84f17e47597c1027.long-type-12017482340628741203.txt'

For more information about this error, try `rustc --explain E0275`.
error: could not compile `baz` due to previous error
$ cargo clean
$ cargo run --bin a --features bar
   Compiling baz v0.1.0 (/home/Toru3/polynomial-ring2)
    Finished dev [unoptimized + debuginfo] target(s) in 0.68s
     Running `target/debug/a`
Hello, world!
```

</p>
</details>

<details><summary>log beta</summary>
<p>

```terminal
$ rustc --version --verbose
rustc 1.66.0-beta.2 (0040709e3 2022-11-20)
binary: rustc
commit-hash: 0040709e39bfa159d099ee14628ad4ac72f91406
commit-date: 2022-11-20
host: x86_64-unknown-linux-gnu
release: 1.66.0-beta.2
LLVM version: 15.0.2
$ cargo clean
$ cargo run --bin a
   Compiling baz v0.1.0 (/home/Toru3/polynomial-ring2)
error[E0275]: overflow evaluating the requirement `for<'x> &'x Simd<_, _>: Add`
  |
  = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`a`)
  = note: required for `&'x S<Simd<_, _>>` to implement `for<'x> Add`
  = note: 127 redundant requirements hidden
  = note: required for `&'x S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<Simd<_, _>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>` to implement `for<'x> Add`

For more information about this error, try `rustc --explain E0275`.
error: could not compile `baz` due to previous error
$ cargo clean
$ cargo run --bin a --features bar
   Compiling baz v0.1.0 (/home/Toru3/polynomial-ring2)
    Finished dev [unoptimized + debuginfo] target(s) in 0.64s
     Running `target/debug/a`
Hello, world!
```

</p>
</details>

<details><summary>log stable</summary>
<p>

```terminal
$ rustc --version --verbose
rustc 1.65.0 (897e37553 2022-11-02)
binary: rustc
commit-hash: 897e37553bba8b42751c67658967889d11ecd120
commit-date: 2022-11-02
host: x86_64-unknown-linux-gnu
release: 1.65.0
LLVM version: 15.0.0
$ cargo clean
$ cargo run --bin a
   Compiling baz v0.1.0 (/home/Toru3/polynomial-ring2)
error[E0275]: overflow evaluating the requirement `for<'x> &'x Simd<_, _>: Add`
  |
  = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`a`)
  = note: required for `&'x S<Simd<_, _>>` to implement `for<'x> Add`
  = note: 127 redundant requirements hidden
  = note: required for `&'x S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<Simd<_, _>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>` to implement `for<'x> Add`

For more information about this error, try `rustc --explain E0275`.
error: could not compile `baz` due to previous error
$ cargo clean
$ cargo run --bin a --features bar
   Compiling baz v0.1.0 (/home/Toru3/polynomial-ring2)
    Finished dev [unoptimized + debuginfo] target(s) in 0.66s
     Running `target/debug/a`
Hello, world!
```

</p>
</details>