Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE when returning struct with borrowed pointer to trait #5708

Closed
ghost opened this issue Apr 3, 2013 · 8 comments
Closed

ICE when returning struct with borrowed pointer to trait #5708

ghost opened this issue Apr 3, 2013 · 8 comments
Labels
A-lifetimes Area: Lifetimes / regions E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@ghost
Copy link

ghost commented Apr 3, 2013

A function which takes a borrowed pointer to a trait and returns a struct with that borrowed pointer results in an ICE:

trait Inner {
    fn print(&self);
}

impl Inner for int {
    fn print(&self) { io::print(fmt!("Inner: %d\n", *self)); }
}

struct Outer<'self> {
    inner: &'self Inner
}

impl<'self> Outer<'self> {
    fn new<'r>(inner: &'r Inner) -> Outer<'r> {
        Outer {
            inner: inner
        }
    }
}

fn main() {
    let inner = 5;
    let outer = Outer::new(&inner as &Inner);
    outer.inner.print();
}

This is the resulting ICE:

borrowtest-4.rs:16:19: 16:24 error: internal compiler error: Cannot relate bound region as subregion: br_self
borrowtest-4.rs:16             inner: inner

This does not occur with concrete types, only with borrowed pointers to traits.

@catamorphism
Copy link
Contributor

Reproduced as of 0252c30 -- nominating for milestone 5, production-ready

@bblum
Copy link
Contributor

bblum commented Jun 26, 2013

@zargony found a simpler test: https://gist.github.com/zargony/1780399775004b28f0b4

Oddly this one works fine if you remove the type parameter.

@zargony
Copy link
Contributor

zargony commented Jun 29, 2013

Here's another case that seems to trigger the same ICE. Both methods result in the ICE: Cannot relate bound region as subregion: br_self. Seems to be related to the type parameter, since everything compiles fine if you remove from MyTrait.

trait MyTrait<T> { }

struct MyContainer<'self, T> {
    elems: ~[&'self MyTrait<T>],
}

impl<'self, T> MyContainer<'self, T> {
    fn foo (&self, f: &fn (&'self MyTrait<T>)) {
        f(self.elems[0]);
    }
    fn bar (&self) -> &'self MyTrait<T> {
        self.elems[0]
    }
}

fn main () {}

@mstewartgallus
Copy link
Contributor

Ugh, I ran into this bug while trying to re-factor extra::arc. +1 internet points towards whoever fixes this.

@jmgrosen
Copy link
Contributor

jmgrosen commented Jul 9, 2013

It would be very nice if this were fixed, not sure how to do what I'm doing without it.

@graydon
Copy link
Contributor

graydon commented Aug 15, 2013

accepted for production-ready milestone

@nikomatsakis
Copy link
Contributor

I will try to take a look at this soon

@alexcrichton
Copy link
Member

This appears to work now, flagging as needstest

@huonw huonw closed this as completed in 12099ce Sep 3, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

No branches or pull requests

8 participants