Add tests
This commit is contained in:
parent
b2eed3a559
commit
8412da6829
9 changed files with 139 additions and 1 deletions
|
@ -1,5 +1,5 @@
|
|||
error[E0506]: cannot assign to `self.container_field` because it is borrowed
|
||||
--> $DIR/issue-81365.rs:21:9
|
||||
--> $DIR/issue-81365-1.rs:21:9
|
||||
|
|
||||
LL | let first = &self.target_field;
|
||||
| ---- borrow of `self.container_field` occurs here
|
26
src/test/ui/borrowck/issue-81365-10.rs
Normal file
26
src/test/ui/borrowck/issue-81365-10.rs
Normal file
|
@ -0,0 +1,26 @@
|
|||
use std::ops::Deref;
|
||||
|
||||
struct DerefTarget {
|
||||
target_field: bool,
|
||||
}
|
||||
struct Container {
|
||||
target: DerefTarget,
|
||||
container_field: bool,
|
||||
}
|
||||
|
||||
impl Deref for Container {
|
||||
type Target = DerefTarget;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.target
|
||||
}
|
||||
}
|
||||
|
||||
impl Container {
|
||||
fn bad_borrow(&mut self) {
|
||||
let first = &self.deref().target_field;
|
||||
self.container_field = true; //~ ERROR E0506
|
||||
first;
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
13
src/test/ui/borrowck/issue-81365-10.stderr
Normal file
13
src/test/ui/borrowck/issue-81365-10.stderr
Normal file
|
@ -0,0 +1,13 @@
|
|||
error[E0506]: cannot assign to `self.container_field` because it is borrowed
|
||||
--> $DIR/issue-81365-10.rs:21:9
|
||||
|
|
||||
LL | let first = &self.deref().target_field;
|
||||
| ---- borrow of `self.container_field` occurs here
|
||||
LL | self.container_field = true;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `self.container_field` occurs here
|
||||
LL | first;
|
||||
| ----- borrow later used here
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0506`.
|
32
src/test/ui/borrowck/issue-81365-11.rs
Normal file
32
src/test/ui/borrowck/issue-81365-11.rs
Normal file
|
@ -0,0 +1,32 @@
|
|||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
struct DerefTarget {
|
||||
target_field: bool,
|
||||
}
|
||||
struct Container {
|
||||
target: DerefTarget,
|
||||
container_field: bool,
|
||||
}
|
||||
|
||||
impl Deref for Container {
|
||||
type Target = DerefTarget;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.target
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for Container {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.target
|
||||
}
|
||||
}
|
||||
|
||||
impl Container {
|
||||
fn bad_borrow(&mut self) {
|
||||
let first = &mut self.target_field;
|
||||
self.container_field = true; //~ ERROR E0506
|
||||
first;
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
13
src/test/ui/borrowck/issue-81365-11.stderr
Normal file
13
src/test/ui/borrowck/issue-81365-11.stderr
Normal file
|
@ -0,0 +1,13 @@
|
|||
error[E0506]: cannot assign to `self.container_field` because it is borrowed
|
||||
--> $DIR/issue-81365-11.rs:27:9
|
||||
|
|
||||
LL | let first = &mut self.target_field;
|
||||
| ---- borrow of `self.container_field` occurs here
|
||||
LL | self.container_field = true;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `self.container_field` occurs here
|
||||
LL | first;
|
||||
| ----- borrow later used here
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0506`.
|
15
src/test/ui/borrowck/issue-81365-8.stderr
Normal file
15
src/test/ui/borrowck/issue-81365-8.stderr
Normal file
|
@ -0,0 +1,15 @@
|
|||
error[E0506]: cannot assign to `self.container_field` because it is borrowed
|
||||
--> $DIR/issue-81365-8.rs:21:9
|
||||
|
|
||||
LL | let first = &(*self).target_field;
|
||||
| ------- borrow of `self.container_field` occurs here
|
||||
LL | self.container_field = true;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `self.container_field` occurs here
|
||||
LL | first;
|
||||
| ----- borrow later used here
|
||||
|
|
||||
= note: borrow occurs due to deref coercion to `DerefTarget`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0506`.
|
26
src/test/ui/borrowck/issue-81365-9.rs
Normal file
26
src/test/ui/borrowck/issue-81365-9.rs
Normal file
|
@ -0,0 +1,26 @@
|
|||
use std::ops::Deref;
|
||||
|
||||
struct DerefTarget {
|
||||
target_field: bool,
|
||||
}
|
||||
struct Container {
|
||||
target: DerefTarget,
|
||||
container_field: bool,
|
||||
}
|
||||
|
||||
impl Deref for Container {
|
||||
type Target = DerefTarget;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.target
|
||||
}
|
||||
}
|
||||
|
||||
impl Container {
|
||||
fn bad_borrow(&mut self) {
|
||||
let first = &Deref::deref(self).target_field;
|
||||
self.container_field = true; //~ ERROR E0506
|
||||
first;
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
13
src/test/ui/borrowck/issue-81365-9.stderr
Normal file
13
src/test/ui/borrowck/issue-81365-9.stderr
Normal file
|
@ -0,0 +1,13 @@
|
|||
error[E0506]: cannot assign to `self.container_field` because it is borrowed
|
||||
--> $DIR/issue-81365-9.rs:21:9
|
||||
|
|
||||
LL | let first = &Deref::deref(self).target_field;
|
||||
| ---- borrow of `self.container_field` occurs here
|
||||
LL | self.container_field = true;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `self.container_field` occurs here
|
||||
LL | first;
|
||||
| ----- borrow later used here
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0506`.
|
Loading…
Add table
Reference in a new issue