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

"patterns are not allowed to reset the default binding mode" suggestion means nothing to me #133854

Closed
shepmaster opened this issue Dec 4, 2024 · 2 comments · Fixed by #134394
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 A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@shepmaster
Copy link
Member

shepmaster commented Dec 4, 2024

Code

use std::collections::BTreeMap;

fn demo(map: BTreeMap<(usize, usize), char>) {
    map.iter().filter(|(&(_x, _y), &_c)| false);
}

Current output

error: patterns are not allowed to reset the default binding mode in edition 2024
 --> src/lib.rs:4:24
  |
4 |     map.iter().filter(|(&(_x, _y), &_c)| false);
  |                        -^^^^^^^^^^^^^^^
  |                        |
  |                        help: desugar the match ergonomics: `&`

Desired output

error: patterns are not allowed to reset the default binding mode in edition 2024
 --> src/lib.rs:4:24
  |
4 |     map.iter().filter(|(&(_x, _y), &_c)| false);
  |                        -^^^^^^^^^^^^^^^
  |                        |
  |                        help: add an `&` at the beginning of this pattern

Rationale and extra context

Presented with this error, I was completely stumped. I have no idea what the suggestion is attempting to get me to do.

I do not think the word "desugar" is useful here because it's not obvious to me (a) that there was sugar and (b) what the sugaring was. Without that knowledge, the suggestion is non-actionable.

After minutes of reading/reducing/reproducing the problem, I finally realized that that the - part of the -^^^^^^^^^^^^^^^ was pointing to the parenthesis and not to the &, so I tried adding it and it compiled.

Additionally, I worry that "default binding mode" is not an established / well-known terminology so there's not much meat from that message for me to go on either.

Rust Version

rustc 1.85.0-nightly (c44b3d50f 2024-12-03)
binary: rustc
commit-hash: c44b3d50fea96a3e0417e8264c16ea21a0a3fca2
commit-date: 2024-12-03
host: aarch64-apple-darwin
release: 1.85.0-nightly
LLVM version: 19.1.4
@shepmaster shepmaster 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 Dec 4, 2024
@fmease fmease added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-confusing Diagnostics: Confusing error or lint that should be reworked. A-patterns Relating to patterns and pattern matching A-edition-2024 Area: The 2024 edition labels Dec 4, 2024
@traviscross
Copy link
Contributor

cc @Nadrieril @Jules-Bertholet

@dianne
Copy link
Contributor

dianne commented Dec 16, 2024

@rustbot claim

jieyouxu added a commit to jieyouxu/rust that referenced this issue Dec 18, 2024
… r=compiler-errors

Clarify the match ergonomics 2024 migration lint's output

This makes a few changes:
- Rather than using the whole pattern as a span for the lint, this collects spans for each problematic default binding mode reset and labels them with why they're problems.
- The lint's suggestions are now verbose-styled, so that it's clear what's being suggested vs. what's problematic.
- The wording is now less technical, and the hard error version of this diagnostic now links to the same reference material as the lint (currently an unwritten page of the edition guide).

I'm not totally confident in the wording or formatting, so I'd appreciate feedback on that in particular. I tried to draw a connection with word choice between the labels and the suggestion, but it might be imprecise, unclear, or cluttered. If so, it might be worth making the labels more terse and adding notes that explain them, but that's harder to read in a way too.

cc `@Nadrieril` `@Jules-Bertholet`

Closes rust-lang#133854. For reference, the error from that issue becomes:
```
error: pattern uses features incompatible with edition 2024
  --> $DIR/remove-me.rs:6:25
   |
LL |     map.iter().filter(|(&(_x, _y), &_c)| false);
   |                         ^          ^ cannot implicitly match against multiple layers of reference
   |                         |
   |                         cannot implicitly match against multiple layers of reference
   |
help: make the implied reference pattern explicit
   |
LL |     map.iter().filter(|&(&(_x, _y), &_c)| false);
   |                        +
```
jieyouxu added a commit to jieyouxu/rust that referenced this issue Dec 18, 2024
… r=compiler-errors

Clarify the match ergonomics 2024 migration lint's output

This makes a few changes:
- Rather than using the whole pattern as a span for the lint, this collects spans for each problematic default binding mode reset and labels them with why they're problems.
- The lint's suggestions are now verbose-styled, so that it's clear what's being suggested vs. what's problematic.
- The wording is now less technical, and the hard error version of this diagnostic now links to the same reference material as the lint (currently an unwritten page of the edition guide).

I'm not totally confident in the wording or formatting, so I'd appreciate feedback on that in particular. I tried to draw a connection with word choice between the labels and the suggestion, but it might be imprecise, unclear, or cluttered. If so, it might be worth making the labels more terse and adding notes that explain them, but that's harder to read in a way too.

cc ``@Nadrieril`` ``@Jules-Bertholet``

