Skip to content

Commit be1dbaf

Browse files
committed
Auto merge of #60048 - estebank:issue-54954, r=sanxiyn
Fix ICE on const evaluation of const method Fix #54954.
2 parents fb1b222 + d56c820 commit be1dbaf

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

src/librustc/ty/sty.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,16 @@ impl<'tcx> FnSig<'tcx> {
10071007
pub fn output(&self) -> Ty<'tcx> {
10081008
self.inputs_and_output[self.inputs_and_output.len() - 1]
10091009
}
1010+
1011+
// Create a minimal `FnSig` to be used when encountering a `TyKind::Error` in a fallible method
1012+
fn fake() -> FnSig<'tcx> {
1013+
FnSig {
1014+
inputs_and_output: List::empty(),
1015+
c_variadic: false,
1016+
unsafety: hir::Unsafety::Normal,
1017+
abi: abi::Abi::Rust,
1018+
}
1019+
}
10101020
}
10111021

10121022
pub type PolyFnSig<'tcx> = Binder<FnSig<'tcx>>;
@@ -1955,6 +1965,9 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
19551965
tcx.fn_sig(def_id).subst(tcx, substs)
19561966
}
19571967
FnPtr(f) => f,
1968+
Error => { // ignore errors (#54954)
1969+
ty::Binder::dummy(FnSig::fake())
1970+
}
19581971
_ => bug!("Ty::fn_sig() called on non-fn type: {:?}", self)
19591972
}
19601973
}

src/test/ui/issues/issue-54954.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![feature(const_fn)]
2+
3+
const ARR_LEN: usize = Tt::const_val::<[i8; 123]>();
4+
//~^ ERROR constant contains unimplemented expression type
5+
6+
trait Tt {
7+
const fn const_val<T: Sized>() -> usize {
8+
//~^ ERROR trait fns cannot be declared const
9+
core::mem::size_of::<T>()
10+
}
11+
}
12+
13+
fn f(z: [f32; ARR_LEN]) -> [f32; ARR_LEN] {
14+
z
15+
}
16+
17+
fn main() {
18+
let _ = f([1f32; ARR_LEN]);
19+
}

src/test/ui/issues/issue-54954.stderr

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

0 commit comments

Comments
 (0)