about summary refs log tree commit diff
path: root/src/test/ui
diff options
context:
space:
mode:
authorYuki Okushi <huyuumi.dev@gmail.com>2020-01-15 21:51:43 +0900
committerGitHub <noreply@github.com>2020-01-15 21:51:43 +0900
commit89b065dbd2b953ea3ae15ebfb67a799e8b0a3ecc (patch)
treeb64b104fcd7356a07d2e43c431389c559d1921d8 /src/test/ui
parente800fe199cbfbbaa46dfa519e46b594512c068be (diff)
parente390b91e5717a338db20360a1ddffa23ba66701d (diff)
downloadrust-89b065dbd2b953ea3ae15ebfb67a799e8b0a3ecc.tar.gz
rust-89b065dbd2b953ea3ae15ebfb67a799e8b0a3ecc.zip
Rollup merge of #67914 - Aaron1011:fix/const-prop-impossible, r=matthewjasper,oli-obk
Don't run const propagation on items with inconsistent bounds

Fixes #67696

Using `#![feature(trivial_bounds)]`, it's possible to write functions
with unsatisfiable 'where' clauses, making them uncallable. However, the
user can act as if these 'where' clauses are true inside the body of the
function, leading to code that would normally be impossible to write.

Since const propgation can run even without any user-written calls to a
function, we need to explcitly check for these uncallable functions.
Diffstat (limited to 'src/test/ui')
-rw-r--r--src/test/ui/consts/issue-67696-const-prop-ice.rs20
-rw-r--r--src/test/ui/trivial-bounds/trivial-bounds-inconsistent-associated-functions.rs6
2 files changed, 25 insertions, 1 deletions
diff --git a/src/test/ui/consts/issue-67696-const-prop-ice.rs b/src/test/ui/consts/issue-67696-const-prop-ice.rs
new file mode 100644
index 00000000000..ad52608b3f4
--- /dev/null
+++ b/src/test/ui/consts/issue-67696-const-prop-ice.rs
@@ -0,0 +1,20 @@
+// check-pass
+// compile-flags: --emit=mir,link
+// Checks that we don't ICE due to attempting to run const prop
+// on a function with unsatisifable 'where' clauses
+
+#![allow(unused)]
+
+trait A {
+    fn foo(&self) -> Self where Self: Copy;
+}
+
+impl A for [fn(&())] {
+    fn foo(&self) -> Self where Self: Copy { *(&[] as &[_]) }
+}
+
+impl A for i32 {
+    fn foo(&self) -> Self { 3 }
+}
+
+fn main() {}
diff --git a/src/test/ui/trivial-bounds/trivial-bounds-inconsistent-associated-functions.rs b/src/test/ui/trivial-bounds/trivial-bounds-inconsistent-associated-functions.rs
index 6450ddd1b67..69eee66e64d 100644
--- a/src/test/ui/trivial-bounds/trivial-bounds-inconsistent-associated-functions.rs
+++ b/src/test/ui/trivial-bounds/trivial-bounds-inconsistent-associated-functions.rs
@@ -1,4 +1,8 @@
-// run-pass
+// check-pass
+// compile-flags: --emit=mir,link
+// Force mir to be emitted, to ensure that const
+// propagation doesn't ICE on a function
+// with an 'impossible' body. See issue #67696
 // Inconsistent bounds with trait implementations
 
 #![feature(trivial_bounds)]