forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
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#121716 - Nadrieril:simple-binding-order, r=…
…matthewjasper match lowering: Lower bindings in a predictable order After the recent refactorings, we can now lower bindings in a truly predictable order. The order in rust-lang#120214 was an improvement but not very clear. With this PR, we lower bindings from left to right, with the special case that `x @ pat` is traversed as `pat @ x` (i.e. `x` is lowered after any bindings in `pat`). This description only applies in the absence of or-patterns. Or-patterns make everything complicated, because the binding place depends on the subpattern. Until I have a better idea I leave them to be handled in whatever weird order arises from today's code. r? `@matthewjasper`
- Loading branch information
Showing
11 changed files
with
118 additions
and
100 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
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
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
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,17 @@ | ||
//@ known-bug: unknown | ||
#![allow(unused)] | ||
|
||
struct A(u32); | ||
|
||
pub fn main() { | ||
// The or-pattern bindings are lowered after `x`, which triggers the error. | ||
let x @ (A(a) | A(a)) = A(10); | ||
// ERROR: use of moved value | ||
assert!(x.0 == 10); | ||
assert!(a == 10); | ||
|
||
// This works. | ||
let (x @ A(a) | x @ A(a)) = A(10); | ||
assert!(x.0 == 10); | ||
assert!(a == 10); | ||
} |
31 changes: 31 additions & 0 deletions
31
tests/ui/pattern/bindings-after-at/bind-by-copy-or-pat.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,31 @@ | ||
error[E0382]: use of moved value | ||
--> $DIR/bind-by-copy-or-pat.rs:8:16 | ||
| | ||
LL | let x @ (A(a) | A(a)) = A(10); | ||
| - ^ ----- move occurs because value has type `A`, which does not implement the `Copy` trait | ||
| | | | ||
| | value used here after move | ||
| value moved here | ||
| | ||
help: borrow this binding in the pattern to avoid moving the value | ||
| | ||
LL | let ref x @ (A(a) | A(a)) = A(10); | ||
| +++ | ||
|
||
error[E0382]: use of moved value | ||
--> $DIR/bind-by-copy-or-pat.rs:8:23 | ||
| | ||
LL | let x @ (A(a) | A(a)) = A(10); | ||
| - ^ ----- move occurs because value has type `A`, which does not implement the `Copy` trait | ||
| | | | ||
| | value used here after move | ||
| value moved here | ||
| | ||
help: borrow this binding in the pattern to avoid moving the value | ||
| | ||
LL | let ref x @ (A(a) | A(a)) = A(10); | ||
| +++ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0382`. |