Skip to content

Borrow check doesn't look through newtypes #2573

@catamorphism

Description

@catamorphism
enum foo = { mut bar: baz };

enum baz = @quux_;

class quux_ { let mut baz: option<baz>;
             new(baz: option<baz>) { self.baz = baz; } }

impl quuux for foo {
    fn frob() {
        really_impure(self.bar);
    }
}

fn really_impure(bar: baz) {
    bar.baz = none;
}

fn main() {}

This gets the error message:

/Users/tchevalier/rust/src/test/run-pass/borrowck-newtype.rs:11:22: 11:30 error: illegal borrow unless pure: creating immutable alias to aliasable, mutable memory
/Users/tchevalier/rust/src/test/run-pass/borrowck-newtype.rs:11         really_impure(self.bar);
                                                                                      ^~~~~~~~
/Users/tchevalier/rust/src/test/run-pass/borrowck-newtype.rs:11:8: 11:21 note: impure due to access to impure function
/Users/tchevalier/rust/src/test/run-pass/borrowck-newtype.rs:11         really_impure(self.bar);

I think it should be legal, since baz is operationally a boxed type.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions