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

Borrow checker unsoundness when using lifetimes on associated types #23259

Closed
ebfull opened this issue Mar 10, 2015 · 3 comments
Closed

Borrow checker unsoundness when using lifetimes on associated types #23259

ebfull opened this issue Mar 10, 2015 · 3 comments
Labels
A-borrow-checker Area: The borrow checker A-lifetimes Area: Lifetimes / regions

Comments

@ebfull
Copy link
Contributor

ebfull commented Mar 10, 2015

struct Foo<'a> {
    inner: &'a mut [u8]
}

impl<'a, 'b> Iterator for Foo<'a> {
    type Item = &'b mut u8;

    fn next(&mut self) -> Option<&mut u8> {
        Some(&mut self.inner[0])
    }
}

fn main() {
    let mut fun = [1,2,3,4,5];
    let mut foo = Foo {
        inner: &mut fun
    };
    {
        let a = foo.next().unwrap();
        let b = foo.next().unwrap();
        *a = 1;
        *b = 2;
        println!("{}", a);
    }
}
@ebfull ebfull changed the title Borrow checker soundness hole Abuse of elision exposes borrow checker soundness hole? Mar 10, 2015
@emberian emberian added A-type-system Area: Type system I-wrong labels Mar 10, 2015
@talchas
Copy link

talchas commented Mar 10, 2015

It's not an elision issue, an explicit fn next<'x>(&'x mut self) -> Option<&'x mut u8> still compiles incorrectly. Changing it to be Foo<'a> and Item = &'a mut u8 requires fn next<'x>(&'x mut self) -> Option<&'a mut u8> which of course can't be written.

@emberian emberian added A-lifetimes Area: Lifetimes / regions A-borrow-checker Area: The borrow checker and removed A-type-system Area: Type system labels Mar 10, 2015
@emberian emberian changed the title Abuse of elision exposes borrow checker soundness hole? Borrow checker unsoundness when using lifetimes on associated types Mar 10, 2015
@nikomatsakis
Copy link
Contributor

Dup of #22077 I think

@emberian
Copy link
Member

Indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-borrow-checker Area: The borrow checker A-lifetimes Area: Lifetimes / regions
Projects
None yet
Development

No branches or pull requests

4 participants