-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
73c0ae6
commit e57789f
Showing
15 changed files
with
334 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
tests/ui/async-await/pin-ergonomics/borrow-mut-xor-share.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#![feature(pin_ergonomics)] | ||
#![allow(dead_code, incomplete_features)] | ||
|
||
// Makes sure `&pin mut place` and `&pin const place` cannot violate the mut-xor-share rules. | ||
|
||
use std::pin::Pin; | ||
|
||
struct Foo; | ||
|
||
fn foo_mut(_: &mut Foo) { | ||
} | ||
|
||
fn foo_ref(_: &Foo) { | ||
} | ||
|
||
fn foo_pin_mut(_: Pin<&mut Foo>) { | ||
} | ||
|
||
fn foo_pin_ref(_: Pin<&Foo>) { | ||
} | ||
|
||
fn bar() { | ||
let foo = Foo; | ||
foo_pin_mut(&pin mut foo); //~ ERROR cannot borrow `foo` as mutable, as it is not declared as mutable | ||
|
||
let mut foo = Foo; | ||
let x = &pin mut foo; | ||
foo_pin_ref(&pin const foo); //~ ERROR cannot borrow `foo` as immutable because it is also borrowed as mutable | ||
foo_pin_mut(&pin mut foo); //~ ERROR cannot borrow `foo` as mutable more than once at a time | ||
foo_ref(&foo); //~ ERROR cannot borrow `foo` as immutable because it is also borrowed as mutable | ||
foo_mut(&mut foo); //~ ERROR cannot borrow `foo` as mutable more than once at a time | ||
|
||
foo_pin_mut(x); | ||
|
||
let mut foo = Foo; | ||
let x = &pin const foo; | ||
foo_pin_ref(&pin const foo); // ok | ||
foo_pin_mut(&pin mut foo); //~ ERROR cannot borrow `foo` as mutable because it is also borrowed as immutable | ||
foo_ref(&foo); // ok | ||
foo_mut(&mut foo); //~ ERROR cannot borrow `foo` as mutable because it is also borrowed as immutable | ||
|
||
foo_pin_ref(x); | ||
|
||
let mut foo = Foo; | ||
let x = &mut foo; | ||
foo_pin_ref(&pin const foo); //~ ERROR cannot borrow `foo` as immutable because it is also borrowed as mutable | ||
foo_pin_mut(&pin mut foo); //~ ERROR cannot borrow `foo` as mutable more than once at a time | ||
|
||
foo_mut(x); | ||
|
||
let mut foo = Foo; | ||
let x = &foo; | ||
foo_pin_ref(&pin const foo); // ok | ||
foo_pin_mut(&pin mut foo); //~ ERROR cannot borrow `foo` as mutable because it is also borrowed as immutable | ||
|
||
foo_ref(x); | ||
} | ||
|
||
fn main() {} |
121 changes: 121 additions & 0 deletions
121
tests/ui/async-await/pin-ergonomics/borrow-mut-xor-share.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
error[E0596]: cannot borrow `foo` as mutable, as it is not declared as mutable | ||
--> $DIR/borrow-mut-xor-share.rs:24:17 | ||
| | ||
LL | foo_pin_mut(&pin mut foo); | ||
| ^^^^^^^^^^^^ cannot borrow as mutable | ||
| | ||
help: consider changing this to be mutable | ||
| | ||
LL | let mut foo = Foo; | ||
| +++ | ||
|
||
error[E0502]: cannot borrow `foo` as immutable because it is also borrowed as mutable | ||
--> $DIR/borrow-mut-xor-share.rs:28:17 | ||
| | ||
LL | let x = &pin mut foo; | ||
| ------------ mutable borrow occurs here | ||
LL | foo_pin_ref(&pin const foo); | ||
| ^^^^^^^^^^^^^^ immutable borrow occurs here | ||
... | ||
LL | foo_pin_mut(x); | ||
| - mutable borrow later used here | ||
|
||
error[E0499]: cannot borrow `foo` as mutable more than once at a time | ||
--> $DIR/borrow-mut-xor-share.rs:29:17 | ||
| | ||
LL | let x = &pin mut foo; | ||
| ------------ first mutable borrow occurs here | ||
LL | foo_pin_ref(&pin const foo); | ||
LL | foo_pin_mut(&pin mut foo); | ||
| ^^^^^^^^^^^^ second mutable borrow occurs here | ||
... | ||
LL | foo_pin_mut(x); | ||
| - first borrow later used here | ||
|
||
error[E0502]: cannot borrow `foo` as immutable because it is also borrowed as mutable | ||
--> $DIR/borrow-mut-xor-share.rs:30:13 | ||
| | ||
LL | let x = &pin mut foo; | ||
| ------------ mutable borrow occurs here | ||
... | ||
LL | foo_ref(&foo); | ||
| ^^^^ immutable borrow occurs here | ||
... | ||
LL | foo_pin_mut(x); | ||
| - mutable borrow later used here | ||
|
||
error[E0499]: cannot borrow `foo` as mutable more than once at a time | ||
--> $DIR/borrow-mut-xor-share.rs:31:13 | ||
| | ||
LL | let x = &pin mut foo; | ||
| ------------ first mutable borrow occurs here | ||
... | ||
LL | foo_mut(&mut foo); | ||
| ^^^^^^^^ second mutable borrow occurs here | ||
LL | | ||
LL | foo_pin_mut(x); | ||
| - first borrow later used here | ||
|
||
error[E0502]: cannot borrow `foo` as mutable because it is also borrowed as immutable | ||
--> $DIR/borrow-mut-xor-share.rs:38:17 | ||
| | ||
LL | let x = &pin const foo; | ||
| -------------- immutable borrow occurs here | ||
LL | foo_pin_ref(&pin const foo); // ok | ||
LL | foo_pin_mut(&pin mut foo); | ||
| ^^^^^^^^^^^^ mutable borrow occurs here | ||
... | ||
LL | foo_pin_ref(x); | ||
| - immutable borrow later used here | ||
|
||
error[E0502]: cannot borrow `foo` as mutable because it is also borrowed as immutable | ||
--> $DIR/borrow-mut-xor-share.rs:40:13 | ||
| | ||
LL | let x = &pin const foo; | ||
| -------------- immutable borrow occurs here | ||
... | ||
LL | foo_mut(&mut foo); | ||
| ^^^^^^^^ mutable borrow occurs here | ||
LL | | ||
LL | foo_pin_ref(x); | ||
| - immutable borrow later used here | ||
|
||
error[E0502]: cannot borrow `foo` as immutable because it is also borrowed as mutable | ||
--> $DIR/borrow-mut-xor-share.rs:46:17 | ||
| | ||
LL | let x = &mut foo; | ||
| -------- mutable borrow occurs here | ||
LL | foo_pin_ref(&pin const foo); | ||
| ^^^^^^^^^^^^^^ immutable borrow occurs here | ||
... | ||
LL | foo_mut(x); | ||
| - mutable borrow later used here | ||
|
||
error[E0499]: cannot borrow `foo` as mutable more than once at a time | ||
--> $DIR/borrow-mut-xor-share.rs:47:17 | ||
| | ||
LL | let x = &mut foo; | ||
| -------- first mutable borrow occurs here | ||
LL | foo_pin_ref(&pin const foo); | ||
LL | foo_pin_mut(&pin mut foo); | ||
| ^^^^^^^^^^^^ second mutable borrow occurs here | ||
LL | | ||
LL | foo_mut(x); | ||
| - first borrow later used here | ||
|
||
error[E0502]: cannot borrow `foo` as mutable because it is also borrowed as immutable | ||
--> $DIR/borrow-mut-xor-share.rs:54:17 | ||
| | ||
LL | let x = &foo; | ||
| ---- immutable borrow occurs here | ||
LL | foo_pin_ref(&pin const foo); // ok | ||
LL | foo_pin_mut(&pin mut foo); | ||
| ^^^^^^^^^^^^ mutable borrow occurs here | ||
LL | | ||
LL | foo_ref(x); | ||
| - immutable borrow later used here | ||
|
||
error: aborting due to 10 previous errors | ||
|
||
Some errors have detailed explanations: E0499, E0502, E0596. | ||
For more information about an error, try `rustc --explain E0499`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//@ check-pass | ||
|
||
#![feature(pin_ergonomics)] | ||
#![allow(dead_code, incomplete_features)] | ||
|
||
// Makes sure we can handle `&pin mut place` and `&pin const place` as sugar for | ||
// `unsafe { Pin::new_unchecked(&mut place) }` and `Pin::new(&place)`. | ||
|
||
use std::pin::Pin; | ||
|
||
struct Foo; | ||
|
||
fn foo(_: Pin<&mut Foo>) { | ||
} | ||
|
||
fn foo_const(_: Pin<&Foo>) { | ||
} | ||
|
||
fn bar() { | ||
let mut x: Pin<&mut _> = &pin mut Foo; | ||
foo(x.as_mut()); | ||
foo(x.as_mut()); | ||
foo_const(x); | ||
|
||
let x: Pin<&_> = &pin const Foo; | ||
|
||
foo_const(x); | ||
foo_const(x); | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.