Skip to content

Conversation

dianne
Copy link
Contributor

@dianne dianne commented Jul 16, 2025

Partially addresses #143557:

  • Uses different wording than the Edition Guide chapter, to hopefully stand alone a bit better. Instead of referring to the "default binding mode", it now talks about what can't be written "within elided reference patterns". I ended up going with "elided" instead of "implicit" in hope that it reads bit less like it should behave the same as an explicit reference pattern, but I'm not totally happy with that wording.
  • The explanatory note still points to where the default binding mode was introduced, but only refers to its effect, not what we call it. How that relates to the rest of the diagnostic may still be a bit of a puzzle, but hopefully it isn't too much of one? It also doesn't make sense anymore for the case of & written under a by-ref binding mode, so I've left the note out in that case (but kept the label). It's more cramped, but talking about binding modes would feel like a non-sequitur for the error about & patterns without further explanation.
  • Links to the stable version of the Edition Guide instead of the nightly version. It looks like almost every link to the Edition Guide in diagnostics is to the nightly version, presumably for the same reason as here: the diagnostics were added before the new Edition was stabilized, then never updated. I'll make a separate PR to clean up the others.

This only changes the diagnostic messages, not the code suggestion or the Edition Guide.

r? @Nadrieril or reassign

@rustbot
Copy link
Collaborator

rustbot commented Jul 16, 2025

Nadrieril is not on the review rotation at the moment.
They may take a while to respond.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 16, 2025
@dianne dianne force-pushed the match-ergonomics-jargon branch from b968622 to 6751630 Compare July 16, 2025 07:13
@rustbot
Copy link
Collaborator

rustbot commented Jul 16, 2025

Some changes occurred in match checking

cc @Nadrieril

@dianne dianne force-pushed the match-ergonomics-jargon branch from 6751630 to 981b966 Compare July 20, 2025 13:22
fmease added a commit to fmease/rust that referenced this pull request Jul 23, 2025
…bank

don't link to the nightly version of the Edition Guide in stable lints

As reported in rust-lang#143557 for `rust_2024_incompatible_pat`, most future-Edition-incompatibility lints link to the nightly version of the Edition Guide; the lints were written before their respective Editions (and their guides) stabilized. But now that Rusts 2021 and 2024 are stable, these lints are emitted on stable versions of the compiler, where it makes more sense to present users with links that don't say "nightly" in them.

This does not change the link for `rust_2024_incompatible_pat`. That's handled in rust-lang#144006.
fmease added a commit to fmease/rust that referenced this pull request Jul 23, 2025
…bank

don't link to the nightly version of the Edition Guide in stable lints

As reported in rust-lang#143557 for `rust_2024_incompatible_pat`, most future-Edition-incompatibility lints link to the nightly version of the Edition Guide; the lints were written before their respective Editions (and their guides) stabilized. But now that Rusts 2021 and 2024 are stable, these lints are emitted on stable versions of the compiler, where it makes more sense to present users with links that don't say "nightly" in them.

This does not change the link for `rust_2024_incompatible_pat`. That's handled in rust-lang#144006.
fmease added a commit to fmease/rust that referenced this pull request Jul 24, 2025
…bank

don't link to the nightly version of the Edition Guide in stable lints

As reported in rust-lang#143557 for `rust_2024_incompatible_pat`, most future-Edition-incompatibility lints link to the nightly version of the Edition Guide; the lints were written before their respective Editions (and their guides) stabilized. But now that Rusts 2021 and 2024 are stable, these lints are emitted on stable versions of the compiler, where it makes more sense to present users with links that don't say "nightly" in them.

This does not change the link for `rust_2024_incompatible_pat`. That's handled in rust-lang#144006.
fmease added a commit to fmease/rust that referenced this pull request Jul 24, 2025
…bank

don't link to the nightly version of the Edition Guide in stable lints

As reported in rust-lang#143557 for `rust_2024_incompatible_pat`, most future-Edition-incompatibility lints link to the nightly version of the Edition Guide; the lints were written before their respective Editions (and their guides) stabilized. But now that Rusts 2021 and 2024 are stable, these lints are emitted on stable versions of the compiler, where it makes more sense to present users with links that don't say "nightly" in them.

This does not change the link for `rust_2024_incompatible_pat`. That's handled in rust-lang#144006.
@dianne dianne force-pushed the match-ergonomics-jargon branch from 981b966 to 271e81f Compare July 24, 2025 12:41
fmease added a commit to fmease/rust that referenced this pull request Jul 24, 2025
…bank

don't link to the nightly version of the Edition Guide in stable lints

As reported in rust-lang#143557 for `rust_2024_incompatible_pat`, most future-Edition-incompatibility lints link to the nightly version of the Edition Guide; the lints were written before their respective Editions (and their guides) stabilized. But now that Rusts 2021 and 2024 are stable, these lints are emitted on stable versions of the compiler, where it makes more sense to present users with links that don't say "nightly" in them.

This does not change the link for `rust_2024_incompatible_pat`. That's handled in rust-lang#144006.
rust-timer added a commit that referenced this pull request Jul 24, 2025
Rollup merge of #144014 - dianne:edition-guide-links, r=estebank

