diff options
author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2024-06-14 09:20:05 +0000 |
---|---|---|
committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2024-06-17 10:55:42 +0000 |
commit | 97372c8c885bf66a502b88ee7b29e59fb27327e6 (patch) | |
tree | ed1445320baa16c5d728168950b3e03992f618e9 /tests | |
parent | e23ae72ac7a393961886ea62df065ebb6def7d51 (diff) |
Add regression test
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ui/statics/const_generics.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/ui/statics/const_generics.rs b/tests/ui/statics/const_generics.rs new file mode 100644 index 00000000000..70d9b933a76 --- /dev/null +++ b/tests/ui/statics/const_generics.rs @@ -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>(); +} |