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

"impl Trait" causes error: overflow evaluating the requirement impl Trait: std::marker::Freeze #50674

Closed
theemathas opened this issue May 11, 2018 · 3 comments
Labels
A-trait-system Area: Trait system C-enhancement Category: An issue proposing an enhancement or a PR with one. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@theemathas
Copy link
Contributor

theemathas commented May 11, 2018

Code:

trait Trait {}

struct Wrap<T>(T);
impl<T: Trait> Trait for Wrap<T> {}

fn f(x: impl Trait) -> impl Trait {
    f(Wrap(x))
}

playground link

This code probably shouldn't compile, since it would probably need to instantiate infinitely many versions of the f function.

It currently doesn't compile as it should. However, it does produce the following error, which is very confusing:

   Compiling playground v0.0.1 (file:///playground)
error[E0275]: overflow evaluating the requirement `impl Trait: std::marker::Freeze`
  |
  = help: consider adding a `#![recursion_limit="128"]` attribute to your crate
  = note: required because it appears within the type `impl Trait`
  = note: required because it appears within the type `impl Trait`
  = note: required because it appears within the type `impl Trait`
  = note: required because it appears within the type `impl Trait`
(many more lines repeating this here...)
  = note: required because it appears within the type `impl Trait`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0275`.
error: Could not compile `playground`.

To learn more, run the command again with --verbose. 

I have no idea what std::marker::Freeze is, and it appearing in the error message will probably be confusing to other users as well. I'm not sure whether this will happen in actual code though.

Most likely a reincarnation of #44349.

@ishitatsuyuki
Copy link
Contributor

Basically the diagnostic is useless if you did any endless recursion. There are a few issues open for this already.

@theemathas
Copy link
Contributor Author

Which is why I said "I'm not sure whether this will happen in actual code though."

@XAMPPRocky XAMPPRocky added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-trait-system Area: Trait system T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 2, 2018
@WaffleLapkin
Copy link
Member

On latest stable (1.45.0) this code correctly (?) errors with

error[E0720]: opaque type expands to a recursive type
 --> src/main.rs:6:24
  |
6 | fn f(x: impl Trait) -> impl Trait {
  |                        ^^^^^^^^^^ expands to a recursive type
  |
  = note: type resolves to itself

I think the issue is resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trait-system Area: Trait system C-enhancement Category: An issue proposing an enhancement or a PR with one. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants