diff options
| author | Albert Larsan <74931857+albertlarsan68@users.noreply.github.com> | 2023-01-05 09:13:28 +0100 |
|---|---|---|
| committer | Albert Larsan <74931857+albertlarsan68@users.noreply.github.com> | 2023-01-11 09:32:08 +0000 |
| commit | cf2dff2b1e3fa55fa5415d524200070d0d7aacfe (patch) | |
| tree | 40a88d9a46aaf3e8870676eb2538378b75a263eb /src/test/ui/expr/compound-assignment | |
| parent | ca855e6e42787ecd062d81d53336fe6788ef51a9 (diff) | |
| download | rust-cf2dff2b1e3fa55fa5415d524200070d0d7aacfe.tar.gz rust-cf2dff2b1e3fa55fa5415d524200070d0d7aacfe.zip | |
Move /src/test to /tests
Diffstat (limited to 'src/test/ui/expr/compound-assignment')
| -rw-r--r-- | src/test/ui/expr/compound-assignment/eval-order.rs | 76 |
1 files changed, 0 insertions, 76 deletions
diff --git a/src/test/ui/expr/compound-assignment/eval-order.rs b/src/test/ui/expr/compound-assignment/eval-order.rs deleted file mode 100644 index 658adae193e..00000000000 --- a/src/test/ui/expr/compound-assignment/eval-order.rs +++ /dev/null @@ -1,76 +0,0 @@ -// Test evaluation order of operands of the compound assignment operators - -// run-pass - -use std::ops::AddAssign; - -enum Side { - Lhs, - Rhs, -} - -// In the following tests, we place our value into a wrapper type so that we -// can do an element access as the outer place expression. If we just had the -// block expression, it'd be a value expression and not compile. -struct Wrapper<T>(T); - -// Evaluation order for `a op= b` where typeof(a) and typeof(b) are primitives -// is first `b` then `a`. -fn primitive_compound() { - let mut side_order = vec![]; - let mut int = Wrapper(0); - - { - side_order.push(Side::Lhs); - int - }.0 += { - side_order.push(Side::Rhs); - 0 - }; - - assert!(matches!(side_order[..], [Side::Rhs, Side::Lhs])); -} - -// Evaluation order for `a op=b` otherwise is first `a` then `b`. -fn generic_compound<T: AddAssign<T> + Default>() { - let mut side_order = vec![]; - let mut add_assignable: Wrapper<T> = Wrapper(Default::default()); - - { - side_order.push(Side::Lhs); - add_assignable - }.0 += { - side_order.push(Side::Rhs); - Default::default() - }; - - assert!(matches!(side_order[..], [Side::Lhs, Side::Rhs])); -} - -fn custom_compound() { - struct Custom; - - impl AddAssign<()> for Custom { - fn add_assign(&mut self, _: ()) { - // this block purposely left blank - } - } - - let mut side_order = vec![]; - let mut custom = Wrapper(Custom); - - { - side_order.push(Side::Lhs); - custom - }.0 += { - side_order.push(Side::Rhs); - }; - - assert!(matches!(side_order[..], [Side::Lhs, Side::Rhs])); -} - -fn main() { - primitive_compound(); - generic_compound::<i32>(); - custom_compound(); -} |
