Skip to content

Commit 9aa77c0

Browse files
committed
Add regression test
1 parent fd7eefc commit 9aa77c0

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/ui/statics/const_generics.rs

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

0 commit comments

Comments
 (0)