forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
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#136093 - dianne:match-2024-for-edition-2021…
…, r=Nadrieril Match Ergonomics 2024: update old-edition behavior of feature gates This updates the behavior of the feature gates `ref_pat_eat_one_layer_2024_structural` and `ref_pat_eat_one_layer_2024` in Editions 2021 and earlier to correspond to the left and right typing rules compared [here](https://nadrieril.github.io/typing-rust-patterns/?opts1=AQEBAQIBAQEBAAAAAAAAAAAAAAAAAAA%3D&style=UserVisible&compare=true&opts2=AQEBAQIBAQABAAAAAQEBAAEBAAABAAA%3D&mode=rules), respectively. Compared to the `stable_rust` rules: - they both allow reference patterns to match a lone inherited ref, - they both allow `&` patterns to eat `&mut` reference types (and lone `&mut` inherited refs) as if they're shared, - they both allow `&mut` patterns to eat `&` reference types when there's a `&mut` inherited reference to also eat, - and the left ruleset has RFC 3627's Rule 3: after encountering a shared reference type in the scrutinee, the default binding mode will be treated as by-shared-ref when it would otherwise be by-mutable-ref. I think there's already tests for all of those typing rules, so I've added revisions to use the existing tests with the new rulesets. Additionally, I've added a few tests to make sure we handle mixed-edition patterns appropriately, and I've added references to the unstable book. Relevant tracking issue: rust-lang#123076 r? ``@ghost``
- Loading branch information
Showing
45 changed files
with
1,866 additions
and
523 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
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
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
48 changes: 48 additions & 0 deletions
48
...ui/pattern/rfc-3627-match-ergonomics-2024/experimental/auxiliary/mixed-editions-macros.rs
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,48 @@ | ||
//@[classic2021] edition: 2024 | ||
//@[structural2021] edition: 2024 | ||
//@[classic2024] edition: 2021 | ||
//@[structural2024] edition: 2021 | ||
//! This contains macros in an edition *different* to the one used in `../mixed-editions.rs`, in | ||
//! order to test typing mixed-edition patterns. | ||
#[macro_export] | ||
macro_rules! match_ctor { | ||
($p:pat) => { | ||
[$p] | ||
}; | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! match_ref { | ||
($p:pat) => { | ||
&$p | ||
}; | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! bind { | ||
($i:ident) => { | ||
$i | ||
} | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! bind_ref { | ||
($i:ident) => { | ||
ref $i | ||
} | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! bind_mut { | ||
($i:ident) => { | ||
mut $i | ||
} | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! bind_ref_mut { | ||
($i:ident) => { | ||
ref mut $i | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.classic2021.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,37 @@ | ||
error[E0507]: cannot move out of a shared reference | ||
--> $DIR/borrowck-errors.rs:31: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:36: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:41: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:46:11 | ||
| | ||
LL | let &[x] = &&mut [0]; | ||
| ^ cannot borrow as mutable | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
Some errors have detailed explanations: E0507, 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
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
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
Oops, something went wrong.