|
1 | 1 | #![feature(offset_of)]
|
2 | 2 | #![feature(builtin_syntax)]
|
3 | 3 |
|
| 4 | +use std::mem::offset_of; |
| 5 | + |
4 | 6 | fn main() {
|
5 |
| - core::mem::offset_of!((u8, u8), _0); //~ ERROR no field `_0` |
6 |
| - core::mem::offset_of!((u8, u8), +1); //~ ERROR no rules expected |
7 |
| - core::mem::offset_of!((u8, u8), -1); //~ ERROR no rules expected |
| 7 | + offset_of!((u8, u8), _0); //~ ERROR no field `_0` |
| 8 | + offset_of!((u8, u8), 01); //~ ERROR no field `01` |
| 9 | + offset_of!((u8, u8), 1e2); //~ ERROR no field `1e2` |
| 10 | + offset_of!((u8, u8), 1_u8); //~ ERROR no field `1_` |
| 11 | + //~| ERROR suffixes on a tuple index |
| 12 | + offset_of!((u8, u8), +1); //~ ERROR no rules expected |
| 13 | + offset_of!((u8, u8), -1); //~ ERROR no rules expected |
| 14 | + offset_of!((u8, u8), 1.); //~ ERROR expected identifier, found `)` |
| 15 | + offset_of!((u8, u8), 1 .); //~ ERROR unexpected end of macro |
| 16 | + builtin # offset_of((u8, u8), 1e2); //~ ERROR no field `1e2` |
8 | 17 | builtin # offset_of((u8, u8), _0); //~ ERROR no field `_0`
|
9 |
| - builtin # offset_of((u8, u8), +1); //~ ERROR expected identifier |
| 18 | + builtin # offset_of((u8, u8), 01); //~ ERROR no field `01` |
| 19 | + builtin # offset_of((u8, u8), 1_u8); //~ ERROR no field `1_` |
| 20 | + //~| ERROR suffixes on a tuple index |
| 21 | + // We need to put these into curly braces, otherwise only one of the |
| 22 | + // errors will be emitted and the others suppressed. |
| 23 | + { builtin # offset_of((u8, u8), +1) }; //~ ERROR expected identifier, found `+` |
| 24 | + { builtin # offset_of((u8, u8), 1.) }; //~ ERROR expected identifier, found `)` |
| 25 | + { builtin # offset_of((u8, u8), 1 .) }; //~ ERROR expected identifier, found `)` |
| 26 | +} |
| 27 | + |
| 28 | +type ComplexTup = ((u8, (u8, u8)), u8); |
| 29 | + |
| 30 | +fn nested() { |
| 31 | + offset_of!(((u8, u16), (u32, u16, u8)), 0.2); //~ ERROR no field `2` |
| 32 | + offset_of!(((u8, u16), (u32, u16, u8)), 1.2); |
| 33 | + offset_of!(((u8, u16), (u32, u16, u8)), 1.2.0); //~ ERROR no field `0` |
| 34 | + |
| 35 | + // All combinations of spaces (this sends different tokens to the parser) |
| 36 | + offset_of!(ComplexTup, 0.0.1.); //~ ERROR expected identifier |
| 37 | + offset_of!(ComplexTup, 0 .0.1.); //~ ERROR unexpected end of macro |
| 38 | + offset_of!(ComplexTup, 0 . 0.1.); //~ ERROR unexpected end of macro |
| 39 | + offset_of!(ComplexTup, 0. 0.1.); //~ ERROR no rules expected |
| 40 | + offset_of!(ComplexTup, 0.0 .1.); //~ ERROR expected identifier, found `)` |
| 41 | + offset_of!(ComplexTup, 0.0 . 1.); //~ ERROR expected identifier, found `)` |
| 42 | + offset_of!(ComplexTup, 0.0. 1.); //~ ERROR expected identifier, found `)` |
| 43 | + |
| 44 | + // Test for builtin too to ensure that the builtin syntax can also handle these cases |
| 45 | + // We need to put these into curly braces, otherwise only one of the |
| 46 | + // errors will be emitted and the others suppressed. |
| 47 | + { builtin # offset_of(ComplexTup, 0.0.1.) }; //~ ERROR expected identifier, found `)` |
| 48 | + { builtin # offset_of(ComplexTup, 0 .0.1.) }; //~ ERROR expected identifier, found `)` |
| 49 | + { builtin # offset_of(ComplexTup, 0 . 0.1.) }; //~ ERROR expected identifier, found `)` |
| 50 | + { builtin # offset_of(ComplexTup, 0. 0.1.) }; //~ ERROR expected identifier, found `)` |
| 51 | + { builtin # offset_of(ComplexTup, 0.0 .1.) }; //~ ERROR expected identifier, found `)` |
| 52 | + { builtin # offset_of(ComplexTup, 0.0 . 1.) }; //~ ERROR expected identifier, found `)` |
| 53 | + { builtin # offset_of(ComplexTup, 0.0. 1.) }; //~ ERROR expected identifier, found `)` |
10 | 54 | }
|
0 commit comments