forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#135434 - dianne:match-2024-for-edition-2024, r=Nadrieril Match Ergonomics 2024: update edition 2024 behavior of feature gates This updates the edition 2024 behavior of the feature gates `ref_pat_eat_one_layer_2024_structural` and `ref_pat_eat_one_layer_2024` to correspond to the left and right typing rules compared [here](https://nadrieril.github.io/typing-rust-patterns/?compare=true&opts2=AQEBAAABAQABAgIAAQEBAAEBAAABAAA%3D&opts1=AQEBAgEBAQEBAgIAAAAAAAAAAAAAAAA%3D&mode=rules&do_cmp=true&ty_d=3&style=SequentBindingMode), respectively. I'll implement the proposed new behavior for editions ≤ 2021 in another PR. The tests are split up a bit awkwardly for practical reasons, but I've added new tests from 3 places: - I got tests for where the typing rules differ from the "Compare" tab of the page linked above. These had to be split up based on where the errors are emitted and how rustfixable they are, so they've ended up in different files to keep tidy. Within each file, though, the order of the tests matches the order the typing differences appear in that comparison (as of when this was written). - I used [this other comparison](https://nadrieril.github.io/typing-rust-patterns/?q=%5B%26mut+%26%28mut+x%29%5D%3A+%26mut+%5B%26CT%5D&compare=true&opts2=AQEBAgABAQEBAgIAAQEBAAEBAAABAAA%3D&opts1=AQEBAgEBAQEBAgIAAAAAAAAAAAAAAAA%3D&mode=compare&do_cmp=true&ty_d=3&style=SequentBindingMode) to test the `Deref(EatInner, FallbackToOuter)` rule of the left/"structural"/eat-inner ruleset. These are all in `well-typed-edition-2024.rs`. - I added some select tests for cases where the new typing rules differ from current stable Rust. I had to be pickier about what I included here, but I tried to make sure each typing rule got some coverage. That said, my approach for these tests was a bit ad-hoc, so I may have missed something. Relevant tracking issue: rust-lang#123076 r? ````@ghost````
- Loading branch information
Showing
34 changed files
with
1,923 additions
and
336 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...oc/unstable-book/src/language-features/ref-pat-eat-one-layer-2024-structural.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# `ref_pat_eat_one_layer_2024_structural` | ||
|
||
The tracking issue for this feature is: [#123076] | ||
|
||
[#123076]: https://github.com/rust-lang/rust/issues/123076 | ||
|
||
--- | ||
|
||
This feature is incomplete and not yet intended for general use. | ||
|
||
This implements experimental, Edition-dependent match ergonomics under consideration for inclusion | ||
in Rust. | ||
For more information, see the corresponding typing rules for [Editions 2024 and later]. | ||
On earlier Editions, the current behavior is unspecified. | ||
|
||
For alternative experimental match ergonomics, see the feature | ||
[`ref_pat_eat_one_layer_2024`](./ref-pat-eat-one-layer-2024.md). | ||
|
||
[Editions 2024 and later]: https://nadrieril.github.io/typing-rust-patterns/?compare=false&opts1=AQEBAgEBAQEBAgIAAAAAAAAAAAAAAAA%3D&mode=rules&do_cmp=false |
19 changes: 19 additions & 0 deletions
19
src/doc/unstable-book/src/language-features/ref-pat-eat-one-layer-2024.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# `ref_pat_eat_one_layer_2024` | ||
|
||
The tracking issue for this feature is: [#123076] | ||
|
||
[#123076]: https://github.com/rust-lang/rust/issues/123076 | ||
|
||
--- | ||
|
||
This feature is incomplete and not yet intended for general use. | ||
|
||
This implements experimental, Edition-dependent match ergonomics under consideration for inclusion | ||
in Rust. | ||
For more information, see the corresponding typing rules for [Editions 2024 and later]. | ||
On earlier Editions, the current behavior is unspecified. | ||
|
||
For alternative experimental match ergonomics, see the feature | ||
[`ref_pat_eat_one_layer_2024_structural`](./ref-pat-eat-one-layer-2024-structural.md). | ||
|
||
[Editions 2024 and later]: https://nadrieril.github.io/typing-rust-patterns/?compare=false&opts1=AQEBAAABAQABAgIAAQEBAAEBAAABAAA%3D&mode=rules&do_cmp=false |
79 changes: 79 additions & 0 deletions
79
...ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.classic2024.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
error[E0508]: cannot move out of type `[&mut u32; 1]`, a non-copy array | ||
--> $DIR/borrowck-errors.rs:13:16 | ||
| | ||
LL | let [&x] = &[&mut 0]; | ||
| - ^^^^^^^^^ cannot move out of here | ||
| | | ||
| data moved here | ||
| move occurs because `x` has type `&mut u32`, which does not implement the `Copy` trait | ||
| | ||
help: consider borrowing the pattern binding | ||
| | ||
LL | let [&ref x] = &[&mut 0]; | ||
| +++ | ||
|
||
error[E0508]: cannot move out of type `[&mut u32; 1]`, a non-copy array | ||
--> $DIR/borrowck-errors.rs:19:16 | ||
| | ||
LL | let [&x] = &mut [&mut 0]; | ||
| - ^^^^^^^^^^^^^ cannot move out of here | ||
| | | ||
| data moved here | ||
| move occurs because `x` has type `&mut u32`, which does not implement the `Copy` trait | ||
| | ||
help: consider borrowing the pattern binding | ||
| | ||
LL | let [&ref x] = &mut [&mut 0]; | ||
| +++ | ||
|
||
error[E0507]: cannot move out of a shared reference | ||
--> $DIR/borrowck-errors.rs:27:29 | ||
| | ||
LL | if let Some(&Some(x)) = Some(&Some(&mut 0)) { | ||
| - ^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| data moved here | ||
| move occurs because `x` has type `&mut u32`, which does not implement the `Copy` trait | ||
| | ||
help: consider removing the borrow | ||
| | ||
LL - if let Some(&Some(x)) = Some(&Some(&mut 0)) { | ||
LL + if let Some(Some(x)) = Some(&Some(&mut 0)) { | ||
| | ||
|
||
error[E0596]: cannot borrow data in a `&` reference as mutable | ||
--> $DIR/borrowck-errors.rs:32:10 | ||
| | ||
LL | let &ref mut x = &0; | ||
| ^^^^^^^^^ cannot borrow as mutable | ||
|
||
error[E0596]: cannot borrow data in a `&` reference as mutable | ||
--> $DIR/borrowck-errors.rs:35:23 | ||
| | ||
LL | if let &Some(Some(x)) = &Some(&mut Some(0)) { | ||
| ^ cannot borrow as mutable | ||
|
||
error[E0596]: cannot borrow data in a `&` reference as mutable | ||
--> $DIR/borrowck-errors.rs:40:11 | ||
| | ||
LL | let &[x] = &&mut [0]; | ||
| ^ cannot borrow as mutable | ||
|
||
error[E0508]: cannot move out of type `[&mut i32; 1]`, a non-copy array | ||
--> $DIR/borrowck-errors.rs:44:20 | ||
| | ||
LL | let [&mut x] = &mut [&mut 0]; | ||
| - ^^^^^^^^^^^^^ cannot move out of here | ||
| | | ||
| data moved here | ||
| move occurs because `x` has type `&mut i32`, which does not implement the `Copy` trait | ||
| | ||
help: consider borrowing the pattern binding | ||
| | ||
LL | let [&mut ref x] = &mut [&mut 0]; | ||
| +++ | ||
|
||
error: aborting due to 7 previous errors | ||
|
||
Some errors have detailed explanations: E0507, E0508, E0596. | ||
For more information about an error, try `rustc --explain E0507`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
.../ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.stable2021.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/borrowck-errors.rs:13:10 | ||
| | ||
LL | let [&x] = &[&mut 0]; | ||
| ^^ --------- this expression has type `&[&mut {integer}; 1]` | ||
| | | ||
| types differ in mutability | ||
| | ||
= note: expected mutable reference `&mut {integer}` | ||
found reference `&_` | ||
help: consider removing `&` from the pattern | ||
| | ||
LL - let [&x] = &[&mut 0]; | ||
LL + let [x] = &[&mut 0]; | ||
| | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/borrowck-errors.rs:19:10 | ||
| | ||
LL | let [&x] = &mut [&mut 0]; | ||
| ^^ ------------- this expression has type `&mut [&mut {integer}; 1]` | ||
| | | ||
| types differ in mutability | ||
| | ||
= note: expected mutable reference `&mut {integer}` | ||
found reference `&_` | ||
help: consider removing `&` from the pattern | ||
| | ||
LL - let [&x] = &mut [&mut 0]; | ||
LL + let [x] = &mut [&mut 0]; | ||
| | ||
|
||
error[E0507]: cannot move out of a shared reference | ||
--> $DIR/borrowck-errors.rs:27:29 | ||
| | ||
LL | if let Some(&Some(x)) = Some(&Some(&mut 0)) { | ||
| - ^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| data moved here | ||
| move occurs because `x` has type `&mut u32`, which does not implement the `Copy` trait | ||
| | ||
help: consider removing the borrow | ||
| | ||
LL - if let Some(&Some(x)) = Some(&Some(&mut 0)) { | ||
LL + if let Some(Some(x)) = Some(&Some(&mut 0)) { | ||
| | ||
|
||
error[E0596]: cannot borrow data in a `&` reference as mutable | ||
--> $DIR/borrowck-errors.rs:32:10 | ||
| | ||
LL | let &ref mut x = &0; | ||
| ^^^^^^^^^ cannot borrow as mutable | ||
|
||
error[E0596]: cannot borrow data in a `&` reference as mutable | ||
--> $DIR/borrowck-errors.rs:35:23 | ||
| | ||
LL | if let &Some(Some(x)) = &Some(&mut Some(0)) { | ||
| ^ cannot borrow as mutable | ||
|
||
error[E0596]: cannot borrow data in a `&` reference as mutable | ||
--> $DIR/borrowck-errors.rs:40:11 | ||
| | ||
LL | let &[x] = &&mut [0]; | ||
| ^ cannot borrow as mutable | ||
|
||
error: aborting due to 6 previous errors | ||
|
||
Some errors have detailed explanations: E0308, E0507, E0596. | ||
For more information about an error, try `rustc --explain E0308`. |
25 changes: 0 additions & 25 deletions
25
.../ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.structural.stderr
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.