Skip to content

Hang from infinitely-self-recursive trait alias #133901

Closed
@wxie7

Description

@wxie7

I tried this code:

#![feature(trait_alias)]
#![feature(impl_trait_in_assoc_type)]
trait Foo {
    type Bar: Baz<Self, Self>;
    fn bar(&self) -> Self::Bar;
}
struct X;
impl Foo for X {
    type Bar = impl Baz<Self, Self>;
    fn bar(&self) -> Self::Bar {
        |x| x
    }
}
trait Baz<A: ?Sized, B: ?Sized> = Baz(&A) -> &B;
fn main() {}

It mutates from the following file, but the following code will not cause a hang.

#![feature(trait_alias)]
#![feature(impl_trait_in_assoc_type)]

trait Foo {
    type Bar: Baz<Self, Self>;

    fn bar(&self) -> Self::Bar;
}

struct X;

impl Foo for X {
    type Bar = impl Baz<Self, Self>;

    fn bar(&self) -> Self::Bar {
        |x| x
    }
}

trait Baz<A: ?Sized, B: ?Sized> = Fn(&A) -> &B;

fn main() {}

Also, I used impl_trait_in_assoc_type and Baz as search keywords but didn’t find any related issues with open.

Meta

rustc --version --verbose:

rustc 1.85.0-nightly (acabb5248 2024-12-04)
binary: rustc
commit-hash: acabb5248231987ae1f0c215208d1005a5db402d
commit-date: 2024-12-04
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.5
Backtrace

<backtrace>

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-trait_alias`#![feature(trait_alias)]`I-hangIssue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types 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