forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow try as scrutinee, e.g.
match try ...
- Loading branch information
Showing
7 changed files
with
88 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
// run-pass | ||
// compile-flags: --edition 2018 | ||
|
||
#![feature(try_blocks)] | ||
|
||
fn main() { | ||
match try { false } { _ => {} } //~ ERROR expected expression, found reserved keyword `try` | ||
match try { } { | ||
Err(()) => (), | ||
Ok(()) => (), | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
error: expected expression, found reserved keyword `try` | ||
--> $DIR/try-block-in-while.rs:6:11 | ||
error[E0277]: the trait bound `bool: std::ops::Try` is not satisfied | ||
--> $DIR/try-block-in-while.rs:6:15 | ||
| | ||
LL | while try { false } {} | ||
| ^^^ expected expression | ||
| ^^^^^^^^^ the trait `std::ops::Try` is not implemented for `bool` | ||
| | ||
= note: required by `std::ops::Try::from_ok` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
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,28 @@ | ||
// check-pass | ||
// compile-flags: --edition 2018 | ||
|
||
#![feature(try_blocks)] | ||
#![warn(unused_parens, unused_braces)] | ||
|
||
fn consume<T>(_: Result<T, T>) -> T { todo!() } | ||
|
||
fn main() { | ||
consume((try {})); | ||
//~^ WARN unnecessary parentheses | ||
|
||
consume({ try {} }); | ||
//~^ WARN unnecessary braces | ||
|
||
match (try {}) { | ||
//~^ WARN unnecessary parentheses | ||
Ok(()) | Err(()) => (), | ||
} | ||
|
||
if let Err(()) = (try {}) {} | ||
//~^ WARN unnecessary parentheses | ||
|
||
match (try {}) { | ||
//~^ WARN unnecessary parentheses | ||
Ok(()) | Err(()) => (), | ||
} | ||
} |
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,44 @@ | ||
warning: unnecessary parentheses around function argument | ||
--> $DIR/try-block-unused-delims.rs:10:13 | ||
| | ||
LL | consume((try {})); | ||
| ^^^^^^^^ help: remove these parentheses | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/try-block-unused-delims.rs:5:9 | ||
| | ||
LL | #![warn(unused_parens, unused_braces)] | ||
| ^^^^^^^^^^^^^ | ||
|
||
warning: unnecessary braces around function argument | ||
--> $DIR/try-block-unused-delims.rs:13:13 | ||
| | ||
LL | consume({ try {} }); | ||
| ^^^^^^^^^^ help: remove these braces | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/try-block-unused-delims.rs:5:24 | ||
| | ||
LL | #![warn(unused_parens, unused_braces)] | ||
| ^^^^^^^^^^^^^ | ||
|
||
warning: unnecessary parentheses around `match` scrutinee expression | ||
--> $DIR/try-block-unused-delims.rs:16:11 | ||
| | ||
LL | match (try {}) { | ||
| ^^^^^^^^ help: remove these parentheses | ||
|
||
warning: unnecessary parentheses around `let` scrutinee expression | ||
--> $DIR/try-block-unused-delims.rs:21:22 | ||
| | ||
LL | if let Err(()) = (try {}) {} | ||
| ^^^^^^^^ help: remove these parentheses | ||
|
||
warning: unnecessary parentheses around `match` scrutinee expression | ||
--> $DIR/try-block-unused-delims.rs:24:11 | ||
| | ||
LL | match (try {}) { | ||
| ^^^^^^^^ help: remove these parentheses | ||
|
||
warning: 5 warnings emitted | ||
|