don't link to the nightly version of the Edition Guide in stable lints

As reported in #143557 for `rust_2024_incompatible_pat`, most future-Edition-incompatibility lints link to the nightly version of the Edition Guide; the lints were written before their respective Editions (and their guides) stabilized. But now that Rusts 2021 and 2024 are stable, these lints are emitted on stable versions of the compiler, where it makes more sense to present users with links that don't say "nightly" in them.

This does not change the link for `rust_2024_incompatible_pat`. That's handled in #144006.
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Jul 25, 2025
don't link to the nightly version of the Edition Guide in stable lints

As reported in rust-lang/rust#143557 for `rust_2024_incompatible_pat`, most future-Edition-incompatibility lints link to the nightly version of the Edition Guide; the lints were written before their respective Editions (and their guides) stabilized. But now that Rusts 2021 and 2024 are stable, these lints are emitted on stable versions of the compiler, where it makes more sense to present users with links that don't say "nightly" in them.

This does not change the link for `rust_2024_incompatible_pat`. That's handled in rust-lang/rust#144006.
@dianne dianne force-pushed the match-ergonomics-jargon branch from 271e81f to 8ea73c4 Compare July 27, 2025 13:26
| ^^^^^^^^^^^^^^ this non-reference pattern matches on a reference type `&_`
= note: this error originates in the macro `bind_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
help: make the implied reference pattern explicit
help: match on the reference with a reference pattern
Copy link
Member

@Nadrieril Nadrieril Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm torn about this, the "make the implicit explicit" wording has the benefit that it's a logical consequence of the error: "can't do X when there's an implicit borrow" => "make the thing explicit".

What do you think of:

error: cannot borrow again a binding that implicitly borrows its contents
...
note: matching on a reference type with a non-reference pattern implicitly borrows the contents
...
help: match on the reference explicitly to avoid the implicit borrow

And uh actually, why do we suggest adding a & pattern instead of removing the ref binding? I don't remember what led to this choice. Imo we should move users away from explicit binding modes. Even if they were doing [ref x]: &mut [T] to downgrade &mut to &, I think it's fine to suggest removing the ref. If they really want &mut [ref x] they'll know to write that, and otherwise they can often shared-bottow the scrutinee instead, or let coercions just work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the "to avoid the implicit borrow"! I was worried adding something like that would make the help too long when refs need to be added, but I do like having this when they don't. I've pushed an update with that, though I changed it to "to avoid implicitly borrowing" to not have to worry about pluralization. When refs do need adding, I haven't found a way to make room, but the current "and borrow explicitly using a variable binding mode" message is also explicit about making the borrow explicit, so that might be sufficient.

For the "cannot borrow again a binding that implicitly borrows its contents" error message, would that be for if the only problem with the pattern is ref/ref mut under an inherited ref? Since we use a single error for all the match ergonomics problems in a pattern (so that we can give a single suggestion), I've tried to make the messages a bit more terse than is maybe ideal so that they can fit together without getting too overwhelming. Maybe there's a better approach though?

And uh actually, why do we suggest adding a & pattern instead of removing the ref binding? I don't remember what led to this choice.

For this file's suggestions (experimental/mixed-editions.rs), it's because the current ref-eliding suggestion logic makes some assumptions that don't work for match ergonomics 2.0, so I made it not run when those feature gates are enabled. The desugaring suggestions might also be a bit wrong (I don't remember), but the ref-eliding logic could produce empty suggestions, which was a problem. We'll need to rework the diagnostics before stabilization, but we'll be able to do better then too. Also the ref in this particular error was from a macro expansion, so it can't be elided. The removing-ref tests are in migration_lint.rs. I'd just linked to the first test stderr on the diff page; it didn't occur to me it might not be the most helpful one to review ^^;

For [ref x]: &mut [T], I've kept the ref in the suggestion for two reasons. First, it's because the suggestion logic is shared by the rust_2024_incompatible_pat lint, where applying a type-changing suggestion could cause valid Rust 2021 code to stop compiling. Second, in pathological cases, &mut [ref x] and [x] may both compile but behave differently at runtime, due to the change in type influencing trait selection. If we want to discourage writing that, maybe we could lint on it.

We do suggest removing ref in other cases (see migration-lint.rs), but e.g. if &s need to be added we give up and desugar everything for simplicity, since that may result in needing to add more &s and binding modifiers elsewhere in the pattern. I had a too-complex PR for giving nicer suggestions more often, and I think you suggested a simpler approach, but we ended up closing the PR since we'd already covered the most common case and we'll be able to do better for match ergonomics 2.0.

Copy link
Member

@Nadrieril Nadrieril Oct 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok yeah I remember that. This is good enough and we can indeed revisit once we're going to stabilization.

@dianne dianne force-pushed the match-ergonomics-jargon branch from 8ea73c4 to 55da30e Compare July 27, 2025 18:11
Comment on lines 55 to 56
// provide the same reference link as the lint
err.note(format!("for more information, see {}", info.reference));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, maybe the hard error version of this would be better serviced by linking to the Reference rather than the Edition Guide? Specifically https://doc.rust-lang.org/reference/patterns.html#r-patterns.ident.binding. There's less highlighting of the error cases, but being less focused on Edition migration could be helpful going forward. It also uses (and elaborates on!) the "non-reference pattern" wording and is very methodical about explaining match ergonomics, which I think is helpful. It's a bit easier for me to follow than the Edition Guide's presentation, too. Of course, if we want to be consistent with terminology and presentation, we'll probably also want to update the Edition Guide; #143557 indicates that it may need some rewriting.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah that reads much better, it even has the "edition differences" clearly indicated. +1 on this

Copy link
Contributor Author

@dianne dianne Oct 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! I went with https://doc.rust-lang.org/reference/patterns.html#binding-modes for the hard error; it goes to the same section but it's a bit cleaner (and more legible) than the rule link I suggested earlier. The lint still directs to the edition guide since it's paired with a "warning: this changes meaning in Rust 2024" and it seems helpful to have as much explanation as possible for the edition change specifically.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

Copy link
Member

@Nadrieril Nadrieril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I quite like this now, the "implicit borrow" terminology feels quite clear. r=me after the link change!

View changes since this review

@dianne dianne force-pushed the match-ergonomics-jargon branch from 55da30e to ec99e3e Compare October 8, 2025 09:13
@rustbot
Copy link
Collaborator

rustbot commented Oct 8, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@Nadrieril
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Oct 8, 2025

📌 Commit ec99e3e has been approved by Nadrieril

It is now in the queue for this repository.

@bors bors removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 8, 2025
@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Oct 8, 2025
bors added a commit that referenced this pull request Oct 8, 2025
Rollup of 6 pull requests

Successful merges:

 - #144006 (clarify wording of match ergonomics diagnostics (`rust_2024_incompatible_pat` lint and error))
 - #147386 (some more `proc_macro` cleanups)
 - #147412 (Convert impossible cases in macro resolution into assertions)
 - #147464 (prefer repeat_n() over repeat().take())
 - #147469 (Add rustdoc crate name in error)
 - #147472 (refactor: replace `LLVMRustAtomicLoad/Store` with LLVM built-in functions)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 8, 2025
…Nadrieril

clarify wording of match ergonomics diagnostics (`rust_2024_incompatible_pat` lint and error)

Partially addresses rust-lang#143557:
- Uses different wording than the Edition Guide chapter, to hopefully stand alone a bit better. Instead of referring to the "default binding mode", it now talks about what can't be written "within elided reference patterns". I ended up going with "elided" instead of "implicit" in hope that it reads bit less like it should behave the same as an explicit reference pattern, but I'm not totally happy with that wording.
- The explanatory note still points to where the default binding mode was introduced, but only refers to its effect, not what we call it. How that relates to the rest of the diagnostic may still be a bit of a puzzle, but hopefully it isn't too much of one? It also doesn't make sense anymore for the case of `&` written under a by-ref binding mode, so I've left the note out in that case (but kept the label). It's more cramped, but talking about binding modes would feel like a non-sequitur for the error about `&` patterns without further explanation.
- Links to the stable version of the Edition Guide instead of the nightly version. It looks like almost every link to the Edition Guide in diagnostics is to the nightly version, presumably for the same reason as here: the diagnostics were added before the new Edition was stabilized, then never updated. I'll make a separate PR to clean up the others.

This only changes the diagnostic messages, not the code suggestion or the Edition Guide.

r? ``@Nadrieril`` or reassign
@bors bors merged commit 193a28d into rust-lang:master Oct 8, 2025
10 checks passed
@rustbot rustbot added this to the 1.92.0 milestone Oct 8, 2025
rust-timer added a commit that referenced this pull request Oct 8, 2025
Rollup merge of #144006 - dianne:match-ergonomics-jargon, r=Nadrieril

clarify wording of match ergonomics diagnostics (`rust_2024_incompatible_pat` lint and error)

Partially addresses #143557:
- Uses different wording than the Edition Guide chapter, to hopefully stand alone a bit better. Instead of referring to the "default binding mode", it now talks about what can't be written "within elided reference patterns". I ended up going with "elided" instead of "implicit" in hope that it reads bit less like it should behave the same as an explicit reference pattern, but I'm not totally happy with that wording.
- The explanatory note still points to where the default binding mode was introduced, but only refers to its effect, not what we call it. How that relates to the rest of the diagnostic may still be a bit of a puzzle, but hopefully it isn't too much of one? It also doesn't make sense anymore for the case of `&` written under a by-ref binding mode, so I've left the note out in that case (but kept the label). It's more cramped, but talking about binding modes would feel like a non-sequitur for the error about `&` patterns without further explanation.
- Links to the stable version of the Edition Guide instead of the nightly version. It looks like almost every link to the Edition Guide in diagnostics is to the nightly version, presumably for the same reason as here: the diagnostics were added before the new Edition was stabilized, then never updated. I'll make a separate PR to clean up the others.

This only changes the diagnostic messages, not the code suggestion or the Edition Guide.

r? `@Nadrieril` or reassign
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants