Skip to content

Commit

Permalink
Auto merge of #60048 - estebank:issue-54954, r=sanxiyn
Browse files Browse the repository at this point in the history
Fix ICE on const evaluation of const method

Fix #54954.
  • Loading branch information
bors committed Apr 18, 2019
2 parents fb1b222 + d56c820 commit be1dbaf
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/librustc/ty/sty.rs
Expand Up @@ -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>>;
Expand Down Expand Up @@ -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)
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/test/ui/issues/issue-54954.rs
@@ -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]);
}
16 changes: 16 additions & 0 deletions src/test/ui/issues/issue-54954.stderr
@@ -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`.

0 comments on commit be1dbaf

Please sign in to comment.