Skip to content

Commit

Permalink
Minimized (and then greatly expanded) test of failure cases from #52934.
Browse files Browse the repository at this point in the history
  • Loading branch information
pnkfelix committed Sep 4, 2018
1 parent 4efc0a7 commit 6bde429
Show file tree
Hide file tree
Showing 4 changed files with 692 additions and 0 deletions.
133 changes: 133 additions & 0 deletions src/test/ui/borrowck/two-phase-surprise-no-conflict.ast.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
error[E0503]: cannot use `self.cx` because it was mutably borrowed
--> $DIR/two-phase-surprise-no-conflict.rs:40:13
|
LL | let _mut_borrow = &mut *self;
| ----- borrow of `*self` occurs here
LL | let _access = self.cx;
| ^^^^^^^ use of borrowed `*self`

error[E0502]: cannot borrow `*self.cx_mut` as immutable because `*self` is also borrowed as mutable
--> $DIR/two-phase-surprise-no-conflict.rs:79:33
|
LL | self.hash_expr(&self.cx_mut.body(eid).value);
| ---- ^^^^^^^^^^^ - mutable borrow ends here
| | |
| | immutable borrow occurs here
| mutable borrow occurs here

error[E0502]: cannot borrow `reg.sess_mut` as immutable because `*reg` is also borrowed as mutable
--> $DIR/two-phase-surprise-no-conflict.rs:131:52
|
LL | reg.register_static(Box::new(TrivialPass::new(&reg.sess_mut)));
| --- ^^^^^^^^^^^^ - mutable borrow ends here
| | |
| mutable borrow occurs here immutable borrow occurs here

error[E0502]: cannot borrow `reg.sess_mut` as immutable because `*reg` is also borrowed as mutable
--> $DIR/two-phase-surprise-no-conflict.rs:135:51
|
LL | reg.register_bound(Box::new(TrivialPass::new(&reg.sess_mut)));
| --- ^^^^^^^^^^^^ - mutable borrow ends here
| | |
| mutable borrow occurs here immutable borrow occurs here

error[E0502]: cannot borrow `reg.sess_mut` as immutable because `*reg` is also borrowed as mutable
--> $DIR/two-phase-surprise-no-conflict.rs:139:50
|
LL | reg.register_univ(Box::new(TrivialPass::new(&reg.sess_mut)));
| --- ^^^^^^^^^^^^ - mutable borrow ends here
| | |
| mutable borrow occurs here immutable borrow occurs here

error[E0502]: cannot borrow `reg.sess_mut` as immutable because `*reg` is also borrowed as mutable
--> $DIR/two-phase-surprise-no-conflict.rs:143:41
|
LL | reg.register_ref(&TrivialPass::new(&reg.sess_mut));
| --- ^^^^^^^^^^^^ - mutable borrow ends here
| | |
| mutable borrow occurs here immutable borrow occurs here

error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
--> $DIR/two-phase-surprise-no-conflict.rs:151:56
|
LL | reg.register_static(Box::new(TrivialPass::new(&mut reg.sess_mut)));
| --- ^^^^^^^^^^^^ - first borrow ends here
| | |
| first mutable borrow occurs here second mutable borrow occurs here

error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
--> $DIR/two-phase-surprise-no-conflict.rs:156:59
|
LL | reg.register_bound(Box::new(TrivialPass::new_mut(&mut reg.sess_mut)));
| --- ^^^^^^^^^^^^ - first borrow ends here
| | |
| first mutable borrow occurs here second mutable borrow occurs here

error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
--> $DIR/two-phase-surprise-no-conflict.rs:161:58
|
LL | reg.register_univ(Box::new(TrivialPass::new_mut(&mut reg.sess_mut)));
| --- ^^^^^^^^^^^^ - first borrow ends here
| | |
| first mutable borrow occurs here second mutable borrow occurs here

error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
--> $DIR/two-phase-surprise-no-conflict.rs:166:49
|
LL | reg.register_ref(&TrivialPass::new_mut(&mut reg.sess_mut));
| --- ^^^^^^^^^^^^ - first borrow ends here
| | |
| first mutable borrow occurs here second mutable borrow occurs here

