Skip to content

Out of memory with tuple struct initialization, async fn and use #122057

Closed as not planned
@sgdxbc

Description

@sgdxbc

It's very hard to precisely summarize the keywords, feel sorry if I missed a duplicated case when checking previous issues.

Code

In lib.rs

pub struct Foo<F> {
    pub f: F,
}
// these also works: private `f` field, `pub Foo<F>(F);`

impl<F> Foo<F> {
    pub async fn foo() {}
}

In main.rs

use foo::Foo;  // package named `foo`

fn main() {
    Foo(());
}

Run cargo check or cargo build, it looks like compiler allocate memory in infinite loop/recursion and eventually get killed.

Either the following does not trigger...:

  • Replace use foo::Foo with mod foo { /* lib.rs content */ }
  • Replace Foo(()) with Foo { f: () } with a private f field
  • All other variants that passes compilation. (the two cases above reports correct error)

...and after do either of them once, revert the code, rerun

error[E0391]: cycle detected when getting the resolver for lowering
  |
  = note: ...which requires normalizing `foo::Foo<F>::foo::{opaque#0}`...
  = note: ...which requires looking up limits...
  = note: ...which requires getting the crate HIR...
  = note: ...which again requires getting the resolver for lowering, completing the cycle
  = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information

For more information about this error, try `rustc --explain E0391`.

cargo clean and rerun, the issue is back.

Meta

rustc --version --verbose:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler 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