]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/ty/layout.rs
Sanity-check all constants
[rust.git] / src / librustc / ty / layout.rs
index faad32a5d994ec3402fa659295787672457ce82b..81cc897232ab05da5b11bfc8f0885a56971a890b 100644 (file)
@@ -1599,7 +1599,7 @@ fn field(this: TyLayout<'tcx>, cx: C, i: usize) -> C::TyLayout {
             // Potentially-fat pointers.
             ty::TyRef(_, pointee, _) |
             ty::TyRawPtr(ty::TypeAndMut { ty: pointee, .. }) => {
-                assert!(i < 2);
+                assert!(i < this.fields.count());
 
                 // Reuse the fat *T type as its own thin pointer data field.
                 // This provides information about e.g. DST struct pointees
@@ -1621,10 +1621,25 @@ fn field(this: TyLayout<'tcx>, cx: C, i: usize) -> C::TyLayout {
                 match tcx.struct_tail(pointee).sty {
                     ty::TySlice(_) |
                     ty::TyStr => tcx.types.usize,
-                    ty::TyDynamic(..) => {
-                        // FIXME(eddyb) use an usize/fn() array with
-                        // the correct number of vtables slots.
-                        tcx.mk_imm_ref(tcx.types.re_static, tcx.mk_nil())
+                    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();
+                        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<fn()>),
+                        ])
+                        */
                     }
                     _ => bug!("TyLayout::field_type({:?}): not applicable", this)
                 }