diff --git a/tests/ui/swap.rs b/tests/ui/swap.rs index b508c1ee0096..f5e9182bed1e 100644 --- a/tests/ui/swap.rs +++ b/tests/ui/swap.rs @@ -46,6 +46,15 @@ fn slice() { foo.swap(0, 1); } +fn unswappable_slice() { + let foo = &mut [vec![1, 2], vec![3, 4]]; + let temp = foo[0][1]; + foo[0][1] = foo[1][0]; + foo[1][0] = temp; + + // swap(foo[0][1], foo[1][0]) would fail +} + fn vec() { let mut foo = vec![1, 2]; let temp = foo[0]; diff --git a/tests/ui/swap.stderr b/tests/ui/swap.stderr index b45187b58050..f3622230042b 100644 --- a/tests/ui/swap.stderr +++ b/tests/ui/swap.stderr @@ -17,7 +17,7 @@ LL | | foo[1] = temp; | |_________________^ help: try: `foo.swap(0, 1)` error: this looks like you are swapping elements of `foo` manually - --> $DIR/swap.rs:51:5 + --> $DIR/swap.rs:60:5 | LL | / let temp = foo[0]; LL | | foo[0] = foo[1]; @@ -25,7 +25,7 @@ LL | | foo[1] = temp; | |_________________^ help: try: `foo.swap(0, 1)` error: this looks like you are swapping `a` and `b` manually - --> $DIR/swap.rs:71:7 + --> $DIR/swap.rs:80:7 | LL | ; let t = a; | _______^ @@ -36,7 +36,7 @@ LL | | b = t; = note: or maybe you should use `std::mem::replace`? error: this looks like you are swapping `c.0` and `a` manually - --> $DIR/swap.rs:80:7 + --> $DIR/swap.rs:89:7 | LL | ; let t = c.0; | _______^ @@ -47,7 +47,7 @@ LL | | a = t; = note: or maybe you should use `std::mem::replace`? error: this looks like you are trying to swap `a` and `b` - --> $DIR/swap.rs:68:5 + --> $DIR/swap.rs:77:5 | LL | / a = b; LL | | b = a; @@ -57,7 +57,7 @@ LL | | b = a; = note: or maybe you should use `std::mem::replace`? error: this looks like you are trying to swap `c.0` and `a` - --> $DIR/swap.rs:77:5 + --> $DIR/swap.rs:86:5 | LL | / c.0 = a; LL | | a = c.0;