Skip to content

Commit 5b88fba

Browse files
committed
Check FnHeader not to cause ICE
1 parent 082cf2f commit 5b88fba

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

src/librustc/middle/reachable.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,15 @@ fn item_might_be_inlined(tcx: TyCtxt<'tcx>, item: &hir::Item, attrs: CodegenFnAt
3232
return true
3333
}
3434

35-
match item.node {
36-
hir::ItemKind::Impl(..) |
37-
hir::ItemKind::Fn(..) => {
35+
match item.node {
36+
hir::ItemKind::Fn(_, header, ..) => {
37+
if header.constness == hir::Constness::Const {
38+
return true;
39+
}
40+
let generics = tcx.generics_of(tcx.hir().local_def_id(item.hir_id));
41+
generics.requires_monomorphization(tcx)
42+
}
43+
hir::ItemKind::Impl(..) => {
3844
let generics = tcx.generics_of(tcx.hir().local_def_id(item.hir_id));
3945
generics.requires_monomorphization(tcx)
4046
}
@@ -52,6 +58,11 @@ fn method_might_be_inlined(
5258
if codegen_fn_attrs.requests_inline() || generics.requires_monomorphization(tcx) {
5359
return true
5460
}
61+
if let hir::ImplItemKind::Method(method_sig, _) = &impl_item.node {
62+
if method_sig.header.constness == hir::Constness::Const {
63+
return true
64+
}
65+
}
5566
if let Some(impl_hir_id) = tcx.hir().as_local_hir_id(impl_src) {
5667
match tcx.hir().find(impl_hir_id) {
5768
Some(Node::Item(item)) =>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pub struct VTable{
2+
state:extern fn(),
3+
}
4+
5+
impl VTable{
6+
pub const fn vtable()->&'static VTable{
7+
Self::VTABLE
8+
}
9+
10+
const VTABLE: &'static VTable =
11+
&VTable{state};
12+
}
13+
14+
extern fn state() {}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// aux-build:issue-63226.rs
2+
// compile-flags:--extern issue_63226
3+
// edition:2018
4+
// build-pass
5+
6+
use issue_63226::VTable;
7+
8+
static ICE_ICE:&'static VTable=VTable::vtable();
9+
10+
fn main() {}

0 commit comments

Comments
 (0)