Skip to content

Compiler (effectively) hangs, regression from overflow error #93774

Closed

Description

@steffahn
pub enum Either<L, R> {
    Left(L),
    Right(R),
}

pub trait HasItem<'a, _Constraint = &'a Self> {
    type Item;
}

pub type Item<'a, Self_> = <Self_ as HasItem<'a>>::Item;

pub trait LendingIterator: for<'a> HasItem<'a> {
    fn next(&mut self) -> Option<Item<'_, Self>>;
}

impl<'a, A: 'a, B: 'a> HasItem<'a> for Either<A, B>
where A: LendingIterator, B: LendingIterator,
 for<'b> B: HasItem<'b, Item = Item<'b, Self>>
{
    type Item = Item<'a, Self>;
}

impl<A, B> LendingIterator for Either<A, B>
where A: LendingIterator, B: LendingIterator,
 for<'b> B: HasItem<'b, Item = Item<'b, Self>>
{
    fn next(&mut self) -> Option<Item<'_, Self>> {
        match self {
            Either::Left(iter) => iter.next(),
            Either::Right(iter) => iter.next(),
        }
    }
}

hangs since 1.56
error on 1.55

error[E0275]: overflow evaluating the requirement `for<'b> <B as HasItem<'b>>::Item == <Either<A, B> as HasItem<'b>>::Item`
  --> <source>:16:24
   |
