Skip to content

Bad associated type usage causes infinite build/check/run  #76187

@Avi-D-coder

Description

@Avi-D-coder

Bad: compilation never completes

struct Elem<'r, T: Life> {
    next: List<'r, T::L<'r>>,
    value: T,
}

Good: compilation completes

struct Elem<'r, T: Life> {
    next: List<'r, T>,
    value: T,
}

Common

#![allow(incomplete_features)]
#![feature(generic_associated_types)]

fn main() {
    println!("Hello, world!");
}

unsafe trait Life {
    type L<'l>: 'l + Life;
}

struct Gc<'r, T>(&'r T);
unsafe impl<'r, T: Life> Life for Gc<'r, T> {
    type L<'l> = Gc<'l, T::L<'l>>;
}

unsafe impl<'r, T: Life> Life for Option<T> {
    type L<'l> = Option<T::L<'l>>;
}


unsafe impl<'r, T: Life> Life for List<'r, T> {
    type L<'l> = List<'l, T::L<'l>>;
}

unsafe impl<'r, T: Life> Life for Elem<'r, T> {
    type L<'l> = Elem<'l, T::L<'l>>;
}

struct List<'r, T: Life>(Option<Gc<'r, Elem<'r, T>>>);

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)C-bugCategory: This is a bug.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.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions