Skip to content

Fix ICE on const evaluation of const method #60048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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`.