File: raw-ref-temp.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 893,176 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; lisp: 29; perl: 29; ruby: 19; sql: 11
file content (31 lines) | stat: -rw-r--r-- 1,774 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Ensure that we don't allow taking the address of temporary values
#![feature(type_ascription)]

const FOUR: u64 = 4;

const PAIR: (i32, i64) = (1, 2);

const ARRAY: [i32; 2] = [1, 2];

fn main() {
    let ref_expr = &raw const 2;                                    //~ ERROR cannot take address
    let mut_ref_expr = &raw mut 3;                                  //~ ERROR cannot take address
    let ref_const = &raw const FOUR;                                //~ ERROR cannot take address
    let mut_ref_const = &raw mut FOUR;                              //~ ERROR cannot take address

    let field_ref_expr = &raw const (1, 2).0;                       //~ ERROR cannot take address
    let mut_field_ref_expr = &raw mut (1, 2).0;                     //~ ERROR cannot take address
    let field_ref = &raw const PAIR.0;                              //~ ERROR cannot take address
    let mut_field_ref = &raw mut PAIR.0;                            //~ ERROR cannot take address

    let index_ref_expr = &raw const [1, 2][0];                      //~ ERROR cannot take address
    let mut_index_ref_expr = &raw mut [1, 2][0];                    //~ ERROR cannot take address
    let index_ref = &raw const ARRAY[0];                            //~ ERROR cannot take address
    let mut_index_ref = &raw mut ARRAY[1];                          //~ ERROR cannot take address

    let ref_ascribe = &raw const type_ascribe!(2, i32);             //~ ERROR cannot take address
    let mut_ref_ascribe = &raw mut type_ascribe!(3, i32);           //~ ERROR cannot take address

    let ascribe_field_ref = &raw const type_ascribe!(PAIR.0, i32);  //~ ERROR cannot take address
    let ascribe_index_ref = &raw mut type_ascribe!(ARRAY[0], i32);  //~ ERROR cannot take address
}