Skip to content

Commit bddfece

Browse files
committed
Don't sanity check function pointers in vtables
1 parent d600a94 commit bddfece

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

src/librustc/ty/layout.rs

+2-16
Original file line numberDiff line numberDiff line change
@@ -1621,25 +1621,11 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
16211621
match tcx.struct_tail(pointee).sty {
16221622
ty::TySlice(_) |
16231623
ty::TyStr => tcx.types.usize,
1624-
ty::TyDynamic(data, _) => {
1625-
let trait_def_id = data.principal().unwrap().def_id();
1626-
let num_fns: u64 = crate::traits::supertrait_def_ids(tcx, trait_def_id)
1627-
.map(|trait_def_id| {
1628-
tcx.associated_items(trait_def_id)
1629-
.filter(|item| item.kind == ty::AssociatedKind::Method)
1630-
.count() as u64
1631-
})
1632-
.sum();
1624+
ty::TyDynamic(_, _) => {
16331625
tcx.mk_imm_ref(
16341626
tcx.types.re_static,
1635-
tcx.mk_array(tcx.types.usize, 3 + num_fns),
1636-
)
1637-
/* FIXME use actual fn pointers
1638-
tcx.mk_tup(&[
16391627
tcx.mk_array(tcx.types.usize, 3),
1640-
tcx.mk_array(Option<fn()>),
1641-
])
1642-
*/
1628+
)
16431629
}
16441630
_ => bug!("TyLayout::field_type({:?}): not applicable", this)
16451631
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-pass
12+
13+
pub const STATIC_TRAIT: &Test = &();
14+
15+
fn main() {}
16+
17+
pub trait Test {
18+
fn test() where Self: Sized {}
19+
}
20+
21+
impl Test for () {}

0 commit comments

Comments
 (0)