-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #68120 - Centril:ban-range-to-dotdotdot, r=oli-obk
Ban `...X` pats, harden tests, and improve diagnostics Follow up to #67258 (comment) and #67258 (comment). r? @cramertj @oli-obk
- Loading branch information
Showing
19 changed files
with
260 additions
and
121 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
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
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
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
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
32 changes: 32 additions & 0 deletions
32
src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-dotdotdot-bad-syntax.rs
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,32 @@ | ||
// Test that `...X` range-to patterns are syntactically invalid. | ||
// | ||
// See https://github.com/rust-lang/rust/pull/67258#issuecomment-565656155 | ||
// for the reason why. To summarize, we might want to introduce `...expr` as | ||
// an expression form for splatting (or "untupling") in an expression context. | ||
// While there is no syntactic ambiguity with `...X` in a pattern context, | ||
// there's a potential confusion factor here, and we would prefer to keep patterns | ||
// and expressions in-sync. As such, we do not allow `...X` in patterns either. | ||
|
||
#![feature(half_open_range_patterns)] | ||
|
||
fn main() {} | ||
|
||
#[cfg(FALSE)] | ||
fn syntax() { | ||
match scrutinee { | ||
...X => {} //~ ERROR range-to patterns with `...` are not allowed | ||
...0 => {} //~ ERROR range-to patterns with `...` are not allowed | ||
...'a' => {} //~ ERROR range-to patterns with `...` are not allowed | ||
...0.0f32 => {} //~ ERROR range-to patterns with `...` are not allowed | ||
} | ||
} | ||
|
||
fn syntax2() { | ||
macro_rules! mac { | ||
($e:expr) => { | ||
let ...$e; //~ ERROR range-to patterns with `...` are not allowed | ||
} | ||
} | ||
|
||
mac!(0); | ||
} |
35 changes: 35 additions & 0 deletions
35
...st/ui/half-open-range-patterns/half-open-range-pats-inclusive-dotdotdot-bad-syntax.stderr
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,35 @@ | ||
error: range-to patterns with `...` are not allowed | ||
--> $DIR/half-open-range-pats-inclusive-dotdotdot-bad-syntax.rs:17:9 | ||
| | ||
LL | ...X => {} | ||
| ^^^ help: use `..=` instead | ||
|
||
error: range-to patterns with `...` are not allowed | ||
--> $DIR/half-open-range-pats-inclusive-dotdotdot-bad-syntax.rs:18:9 | ||
| | ||
LL | ...0 => {} | ||
| ^^^ help: use `..=` instead | ||
|
||
error: range-to patterns with `...` are not allowed | ||
--> $DIR/half-open-range-pats-inclusive-dotdotdot-bad-syntax.rs:19:9 | ||
| | ||
LL | ...'a' => {} | ||
| ^^^ help: use `..=` instead | ||
|
||
error: range-to patterns with `...` are not allowed | ||
--> $DIR/half-open-range-pats-inclusive-dotdotdot-bad-syntax.rs:20:9 | ||
| | ||
LL | ...0.0f32 => {} | ||
| ^^^ help: use `..=` instead | ||
|
||
error: range-to patterns with `...` are not allowed | ||
--> $DIR/half-open-range-pats-inclusive-dotdotdot-bad-syntax.rs:27:17 | ||
| | ||
LL | let ...$e; | ||
| ^^^ help: use `..=` instead | ||
... | ||
LL | mac!(0); | ||
| -------- in this macro invocation | ||
|
||
error: aborting due to 5 previous errors | ||
|
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
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
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
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
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
Oops, something went wrong.