Skip to content

ICE using trait lifetime in a method definition #10391

Closed
@erickt

Description

@erickt

cc @nikomatsakis. I think this is related to #10153. Here's the example code:

pub enum Value<'self> {
    A(&'self str),
    B,
}

pub trait Decoder<'self> {
    fn read(&'self mut self) -> Value<'self>;
}

pub trait Decodable<'self, D: Decoder<'self>> {
    fn decode(d: &mut D) -> Self;
}

impl<'self, D: Decoder<'self>> Decodable<'self, D> for () {
    fn decode(d: &mut D) -> () {
        match d.read() {
            A(*) => (),
            B => Decodable::decode(d),
        }
    }
}

fn main() { }

It errors with:

foo.rs:18:17: 18:34 error: internal compiler error: Cannot relate bound region: ReLateBound(29, BrNamed(syntax::ast::DefId{crate: 0, node: 33}, self)) <= ReFree(62, BrNamed(syntax::ast::DefId{crate: 0, node: 38}, self))
This message reflects a bug in the Rust compiler.
We would appreciate a bug report: https://github.com/mozilla/rust/wiki/HOWTO-submit-a-Rust-bug-report
foo.rs:18             B => Decodable::decode(d),
                           ^~~~~~~~~~~~~~~~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regionsI-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions