Skip to content

Commit f6725c0

Browse files
committed
fix fn_sig ice
1 parent 6e63f7b commit f6725c0

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
242242
// impl trait is gone in MIR, so check the return type of a const fn by its signature
243243
// instead of the type of the return place.
244244
self.span = body.local_decls[RETURN_PLACE].source_info.span;
245-
let return_ty = tcx.fn_sig(def_id).output();
245+
let return_ty = self.ccx.fn_sig().output();
246246
self.check_local_or_return_ty(return_ty.skip_binder(), RETURN_PLACE);
247247
}
248248

compiler/rustc_const_eval/src/transform/check_consts/mod.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_attr as attr;
88
use rustc_hir as hir;
99
use rustc_hir::def_id::{DefId, LocalDefId};
1010
use rustc_middle::mir;
11-
use rustc_middle::ty::{self, TyCtxt};
11+
use rustc_middle::ty::{self, TyCtxt, PolyFnSig};
1212
use rustc_span::Symbol;
1313

1414
pub use self::qualifs::Qualif;
@@ -64,6 +64,17 @@ impl<'mir, 'tcx> ConstCx<'mir, 'tcx> {
6464
fn is_async(&self) -> bool {
6565
self.tcx.asyncness(self.def_id()).is_async()
6666
}
67+
68+
pub fn fn_sig(&self) -> PolyFnSig<'tcx> {
69+
let did = self.def_id().to_def_id();
70+
if self.tcx.is_closure(did) {
71+
let ty = self.tcx.type_of(did);
72+
let ty::Closure(_, substs) = ty.kind() else { bug!("type_of closure not ty::Closure") };
73+
substs.as_closure().sig()
74+
} else {
75+
self.tcx.fn_sig(did)
76+
}
77+
}
6778
}
6879

6980
pub fn rustc_allow_const_fn_unstable(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![feature(const_closures, const_trait_impl)]
2+
#![allow(incomplete_features)]
3+
4+
trait Foo {
5+
fn foo(&self);
6+
}
7+
8+
impl Foo for () {
9+
fn foo(&self) {}
10+
}
11+
12+
fn main() {
13+
(const || { (()).foo() })();
14+
//~^ ERROR: cannot call non-const fn
15+
}

0 commit comments

Comments
 (0)