@@ -2548,15 +2548,38 @@ pub fn type_is_enum(ty: t) -> bool {
2548
2548
// Is the type's representation size known at compile time?
2549
2549
pub fn type_is_sized ( cx : ctxt , ty : ty:: t ) -> bool {
2550
2550
match get ( ty) . sty {
2551
- // FIXME(#6308) add trait, vec, str, etc here.
2551
+ /* Container types depend on their elements. */
2552
+ ty_enum( did, ref substs) => {
2553
+ let variants = enum_variants ( cx, did) ;
2554
+ do variants. all |variant| {
2555
+ let tup_ty = mk_tup ( cx, /*bad*/ copy variant. args ) ;
2556
+ let tup_ty = subst ( cx, substs, tup_ty) ;
2557
+ type_is_sized ( cx, tup_ty)
2558
+ }
2559
+ } ,
2560
+ ty_tup( ref elts) => {
2561
+ do elts. all |elt| { type_is_sized ( cx, * elt) }
2562
+ } ,
2563
+ ty_struct( did, ref substs) => {
2564
+ do lookup_struct_fields ( cx, did) . all |f| {
2565
+ let fty = ty:: lookup_item_type ( cx, f. id ) ;
2566
+ let sty = subst ( cx, substs, fty. ty ) ;
2567
+ type_is_sized ( cx, sty)
2568
+ }
2569
+ } ,
2570
+ ty_evec( ref mt, vstore_fixed( _) ) => {
2571
+ type_is_sized ( cx, mt. ty )
2572
+ } ,
2573
+ /* Type parameters must have "Sized" bound. */
2552
2574
ty_param( p) => {
2553
2575
let param_def = cx. ty_param_defs . get ( & p. def_id . node ) ;
2554
- if param_def. bounds . builtin_bounds . contains_elem ( BoundSized ) {
2555
- return true ;
2556
- }
2557
- return false ;
2576
+ param_def. bounds . builtin_bounds . contains_elem ( BoundSized )
2558
2577
} ,
2559
- _ => return true ,
2578
+ /* Dynamically-sized types. */
2579
+ // FIXME(#6308) add bare trait, vec, str, etc => false
2580
+ ty_unboxed_vec( * ) => false ,
2581
+ /* Primitives and pointers are all sized. */
2582
+ _ => true ,
2560
2583
}
2561
2584
}
2562
2585
0 commit comments