Skip to content

(use<> forgets to look for ) #145470

@dtolnay

Description

@dtolnay

In the following code, after (use<>, while still inside parenthesized content, the parser successfully parses the function body and tuple struct, oblivious that these were supposed to have been outside ).

fn repro() -> impl (use<> {
    println!("?");
}

#[derive(Debug)]
struct Struct<F>(i32, F)
where
    T: Fn() -> i32;

)
error: expected item, found `)`
  --> src/lib.rs:10:1
   |
10 | )
   | ^ expected item
   |
   = note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>

It seems pretty clear to me that this is unintended behavior, not some kind of intentional parsing recovery. The same bug does not occur for a mismatched parenthesis around lifetime bound or trait bound.

error: expected `)`, found `{`
 --> src/lib.rs:1:24
  |
1 | fn repro() -> impl ('a {
  |                        ^ expected `)`
error: expected one of `(`, `)`, `::`, or `<`, found `{`
 --> src/lib.rs:1:27
  |
1 | fn repro() -> impl (Trait {
  |                           ^ expected one of `(`, `)`, `::`, or `<`

Metadata

Metadata

Assignees

Labels

A-parserArea: The lexing & parsing of Rust source code to an ASTC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions