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

Program Hangs when Using Associated Types in Structs with Trait Bounds #115407

Open
iamanonymouscs opened this issue Aug 31, 2023 · 3 comments
Open
Labels
A-associated-items Area: Associated items (types, constants & functions) A-implied-bounds Area: Implied bounds / inferred outlives-bounds A-trait-system Area: Trait system C-bug Category: This is a bug. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@iamanonymouscs
Copy link

I tried this code(reduced):

//...
trait Trait {
    type AssTrait;
}
//...
struct St<'a, T: Trait> {
    _var1: Box<&'a T>,
    _var2: Box<St<'a, T::AssTrait>>,
}

fn main() {
//...
}

When attempting to compile the provided code, the program hangs indefinitely, resulting in a non-responsive state. This issue occurs when using associated types in structs with trait bounds.

😃I expected to see this happen: The code should compile successfully or produce a clear error message indicating the cause of the issue.

😥Instead, this happened: The compilation process hangs indefinitely, and the program does not execute.

Meta

rustc --version --verbose:

rustc 1.72.0 (5680fa18f 2023-08-23)
binary: rustc
commit-hash: 5680fa18feaa87f3ff04063800aec256c3d4b4be
commit-date: 2023-08-23
host: x86_64-unknown-linux-gnu
release: 1.72.0
LLVM version: 16.0.5

We have attempted to use the BACKTRACE=1command to obtain a backtrace for debugging purposes😢, but no output is generated. It is worth mentioning that the provided code snippet causes a hang issue on both the latest stable and nightly(nightly-x86_64-unknown-linux-gnu unchanged - rustc 1.74.0-nightly (59a8294 2023-08-30)) versions of Rust.

What‘s more,when we change _var2: Box<St<'a, T::AssTrait>> to _var2: Box<St<'a, T>>, the program will produce the correct output

Backtrace

<backtrace>

@iamanonymouscs iamanonymouscs added the C-bug Category: This is a bug. label Aug 31, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 31, 2023
@fmease
Copy link
Member

fmease commented Aug 31, 2023

Hangs in the current version of the next solver, too. Haven't looked for potential duplicates of this issue yet.

@rustbot label -needs-triage T-compiler I-hang A-traits A-associated-items

@rustbot rustbot added A-associated-items Area: Associated items (types, constants & functions) A-trait-system Area: Trait system I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Aug 31, 2023
@fmease fmease added the A-implied-bounds Area: Implied bounds / inferred outlives-bounds label Aug 15, 2024
@fmease
Copy link
Member

fmease commented Aug 15, 2024

Inference of implied outlives-bounds might be the culprit, it seems to loop indefinitely on

15ms DEBUG rustc_hir_analysis::outlives::implicit_infer check_explicit_predicates(def_id=DefId(0:5 ~ e[892c]::St2), args=['a/#0, Alias(Projection, AliasTy { args: [T/#1], def_id: DefId(0:4 ~ e[892c]::Trait::AssTrait), .. })]

@fmease
Copy link
Member

fmease commented Aug 15, 2024

Potential duplicate of #102966.

@fmease fmease added the T-types Relevant to the types team, which will review and decide on the PR/issue. label Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-implied-bounds Area: Implied bounds / inferred outlives-bounds A-trait-system Area: Trait system C-bug Category: This is a bug. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants