mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Auto merge of #60048 - estebank:issue-54954, r=sanxiyn
Fix ICE on const evaluation of const method Fix #54954.
This commit is contained in:
commit
be1dbaffed
@ -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)
|
||||
}
|
||||
}
|
||||
|
19
src/test/ui/issues/issue-54954.rs
Normal file
19
src/test/ui/issues/issue-54954.rs
Normal 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]);
|
||||
}
|
16
src/test/ui/issues/issue-54954.stderr
Normal file
16
src/test/ui/issues/issue-54954.stderr
Normal 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`.
|
Loading…
Reference in New Issue
Block a user