diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2020-02-03 17:58:28 -0800 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2020-02-03 18:00:14 -0800 |
| commit | 0f73133be6a6915e2d5836ce9986eaffc1b2954d (patch) | |
| tree | 1e3d7407c8fed2ab2606758d19d6208527c3b49c /src/test | |
| parent | 994e5e74653ae4bfe51094ce487a8b63f30ad3a4 (diff) | |
| download | rust-0f73133be6a6915e2d5836ce9986eaffc1b2954d.tar.gz rust-0f73133be6a6915e2d5836ce9986eaffc1b2954d.zip | |
Suggest `split_at_mut` on multiple mutable index access
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/suggestions/suggest-split-at-mut.rs | 8 | ||||
| -rw-r--r-- | src/test/ui/suggestions/suggest-split-at-mut.stderr | 15 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/test/ui/suggestions/suggest-split-at-mut.rs b/src/test/ui/suggestions/suggest-split-at-mut.rs new file mode 100644 index 00000000000..d294c20b824 --- /dev/null +++ b/src/test/ui/suggestions/suggest-split-at-mut.rs @@ -0,0 +1,8 @@ +fn main() { + let mut foo = [1, 2, 3, 4]; + let a = &mut foo[2]; + let b = &mut foo[3]; //~ ERROR cannot borrow `foo[_]` as mutable more than once at a time + *a = 5; + *b = 6; + println!("{:?} {:?}", a, b); +} diff --git a/src/test/ui/suggestions/suggest-split-at-mut.stderr b/src/test/ui/suggestions/suggest-split-at-mut.stderr new file mode 100644 index 00000000000..330f012b2a9 --- /dev/null +++ b/src/test/ui/suggestions/suggest-split-at-mut.stderr @@ -0,0 +1,15 @@ +error[E0499]: cannot borrow `foo[_]` as mutable more than once at a time + --> $DIR/suggest-split-at-mut.rs:4:13 + | +LL | let a = &mut foo[2]; + | ----------- first mutable borrow occurs here +LL | let b = &mut foo[3]; + | ^^^^^^^^^^^ second mutable borrow occurs here +LL | *a = 5; + | ------ first borrow later used here + | + = help: consider using `.split_at_mut(position)` or similar method to obtain two mutable non-overlapping sub-slices + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0499`. |
