about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-10-14 13:21:46 +0000
committerbors <bors@rust-lang.org>2021-10-14 13:21:46 +0000
commit0a56eb11fafdd3c9d86c100b6b90505f5f9fdb00 (patch)
tree37f0352dc7c9bb2f06bdbf0728e83623b075a845 /src
parentc34ac8747ca96d09cb08b8f5adddead826e77c06 (diff)
parent8fc329f5d2305d2f127752e7af3a37e07a1a89dc (diff)
downloadrust-0a56eb11fafdd3c9d86c100b6b90505f5f9fdb00.tar.gz
rust-0a56eb11fafdd3c9d86c100b6b90505f5f9fdb00.zip
Auto merge of #88698 - Noble-Mushtak:master, r=nikomatsakis,oli-obk
Add check that live_region is live in sanitize_promoted

This pull request fixes #88434 by adding a check in `sanitize_promoted` to ensure that only regions which are actually live are added to the `liveness_constraints` of the `BorrowCheckContext`.

To implement this change, I needed to add a method to `LivenessValues` which gets the elements contained by a region:

    /// Returns an iterator of all the elements contained by the region `r`
    crate fn get_elements(&self, row: N) -> impl Iterator<Item = Location> + '_

Then, inside `sanitize_promoted`, we check whether the iterator returned by this method is non-empty to ensure that the region is actually live at at least one location before adding that region to the `liveness_constraints` of the `BorrowCheckContext`.

This is my first pull request to the Rust repo, so any feedback on how I can improve this pull request or if there is a better way to fix this issue would be very appreciated.
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/borrowck/issue-88434-minimal-example.rs13
-rw-r--r--src/test/ui/borrowck/issue-88434-minimal-example.stderr17
-rw-r--r--src/test/ui/borrowck/issue-88434-removal-index-should-be-less.rs13
-rw-r--r--src/test/ui/borrowck/issue-88434-removal-index-should-be-less.stderr17
4 files changed, 60 insertions, 0 deletions
diff --git a/src/test/ui/borrowck/issue-88434-minimal-example.rs b/src/test/ui/borrowck/issue-88434-minimal-example.rs
new file mode 100644
index 00000000000..db348a50aa4
--- /dev/null
+++ b/src/test/ui/borrowck/issue-88434-minimal-example.rs
@@ -0,0 +1,13 @@
+#![feature(const_fn_trait_bound)]
+// Regression test related to issue 88434
+
+const _CONST: &() = &f(&|_| {});
+
+const fn f<F>(_: &F)
+where
+    F: FnMut(&u8),
+{
+    panic!() //~ ERROR evaluation of constant value failed
+}
+
+fn main() { }
diff --git a/src/test/ui/borrowck/issue-88434-minimal-example.stderr b/src/test/ui/borrowck/issue-88434-minimal-example.stderr
new file mode 100644
index 00000000000..845e1bdba8f
--- /dev/null
+++ b/src/test/ui/borrowck/issue-88434-minimal-example.stderr
@@ -0,0 +1,17 @@
+error[E0080]: evaluation of constant value failed
+  --> $DIR/issue-88434-minimal-example.rs:10:5
+   |
+LL | const _CONST: &() = &f(&|_| {});
+   |                      ---------- inside `_CONST` at $DIR/issue-88434-minimal-example.rs:4:22
+...
+LL |     panic!()
+   |     ^^^^^^^^
+   |     |
+   |     the evaluated program panicked at 'explicit panic', $DIR/issue-88434-minimal-example.rs:10:5
+   |     inside `f::<[closure@$DIR/issue-88434-minimal-example.rs:4:25: 4:31]>` at $SRC_DIR/std/src/panic.rs:LL:COL
+   |
+   = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/borrowck/issue-88434-removal-index-should-be-less.rs b/src/test/ui/borrowck/issue-88434-removal-index-should-be-less.rs
new file mode 100644
index 00000000000..4db073c66b1
--- /dev/null
+++ b/src/test/ui/borrowck/issue-88434-removal-index-should-be-less.rs
@@ -0,0 +1,13 @@
+#![feature(const_fn_trait_bound)]
+// Regression test for issue 88434
+
+const _CONST: &[u8] = &f(&[], |_| {});
+
+const fn f<F>(_: &[u8], _: F) -> &[u8]
+where
+    F: FnMut(&u8),
+{
+    panic!() //~ ERROR evaluation of constant value failed
+}
+
+fn main() { }
diff --git a/src/test/ui/borrowck/issue-88434-removal-index-should-be-less.stderr b/src/test/ui/borrowck/issue-88434-removal-index-should-be-less.stderr
new file mode 100644
index 00000000000..8cbb6a6340c
--- /dev/null
+++ b/src/test/ui/borrowck/issue-88434-removal-index-should-be-less.stderr
@@ -0,0 +1,17 @@
+error[E0080]: evaluation of constant value failed
+  --> $DIR/issue-88434-removal-index-should-be-less.rs:10:5
+   |
+LL | const _CONST: &[u8] = &f(&[], |_| {});
+   |                        -------------- inside `_CONST` at $DIR/issue-88434-removal-index-should-be-less.rs:4:24
+...
+LL |     panic!()
+   |     ^^^^^^^^
+   |     |
+   |     the evaluated program panicked at 'explicit panic', $DIR/issue-88434-removal-index-should-be-less.rs:10:5
+   |     inside `f::<[closure@$DIR/issue-88434-removal-index-should-be-less.rs:4:31: 4:37]>` at $SRC_DIR/std/src/panic.rs:LL:COL
+   |
+   = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0080`.