This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +91
-0
lines changed Expand file tree Collapse file tree 2 files changed +91
-0
lines changed Original file line number Diff line number Diff line change 1+ // Tests some cases relating to `parse_literal_maybe_minus`, which used to
2+ // accept more interpolated expressions than it should have.
3+
4+ const A : u32 = 0 ;
5+ const B : u32 = 1 ;
6+
7+ macro_rules! identity {
8+ ( $val: expr) => { $val }
9+ }
10+
11+ macro_rules! range1 {
12+ ( $min: expr) => {
13+ $min..
14+ }
15+ }
16+
17+ macro_rules! range2 {
18+ ( $min: expr, $max: expr) => {
19+ $min ..= $max
20+ }
21+ }
22+
23+ macro_rules! range3 {
24+ ( $max: expr) => {
25+ .. $max
26+ }
27+ }
28+
29+ macro_rules! m {
30+ ( $a: expr, $b: ident, $identity_mac_call: expr) => {
31+ fn _f( ) {
32+ match [ 1 , 2 ] {
33+ [ $a, $b] => { } // FIXME: doesn't compile, probably should
34+ _ => { }
35+ }
36+
37+ match ( 1 , 2 ) {
38+ ( $a, $b) => { } // FIXME: doesn't compile, probably should
39+ _ => { }
40+ }
41+
42+ match 3 {
43+ $identity_mac_call => { }
44+ 0 ..$identity_mac_call => { }
45+ _ => { }
46+ }
47+ }
48+ } ;
49+ }
50+
51+ m ! ( A , B , identity!( 10 ) ) ;
52+ //~^ ERROR arbitrary expressions aren't allowed in patterns
53+ //~| ERROR arbitrary expressions aren't allowed in patterns
54+
55+ fn main ( ) {
56+ match 3 {
57+ identity ! ( A ) => { } // FIXME: doesn't compile, probably should
58+ //~^ ERROR arbitrary expressions aren't allowed in patterns
59+ range1 ! ( A ) => { }
60+ range2 ! ( A , B ) => { }
61+ range3 ! ( B ) => { }
62+ _ => { }
63+ }
64+ }
Original file line number Diff line number Diff line change 1+ error: arbitrary expressions aren't allowed in patterns
2+ --> $DIR/parse-literal-maybe-minus.rs:57:19
3+ |
4+ LL | identity!(A) => {} // FIXME: doesn't compile, probably should
5+ | ^
6+ |
7+ = note: the `expr` fragment specifier forces the metavariable's content to be an expression
8+
9+ error: arbitrary expressions aren't allowed in patterns
10+ --> $DIR/parse-literal-maybe-minus.rs:51:4
11+ |
12+ LL | m!(A, B, identity!(10));
13+ | ^
14+ |
15+ = note: the `expr` fragment specifier forces the metavariable's content to be an expression
16+
17+ error: arbitrary expressions aren't allowed in patterns
18+ --> $DIR/parse-literal-maybe-minus.rs:51:4
19+ |
20+ LL | m!(A, B, identity!(10));
21+ | ^
22+ |
23+ = note: the `expr` fragment specifier forces the metavariable's content to be an expression
24+ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
25+
26+ error: aborting due to 3 previous errors
27+
You can’t perform that action at this time.
0 commit comments