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

Unsoundness: can put borrowed pointer in @Trait, and have it outlive its lifetime #7175

Closed
bill-myers opened this issue Jun 16, 2013 · 1 comment

Comments

@bill-myers
Copy link
Contributor

Not totally sure what the root issue is, I guess it is that borrowck doesn't realize that the lifetime of "x as @mut Trait" needs to be limited to the lifetime of x.

Or perhaps it shouldn't be allowed at all to implement traits without lifetime parameters for structs with lifetime parameters.

trait R
{
    fn set_v(&mut self, v: int);
}

struct A<'self>
{
    v: &'self mut int
}

impl<'self> R for A<'self>
{
    fn set_v(&mut self, v: int)
    {
        *self.v = v;
    }
}

fn boom() -> @mut R
{
    let mut i = 3;
    let a = @mut A {v: &mut i};
    let f: @mut R = a as @mut R;
    f
}

pub fn main()
{
    let mut f = boom();
    f.set_v(66); // write to random place on stack
}
@nikomatsakis
Copy link
Contributor

Dup of #5723

flip1995 pushed a commit to flip1995/rust that referenced this issue May 6, 2021
Fix unnecessary_filter_map false positive

changelog: Fix an [`unnecessary_filter_map`] false positive

Fixes rust-lang#6804
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