-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stabilize const_refs_to_static
#129759
Open
dingxiangfei2009
wants to merge
9
commits into
rust-lang:master
Choose a base branch
from
dingxiangfei2009:stabilize-const-refs-to-static
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Stabilize const_refs_to_static
#129759
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
eeaaa21
Stabilize `const_refs_to_static`
dingxiangfei2009 e9f611b
restore tests on rejecting const access to mutable global mem
dingxiangfei2009 73f01a4
update tests
dingxiangfei2009 8e6604d
apply suggestions
dingxiangfei2009 ede0e45
add missing stderr reports
dingxiangfei2009 539b624
fix bitwidth-sensitive stderr output
dingxiangfei2009 3b0701a
use build-fail for asm tests
dingxiangfei2009 421093b
revert the comment on consts
dingxiangfei2009 29fbe2e
use regex to match numbers
dingxiangfei2009 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
//@ compile-flags: --emit=asm | ||
|
||
#![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 | ||
// Constants should be allowed to use the *value* of immutable statics. | ||
|
||
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,18 @@ | ||
error[E0658]: referencing statics in constants is unstable | ||
--> $DIR/type-check-4.rs:24:25 | ||
error[E0080]: evaluation of constant value failed | ||
| | ||
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 | ||
| | ||
= 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 | ||
| | ||
= 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 | ||
//@ compile-flags: --emit asm | ||
|
||
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 | ||
// Constants should be allowed to use the *value* of immutable statics. | ||
|
||
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oli-obk you added this as a failing ui test, but now it no longer fails. Is this test intended to check "what happens when an asm block references a failing const", or something else? It's a bit unclear what this test is even intended to test. But if it is about asm + failing const, we should probably adjust the test so that it still shows an error, we just need a different operation to cause the error?