Skip to content

Dereferencing of mutable &mut paths found in borrowed paths should not be permitted #8625

Closed
@nikomatsakis

Description

@nikomatsakis

In particular this program ought to be illegal:

struct S<'self> {
    pointer: &'self mut int
}

fn copy_borrowed_ptr2<'a>(p: &'a mut S<'a>) -> S<'a> {
    S { pointer: &mut *p.pointer }
}

fn main() {
    let mut x = 1;

    {
        let mut y = S { pointer: &mut x };
        let z = copy_borrowed_ptr2(&mut y);
        *y.pointer += 1; // ERROR EXPECTED HERE
        *z.pointer += 1;
    }
}

See also #8624

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions