Skip to content

Two test cases for incorrect region inference #4036

Closed
@brson

Description

@brson

I came up with these two similar test cases for region-related ICEs. They both have to do with JsonDeserializer's interior pointer.

pub trait Deserializable<D> {
    static fn deserialize(&self, d: &D) -> self;
}

pub impl<D> int: Deserializable<D> {
    static fn deserialize(&self, _d: &D) -> int { fail }
}

struct JsonDeserializer {
    stack: &int,
}

impl JsonDeserializer {
}

trait Unflattenator<T> {
    fn unflatten(&self) -> T;
}

struct DeserializingUnflattenator<D, T: Deserializable<D>> {
    bogus: ()
}

fn from_reader<D>() -> D { fail }

fn unflatten<D, T: Deserializable<D>>(_s: &DeserializingUnflattenator<D, T>) -> T {
    let deser: &D = &from_reader();
    deserialize(deser)
}

fn m(_t: &r/int) {
    let unflat: DeserializingUnflattenator<JsonDeserializer, int> = DeserializingUnflattenator { bogus: () };
    unflatten(&unflat);
}

fn main() {
}
note: cannot encode region variables lifetime re_infer(ReVar(RegionVid(0)))
error: internal compiler error: Cannot encode region variables
pub trait Deserializable<D> {
    static fn deserialize(&self, d: &D) -> self;
}

pub impl<D> int: Deserializable<D> {
    static fn deserialize(&self, d: &D) -> int { fail }
}

struct JsonDeserializer {
    stack: &int,
}

impl JsonDeserializer {
}

trait Unflattenator<T> {
    fn unflatten(&self) -> T;
}

struct DeserializingUnflattenator<D, T: Deserializable<D>> {
    bogus: ()
}

fn from_reader<D>() -> D { fail }

fn unflatten<D, T: Deserializable<D>>() -> T {
    let deser: &D = &from_reader();
    deserialize(deser)
}

fn m(foo: &r/int) {
    unflatten::<JsonDeserializer, int>();
}

fn main() {
}
/home/brian/dev/rust2/src/test/run-pass/flatpipe-encode2.rs:32:16: 32:32 error: Unconstrained region variable #0
/home/brian/dev/rust2/src/test/run-pass/flatpipe-encode2.rs:32     unflatten::<JsonDeserializer, int>();

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