]> git.lizzy.rs Git - rust.git/blob - src/test/ui/raw-ref-op/raw-ref-temp.rs
Rollup merge of #98640 - cuviper:stable-rust-analyzer, r=Mark-Simulacrum
[rust.git] / src / test / ui / raw-ref-op / raw-ref-temp.rs
1 // Ensure that we don't allow taking the address of temporary values
2 #![feature(raw_ref_op, type_ascription)]
3
4 const FOUR: u64 = 4;
5
6 const PAIR: (i32, i64) = (1, 2);
7
8 const ARRAY: [i32; 2] = [1, 2];
9
10 fn main() {
11     let ref_expr = &raw const 2;                        //~ ERROR cannot take address
12     let mut_ref_expr = &raw mut 3;                      //~ ERROR cannot take address
13     let ref_const = &raw const FOUR;                    //~ ERROR cannot take address
14     let mut_ref_const = &raw mut FOUR;                  //~ ERROR cannot take address
15
16     let field_ref_expr = &raw const (1, 2).0;           //~ ERROR cannot take address
17     let mut_field_ref_expr = &raw mut (1, 2).0;         //~ ERROR cannot take address
18     let field_ref = &raw const PAIR.0;                  //~ ERROR cannot take address
19     let mut_field_ref = &raw mut PAIR.0;                //~ ERROR cannot take address
20
21     let index_ref_expr = &raw const [1, 2][0];          //~ ERROR cannot take address
22     let mut_index_ref_expr = &raw mut [1, 2][0];        //~ ERROR cannot take address
23     let index_ref = &raw const ARRAY[0];                //~ ERROR cannot take address
24     let mut_index_ref = &raw mut ARRAY[1];              //~ ERROR cannot take address
25
26     let ref_ascribe = &raw const (2: i32);              //~ ERROR cannot take address
27     let mut_ref_ascribe = &raw mut (3: i32);            //~ ERROR cannot take address
28
29     let ascribe_field_ref = &raw const (PAIR.0: i32);   //~ ERROR cannot take address
30     let ascribe_index_ref = &raw mut (ARRAY[0]: i32);   //~ ERROR cannot take address
31 }