Skip to content

Recursive trait constraints crash compiler with exit code 3221225501 #51296

Open
@bergus

Description

@bergus

I've got a crate that doesn't compile, it just starts eating memory until it stops without an error message. Only passing the --verbose flag to cargo build tells me

error: Could not compile `the-crate`.

Caused by:
  process didn't exit successfully: `rustc …` (exit code: 3221225501)

Seems to be the same exit code as in #42544.

Here's the (not exactly minimal) example to reproduce the issue:

pub struct Example<A, B, D>
where
    A: StrategyA<Example<A, B, D>>,
    B: StrategyB<Example<A, B, D>> {
    pub a: A,
    pub b: B,
    pub element: B::Element,
    pub data: D,
}
pub trait StrategyA<T: HasData> {
    fn do_a(&self, &T::Data);
}
pub trait StrategyB<T> {
    type Element;
    fn do_b(&self, &T);
}
impl<A: StrategyA<Self>, B: StrategyB<Self>, D> Example<A, B, D> {
    pub fn do_it(&self, args: bool) {
        if args {
            self.a.do_a(self.get_data());
        } else {
            self.b.do_b(self);
        }
    }
}
pub trait HasData {
    type Data;
    fn get_data(&self) -> &Self::Data;
}
impl<A: StrategyA<Self>, B: StrategyB<Self>, D> HasData for Example<A, B, D> {
    type Data = D;
    fn get_data(&self) -> &D {
        &self.data
    }
}

pub struct ExampleA;
pub struct ExampleB;
pub struct ExampleData;

impl<E: HasData<Data=ExampleData>> StrategyA<E> for ExampleA {
    fn do_a(&self, e: &ExampleData) {
        e; // using ExampleData here
    }
}
impl<E: HasData<Data=ExampleData>> StrategyB<E> for ExampleB {
    type Element = ExampleData;
    fn do_b(&self, e: &E) { /* same */}
}

fn x() {
    let example = Example { a: ExampleA, b: ExampleB, data: ExampleData };
    example.sized.do_it(true);
    example.sized.do_it(false);
}

Removing the StrategyA parts causes it to produce an "overflow evaluating the requirement …" error, not sure whether related.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemC-bugCategory: This is a bug.I-compilememIssue: Problems and improvements with respect to memory usage during compilation.I-compiletimeIssue: Problems and improvements with respect to compile times.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