File tree 1 file changed +26
-0
lines changed
1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments