Skip to content

Commit 97372c8

Browse files
committed
Add regression test
1 parent e23ae72 commit 97372c8

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/ui/statics/const_generics.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//! Check that we lose the information that `BAR` points to `FOO`
2+
//! when going through a const generic.
3+
//! This is not an intentional guarantee, it just describes the status quo.
4+
5+
//@ run-pass
6+
// With optimizations, LLVM will deduplicate the constant `X` whose
7+
// value is `&42` to just be a reference to the static. This is correct,
8+
// but obscures the issue we're trying to show.
9+
//@ revisions: opt noopt
10+
//@[noopt] compile-flags: -Copt-level=0
11+
//@[opt] compile-flags: -O
12+
13+
#![feature(const_refs_to_static)]
14+
#![feature(adt_const_params)]
15+
#![allow(incomplete_features)]
16+
17+
static FOO: usize = 42;
18+
const BAR: &usize = &FOO;
19+
fn foo<const X: &'static usize>() {
20+
// Without optimizations, `X` ends up pointing to a copy of `FOO` instead of `FOO` itself.
21+
assert_eq!(cfg!(opt), std::ptr::eq(X, &FOO));
22+
}
23+
24+
fn main() {
25+
foo::<BAR>();
26+
}

0 commit comments

Comments
 (0)