Skip to content

Upgrading to 2018 edition with nameless trait arguments gives opaque error message. #82729

Closed
@edre

Description

@edre
Contributor

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=2d5990f9266a843f299cffb49ea24f36

The current output is:

error: expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `)`
 --> src/main.rs:3:46
  |
3 |     fn apply(&self, &mut <Self::G as Game>::S);
  |                                              ^ expected one of 8 possible tokens

Ideally the output should look like:

error: traits require argument names

This was very painful to debug, because there's some type shenanigans going on, and it wasn't clear if some of those didn't work in the 2018 edition now.

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Mar 3, 2021
ehuss

ehuss commented on Mar 3, 2021

@ehuss
Contributor

Just FYI, it is usually recommended to use cargo fix --edition to transition from 2015 to 2018. That will automatically fix the syntax so it works on both editions.

If cargo fix isn't an option, or if you want to do it manually, you can use the #![warn(rust_2018_compatibility)] attribute in the crate root while still on the 2015 edition. This will cause it to show warnings for each thing that needs to be fixed. If your editor supports "quick fixes", it can automatically fix each one.

I agree that the error could be better. It was supposed to be fixed by #53990, but it seems to be confused by reference patterns.

// Gives bad error on 2018.
trait Foo {
    fn f(&mut i32);
}
added
A-parserArea: The lexing & parsing of Rust source code to an AST
C-enhancementCategory: An issue proposing an enhancement or a PR with one.
D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.
on Mar 4, 2021
added a commit that references this issue on Mar 17, 2021

Rollup merge of rust-lang#82774 - JohnTitor:bad-diag-for-anon-params-…

a16db3d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.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

      Participants

      @ehuss@edre@JohnTitor

      Issue actions

        Upgrading to 2018 edition with nameless trait arguments gives opaque error message. · Issue #82729 · rust-lang/rust