Skip to content

Match ergonomics error message about Rust 2024 future compatibility in Rust 2024 #136456

Closed

Description

@traviscross

In Rust 2024, the following error message is emitted:

//@ edition: 2024
fn main() {
    let [&_x] = &mut [&()];
    //~^ ERROR this pattern relies on behavior which may change in edition 2024
    //~| ERROR cannot implicitly match against multiple layers of reference
    //~| NOTE make the implied reference pattern explicit
}

This message isn't great. The problem isn't really that the behavior may change in Rust 2024, it's that this is simply disallowed (starting in Rust 2024).

We should probably also remove the bit about "implicitly matching against multiple layers of references". If someone is in the Rust 2024 headspace, this isn't necessarily what the person was trying to do in writing this.

cc @Nadrieril @dianne

Tracking:

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    A-patternsRelating to patterns and pattern matching
    C-bugCategory: This is a bug.
    I-edition-triagedIssue: This issue has been reviewed and triaged by the Edition team.
    on Feb 3, 2025
  2. dianne commented on Feb 3, 2025

    @dianne
    Member

    I've been wondering about how to word this better.. I agree that "cannot implicitly match against multiple layers of reference" isn't ideal, but I'd like some explanation of what went wrong on that label, since it does point to the & that's disallowed. Maybe something that matches the wording in the edition guide, since there's a link in the error? e.g. "reference patterns can only be written when the pattern is fully explicit up to that point" or "reference patterns can only be written when the default binding mode is by-move". Or one of those with "&"/"&mut" as appropriate instead of "reference" to be a little more concise. Or maybe it could be framed in terms of being disallowed when the default binding mode is by-reference, to match with the other labels the error can have (or maybe those labels should also be framed in terms of only being allowed when the default binding mode is by-move?). I'll think about it.

    In any case, I'll update the error message and label text. If anyone has wording ideas or opinions, please let me know. @rustbot claim

  3. dianne commented on Feb 10, 2025

    @dianne
    Member

    The commits from #136475 were merged via #136577. I completely forgot this wouldn't automatically be closed that way, but the improved wording is now in nightly (playground link).

  4. traviscross commented on Feb 10, 2025

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

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-edition-2024Area: The 2024 editionA-patternsRelating to patterns and pattern matchingC-bugCategory: This is a bug.I-edition-triagedIssue: This issue has been reviewed and triaged by the Edition team.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions