forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#126577 - oli-obk:static_valtrees, r=RalfJung
const_refs_to_static test and cleanup r? ``@RalfJung`` test the existing behaviour of adt_const_params combined with const_refs_to_static. also remove a dead error variant about consts referring to statics
- Loading branch information
Showing
4 changed files
with
26 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//! Check that we lose the information that `BAR` points to `FOO` | ||
//! when going through a const generic. | ||
//! This is not an intentional guarantee, it just describes the status quo. | ||
|
||
//@ run-pass | ||
// With optimizations, LLVM will deduplicate the constant `X` whose | ||
// value is `&42` to just be a reference to the static. This is correct, | ||
// but obscures the issue we're trying to show. | ||
//@ revisions: opt noopt | ||
//@[noopt] compile-flags: -Copt-level=0 | ||
//@[opt] compile-flags: -O | ||
|
||
#![feature(const_refs_to_static)] | ||
#![feature(adt_const_params)] | ||
#![allow(incomplete_features)] | ||
|
||
static FOO: usize = 42; | ||
const BAR: &usize = &FOO; | ||
fn foo<const X: &'static usize>() { | ||
// Without optimizations, `X` ends up pointing to a copy of `FOO` instead of `FOO` itself. | ||
assert_eq!(cfg!(opt), std::ptr::eq(X, &FOO)); | ||
} | ||
|
||
fn main() { | ||
foo::<BAR>(); | ||
} |