forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
const_refs_to_cell: dont let mutable references sneak past the interi…
…or mutability check
- Loading branch information
Showing
5 changed files
with
59 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
//@ check-pass | ||
|
||
#![feature(const_refs_to_cell)] | ||
|
||
const FOO: () = { | ||
let x = std::cell::Cell::new(42); | ||
let y = &x; | ||
let y = &x; //~ERROR: cannot borrow here | ||
}; | ||
|
||
const FOO2: () = { | ||
let mut x = std::cell::Cell::new(42); | ||
let y = &*&mut x; //~ERROR: cannot borrow here | ||
}; | ||
|
||
const FOO3: () = unsafe { | ||
let mut x = std::cell::Cell::new(42); | ||
let y = &*(&mut x as *mut _); //~ERROR: cannot borrow here | ||
}; | ||
|
||
fn main() { | ||
FOO; | ||
} | ||
fn main() {} |
33 changes: 33 additions & 0 deletions
33
tests/ui/feature-gates/feature-gate-const_refs_to_cell.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,33 @@ | ||
error[E0658]: cannot borrow here, since the borrowed element may contain interior mutability | ||
--> $DIR/feature-gate-const_refs_to_cell.rs:3:13 | ||
| | ||
LL | let y = &x; | ||
| ^^ | ||
| | ||
= note: see issue #80384 <https://github.com/rust-lang/rust/issues/80384> for more information | ||
= help: add `#![feature(const_refs_to_cell)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error[E0658]: cannot borrow here, since the borrowed element may contain interior mutability | ||
--> $DIR/feature-gate-const_refs_to_cell.rs:8:13 | ||
| | ||
LL | let y = &*&mut x; | ||
| ^^^^^^^^ | ||
| | ||
= note: see issue #80384 <https://github.com/rust-lang/rust/issues/80384> for more information | ||
= help: add `#![feature(const_refs_to_cell)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error[E0658]: cannot borrow here, since the borrowed element may contain interior mutability | ||
--> $DIR/feature-gate-const_refs_to_cell.rs:13:13 | ||
| | ||
LL | let y = &*(&mut x as *mut _); | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #80384 <https://github.com/rust-lang/rust/issues/80384> for more information | ||
= help: add `#![feature(const_refs_to_cell)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
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