Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overflow while adding drop-check rules on a generic tree #133356

Open
cyypherus opened this issue Nov 23, 2024 · 1 comment
Open

Overflow while adding drop-check rules on a generic tree #133356

cyypherus opened this issue Nov 23, 2024 · 1 comment
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@cyypherus
Copy link

I tried this code:

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.

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

Meta

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
Error

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>

@cyypherus cyypherus added the C-bug Category: This is a bug. label Nov 23, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 23, 2024
@cyypherus
Copy link
Author

Working around this drop-checking overflow also led to an issue with clippy
rust-lang/rust-clippy#13544

@saethlin saethlin added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Nov 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants