-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
5eb17c3
commit 68fed49
Showing
31 changed files
with
590 additions
and
168 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// pp-exact | ||
#![feature(raw_ref_op)] | ||
|
||
const C_PTR: () = { let a = 1; &raw const a; }; | ||
static S_PTR: () = { let b = false; &raw const b; }; | ||
|
||
fn main() { | ||
let x = 123; | ||
let mut y = 345; | ||
let c_p = &raw const x; | ||
let parens = unsafe { *(&raw mut (y)) }; | ||
} |
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,22 @@ | ||
#![feature(raw_ref_op)] | ||
|
||
fn address_of_shared() { | ||
let mut x = 0; | ||
let y = &x; | ||
|
||
let q = &raw mut x; //~ ERROR cannot borrow | ||
|
||
drop(y); | ||
} | ||
|
||
fn address_of_mutably_borrowed() { | ||
let mut x = 0; | ||
let y = &mut x; | ||
|
||
let p = &raw const x; //~ ERROR cannot borrow | ||
let q = &raw mut x; //~ ERROR cannot borrow | ||
|
||
drop(y); | ||
} | ||
|
||
fn main() {} |
40 changes: 40 additions & 0 deletions
40
src/test/ui/borrowck/borrow-raw-address-of-borrowed.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,40 @@ | ||
error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable | ||
--> $DIR/borrow-raw-address-of-borrowed.rs:7:13 | ||
| | ||
LL | let y = &x; | ||
| -- immutable borrow occurs here | ||
LL | | ||
LL | let q = &raw mut x; | ||
| ^^^^^^^^^^ mutable borrow occurs here | ||
LL | | ||
LL | drop(y); | ||
| - immutable borrow later used here | ||
|
||
error[E0502]: cannot borrow `x` as immutable because it is also borrowed as mutable | ||
--> $DIR/borrow-raw-address-of-borrowed.rs:16:13 | ||
| | ||
LL | let y = &mut x; | ||
| ------ mutable borrow occurs here | ||
LL | | ||
LL | let p = &raw const x; | ||
| ^^^^^^^^^^^^ immutable borrow occurs here | ||
... | ||
LL | drop(y); | ||
| - mutable borrow later used here | ||
|
||
error[E0499]: cannot borrow `x` as mutable more than once at a time | ||
--> $DIR/borrow-raw-address-of-borrowed.rs:17:13 | ||
| | ||
LL | let y = &mut x; | ||
| ------ first mutable borrow occurs here | ||
... | ||
LL | let q = &raw mut x; | ||
| ^^^^^^^^^^ second mutable borrow occurs here | ||
LL | | ||
LL | drop(y); | ||
| - first borrow later used here | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
Some errors have detailed explanations: E0499, E0502. | ||
For more information about an error, try `rustc --explain E0499`. |
23 changes: 23 additions & 0 deletions
23
src/test/ui/borrowck/borrow-raw-address-of-deref-mutability-ok.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,23 @@ | ||
// check-pass | ||
|
||
#![feature(raw_ref_op)] | ||
|
||
fn raw_reborrow() { | ||
let x = &0; | ||
let y = &mut 0; | ||
|
||
let p = &raw const *x; | ||
let r = &raw const *y; | ||
let s = &raw mut *y; | ||
} | ||
|
||
unsafe fn raw_reborrow_of_raw() { | ||
let x = &0 as *const i32; | ||
let y = &mut 0 as *mut i32; | ||
|
||
let p = &raw const *x; | ||
let r = &raw const *y; | ||
let s = &raw mut *y; | ||
} | ||
|
||
fn main() {} |
17 changes: 17 additions & 0 deletions
17
src/test/ui/borrowck/borrow-raw-address-of-deref-mutability.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,17 @@ | ||
// Check that `&raw mut` cannot be used to turn a `&T` into a `*mut T`. | ||
|
||
#![feature(raw_ref_op)] | ||
|
||
fn raw_reborrow() { | ||
let x = &0; | ||
|
||
let q = &raw mut *x; //~ ERROR cannot borrow | ||
} | ||
|
||
unsafe fn raw_reborrow_of_raw() { | ||
let x = &0 as *const i32; | ||
|
||
let q = &raw mut *x; //~ ERROR cannot borrow | ||
} | ||
|
||
fn main() {} |
21 changes: 21 additions & 0 deletions
21
src/test/ui/borrowck/borrow-raw-address-of-deref-mutability.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,21 @@ | ||
error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference | ||
--> $DIR/borrow-raw-address-of-deref-mutability.rs:8:13 | ||
| | ||
LL | let x = &0; | ||
| -- help: consider changing this to be a mutable reference: `&mut 0` | ||
LL | | ||
LL | let q = &raw mut *x; | ||
| ^^^^^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable | ||
|
||
error[E0596]: cannot borrow `*x` as mutable, as it is behind a `*const` pointer | ||
--> $DIR/borrow-raw-address-of-deref-mutability.rs:14:13 | ||
| | ||
LL | let x = &0 as *const i32; | ||
| -- help: consider changing this to be a mutable pointer: `&mut 0` | ||
LL | | ||
LL | let q = &raw mut *x; | ||
| ^^^^^^^^^^^ `x` is a `*const` pointer, so the data it refers to cannot be borrowed as mutable | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0596`. |
44 changes: 44 additions & 0 deletions
44
src/test/ui/borrowck/borrow-raw-address-of-mutability-ok.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,44 @@ | ||
// check-pass | ||
|
||
#![feature(raw_ref_op)] | ||
|
||
fn mutable_address_of() { | ||
let mut x = 0; | ||
let y = &raw mut x; | ||
} | ||
|
||
fn mutable_address_of_closure() { | ||
let mut x = 0; | ||
let mut f = || { | ||
let y = &raw mut x; | ||
}; | ||
f(); | ||
} | ||
|
||
fn const_address_of_closure() { | ||
let x = 0; | ||
let f = || { | ||
let y = &raw const x; | ||
}; | ||
f(); | ||
} | ||
|
||
fn make_fn<F: Fn()>(f: F) -> F { f } | ||
|
||
fn const_address_of_fn_closure() { | ||
let x = 0; | ||
let f = make_fn(|| { | ||
let y = &raw const x; | ||
}); | ||
f(); | ||
} | ||
|
||
fn const_address_of_fn_closure_move() { | ||
let x = 0; | ||
let f = make_fn(move || { | ||
let y = &raw const x; | ||
}); | ||
f(); | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#![feature(raw_ref_op)] | ||
|
||
fn mutable_address_of() { | ||
let x = 0; | ||
let y = &raw mut x; //~ ERROR cannot borrow | ||
} | ||
|
||
fn mutable_address_of_closure() { | ||
let x = 0; | ||
let mut f = || { | ||
let y = &raw mut x; //~ ERROR cannot borrow | ||
}; | ||
f(); | ||
} | ||
|
||
fn mutable_address_of_imm_closure() { | ||
let mut x = 0; | ||
let f = || { | ||
let y = &raw mut x; | ||
}; | ||
f(); //~ ERROR cannot borrow | ||
} | ||
|
||
fn make_fn<F: Fn()>(f: F) -> F { f } | ||
|
||
fn mutable_address_of_fn_closure() { | ||
let mut x = 0; | ||
let f = make_fn(|| { | ||
let y = &raw mut x; //~ ERROR cannot borrow | ||
}); | ||
f(); | ||
} | ||
|
||
fn mutable_address_of_fn_closure_move() { | ||
let mut x = 0; | ||
let f = make_fn(move || { | ||
let y = &raw mut x; //~ ERROR cannot borrow | ||
}); | ||
f(); | ||
} | ||
|
||
fn main() {} |
59 changes: 59 additions & 0 deletions
59
src/test/ui/borrowck/borrow-raw-address-of-mutability.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,59 @@ | ||
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable | ||
--> $DIR/borrow-raw-address-of-mutability.rs:5:13 | ||
| | ||
LL | let x = 0; | ||
| - help: consider changing this to be mutable: `mut x` | ||
LL | let y = &raw mut x; | ||
| ^^^^^^^^^^ cannot borrow as mutable | ||
|
||
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable | ||
--> $DIR/borrow-raw-address-of-mutability.rs:11:17 | ||
| | ||
LL | let x = 0; | ||
| - help: consider changing this to be mutable: `mut x` | ||
LL | let mut f = || { | ||
LL | let y = &raw mut x; | ||
| ^^^^^^^^^^ cannot borrow as mutable | ||
|
||
error[E0596]: cannot borrow `f` as mutable, as it is not declared as mutable | ||
--> $DIR/borrow-raw-address-of-mutability.rs:21:5 | ||
| | ||
LL | let f = || { | ||
| - help: consider changing this to be mutable: `mut f` | ||
... | ||
LL | f(); | ||
| ^ cannot borrow as mutable | ||
|
||
error[E0596]: cannot borrow `x` as mutable, as it is a captured variable in a `Fn` closure | ||
--> $DIR/borrow-raw-address-of-mutability.rs:29:17 | ||
| | ||
LL | let y = &raw mut x; | ||
| ^^^^^^^^^^ cannot borrow as mutable | ||
| | ||
help: consider changing this to accept closures that implement `FnMut` | ||
--> $DIR/borrow-raw-address-of-mutability.rs:28:21 | ||
| | ||
LL | let f = make_fn(|| { | ||
| _____________________^ | ||
LL | | let y = &raw mut x; | ||
LL | | }); | ||
| |_____^ | ||
|
||
error[E0596]: cannot borrow `x` as mutable, as it is a captured variable in a `Fn` closure | ||
--> $DIR/borrow-raw-address-of-mutability.rs:37:17 | ||
| | ||
LL | let y = &raw mut x; | ||
| ^^^^^^^^^^ cannot borrow as mutable | ||
| | ||
help: consider changing this to accept closures that implement `FnMut` | ||
--> $DIR/borrow-raw-address-of-mutability.rs:36:21 | ||
| | ||
LL | let f = make_fn(move || { | ||
| _____________________^ | ||
LL | | let y = &raw mut x; | ||
LL | | }); | ||
| |_____^ | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0596`. |
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,16 @@ | ||
#![feature(raw_ref_op)] | ||
|
||
use std::cell::Cell; | ||
|
||
const A: () = { let x = Cell::new(2); &raw const x; }; //~ ERROR interior mutability | ||
|
||
static B: () = { let x = Cell::new(2); &raw const x; }; //~ ERROR interior mutability | ||
|
||
static mut C: () = { let x = Cell::new(2); &raw const x; }; //~ ERROR interior mutability | ||
|
||
const fn foo() { | ||
let x = Cell::new(0); | ||
let y = &raw const x; //~ ERROR interior mutability | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead | ||
--> $DIR/const-address-of-interior-mut.rs:5:39 | ||
| | ||
LL | const A: () = { let x = Cell::new(2); &raw const x; }; | ||
| ^^^^^^^^^^^^ | ||
|
||
error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead | ||
--> $DIR/const-address-of-interior-mut.rs:7:40 | ||
| | ||
LL | static B: () = { let x = Cell::new(2); &raw const x; }; | ||
| ^^^^^^^^^^^^ | ||
|
||
error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead | ||
--> $DIR/const-address-of-interior-mut.rs:9:44 | ||
| | ||
LL | static mut C: () = { let x = Cell::new(2); &raw const x; }; | ||
| ^^^^^^^^^^^^ | ||
|
||
error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead | ||
--> $DIR/const-address-of-interior-mut.rs:13:13 | ||
| | ||
LL | let y = &raw const x; | ||
| ^^^^^^^^^^^^ | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0492`. |
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,14 @@ | ||
#![feature(raw_ref_op)] | ||
|
||
const A: () = { let mut x = 2; &raw mut x; }; //~ ERROR `&raw mut` is not allowed | ||
|
||
static B: () = { let mut x = 2; &raw mut x; }; //~ ERROR `&raw mut` is not allowed | ||
|
||
static mut C: () = { let mut x = 2; &raw mut x; }; //~ ERROR `&raw mut` is not allowed | ||
|
||
const fn foo() { | ||
let mut x = 0; | ||
let y = &raw mut x; //~ ERROR `&raw mut` is not allowed | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
error[E0658]: `&raw mut` is not allowed in constants | ||
--> $DIR/const-address-of-mut.rs:3:32 | ||
| | ||
LL | const A: () = { let mut x = 2; &raw mut x; }; | ||
| ^^^^^^^^^^ | ||
| | ||
= note: for more information, see https://github.com/rust-lang/rust/issues/57349 | ||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable | ||
|
||
error[E0658]: `&raw mut` is not allowed in statics | ||
--> $DIR/const-address-of-mut.rs:5:33 | ||
| | ||
LL | static B: () = { let mut x = 2; &raw mut x; }; | ||
| ^^^^^^^^^^ | ||
| | ||
= note: for more information, see https://github.com/rust-lang/rust/issues/57349 | ||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable | ||
|
||
error[E0658]: `&raw mut` is not allowed in statics | ||
--> $DIR/const-address-of-mut.rs:7:37 | ||
| | ||
LL | static mut C: () = { let mut x = 2; &raw mut x; }; | ||
| ^^^^^^^^^^ | ||
| | ||
= note: for more information, see https://github.com/rust-lang/rust/issues/57349 | ||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable | ||
|
||
error[E0658]: `&raw mut` is not allowed in constant functions | ||
--> $DIR/const-address-of-mut.rs:11:13 | ||
| | ||
LL | let y = &raw mut x; | ||
| ^^^^^^^^^^ | ||
| | ||
= note: for more information, see https://github.com/rust-lang/rust/issues/57349 | ||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
Oops, something went wrong.