Repository: rust
Issue: Overflow while adding drop-check rules on a generic tree
Labels: T-compiler,C-bug,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:

```rust
enum Tree<T: Scopable> {
    Group(Vec<Tree<T>>),
    Subtree(Box<Tree<T::SubType>>),
    Leaf(T),
}

trait Scopable: Sized {
    type SubType: Scopable;
}

impl<T: Scopable> Tree<T> {
    fn foo(self) -> Self { // error[E0320]: overflow while adding drop-check rules for Tree<T>
        self
    }
}
```

I expected this to compile as it doesn't seem to unconditionally introduce a type of infinite length, but no luck, drop checking does not succeed.

When the type is not passed in as an argument, or passed by reference of course, there are no issues & the code compiles.

```rust
fn bar() {
    let _ = Tree::Leaf(()); // no problem!
}
```

### 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.
-->

Reproduced on these versions,
`rustc --version --verbose`:
```
rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: aarch64-apple-darwin
release: 1.81.0
LLVM version: 18.1.7
```

```
rustc 1.83.0-nightly (1bc403daa 2024-10-11)
binary: rustc
commit-hash: 1bc403daadbebb553ccc211a0a8eebb73989665f
commit-date: 2024-10-11
host: aarch64-apple-darwin
release: 1.83.0-nightly
LLVM version: 19.1.1
```

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary>Error</summary>
<p>

```
error[E0320]: overflow while adding drop-check rules for Tree<T>
  --> src/main.rs:68:21
   |
68 |     fn foo(self) -> Self {
   |                     ^^^^
   |
   = note: overflowed on Tree<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<T as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType as Scopable>::SubType>
```

</p>
</details>