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

Bad diagnostic for misplaced where clause #126311

Closed
bugaevc opened this issue Jun 12, 2024 · 1 comment · Fixed by #127350
Closed

Bad diagnostic for misplaced where clause #126311

bugaevc opened this issue Jun 12, 2024 · 1 comment · Fixed by #127350
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@bugaevc
Copy link

bugaevc commented Jun 12, 2024

Code

trait Service {
    type Output;
    type Error;
}

fn takes_service<S: Service>(s: S) where S::Error: Debug -> S::Output { loop {} }

Current output

Compiling playground v0.0.1 (/playground)
error: expected one of `(`, `+`, `,`, `::`, `<`, or `{`, found `->`
  --> src/main.rs:31:58
   |
31 | fn takes_service<S: Service>(s: S) where S::Error: Debug -> S::Output {
   |                                                    ------^^ expected one of `(`, `+`, `,`, `::`, `<`, or `{`
   |                                                    |    |
   |                                                    |    help: try adding parentheses
   |                                                    `Fn` bounds require arguments in parentheses

error: could not compile `playground` (bin "playground") due to 1 previous error

Desired output

Something about misplaced where clause, directing me to place it _after_ the return type

Rationale and extra context

No response

Other cases

No response

Rust Version

Build using the Nightly version: 1.81.0-nightly

(2024-06-11 d0227c6a19c2d6e8dceb)

Anything else?

No response

@bugaevc bugaevc added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 12, 2024
@veera-sivarajan
Copy link
Contributor

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jul 19, 2024
Parser: Suggest Placing the Return Type After Function Parameters

Fixes rust-lang#126311

This PR suggests placing the return type after the function parameters when it's misplaced after a `where` clause.

This also tangentially improves diagnostics for cases like [this](https://github.com/veera-sivarajan/rust/blob/86d6f1312a77997ef994240e716288d61a343a6d/tests/ui/parser/issues/misplaced-return-type-without-where-issue-126311.rs#L1C1-L1C28) and adds doc comments for `parser::AllowPlus`.
tgross35 added a commit to tgross35/rust that referenced this issue Jul 19, 2024
Parser: Suggest Placing the Return Type After Function Parameters

Fixes rust-lang#126311

This PR suggests placing the return type after the function parameters when it's misplaced after a `where` clause.

This also tangentially improves diagnostics for cases like [this](https://github.com/veera-sivarajan/rust/blob/86d6f1312a77997ef994240e716288d61a343a6d/tests/ui/parser/issues/misplaced-return-type-without-where-issue-126311.rs#L1C1-L1C28) and adds doc comments for `parser::AllowPlus`.
@bors bors closed this as completed in c86e13f Jul 19, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jul 19, 2024
Rollup merge of rust-lang#127350 - veera-sivarajan:bugfix-126311, r=lcnr

Parser: Suggest Placing the Return Type After Function Parameters

Fixes rust-lang#126311

This PR suggests placing the return type after the function parameters when it's misplaced after a `where` clause.

This also tangentially improves diagnostics for cases like [this](https://github.com/veera-sivarajan/rust/blob/86d6f1312a77997ef994240e716288d61a343a6d/tests/ui/parser/issues/misplaced-return-type-without-where-issue-126311.rs#L1C1-L1C28) and adds doc comments for `parser::AllowPlus`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants