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

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

Open
traviscross opened this issue Feb 3, 2025 · 1 comment · May be fixed by #136475
Open

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

traviscross opened this issue Feb 3, 2025 · 1 comment · May be fixed by #136475
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-edition-2024 Area: The 2024 edition A-patterns Relating to patterns and pattern matching C-bug Category: This is a bug. I-edition-triaged Issue: This issue has been reviewed and triaged by the Edition team.

Comments

@traviscross
Copy link
Contributor

traviscross commented Feb 3, 2025

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:

@traviscross traviscross added A-diagnostics Area: Messages for errors, warnings, and lints A-patterns Relating to patterns and pattern matching C-bug Category: This is a bug. A-edition-2024 Area: The 2024 edition I-edition-triaged Issue: This issue has been reviewed and triaged by the Edition team. labels Feb 3, 2025
@dianne
Copy link
Contributor

dianne commented Feb 3, 2025

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

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 A-edition-2024 Area: The 2024 edition A-patterns Relating to patterns and pattern matching C-bug Category: This is a bug. I-edition-triaged Issue: This issue has been reviewed and triaged by the Edition team.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants