-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #129759 - dingxiangfei2009:stabilize-const-refs-to-stat…
…ic, r=RalfJung Stabilize `const_refs_to_static` Meanwhile, I am cooking a sub-section in the language reference.
- Loading branch information
Showing
45 changed files
with
157 additions
and
442 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,27 @@ | ||
//@ only-aarch64 | ||
//@ compile-flags: -C target-feature=+neon | ||
//@ build-fail | ||
|
||
#![feature(repr_simd)] | ||
|
||
use std::arch::aarch64::float64x2_t; | ||
use std::arch::{asm, global_asm}; | ||
|
||
#[repr(simd)] | ||
#[derive(Copy, Clone)] | ||
struct Simd256bit([f64; 4]); | ||
use std::arch::global_asm; | ||
|
||
fn main() {} | ||
|
||
// Constants must be... constant | ||
|
||
static S: i32 = 1; | ||
static mut S: i32 = 1; | ||
const fn const_foo(x: i32) -> i32 { | ||
x | ||
} | ||
const fn const_bar<T>(x: T) -> T { | ||
x | ||
} | ||
global_asm!("{}", const S); | ||
//~^ ERROR referencing statics | ||
global_asm!("{}", const unsafe { S }); | ||
//~^ ERROR: evaluation of constant value failed | ||
//~| mutable global memory | ||
global_asm!("{}", const const_foo(0)); | ||
global_asm!("{}", const const_foo(S)); | ||
//~^ ERROR referencing statics | ||
global_asm!("{}", const const_foo(unsafe { S })); | ||
//~^ ERROR: evaluation of constant value failed | ||
//~| mutable global memory | ||
global_asm!("{}", const const_bar(0)); | ||
global_asm!("{}", const const_bar(S)); | ||
//~^ ERROR referencing statics | ||
global_asm!("{}", const const_bar(unsafe { S })); | ||
//~^ ERROR: evaluation of constant value failed | ||
//~| mutable global memory |
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,39 +1,21 @@ | ||
error[E0658]: referencing statics in constants is unstable | ||
--> $DIR/type-check-4.rs:24:25 | ||
error[E0080]: evaluation of constant value failed | ||
--> $DIR/type-check-4.rs:17:34 | ||
| | ||
LL | global_asm!("{}", const S); | ||
| ^ | ||
| | ||
= note: see issue #119618 <https://github.com/rust-lang/rust/issues/119618> for more information | ||
= help: add `#![feature(const_refs_to_static)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
= note: `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable. | ||
= help: to fix this, the value can be extracted to a `const` and then used. | ||
LL | global_asm!("{}", const unsafe { S }); | ||
| ^ constant accesses mutable global memory | ||
|
||
error[E0658]: referencing statics in constants is unstable | ||
--> $DIR/type-check-4.rs:27:35 | ||
| | ||
LL | global_asm!("{}", const const_foo(S)); | ||
| ^ | ||
error[E0080]: evaluation of constant value failed | ||
--> $DIR/type-check-4.rs:21:44 | ||
| | ||
= note: see issue #119618 <https://github.com/rust-lang/rust/issues/119618> for more information | ||
= help: add `#![feature(const_refs_to_static)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
= note: `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable. | ||
= help: to fix this, the value can be extracted to a `const` and then used. | ||
LL | global_asm!("{}", const const_foo(unsafe { S })); | ||
| ^ constant accesses mutable global memory | ||
|
||
error[E0658]: referencing statics in constants is unstable | ||
--> $DIR/type-check-4.rs:30:35 | ||
| | ||
LL | global_asm!("{}", const const_bar(S)); | ||
| ^ | ||
error[E0080]: evaluation of constant value failed | ||
--> $DIR/type-check-4.rs:25:44 | ||
| | ||
= note: see issue #119618 <https://github.com/rust-lang/rust/issues/119618> for more information | ||
= help: add `#![feature(const_refs_to_static)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
= note: `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable. | ||
= help: to fix this, the value can be extracted to a `const` and then used. | ||
LL | global_asm!("{}", const const_bar(unsafe { S })); | ||
| ^ constant accesses mutable global memory | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. | ||
For more information about this error, try `rustc --explain E0080`. |
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,26 +1,27 @@ | ||
//@ only-x86_64 | ||
//@ compile-flags: -C target-feature=+avx512f | ||
//@ build-fail | ||
|
||
use std::arch::{asm, global_asm}; | ||
|
||
use std::arch::x86_64::{_mm256_setzero_ps, _mm_setzero_ps}; | ||
use std::arch::global_asm; | ||
|
||
fn main() {} | ||
|
||
// Constants must be... constant | ||
|
||
static S: i32 = 1; | ||
static mut S: i32 = 1; | ||
const fn const_foo(x: i32) -> i32 { | ||
x | ||
} | ||
const fn const_bar<T>(x: T) -> T { | ||
x | ||
} | ||
global_asm!("{}", const S); | ||
//~^ ERROR referencing statics | ||
global_asm!("{}", const unsafe { S }); | ||
//~^ ERROR evaluation of constant value failed | ||
//~| mutable global memory | ||
global_asm!("{}", const const_foo(0)); | ||
global_asm!("{}", const const_foo(S)); | ||
//~^ ERROR referencing statics | ||
global_asm!("{}", const const_foo(unsafe { S })); | ||
//~^ ERROR evaluation of constant value failed | ||
//~| mutable global memory | ||
global_asm!("{}", const const_bar(0)); | ||
global_asm!("{}", const const_bar(S)); | ||
//~^ ERROR referencing statics | ||
global_asm!("{}", const const_bar(unsafe { S })); | ||
//~^ ERROR evaluation of constant value failed | ||
//~| mutable global memory |
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,39 +1,21 @@ | ||
error[E0658]: referencing statics in constants is unstable | ||
--> $DIR/type-check-4.rs:19:25 | ||
error[E0080]: evaluation of constant value failed | ||
--> $DIR/type-check-4.rs:17:34 | ||
| | ||
LL | global_asm!("{}", const S); | ||
| ^ | ||
| | ||
= note: see issue #119618 <https://github.com/rust-lang/rust/issues/119618> for more information | ||
= help: add `#![feature(const_refs_to_static)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
= note: `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable. | ||
= help: to fix this, the value can be extracted to a `const` and then used. | ||
LL | global_asm!("{}", const unsafe { S }); | ||
| ^ constant accesses mutable global memory | ||
|
||
error[E0658]: referencing statics in constants is unstable | ||
--> $DIR/type-check-4.rs:22:35 | ||
| | ||
LL | global_asm!("{}", const const_foo(S)); | ||
| ^ | ||
error[E0080]: evaluation of constant value failed | ||
--> $DIR/type-check-4.rs:21:44 | ||
| | ||
= note: see issue #119618 <https://github.com/rust-lang/rust/issues/119618> for more information | ||
= help: add `#![feature(const_refs_to_static)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
= note: `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable. | ||
= help: to fix this, the value can be extracted to a `const` and then used. | ||
LL | global_asm!("{}", const const_foo(unsafe { S })); | ||
| ^ constant accesses mutable global memory | ||
|
||
error[E0658]: referencing statics in constants is unstable | ||
--> $DIR/type-check-4.rs:25:35 | ||
| | ||
LL | global_asm!("{}", const const_bar(S)); | ||
| ^ | ||
error[E0080]: evaluation of constant value failed | ||
--> $DIR/type-check-4.rs:25:44 | ||
| | ||
= note: see issue #119618 <https://github.com/rust-lang/rust/issues/119618> for more information | ||
= help: add `#![feature(const_refs_to_static)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
= note: `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable. | ||
= help: to fix this, the value can be extracted to a `const` and then used. | ||
LL | global_asm!("{}", const const_bar(unsafe { S })); | ||
| ^ constant accesses mutable global memory | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. | ||
For more information about this error, try `rustc --explain E0080`. |
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
1 change: 0 additions & 1 deletion
1
tests/ui/consts/const-mut-refs/mut_ref_in_final_dynamic_check.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
Oops, something went wrong.