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

Error: overflow evaluating the requirement ... in Serde, raising recursion limit doesn't help #50040

Closed
LPGhatguy opened this issue Apr 18, 2018 · 2 comments

Comments

@LPGhatguy
Copy link

I was working through a couple Serde issues with @dtolnay when I hit a bad error:

error[E0275]: overflow evaluating the requirement `<&mut serde_json::Serializer<&mut std::vec::Vec<u8>> as serde::Serializer>::Error`
  |
  = help: consider adding a `#![recursion_limit="128"]` attribute to your crate

Minimal playground example:
https://play.rust-lang.org/?gist=c19a458d3246d211beb1ae7d88c0ddee&version=stable

Raising the recursion limit causes the compiler to ask me to raise the recursion limit again and again, out forever.

@dtolnay recommended I file an issue here after minimizing the error case:

<dtolnay> wow that's crazy
<dtolnay> this part looks like a compiler bug -- that associated type should be easy to figure out
<dtolnay> lpg: see how much you can minimize this "overflow evaluating the requirement" error and file an issue in github.com/rust-lang/rust
LPGhatguy added a commit to LPGhatguy/mab that referenced this issue Apr 18, 2018
I want to add #[serde(tag = "type")] to the enum variants, but this
angers rustc and causes a stack overflow in the compiler:

rust-lang/rust#50040
@dtolnay
Copy link
Member

dtolnay commented Apr 18, 2018

#[derive(Serialize)]
#[serde(tag = "type")]
enum Expression {
    Foo,
    Baz(Box<Expression>),
}

After taking a closer look, I think this is a case of the compiler catching something that legitimately doesn't make sense (albeit with not a great error message). In this Expression type how would you expect Baz(Box::new(Baz(Box::new(Foo)))) to be represented in JSON?

{
  "type": "Baz",
  ??? "type": "Baz",
  ??? ??? "type": "Foo"
}

If your expression is a Baz then the "type" tag needs to be inside the nested expression, but if that one is also a Baz then both your tag and its tag need to be inside the next nested expression, but if that one is a Baz as well then etc, overflow.

I filed #50043 to detect this particular type of overflow and handle it with a better error message.

@Mark-Simulacrum
Copy link
Member

It seems like there's nothing in this issue that needs to be fixed? That is, #50043 is the underlying issue. So I'm going to close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants