Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try blocks don't parse after return #76271

Closed
scottmcm opened this issue Sep 3, 2020 · 0 comments · Fixed by #76274
Closed

try blocks don't parse after return #76271

scottmcm opened this issue Sep 3, 2020 · 0 comments · Fixed by #76274
Assignees
Labels
A-parser Area: The parsing of Rust source code to an AST B-unstable Blocker: Implemented in the nightly compiler and unstable. C-bug Category: This is a bug. F-try_blocks `#![feature(try_blocks)]`

Comments

@scottmcm
Copy link
Member

scottmcm commented Sep 3, 2020

Simple demo that won't compile but should be a type error:

#![feature(try_blocks)]
fn demo() {
    return try { 4 };
}

But it gives a parse error instead:

error: expected one of `.`, `;`, `?`, `}`, or an operator, found reserved keyword `try`
 --> src/lib.rs:3:12
  |
3 |     return try { 4 };
  |            ^^^ expected one of `.`, `;`, `?`, `}`, or an operator

error: aborting due to previous error

(It works if you put parens, like return (try { 4 });)

@scottmcm scottmcm added B-unstable Blocker: Implemented in the nightly compiler and unstable. C-bug Category: This is a bug. F-try_blocks `#![feature(try_blocks)]` labels Sep 3, 2020
@scottmcm scottmcm self-assigned this Sep 3, 2020
@scottmcm scottmcm added the A-parser Area: The parsing of Rust source code to an AST label Sep 3, 2020
matklad added a commit to matklad/rust that referenced this issue Sep 4, 2020
Allow try blocks as the argument to return expressions

Fixes rust-lang#76271

I don't think this needs to be edition-aware (phew) since `return try` in 2015 is also the start of an expression, just with a struct literal instead of a block (`return try { x: 4, y: 5 }`).
matklad added a commit to matklad/rust that referenced this issue Sep 4, 2020
Allow try blocks as the argument to return expressions

Fixes rust-lang#76271

I don't think this needs to be edition-aware (phew) since `return try` in 2015 is also the start of an expression, just with a struct literal instead of a block (`return try { x: 4, y: 5 }`).
matklad added a commit to matklad/rust that referenced this issue Sep 4, 2020
Allow try blocks as the argument to return expressions

Fixes rust-lang#76271

I don't think this needs to be edition-aware (phew) since `return try` in 2015 is also the start of an expression, just with a struct literal instead of a block (`return try { x: 4, y: 5 }`).
matklad added a commit to matklad/rust that referenced this issue Sep 4, 2020
Allow try blocks as the argument to return expressions

Fixes rust-lang#76271

I don't think this needs to be edition-aware (phew) since `return try` in 2015 is also the start of an expression, just with a struct literal instead of a block (`return try { x: 4, y: 5 }`).
matklad added a commit to matklad/rust that referenced this issue Sep 4, 2020
Allow try blocks as the argument to return expressions

Fixes rust-lang#76271

I don't think this needs to be edition-aware (phew) since `return try` in 2015 is also the start of an expression, just with a struct literal instead of a block (`return try { x: 4, y: 5 }`).
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Sep 5, 2020
Allow try blocks as the argument to return expressions

Fixes rust-lang#76271

I don't think this needs to be edition-aware (phew) since `return try` in 2015 is also the start of an expression, just with a struct literal instead of a block (`return try { x: 4, y: 5 }`).
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Sep 5, 2020
Allow try blocks as the argument to return expressions

Fixes rust-lang#76271

I don't think this needs to be edition-aware (phew) since `return try` in 2015 is also the start of an expression, just with a struct literal instead of a block (`return try { x: 4, y: 5 }`).
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Sep 6, 2020
Allow try blocks as the argument to return expressions

Fixes rust-lang#76271

I don't think this needs to be edition-aware (phew) since `return try` in 2015 is also the start of an expression, just with a struct literal instead of a block (`return try { x: 4, y: 5 }`).
@bors bors closed this as completed in 6545985 Sep 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: The parsing of Rust source code to an AST B-unstable Blocker: Implemented in the nightly compiler and unstable. C-bug Category: This is a bug. F-try_blocks `#![feature(try_blocks)]`
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant