File: reserved-guarded-strings.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, 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 (73 lines) | stat: -rw-r--r-- 2,370 bytes parent folder | download | duplicates (4)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//@ edition:2024
// ignore-tidy-linelength

macro_rules! demo1 {
    ( $a:tt ) => { println!("one tokens") };
}

macro_rules! demo2 {
    ( $a:tt $b:tt ) => { println!("two tokens") };
}

macro_rules! demo3 {
    ( $a:tt $b:tt $c:tt ) => { println!("three tokens") };
}

macro_rules! demo4 {
    ( $a:tt $b:tt $c:tt $d:tt ) => { println!("four tokens") };
}

macro_rules! demo5 {
    ( $a:tt $b:tt $c:tt $d:tt $e:tt ) => { println!("five tokens") };
}

macro_rules! demo6 {
    ( $a:tt $b:tt $c:tt $d:tt $e:tt $f:tt ) => { println!("six tokens") };
}

macro_rules! demo7 {
    ( $a:tt $b:tt $c:tt $d:tt $e:tt $f:tt $g:tt ) => { println!("seven tokens") };
}

macro_rules! demon {
    ( $($n:tt)* ) => { println!("unknown number of tokens") };
}

fn main() {
    demo1!("");
    demo2!(# "");
    demo3!(# ""#);
    demo2!(# "foo");
    demo3!(# "foo"#);
    demo2!("foo"#);

    demo2!(blah"xx"); //~ ERROR prefix `blah` is unknown
    demo2!(blah#"xx"#);
    //~^ ERROR prefix `blah` is unknown
    //~| ERROR invalid string literal

    demo2!(## "foo"); //~ reserved multi-hash token is forbidden
    demo3!("foo"###); //~ reserved multi-hash token is forbidden
    demo3!(### "foo"); //~ reserved multi-hash token is forbidden
    demo3!(## "foo"#); //~ reserved multi-hash token is forbidden
    demo5!(### "foo"###);
    //~^ reserved multi-hash token is forbidden
    //~| reserved multi-hash token is forbidden

    demo1!(#""); //~ ERROR invalid string literal
    demo1!(#""#); //~ ERROR invalid string literal
    demo1!(####""); //~ ERROR invalid string literal
    demo1!(#"foo"); //~ ERROR invalid string literal
    demo1!(###"foo"); //~ ERROR invalid string literal
    demo1!(#"foo"#); //~ ERROR invalid string literal
    demo1!(###"foo"#); //~ ERROR invalid string literal
    demo1!(###"foo"##); //~ ERROR invalid string literal
    demo1!(###"foo"###); //~ ERROR invalid string literal
    demo2!(#"foo"###);
    //~^ ERROR invalid string literal
    //~| ERROR reserved multi-hash token is forbidden

    // More than 255 hashes
    demon!(####################################################################################################################################################################################################################################################################"foo");
    //~^ ERROR invalid string literal
}