Closes rust-lang#133854. For reference, the error from that issue becomes:
```
error: pattern uses features incompatible with edition 2024
  --> $DIR/remove-me.rs:6:25
   |
LL |     map.iter().filter(|(&(_x, _y), &_c)| false);
   |                         ^          ^ cannot implicitly match against multiple layers of reference
   |                         |
   |                         cannot implicitly match against multiple layers of reference
   |
help: make the implied reference pattern explicit
   |
LL |     map.iter().filter(|&(&(_x, _y), &_c)| false);
   |                        +
```
jieyouxu added a commit to jieyouxu/rust that referenced this issue Dec 18, 2024
… r=compiler-errors

Clarify the match ergonomics 2024 migration lint's output

This makes a few changes:
- Rather than using the whole pattern as a span for the lint, this collects spans for each problematic default binding mode reset and labels them with why they're problems.
- The lint's suggestions are now verbose-styled, so that it's clear what's being suggested vs. what's problematic.
- The wording is now less technical, and the hard error version of this diagnostic now links to the same reference material as the lint (currently an unwritten page of the edition guide).

I'm not totally confident in the wording or formatting, so I'd appreciate feedback on that in particular. I tried to draw a connection with word choice between the labels and the suggestion, but it might be imprecise, unclear, or cluttered. If so, it might be worth making the labels more terse and adding notes that explain them, but that's harder to read in a way too.

cc `@Nadrieril` `@Jules-Bertholet`

Closes rust-lang#133854. For reference, the error from that issue becomes:
```
error: pattern uses features incompatible with edition 2024
  --> $DIR/remove-me.rs:6:25
   |
LL |     map.iter().filter(|(&(_x, _y), &_c)| false);
   |                         ^          ^ cannot implicitly match against multiple layers of reference
   |                         |
   |                         cannot implicitly match against multiple layers of reference
   |
help: make the implied reference pattern explicit
   |
LL |     map.iter().filter(|&(&(_x, _y), &_c)| false);
   |                        +
```
jieyouxu added a commit to jieyouxu/rust that referenced this issue Dec 18, 2024
… r=compiler-errors

Clarify the match ergonomics 2024 migration lint's output

This makes a few changes:
- Rather than using the whole pattern as a span for the lint, this collects spans for each problematic default binding mode reset and labels them with why they're problems.
- The lint's suggestions are now verbose-styled, so that it's clear what's being suggested vs. what's problematic.
- The wording is now less technical, and the hard error version of this diagnostic now links to the same reference material as the lint (currently an unwritten page of the edition guide).

I'm not totally confident in the wording or formatting, so I'd appreciate feedback on that in particular. I tried to draw a connection with word choice between the labels and the suggestion, but it might be imprecise, unclear, or cluttered. If so, it might be worth making the labels more terse and adding notes that explain them, but that's harder to read in a way too.

cc ``@Nadrieril`` ``@Jules-Bertholet``

Closes rust-lang#133854. For reference, the error from that issue becomes:
```
error: pattern uses features incompatible with edition 2024
  --> $DIR/remove-me.rs:6:25
   |
LL |     map.iter().filter(|(&(_x, _y), &_c)| false);
   |                         ^          ^ cannot implicitly match against multiple layers of reference
   |                         |
   |                         cannot implicitly match against multiple layers of reference
   |
help: make the implied reference pattern explicit
   |
LL |     map.iter().filter(|&(&(_x, _y), &_c)| false);
   |                        +
```
@bors bors closed this as completed in f3faaf5 Dec 18, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 18, 2024
Rollup merge of rust-lang#134394 - dianne:clarify-pat-2024-migration, r=compiler-errors

Clarify the match ergonomics 2024 migration lint's output

This makes a few changes:
- Rather than using the whole pattern as a span for the lint, this collects spans for each problematic default binding mode reset and labels them with why they're problems.
- The lint's suggestions are now verbose-styled, so that it's clear what's being suggested vs. what's problematic.
- The wording is now less technical, and the hard error version of this diagnostic now links to the same reference material as the lint (currently an unwritten page of the edition guide).

I'm not totally confident in the wording or formatting, so I'd appreciate feedback on that in particular. I tried to draw a connection with word choice between the labels and the suggestion, but it might be imprecise, unclear, or cluttered. If so, it might be worth making the labels more terse and adding notes that explain them, but that's harder to read in a way too.

cc ```@Nadrieril``` ```@Jules-Bertholet```

Closes rust-lang#133854. For reference, the error from that issue becomes:
```
error: pattern uses features incompatible with edition 2024
  --> $DIR/remove-me.rs:6:25
   |
LL |     map.iter().filter(|(&(_x, _y), &_c)| false);
   |                         ^          ^ cannot implicitly match against multiple layers of reference
   |                         |
   |                         cannot implicitly match against multiple layers of reference
   |
help: make the implied reference pattern explicit
   |
LL |     map.iter().filter(|&(&(_x, _y), &_c)| false);
   |                        +
```
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 A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-confusing Diagnostics: Confusing error or lint that should be reworked. 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.

4 participants