error[E0502]: cannot borrow `reg.sess_mut` as immutable because `*reg` is also borrowed as mutable
--> $DIR/two-phase-surprise-no-conflict.rs:178:51
|
LL | reg.register_bound(Box::new(CapturePass::new(&reg.sess_mut)));
| --- ^^^^^^^^^^^^ - mutable borrow ends here
| | |
| mutable borrow occurs here immutable borrow occurs here

error[E0502]: cannot borrow `reg.sess_mut` as immutable because `*reg` is also borrowed as mutable
--> $DIR/two-phase-surprise-no-conflict.rs:183:50
|
LL | reg.register_univ(Box::new(CapturePass::new(&reg.sess_mut)));
| --- ^^^^^^^^^^^^ - mutable borrow ends here
| | |
| mutable borrow occurs here immutable borrow occurs here

error[E0502]: cannot borrow `reg.sess_mut` as immutable because `*reg` is also borrowed as mutable
--> $DIR/two-phase-surprise-no-conflict.rs:188:41
|
LL | reg.register_ref(&CapturePass::new(&reg.sess_mut));
| --- ^^^^^^^^^^^^ - mutable borrow ends here
| | |
| mutable borrow occurs here immutable borrow occurs here

error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
--> $DIR/two-phase-surprise-no-conflict.rs:200:59
|
LL | reg.register_bound(Box::new(CapturePass::new_mut(&mut reg.sess_mut)));
| --- ^^^^^^^^^^^^ - first borrow ends here
| | |
| first mutable borrow occurs here second mutable borrow occurs here

error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
--> $DIR/two-phase-surprise-no-conflict.rs:206:58
|
LL | reg.register_univ(Box::new(CapturePass::new_mut(&mut reg.sess_mut)));
| --- ^^^^^^^^^^^^ - first borrow ends here
| | |
| first mutable borrow occurs here second mutable borrow occurs here

error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
--> $DIR/two-phase-surprise-no-conflict.rs:212:49
|
LL | reg.register_ref(&CapturePass::new_mut(&mut reg.sess_mut));
| --- ^^^^^^^^^^^^ - first borrow ends here
| | |
| first mutable borrow occurs here second mutable borrow occurs here

error: aborting due to 16 previous errors

Some errors occurred: E0499, E0502, E0503.
For more information about an error, try `rustc --explain E0499`.
165 changes: 165 additions & 0 deletions src/test/ui/borrowck/two-phase-surprise-no-conflict.nll.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
error[E0503]: cannot use `self.cx` because it was mutably borrowed
--> $DIR/two-phase-surprise-no-conflict.rs:40:23
|
LL | let _mut_borrow = &mut *self;
| ---------- borrow of `*self` occurs here
LL | let _access = self.cx;
| ^^^^^^^ use of borrowed `*self`
...
LL | _mut_borrow;
| ----------- borrow later used here

error[E0502]: cannot borrow `*self` as mutable because it is also borrowed as immutable
--> $DIR/two-phase-surprise-no-conflict.rs:79:17
|
LL | self.hash_expr(&self.cx_mut.body(eid).value);
| ^^^^^^^^^^^^^^^^-----------^^^^^^^^^^^^^^^^^
| | |
| | immutable borrow occurs here
| mutable borrow occurs here
| borrow later used here

error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
--> $DIR/two-phase-surprise-no-conflict.rs:151:51
|
LL | reg.register_static(Box::new(TrivialPass::new(&mut reg.sess_mut)));
| ----------------------------------------------^^^^^^^^^^^^^^^^^---
| | |
| | second mutable borrow occurs here
| first mutable borrow occurs here
| borrow later used here

error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
--> $DIR/two-phase-surprise-no-conflict.rs:156:54
|
LL | reg.register_bound(Box::new(TrivialPass::new_mut(&mut reg.sess_mut)));
| -------------------------------------------------^^^^^^^^^^^^^^^^^---
| | |
| | second mutable borrow occurs here
| first mutable borrow occurs here
| borrow later used here

error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
--> $DIR/two-phase-surprise-no-conflict.rs:161:53
|
LL | reg.register_univ(Box::new(TrivialPass::new_mut(&mut reg.sess_mut)));
| ------------------------------------------------^^^^^^^^^^^^^^^^^---
| | |
| | second mutable borrow occurs here
| first mutable borrow occurs here
| borrow later used here

