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 during drop-check on a recursive type #44933

Open
wolfiestyle opened this issue Sep 29, 2017 · 9 comments
Open

overflow during drop-check on a recursive type #44933

wolfiestyle opened this issue Sep 29, 2017 · 9 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@wolfiestyle
Copy link

I get a pretty strange error when trying to compile this: (playground link)

enum Stuff<T> {
    Value(T),
    Nested(Box<Stuff<Stuff<T>>>),
}

fn main() {
    let a = Stuff::Value(1);
}

output:

error[E0320]: overflow while adding drop-check rules for Stuff<i32>
 --> src/main.rs:7:9
  |
7 |     let a = Stuff::Value(1);
  |         ^
  |
  = note: overflowed on Stuff<Stuff<Stuff<Stuff<Stuff<Stuff< ...

If the type isn't used, the program compiles fine. Don't know if the type is actually representable or not, the error is misleading.

@sfackler
Copy link
Member

How is it misleading? Stuff::<i32>::Nested contains a Stuff<Stuff<i32>>, which contains a Stuff<Stuff<Stuff<i32>>>, which contains a....

@nagisa nagisa added the A-diagnostics Area: Messages for errors, warnings, and lints label Oct 5, 2017
@Ixrec
Copy link
Contributor

Ixrec commented Oct 15, 2017

I wouldn't call it misleading either, but "overflow while adding drop-check rules" certainly isn't as clear and to-the-point as "Stuff<T> is unrepresentable" would be. It also seems bad that we don't emit this error until the type gets used somewhere.

@XAMPPRocky XAMPPRocky added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 22, 2018
@pnkfelix pnkfelix added I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. and removed I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. labels Mar 5, 2019
@pnkfelix
Copy link
Member

pnkfelix commented Mar 5, 2019

(I am debating about whether the I-hang label applies here. In my head, stack overflow errors are usually just the result of hangs being caught via very crude means...)

@pnkfelix pnkfelix added the P-medium Medium priority label Mar 5, 2019
@pnkfelix
Copy link
Member

pnkfelix commented Mar 5, 2019

Interestingly, the overflow here doesn't trigger an ICE?

@oli-obk oli-obk added the E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. label May 24, 2019
@oli-obk
Copy link
Contributor

oli-obk commented May 24, 2019

Diagnostics triage: P-low, as it's fairly clear what's going on, just not a great diagnostic message

@oli-obk oli-obk added P-low Low priority and removed P-medium Medium priority labels May 24, 2019
@estebank
Copy link
Contributor

Triage: no change.

@Dylan-DPC
Copy link
Member

Current error:

error[E0320]: overflow while adding drop-check rules for Stuff<i32>
 --> src/main.rs:9:9
  |
9 |     let a = Stuff::Value(1);
  |         ^
  |
  = note: overflowed on Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<Stuff<i32>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

For more information about this error, try `rustc --explain E0320`.

@estebank
Copy link
Contributor

@Dylan-DPC surprised that we don't trim the type name in the note and store it to disk. That would be an easy improvement, as well as modifying the message to surround the type name with `.

@cyypherus
Copy link

cyypherus commented Oct 13, 2024

I've run into a similar error with a type that looks to me to be completely reasonable & only fails to compile in some cases. Perhaps the triage for this issue can be revisited.

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
    }
}

playground

playground + modifications that trigger an ICE

I was hoping to implement a builder API on Tree, but I don't know any way around this error.

I did notice that using references in foo do not trigger the drop check overflow, but I can't implement a builder pattern without owned values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

10 participants