Fix ICE on const evaluation of const method

This commit is contained in:
Esteban Küber 2019-04-17 12:00:35 -07:00
parent 70f130954d
commit d56c82074b
3 changed files with 48 additions and 0 deletions

View file

@ -1007,6 +1007,16 @@ impl<'tcx> FnSig<'tcx> {
pub fn output(&self) -> Ty<'tcx> {
self.inputs_and_output[self.inputs_and_output.len() - 1]
}
// Create a minimal `FnSig` to be used when encountering a `TyKind::Error` in a fallible method
fn fake() -> FnSig<'tcx> {
FnSig {
inputs_and_output: List::empty(),
c_variadic: false,
unsafety: hir::Unsafety::Normal,
abi: abi::Abi::Rust,
}
}
}
pub type PolyFnSig<'tcx> = Binder<FnSig<'tcx>>;
@ -1955,6 +1965,9 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
tcx.fn_sig(def_id).subst(tcx, substs)
}
FnPtr(f) => f,
Error => { // ignore errors (#54954)
ty::Binder::dummy(FnSig::fake())
}
_ => bug!("Ty::fn_sig() called on non-fn type: {:?}", self)
}
}

View file

@ -0,0 +1,19 @@
#![feature(const_fn)]
const ARR_LEN: usize = Tt::const_val::<[i8; 123]>();
//~^ ERROR constant contains unimplemented expression type
trait Tt {
const fn const_val<T: Sized>() -> usize {
//~^ ERROR trait fns cannot be declared const
core::mem::size_of::<T>()
}
}
fn f(z: [f32; ARR_LEN]) -> [f32; ARR_LEN] {
z
}
fn main() {
let _ = f([1f32; ARR_LEN]);
}

View file

@ -0,0 +1,16 @@
error[E0379]: trait fns cannot be declared const
--> $DIR/issue-54954.rs:7:5
|
LL | const fn const_val<T: Sized>() -> usize {
| ^^^^^ trait fns cannot be const
error[E0019]: constant contains unimplemented expression type
--> $DIR/issue-54954.rs:3:24
|
LL | const ARR_LEN: usize = Tt::const_val::<[i8; 123]>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
Some errors occurred: E0019, E0379.
For more information about an error, try `rustc --explain E0019`.