forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add syntactic test for rest patterns.
- Loading branch information
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Here we test that `..` is allowed in all pattern locations *syntactically*. | ||
// The semantic test is in `rest-pat-semantic-disallowed.rs`. | ||
|
||
// check-pass | ||
|
||
fn main() {} | ||
|
||
macro_rules! accept_pat { | ||
($p:pat) => {} | ||
} | ||
|
||
accept_pat!(..); | ||
|
||
#[cfg(FALSE)] | ||
fn rest_patterns() { | ||
// Top level: | ||
fn foo(..: u8) {} | ||
let ..; | ||
|
||
// Box patterns: | ||
let box ..; | ||
|
||
// In or-patterns: | ||
match x { | ||
.. | .. => {} | ||
} | ||
|
||
// Ref patterns: | ||
let &..; | ||
let &mut ..; | ||
|
||
// Ident patterns: | ||
let x @ ..; | ||
let ref x @ ..; | ||
let ref mut x @ ..; | ||
|
||
// Tuple: | ||
let (..); // This is interpreted as a tuple pattern, not a parenthesis one. | ||
let (..,); // Allowing trailing comma. | ||
let (.., .., ..); // Duplicates also. | ||
let (.., P, ..); // Including with things in between. | ||
|
||
// Tuple struct (same idea as for tuple patterns): | ||
let A(..); | ||
let A(..,); | ||
let A(.., .., ..); | ||
let A(.., P, ..); | ||
|
||
// Array/Slice (like with tuple patterns): | ||
let [..]; | ||
let [..,]; | ||
let [.., .., ..]; | ||
let [.., P, ..]; | ||
|
||
// Random walk to guard against special casing: | ||
match x { | ||
.. | | ||
[ | ||
( | ||
box .., | ||
&(..), | ||
&mut .., | ||
x @ .. | ||
), | ||
ref x @ .., | ||
] | | ||
ref mut x @ .. | ||
=> {} | ||
} | ||
} |