File: offset-of-tuple.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 893,396 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; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (54 lines) | stat: -rw-r--r-- 3,023 bytes parent folder | download | duplicates (3)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#![feature(builtin_syntax)]

use std::mem::offset_of;

fn main() {
    offset_of!((u8, u8), _0); //~ ERROR no field `_0`
    offset_of!((u8, u8), 01); //~ ERROR no field `01`
    offset_of!((u8, u8), 1e2); //~ ERROR no field `1e2`
    offset_of!((u8, u8), 1_u8); //~ ERROR no field `1_`
    //~| ERROR suffixes on a tuple index
    offset_of!((u8, u8), +1); //~ ERROR no rules expected
    offset_of!((u8, u8), -1); //~ ERROR offset_of expects dot-separated field and variant names
    offset_of!((u8, u8), 1.); //~ ERROR offset_of expects dot-separated field and variant names
    offset_of!((u8, u8), 1 .); //~ unexpected token: `)`
    builtin # offset_of((u8, u8), 1e2); //~ ERROR no field `1e2`
    builtin # offset_of((u8, u8), _0); //~ ERROR no field `_0`
    builtin # offset_of((u8, u8), 01); //~ ERROR no field `01`
    builtin # offset_of((u8, u8), 1_u8); //~ ERROR no field `1_`
    //~| ERROR suffixes on a tuple index
    // We need to put these into curly braces, otherwise only one of the
    // errors will be emitted and the others suppressed.
    { builtin # offset_of((u8, u8), +1) }; //~ ERROR leading `+` is not supported
    { builtin # offset_of((u8, u8), 1.) }; //~ ERROR offset_of expects dot-separated field and variant names
    { builtin # offset_of((u8, u8), 1 .) }; //~ ERROR unexpected token: `)`
}

type ComplexTup = (((u8, u8), u8), u8);

fn nested() {
    offset_of!(((u8, u16), (u32, u16, u8)), 0.2); //~ ERROR no field `2`
    offset_of!(((u8, u16), (u32, u16, u8)), 0.1e2); //~ ERROR no field `1e2`
    offset_of!(((u8, u16), (u32, u16, u8)), 1.2);
    offset_of!(((u8, u16), (u32, u16, u8)), 1.2.0); //~ ERROR no field `0`

    // All combinations of spaces (this sends different tokens to the parser)
    offset_of!(ComplexTup, 0.0.1.); //~ ERROR unexpected token: `)`
    offset_of!(ComplexTup, 0 .0.1.); //~ ERROR unexpected token: `)`
    offset_of!(ComplexTup, 0 . 0.1.); //~ ERROR unexpected token: `)`
    offset_of!(ComplexTup, 0. 0.1.); //~ ERROR unexpected token: `)`
    offset_of!(ComplexTup, 0.0 .1.); //~ ERROR unexpected token: `)`
    offset_of!(ComplexTup, 0.0 . 1.); //~ ERROR unexpected token: `)`
    offset_of!(ComplexTup, 0.0. 1.); //~ ERROR unexpected token: `)`

    // Test for builtin too to ensure that the builtin syntax can also handle these cases
    // We need to put these into curly braces, otherwise only one of the
    // errors will be emitted and the others suppressed.
    { builtin # offset_of(ComplexTup, 0.0.1.) }; //~ ERROR unexpected token: `)`
    { builtin # offset_of(ComplexTup, 0 .0.1.) }; //~ ERROR unexpected token: `)`
    { builtin # offset_of(ComplexTup, 0 . 0.1.) }; //~ ERROR unexpected token: `)`
    { builtin # offset_of(ComplexTup, 0. 0.1.) }; //~ ERROR unexpected token: `)`
    { builtin # offset_of(ComplexTup, 0.0 .1.) }; //~ ERROR unexpected token: `)`
    { builtin # offset_of(ComplexTup, 0.0 . 1.) }; //~ ERROR unexpected token: `)`
    { builtin # offset_of(ComplexTup, 0.0. 1.) }; //~ ERROR unexpected token: `)`
}