error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
--> $DIR/two-phase-surprise-no-conflict.rs:166:44
|
LL | reg.register_ref(&TrivialPass::new_mut(&mut reg.sess_mut));
| ---------------------------------------^^^^^^^^^^^^^^^^^--
| | |
| | second mutable borrow occurs here
| first mutable borrow occurs here
| borrow later used here

error[E0502]: cannot borrow `*reg` as mutable because it is also borrowed as immutable
--> $DIR/two-phase-surprise-no-conflict.rs:178:5
|
LL | reg.register_bound(Box::new(CapturePass::new(&reg.sess_mut)));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------------^^^
| | |
| | immutable borrow occurs here
| mutable borrow occurs here
| borrow later used here

error[E0502]: cannot borrow `*reg` as mutable because it is also borrowed as immutable
--> $DIR/two-phase-surprise-no-conflict.rs:183:5
|
LL | reg.register_univ(Box::new(CapturePass::new(&reg.sess_mut)));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------------^^^
| | |
| | immutable borrow occurs here
| mutable borrow occurs here
|
note: borrowed value must be valid for the lifetime 'a as defined on the function body at 122:21...
--> $DIR/two-phase-surprise-no-conflict.rs:122:21
|
LL | fn register_plugins<'a>(mk_reg: impl Fn() -> &'a mut Registry<'a>) {
| ^^

error[E0502]: cannot borrow `*reg` as mutable because it is also borrowed as immutable
--> $DIR/two-phase-surprise-no-conflict.rs:188:5
|
LL | reg.register_ref(&CapturePass::new(&reg.sess_mut));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------------^^
| | |
| | immutable borrow occurs here
| mutable borrow occurs here
| borrow later used here

error[E0499]: cannot borrow `*reg` as mutable more than once at a time
--> $DIR/two-phase-surprise-no-conflict.rs:200:5
|
LL | reg.register_bound(Box::new(CapturePass::new_mut(&mut reg.sess_mut)));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------------^^^
| | |
| | first mutable borrow occurs here
| second mutable borrow occurs here
| borrow later used here

error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
--> $DIR/two-phase-surprise-no-conflict.rs:200:54
|
LL | reg.register_bound(Box::new(CapturePass::new_mut(&mut reg.sess_mut)));
| -------------------------------------------------^^^^^^^^^^^^^^^^^---
| | |
| | second mutable borrow occurs here
| first mutable borrow occurs here
| borrow later used here

error[E0499]: cannot borrow `*reg` as mutable more than once at a time
--> $DIR/two-phase-surprise-no-conflict.rs:206:5
|
LL | reg.register_univ(Box::new(CapturePass::new_mut(&mut reg.sess_mut)));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------------^^^
| | |
| | first mutable borrow occurs here
| second mutable borrow occurs here
|
note: borrowed value must be valid for the lifetime 'a as defined on the function body at 122:21...
--> $DIR/two-phase-surprise-no-conflict.rs:122:21
|
LL | fn register_plugins<'a>(mk_reg: impl Fn() -> &'a mut Registry<'a>) {
| ^^

error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
--> $DIR/two-phase-surprise-no-conflict.rs:206:53
|
LL | reg.register_univ(Box::new(CapturePass::new_mut(&mut reg.sess_mut)));
| ------------------------------------------------^^^^^^^^^^^^^^^^^---
| | |
| | second mutable borrow occurs here
| first mutable borrow occurs here
| borrow later used here

error[E0499]: cannot borrow `*reg` as mutable more than once at a time
--> $DIR/two-phase-surprise-no-conflict.rs:212:5
|
LL | reg.register_ref(&CapturePass::new_mut(&mut reg.sess_mut));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------------^^
| | |
| | first mutable borrow occurs here
| second mutable borrow occurs here
| borrow later used here

error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
--> $DIR/two-phase-surprise-no-conflict.rs:212:44
|
LL | reg.register_ref(&CapturePass::new_mut(&mut reg.sess_mut));
| ---------------------------------------^^^^^^^^^^^^^^^^^--
| | |
| | second mutable borrow occurs here
| first mutable borrow occurs here
| borrow later used here

error: aborting due to 15 previous errors

Some errors occurred: E0499, E0502, E0503.
For more information about an error, try `rustc --explain E0499`.
Loading

0 comments on commit 6bde429

Please sign in to comment.