6  | pub trait HasItem<'a, _Constraint = &'a Self> {
   | --------------------------------------------- required by this bound in `HasItem`
...
16 | impl<'a, A: 'a, B: 'a> HasItem<'a> for Either<A, B>
   |                        ^^^^^^^^^^^
   |
note: required because of the requirements on the impl of `HasItem<'a>` for `Either<A, B>`
  --> <source>:16:24
   |
16 | impl<'a, A: 'a, B: 'a> HasItem<'a> for Either<A, B>
   |                        ^^^^^^^^^^^     ^^^^^^^^^^^^

error[E0275]: overflow evaluating the requirement `for<'b> <B as HasItem<'b>>::Item == <Either<A, B> as HasItem<'b>>::Item`
  --> <source>:23:12
   |
12 | pub trait LendingIterator: for<'a> HasItem<'a> {
   |                            ------------------- required by this bound in `LendingIterator`
...
23 | impl<A, B> LendingIterator for Either<A, B>
   |            ^^^^^^^^^^^^^^^
   |
note: required because of the requirements on the impl of `for<'a> HasItem<'a>` for `Either<A, B>`
  --> <source>:16:24
   |
16 | impl<'a, A: 'a, B: 'a> HasItem<'a> for Either<A, B>
   |                        ^^^^^^^^^^^     ^^^^^^^^^^^^

error[E0275]: overflow evaluating the requirement `for<'b> <B as HasItem<'b>>::Item == <Either<A, B> as HasItem<'b>>::Item`
  --> <source>:20:5
   |
20 |     type Item = Item<'a, Self>;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: required because of the requirements on the impl of `HasItem<'a>` for `Either<A, B>`
  --> <source>:16:24
   |
16 | impl<'a, A: 'a, B: 'a> HasItem<'a> for Either<A, B>
   |                        ^^^^^^^^^^^     ^^^^^^^^^^^^

error[E0275]: overflow evaluating the requirement `for<'b> <B as HasItem<'b>>::Item == <Either<A, B> as HasItem<'b>>::Item`
  --> <source>:27:8
   |
27 |     fn next(&mut self) -> Option<Item<'_, Self>> {
   |        ^^^^
   |
note: required because of the requirements on the impl of `HasItem<'_>` for `Either<A, B>`
  --> <source>:16:24
   |
16 | impl<'a, A: 'a, B: 'a> HasItem<'a> for Either<A, B>
   |                        ^^^^^^^^^^^     ^^^^^^^^^^^^

error: aborting due to 4 previous errors

@rustbot label I-hang, regression-from-stable-to-stable, A-traits, A-lifetimes, E-needs-bisection, T-compiler


Edit:

“Hangs” means “runs for a wile on 100% CPU until I cancel it”. Who knows if it would ever terminate… actually, maybe I should test smaller recursion limits.

Note that this code example is not expected to compile successfully. Here’s a version that works / with the mistakes fixed. (The fixed version also works on some older Rust versions, including 1.55 and older.)


Edit2: Using smaller limits (like… around #![recursion_limit = "14"] it starts getting unbearably slow) reveals that this is apparently more like exponential-time slowdown rather than “actual” hanging.

@rustbot label -I-hang, +I-compiletime, +perf-regression

Activity

  1. added
    A-lifetimesArea: Lifetimes / regions
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    I-hangIssue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.
    regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Feb 8, 2022
  2. changed the title [-]Compiler hangs, regression from overflow error[/-] [+]Compiler (effectively) hangs, regression from overflow error[/+] on Feb 8, 2022
  3. added
    I-compiletimeIssue: Problems and improvements with respect to compile times.
    I-hangIssue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.
    and removed
    I-hangIssue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.
    on Feb 8, 2022
  4. apiraino commented on Feb 10, 2022

    @apiraino
    Contributor

    Assigning priority as discussed in the Zulip thread of the Prioritization Working Group.

    @rustbot label -I-prioritize +P-high

  5. added
    P-highHigh priority
    and removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Feb 10, 2022
  6. Badel2 commented on Feb 11, 2022

    @Badel2
    Contributor

    Run a bisect on this, 8d7707f is the first bad commit.

    cargo-bisect-rustc was only able to narrow it down to nightly-2021-08-26, but I checked the remaining range using git bisect.

  7. steffahn commented on Aug 16, 2022

    @steffahn
    MemberAuthor

    Let me remove the bisection label and mention the relevant PR #85499 (cc @jackh726)

    @rustbot label -E-needs-bisection

  8. removed
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    on Aug 16, 2022
  9. pnkfelix commented on Nov 11, 2022

    @pnkfelix
    Contributor

    Discussed in T-compiler P-high review

    Reassigning to T-types to determine what to do, if anything, in response to this.

    @rustbot label -T-compiler +T-types

  10. added
    T-typesRelevant to the types team, which will review and decide on the PR/issue.
    and removed
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Nov 11, 2022
  11. cyrgani commented on Jul 26, 2025

    @cyrgani
    Contributor

    Bisection reveals that this was fixed in nightly-2023-03-09, between 1.69 and 1.70, and now errors directly instead:


    Regression in nightly-2023-03-09


    fetching https://static.rust-lang.org/dist/2023-03-08/channel-rust-nightly-git-commit-hash.txt
    nightly manifest 2023-03-08: 40 B / 40 B [=============================================================================] 100.00 % 524.67 KB/s converted 2023-03-08 to e3dfeea
    fetching https://static.rust-lang.org/dist/2023-03-09/channel-rust-nightly-git-commit-hash.txt
    nightly manifest 2023-03-09: 40 B / 40 B [=============================================================================] 100.00 % 634.84 KB/s converted 2023-03-09 to 900c354
    looking for regression commit between 2023-03-08 and 2023-03-09
    fetching (via remote github) commits from max(e3dfeea, 2023-03-06) to 900c354
    ending github query because we found starting sha: e3dfeea
    get_commits_between returning commits, len: 6
    commit[0] 2023-03-07: Auto merge of #108167 - Zoxc:query-config-instance-slim, r=cjgillot
    commit[1] 2023-03-07: Auto merge of #108877 - matthiaskrgr:rollup-7gwgvgc, r=matthiaskrgr
    commit[2] 2023-03-08: Auto merge of #108312 - michaelwoerister:hash-set-not-hash-stable, r=eholk
    commit[3] 2023-03-08: Auto merge of #108534 - Mark-Simulacrum:compression, r=pietroalbini
    commit[4] 2023-03-08: Auto merge of #108121 - aliemjay:resolve-var-region, r=lcnr
    commit[5] 2023-03-08: Auto merge of #108665 - weihanglo:update-cargo, r=weihanglo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regionsA-trait-systemArea: Trait systemC-bugCategory: This is a bug.I-compiletimeIssue: Problems and improvements with respect to compile times.P-highHigh priorityT-typesRelevant to the types team, which will review and decide on the PR/issue.perf-regressionPerformance regression.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions