Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Nested method calls with `&mut` receivers result in borrowck errors #6268

Closed
nikomatsakis opened this Issue May 6, 2013 · 10 comments

Comments

Projects
None yet
7 participants
Contributor

nikomatsakis commented May 6, 2013

This is challenging to resolve. I thought I could fit into the new borrow checker, but it is worth addressing separately since there are a number of subtle issues. What this really amounts to is that you need to support borrows where the lifetime of the borrow pointer does not encompass the borrow itself. To handle this safely, we wind up with two loans, the primary one and then a secondary, aliasing loan that tracks the fact that a pointer has been created, even if the memory it points at cannot be dereferenced yet.

Part of #5074

Contributor

nikomatsakis commented May 6, 2013

There are various FIXMEs in the code with commented out bits of code related to this issue.

Contributor

Dretch commented May 28, 2013

Here is a test case (at least I think it relates to this issue):

struct MyStruct {x: int}

impl MyStruct {

    fn takes_mut_self(&mut self, _x:int) {}

    fn takes_self(&self) -> int { 42 }

    fn also_takes_mut_self(&mut self) {
        self.takes_mut_self(self.takes_self());
    }

}

fn main() {}

The error rustc produces is:

mut-self-issues.rs:12:28: 12:33 error: cannot borrow `*self` as immutable because it is also borrowed as mutable
mut-self-issues.rs:12         self.takes_mut_self(self.takes_self());
                                                  ^~~~~
mut-self-issues.rs:12:8: 12:13 note: second borrow of `*self` occurs here
mut-self-issues.rs:12         self.takes_mut_self(self.takes_self());
                              ^~~~~
error: aborting due to previous error
Contributor

nikomatsakis commented Jul 3, 2013

Nominated for feature complete (not backwards compatible since it generates strictly more errors than it should)

@bors bors added a commit that referenced this issue Jul 22, 2013

@bors bors auto merge of #7848 : michaelwoerister/rust/trans_cleanup_1, r=jdm
The following types are renamed:
```rust
block_ => Block
block => @mut Block

fn_ctx_ => FunctionContext
fn_ctx => @mut FunctionContext

scope_info => ScopeInfo
```
I also tried to convert instances of `@mut` to `&mut` or `&` but a lot of them are blocked by issue #6268, so I left it for some time later.
2051574

@bors bors added a commit that referenced this issue Jul 23, 2013

@bors bors auto merge of #7848 : michaelwoerister/rust/trans_cleanup_1, r=jdm
The following types are renamed:
```rust
block_ => Block
block => @mut Block

fn_ctx_ => FunctionContext
fn_ctx => @mut FunctionContext

scope_info => ScopeInfo
```
I also tried to convert instances of `@mut` to `&mut` or `&` but a lot of them are blocked by issue #6268, so I left it for some time later.
8990f8b
Contributor

catamorphism commented Aug 29, 2013

accepted for feature-complete

Member

pnkfelix commented Mar 20, 2014

This can be added backwards-compatibly. Its a nice enhancement but not known to be a major problem to work-around.

P-low, not 1.0.

@pnkfelix pnkfelix added P-low and removed P-high-untriaged labels Mar 20, 2014

Member

pnkfelix commented Jun 19, 2014

By the way, the reason that this does not type check under our current model is provided in the internal docs for the type checker; see: typeck/infer/region_inference/doc.rs lines 171 through 262.

Contributor

cmr commented Mar 16, 2015

Triage bump; still an issue.

Contributor

kballard commented Mar 27, 2015

cc me, I still hit this with surprising regularity.

Contributor

nikomatsakis commented Apr 16, 2015

Closing in favor of rust-lang/rfcs#811

@steveklabnik steveklabnik added a commit to steveklabnik/rust that referenced this issue Jun 12, 2015

@steveklabnik steveklabnik Remove a bunch of ignored tests
Most of these are old, but some specific messages for specific tests:

* trait-contravariant-self.rs: failed due to a soundess hole:
  rust-lang@05e3248

* process-detatch: rust-lang@15966c3
  says "this test is being ignored until signals are implemented" That's
  not happening for a long time, and when it is, we'll write tests for
  it.

* deep-vector{,2}.rs: "too big for our poor macro infrastructure", and has
  been ignored over a year.

* borrowck-nested-calls.rs's FIXME #6268 was closed in favor of
  rust-lang/rfcs#811

* issue-15167.rs works properly now
* issue-9737.rs works properly now
* match-var-hygiene.rs works properly now
e609d1b

@steveklabnik steveklabnik added a commit to steveklabnik/rust that referenced this issue Jun 12, 2015

@steveklabnik steveklabnik ignore-test cleanup
Most of these are old, but some specific messages for specific tests:

* trait-contravariant-self.rs: failed due to a soundess hole:
  rust-lang@05e3248

* process-detatch: rust-lang@15966c3
  says "this test is being ignored until signals are implemented" That's
  not happening for a long time, and when it is, we'll write tests for
  it.

* deep-vector{,2}.rs: "too big for our poor macro infrastructure", and has
  been ignored over a year.

* borrowck-nested-calls.rs's FIXME #6268 was closed in favor of
  rust-lang/rfcs#811

* issue-15167.rs works properly now
* issue-9737.rs works properly now
* match-var-hygiene.rs works properly now

Addresses a chunk of #3965
bba934f

Seems to be a blocker for some async IO patterns needed for lowest-latency processing. cc me.

@thepowersgang thepowersgang added a commit to thepowersgang/rust that referenced this issue Jul 25, 2015

@steveklabnik @thepowersgang steveklabnik + thepowersgang ignore-test cleanup
Most of these are old, but some specific messages for specific tests:

* trait-contravariant-self.rs: failed due to a soundess hole:
  rust-lang@05e3248

* process-detatch: rust-lang@15966c3
  says "this test is being ignored until signals are implemented" That's
  not happening for a long time, and when it is, we'll write tests for
  it.

* deep-vector{,2}.rs: "too big for our poor macro infrastructure", and has
  been ignored over a year.

* borrowck-nested-calls.rs's FIXME #6268 was closed in favor of
  rust-lang/rfcs#811

* issue-15167.rs works properly now
* issue-9737.rs works properly now
* match-var-hygiene.rs works properly now

Addresses a chunk of #3965
9be4f2b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment