Match & with &mut in RFC-3627 2024 Match ergonomics

In RFC-3627 it says:

On all editions, & patterns can match against &mut references.

But when i run this code:
let &foo = &mut 42;
the compiler complains that types differ in mutability. I've tested this in multiple versions even before 2024. The result is the same.

It is interesting to me that this is not mentioned in 2024 edition guide!

The ultimately stabilized change doesn't have to match the RFC. And since it's (still) an error on all editions, why would it be in the edition guide?

P.s. your link is to the reference, not the RFC.

2 Likes

Thank's.
Yes. The link is repaired. Sorry about that.

But the RFC in that particular case is talking about all versions not just the 2024!

The RFC was proposing a change to all editions, possible because it did not compile. But ultimately that proposal did not land with the release of edition 2024 or since, on any edition. So it still does not complie. The proposal may or may not land in the future.

What we did get doesn't match the RFC. Instead, on edition 2024 only, we got something that dialed things back to get rid of some annoying parts of binding modes, such as resetting to by-value, while leaving future possibilities -- like perhaps the one under discussion -- compatible, but not stabilized. IIRC there are unstable feature gates for some of these possibilities.

There just wasn't enough agreement or certainty for the newly proposed features to do otherwise, so far as I recall. (The related issues are hundreds of comments long.)

Note that the binding modes we had before edition 2024 do not match their RFC either! Resetting to by-value was not part of that RFC, it was added during development.

The RFCs are a useful source of information, but they are generally not updated to match what is actually implemented and stabilized. You have to hope what is actually stabilized is properly documented instead (and fall back to experimentation or learning compiler internals when it is not).

4 Likes

Thank's

But i didn't know that previous versions could change in the future!

About RFCs your right.
But RFCs usually explain the issue better than the reference itself! May be the reference team (or developers writing the reference) should clarify better!
Rust is sometimes hard to understand, And sometimes the reference makes additional complexity to understand the language.

  • Sorry for bad English

On that I agree, and hope the reference becomes more complete over time.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.