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.
This commit is contained in:
Yuki Okushi 2020-01-15 21:51:43 +09:00 committed by GitHub
commit 89b065dbd2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 115 additions and 14 deletions

View file

@ -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() {}

View file

@ -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)]