Skip to content

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

Closed
@theemathas

Description

@theemathas

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions