From bddfece3a84594aa61248d8cf4beeb35c70d29ed Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Thu, 16 Aug 2018 14:20:16 +0200 Subject: [PATCH 1/2] Don't sanity check function pointers in vtables --- src/librustc/ty/layout.rs | 18 ++--------------- src/test/ui/consts/const-eval/issue-53401.rs | 21 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 16 deletions(-) create mode 100644 src/test/ui/consts/const-eval/issue-53401.rs diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index 81cc897232ab0..cded81ce239a7 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -1621,25 +1621,11 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx> match tcx.struct_tail(pointee).sty { ty::TySlice(_) | ty::TyStr => tcx.types.usize, - ty::TyDynamic(data, _) => { - let trait_def_id = data.principal().unwrap().def_id(); - let num_fns: u64 = crate::traits::supertrait_def_ids(tcx, trait_def_id) - .map(|trait_def_id| { - tcx.associated_items(trait_def_id) - .filter(|item| item.kind == ty::AssociatedKind::Method) - .count() as u64 - }) - .sum(); + ty::TyDynamic(_, _) => { tcx.mk_imm_ref( tcx.types.re_static, - tcx.mk_array(tcx.types.usize, 3 + num_fns), - ) - /* FIXME use actual fn pointers - tcx.mk_tup(&[ tcx.mk_array(tcx.types.usize, 3), - tcx.mk_array(Option), - ]) - */ + ) } _ => bug!("TyLayout::field_type({:?}): not applicable", this) } diff --git a/src/test/ui/consts/const-eval/issue-53401.rs b/src/test/ui/consts/const-eval/issue-53401.rs new file mode 100644 index 0000000000000..cb74f4f8f75f3 --- /dev/null +++ b/src/test/ui/consts/const-eval/issue-53401.rs @@ -0,0 +1,21 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-pass + +pub const STATIC_TRAIT: &Test = &(); + +fn main() {} + +pub trait Test { + fn test() where Self: Sized {} +} + +impl Test for () {} From 690c075e6b2709a8d881218dc714942db6a18061 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Sat, 25 Aug 2018 13:40:49 +0200 Subject: [PATCH 2/2] Update test --- src/test/codegen/function-arguments.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/codegen/function-arguments.rs b/src/test/codegen/function-arguments.rs index 09031508da1f7..0bd021f8ae2d6 100644 --- a/src/test/codegen/function-arguments.rs +++ b/src/test/codegen/function-arguments.rs @@ -120,13 +120,13 @@ pub fn unsafe_slice(_: &[UnsafeInner]) { pub fn str(_: &[u8]) { } -// CHECK: @trait_borrow({}* nonnull %arg0.0, [4 x [[USIZE]]]* noalias readonly dereferenceable({{.*}}) %arg0.1) +// CHECK: @trait_borrow({}* nonnull %arg0.0, [3 x [[USIZE]]]* noalias readonly dereferenceable({{.*}}) %arg0.1) // FIXME #25759 This should also have `nocapture` #[no_mangle] pub fn trait_borrow(_: &Drop) { } -// CHECK: @trait_box({}* noalias nonnull, [4 x [[USIZE]]]* noalias readonly dereferenceable({{.*}})) +// CHECK: @trait_box({}* noalias nonnull, [3 x [[USIZE]]]* noalias readonly dereferenceable({{.*}})) #[no_mangle] pub fn trait_box(_: Box) { }