diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2021-11-26 16:02:26 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-26 16:02:26 +0100 |
| commit | 13c60669ccb75c6a3036570645c2a995b0cc26a9 (patch) | |
| tree | 332d29095ef18cf4dd9b77812405c1c8245f724f /src | |
| parent | fdc305d58d7cf93703a47118538f04b2b53c2873 (diff) | |
| parent | 69d1917672d302e2da14ad6673e6a0478c62d1ad (diff) | |
| download | rust-13c60669ccb75c6a3036570645c2a995b0cc26a9.tar.gz rust-13c60669ccb75c6a3036570645c2a995b0cc26a9.zip | |
Rollup merge of #91212 - compiler-errors:issue91206, r=oli-obk
Fix ICE due to out-of-bounds statement index when reporting borrowck error Replace an `[index]` with a `.get` when `statement_index` points to a basic-block terminator (and is therefore out-of-bounds in the statements list). Fixes #91206 Cc ``@camsteffen`` r? ``@oli-obk``
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui/borrowck/issue-91206.rs | 15 | ||||
| -rw-r--r-- | src/test/ui/borrowck/issue-91206.stderr | 12 |
2 files changed, 27 insertions, 0 deletions
diff --git a/src/test/ui/borrowck/issue-91206.rs b/src/test/ui/borrowck/issue-91206.rs new file mode 100644 index 00000000000..3b1fbf4b699 --- /dev/null +++ b/src/test/ui/borrowck/issue-91206.rs @@ -0,0 +1,15 @@ +struct TestClient; + +impl TestClient { + fn get_inner_ref(&self) -> &Vec<usize> { + todo!() + } +} + +fn main() { + let client = TestClient; + let inner = client.get_inner_ref(); + //~^ HELP consider changing this to be a mutable reference + inner.clear(); + //~^ ERROR cannot borrow `*inner` as mutable, as it is behind a `&` reference [E0596] +} diff --git a/src/test/ui/borrowck/issue-91206.stderr b/src/test/ui/borrowck/issue-91206.stderr new file mode 100644 index 00000000000..535d247452a --- /dev/null +++ b/src/test/ui/borrowck/issue-91206.stderr @@ -0,0 +1,12 @@ +error[E0596]: cannot borrow `*inner` as mutable, as it is behind a `&` reference + --> $DIR/issue-91206.rs:13:5 + | +LL | let inner = client.get_inner_ref(); + | ----- help: consider changing this to be a mutable reference: `&mut Vec<usize>` +LL | +LL | inner.clear(); + | ^^^^^^^^^^^^^ `inner` is a `&` reference, so the data it refers to cannot be borrowed as mutable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0596`. |
