Skip to content

Bad error message for infinite type recursion #121090

Open
@pacak

Description

@pacak

Code

#![recursion_limit = "5"]
#![allow(unconditional_recursion)]

fn quicksort<It, I>(i: I) -> Vec<i32>
where
    It: Iterator<Item = i32>,
    I: IntoIterator<IntoIter = It>,
{
    quicksort(i.into_iter().filter(|_| true))
}

pub fn bar(xs: Vec<i32>) -> Vec<i32> {
    quicksort(xs)
}

Current output

relevant error:

error[E0275]: overflow evaluating the requirement `Filter<Filter<Filter<Filter<Filter<std::vec::IntoIter<i32>, ...>, ...>, ...>, ...>, ...>: Iterator`
  |
  = help: consider increasing the recursion limit by adding a `#![recursion_limit = "10"]` attribute to your crate (`qsort`)
  = note: required for `Filter<Filter<Filter<Filter<Filter<std::vec::IntoIter<i32>, {closure@src/lib.rs:8:36: 8:39}>, {closure@src/lib.rs:8:36: 8:39}>, {closure@src/lib.rs:8:36: 8:39}>, {closure@src/lib.rs:8:36: 8:39}>, {closure@src/lib.rs:8:36: 8:39}>` to implement `IntoIterator`

Desired output

something-something infinite recursion

Rationale and extra context

Suggestion to increase recursion limit is wrong

Other cases

No response

Rust Version

rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-unknown-linux-gnu
release: 1.76.0
LLVM version: 17.0.6

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-diagnosticsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemD-confusingDiagnostics: Confusing error or lint that should be reworked.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions