Skip to content

Commit 0e98621

Browse files
committed
Auto merge of #53757 - oli-obk:validation, r=RalfJung
Use partial but correct vtable layout r? @RalfJung who suggested to also do this change for nightly, not just beta
2 parents 03fe4c7 + f318ba2 commit 0e98621

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

src/librustc/ty/layout.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -1621,20 +1621,19 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
16211621
match tcx.struct_tail(pointee).sty {
16221622
ty::Slice(_) |
16231623
ty::Str => tcx.types.usize,
1624-
ty::Dynamic(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::Dynamic(_, _) => {
16331625
tcx.mk_imm_ref(
16341626
tcx.types.re_static,
1635-
tcx.mk_array(tcx.types.usize, 3 + num_fns),
1627+
tcx.mk_array(tcx.types.usize, 3),
16361628
)
16371629
/* FIXME use actual fn pointers
1630+
Warning: naively computing the number of entries in the
1631+
vtable by counting the methods on the trait + methods on
1632+
all parent traits does not work, because some methods can
1633+
be not object safe and thus excluded from the vtable.
1634+
Increase this counter if you tried to implement this but
1635+
failed to do it without duplicating a lot of code from
1636+
other places in the compiler: 2
16381637
tcx.mk_tup(&[
16391638
tcx.mk_array(tcx.types.usize, 3),
16401639
tcx.mk_array(Option<fn()>),

src/test/codegen/function-arguments.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,13 @@ pub fn unsafe_slice(_: &[UnsafeInner]) {
120120
pub fn str(_: &[u8]) {
121121
}
122122

123-
// CHECK: @trait_borrow({}* nonnull %arg0.0, [4 x [[USIZE]]]* noalias readonly dereferenceable({{.*}}) %arg0.1)
123+
// CHECK: @trait_borrow({}* nonnull %arg0.0, [3 x [[USIZE]]]* noalias readonly dereferenceable({{.*}}) %arg0.1)
124124
// FIXME #25759 This should also have `nocapture`
125125
#[no_mangle]
126126
pub fn trait_borrow(_: &Drop) {
127127
}
128128

129-
// CHECK: @trait_box({}* noalias nonnull, [4 x [[USIZE]]]* noalias readonly dereferenceable({{.*}}))
129+
// CHECK: @trait_box({}* noalias nonnull, [3 x [[USIZE]]]* noalias readonly dereferenceable({{.*}}))
130130
#[no_mangle]
131131
pub fn trait_box(_: Box<Drop>) {
132132
}
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)