Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tests/ui/reborrow/reborrow-generic-mut-field-aliasing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#![feature(reborrow)]

struct Wrap<'a, T>(&'a (), T);

impl<'a> std::marker::Reborrow for Wrap<'a, &'static mut i32> {}

fn get<'a, 'b>(x: Wrap<'a, &'b mut i32>) -> &'b mut i32 {
x.1
}

fn main() {
let mut x = 1;
let thing = Wrap(&(), &mut x);
let y = get(thing);
let z = get(thing); //~ ERROR cannot borrow `thing` as mutable more than once at a time
*y = 2;
*z = 3;
}
13 changes: 13 additions & 0 deletions tests/ui/reborrow/reborrow-generic-mut-field-aliasing.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0499]: cannot borrow `thing` as mutable more than once at a time
--> $DIR/reborrow-generic-mut-field-aliasing.rs:15:17
|
LL | let y = get(thing);
| ----- first mutable borrow occurs here
LL | let z = get(thing);
| ^^^^^ second mutable borrow occurs here
LL | *y = 2;
| ------ first borrow later used here

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0499`.
16 changes: 16 additions & 0 deletions tests/ui/reborrow/reborrow-non-copy-field-double-use.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#![feature(reborrow)]

struct Wrap<'a>(&'a mut (), String);
//~^ ERROR the trait bound `String: Copy` is not satisfied

impl<'a> std::marker::Reborrow for Wrap<'a> {}

fn get(x: Wrap<'_>) -> String {
x.1
}

fn main() {
let x = Wrap(&mut (), String::from("a"));
let _y = get(x);
let _z = get(x);
}
9 changes: 9 additions & 0 deletions tests/ui/reborrow/reborrow-non-copy-field-double-use.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0277]: the trait bound `String: Copy` is not satisfied
--> $DIR/reborrow-non-copy-field-double-use.rs:3:29
|
LL | struct Wrap<'a>(&'a mut (), String);
| ^^^^^^ the trait `Copy` is not implemented for `String`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
Loading