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

HKL-bound associated type's associated type as return makes function call's temporary receiver not live through its statement #30583

Closed
soltanmm opened this issue Dec 28, 2015 · 1 comment

Comments

@soltanmm
Copy link

trait A<'self_> {
    type Foobar; // : 'self_; // <-- adding this doesn't help
    fn i_work(&'self_ self) -> &'self_ usize;
    fn i_fail(&'self_ self) -> Self::Foobar;
}
trait B<'self_> {
    type MyA: for<'s> A<'s>;
    fn my_a(&'self_ self) -> Self::MyA;
    fn do_stuff(&'self_ self) {
        self.my_a().i_work();
        self.my_a().i_fail();
    }
}

fn main() {
}

play-pen

The i_work function is there to emphasize that associated types coming from traits with lifetimes seem to be getting treated weirdly. I don't know what's happening, but I'd have expected that if i_fail failed, so'd i_work...

Error

<anon>:11:9: 11:20 error: borrowed value does not live long enough
<anon>:11         self.my_a().i_fail();
                  ^~~~~~~~~~~
<anon>:11:9: 11:30 note: reference must be valid for the destruction scope surrounding statement at 11:8...
<anon>:11         self.my_a().i_fail();
                  ^~~~~~~~~~~~~~~~~~~~~
<anon>:11:9: 11:30 note: ...but borrowed value is only valid for the statement at 11:8
<anon>:11         self.my_a().i_fail();
                  ^~~~~~~~~~~~~~~~~~~~~
<anon>:11:9: 11:30 help: consider using a `let` binding to increase its lifetime
<anon>:11         self.my_a().i_fail();
                  ^~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
playpen: application terminated with error code 101
@soltanmm soltanmm changed the title HKL-bound associated type's associated type as return makes function call temporary not live through its statement HKL-bound associated type's associated type as return makes function call's temporary receiver not live through its statement Dec 28, 2015
@arielb1
Copy link
Contributor

arielb1 commented Dec 28, 2015

This is a duplicate of #22323.

@arielb1 arielb1 closed this as completed Dec 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants