Skip to content

Compiler out of stack on generic base trait impl restricted to a derived trait #5988

Closed
@mzabaluev

Description

@mzabaluev

Rustc runs out of stack on this program:

use std::io;
trait B {
    fn f(&self);
}

trait T : B {
}

struct A;

impl<U: T> B for U {
    fn f(&self) { io::println("Hey, I'm a T!"); }
}

impl T for A {
}

fn main() {
    let a = A;
    let br = &a as &B;
    // let tr = &a as &T;
    // let br = tr as &B;
    br.f();
}

The inheritance of trait T from B seemingly triggers the recursion: without it, the program compiles and runs fine.

P.S. The commented-out lines illustrate what I was actually trying to achieve: upcasting a trait pointer to the base trait. That didn't work for other reasons.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.P-lowLow priority

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions