-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Pattern Migration 2024: reword to make sense on all Editions #136475
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
Changes from 2 commits
724b885
bdc6c4d
bbe40ac
9202001
4331f55
203d310
a064e78
767f820
a5cc4cb
060cc37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/ref-binding-on-inh-ref-errors.rs:60:10 | ||
--> $DIR/ref-binding-on-inh-ref-errors.rs:54:10 | ||
| | ||
LL | let [&mut ref x] = &[&mut 0]; | ||
| ^^^^^ | ||
|
@@ -10,11 +10,11 @@ help: replace this `&mut` pattern with `&` | |
LL | let [&ref x] = &[&mut 0]; | ||
| ~ | ||
|
||
error: this pattern relies on behavior which may change in edition 2024 | ||
--> $DIR/ref-binding-on-inh-ref-errors.rs:74:10 | ||
error: binding modifiers may only be written when the default binding mode is `move` | ||
--> $DIR/ref-binding-on-inh-ref-errors.rs:67:10 | ||
| | ||
LL | let [ref mut x] = &[0]; | ||
| ^^^^^^^ cannot override to bind by-reference when that is the implicit default | ||
| ^^^^^^^ default binding mode is `ref` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default binding mode is really a property of the whole subpattern. Could you change this label to something like "this reference/binding mode" and add another label that points to the whole subpattern with "default binding mode is X"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! I'm a little wary about labeling the whole subpattern for reference patterns, though. It looks good for bindings, but with reference patterns it kind of looks like it's highlighting the inside of the pattern, where the default binding mode will be different and can potentially overlap other labels. I've added a test to illustrate:
I wonder if it'd look good to instead put the "default binding mode is X" label where the default binding mode is introduced.. that'd give more information to users too, but I'm not sure how readable it'd be. I'll experiment and fix another small formatting issue before marking this as ready for review. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm that's not very legible indeed. I think there might be an option so that labels are kept more separate than this for legibility? I'm not sure though.
Good point, that could be good yes! I'm thinking this might work well if we could separate it so we can explain a bit more, e.g.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I know how to do that! I like the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could show each transition of the default binding mode leading all the way down to the binding. I'm not really sure how serious I am about that suggestion. On the one hand, it seems maybe a bit much, but on the other, it probably would improve understanding. We have other errors, like our cycle errors, that carefully show each step. It's maybe not inconceivable. (Though to really make sense of it, we'd probably have to elaborate the type as well. Anyway, keeping it simple is fine too. Seeing the default binding mode annotated at all made me smile.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
How does this look? I wanted to get something that worked for both mutable and shared references, in case we're labeling both
Looking at it as a whole though, the note's message feels a bit redundant with the labels on the main diagnostic, so I tried moving the help into the note again:
But then
Likely, yeah. ^^; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like "matching on a reference type with a non-reference pattern changes the default binding mode", it's very clear. do we actually need to say which binding mode there is? saying "non-default binding mode" could be enough? except if the user doesn't know what a binding mode is I guess >< There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, good point. I'm not too worried about terminology; the diagnostic links to the edition guide, which explains it. I think hoping people follow the link if they don't know the terms is the best we can do. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as of a5cc4cb, it now looks like this:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks great. |
||
| | ||
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html> | ||
help: make the implied reference pattern explicit | ||
|
@@ -23,40 +23,40 @@ LL | let &[ref mut x] = &[0]; | |
| + | ||
|
||
error[E0596]: cannot borrow data in a `&` reference as mutable | ||
--> $DIR/ref-binding-on-inh-ref-errors.rs:74:10 | ||
--> $DIR/ref-binding-on-inh-ref-errors.rs:67:10 | ||
| | ||
LL | let [ref mut x] = &[0]; | ||
| ^^^^^^^^^ cannot borrow as mutable | ||
|
||
error: this pattern relies on behavior which may change in edition 2024 | ||
--> $DIR/ref-binding-on-inh-ref-errors.rs:83:10 | ||
error: binding modifiers may only be written when the default binding mode is `move` | ||
--> $DIR/ref-binding-on-inh-ref-errors.rs:75:10 | ||
| | ||
LL | let [ref x] = &[0]; | ||
| ^^^ cannot override to bind by-reference when that is the implicit default | ||
| ^^^ default binding mode is `ref` | ||
| | ||
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html> | ||
help: make the implied reference pattern explicit | ||
| | ||
LL | let &[ref x] = &[0]; | ||
| + | ||
|
||
error: this pattern relies on behavior which may change in edition 2024 | ||
--> $DIR/ref-binding-on-inh-ref-errors.rs:88:10 | ||
error: binding modifiers may only be written when the default binding mode is `move` | ||
--> $DIR/ref-binding-on-inh-ref-errors.rs:79:10 | ||
| | ||
LL | let [ref x] = &mut [0]; | ||
| ^^^ cannot override to bind by-reference when that is the implicit default | ||
| ^^^ default binding mode is `ref mut` | ||
| | ||
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html> | ||
help: make the implied reference pattern explicit | ||
| | ||
LL | let &mut [ref x] = &mut [0]; | ||
| ++++ | ||
|
||
error: this pattern relies on behavior which may change in edition 2024 | ||
--> $DIR/ref-binding-on-inh-ref-errors.rs:93:10 | ||
error: binding modifiers may only be written when the default binding mode is `move` | ||
--> $DIR/ref-binding-on-inh-ref-errors.rs:83:10 | ||
| | ||
LL | let [ref mut x] = &mut [0]; | ||
| ^^^^^^^ cannot override to bind by-reference when that is the implicit default | ||
| ^^^^^^^ default binding mode is `ref mut` | ||
| | ||
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html> | ||
help: make the implied reference pattern explicit | ||
|
Uh oh!
There was an error while loading. Please reload this page.