Skip to content

Commit 49720ea

Browse files
committed
Auto merge of #53425 - oli-obk:validation, r=nikomatsakis
[beta] Don't sanity check function pointers in vtables cc #53401 There's no beta nomination because the full fix (#53424) is not backportable
2 parents 5c5be09 + 690c075 commit 49720ea

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
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
}

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)