@@ -692,9 +692,9 @@ pub fn trait_def_of_item(ccx: &CrateCtxt, it: &ast::Item) -> Rc<ty::TraitDef> {
692
692
_ => { }
693
693
}
694
694
695
- let ( generics, sized , supertraits) = match it. node {
696
- ast:: ItemTrait ( ref generics, sized , ref supertraits, _) => {
697
- ( generics, sized , supertraits)
695
+ let ( generics, unbound , supertraits) = match it. node {
696
+ ast:: ItemTrait ( ref generics, ref unbound , ref supertraits, _) => {
697
+ ( generics, unbound , supertraits)
698
698
}
699
699
ref s => {
700
700
tcx. sess . span_bug (
@@ -711,7 +711,7 @@ pub fn trait_def_of_item(ccx: &CrateCtxt, it: &ast::Item) -> Rc<ty::TraitDef> {
711
711
generics) ;
712
712
713
713
let builtin_bounds =
714
- ensure_supertraits ( ccx, it. id , it. span , supertraits, sized ) ;
714
+ ensure_supertraits ( ccx, it. id , it. span , supertraits, unbound ) ;
715
715
716
716
let substs = mk_item_substs ( ccx, & ty_generics) ;
717
717
let trait_def = Rc :: new ( ty:: TraitDef {
@@ -759,7 +759,7 @@ pub fn trait_def_of_item(ccx: &CrateCtxt, it: &ast::Item) -> Rc<ty::TraitDef> {
759
759
id : ast:: NodeId ,
760
760
sp : codemap:: Span ,
761
761
ast_trait_refs : & Vec < ast:: TraitRef > ,
762
- sized : ast:: Sized )
762
+ unbound : & Option < ast:: TyParamBound > )
763
763
-> ty:: BuiltinBounds
764
764
{
765
765
let tcx = ccx. tcx ;
@@ -798,15 +798,7 @@ pub fn trait_def_of_item(ccx: &CrateCtxt, it: &ast::Item) -> Rc<ty::TraitDef> {
798
798
}
799
799
}
800
800
801
- if sized == ast:: StaticSize {
802
- match tcx. lang_items . require ( SizedTraitLangItem ) {
803
- Ok ( def_id) => {
804
- ty:: try_add_builtin_trait ( tcx, def_id, & mut bounds) ;
805
- }
806
- Err ( s) => tcx. sess . err ( s. as_slice ( ) ) ,
807
- } ;
808
- }
809
-
801
+ add_unsized_bound ( ccx, unbound, & mut bounds, "trait" , sp) ;
810
802
tcx. supertraits . borrow_mut ( ) . insert ( local_def ( id) ,
811
803
Rc :: new ( ty_trait_refs) ) ;
812
804
bounds
@@ -974,6 +966,43 @@ fn ty_generics_for_fn_or_method(ccx: &CrateCtxt,
974
966
& generics. ty_params , base_generics)
975
967
}
976
968
969
+ // Add the Sized bound, unless the type parameter is marked as `Sized?`.
970
+ fn add_unsized_bound ( ccx : & CrateCtxt ,
971
+ unbound : & Option < ast:: TyParamBound > ,
972
+ bounds : & mut ty:: BuiltinBounds ,
973
+ desc : & str ,
974
+ span : Span ) {
975
+ let kind_id = ccx. tcx . lang_items . require ( SizedTraitLangItem ) ;
976
+ match unbound {
977
+ & Some ( TraitTyParamBound ( ref tpb) ) => {
978
+ // #FIXME(8559) currently requires the unbound to be built-in.
979
+ let trait_def_id = ty:: trait_ref_to_def_id ( ccx. tcx , tpb) ;
980
+ match kind_id {
981
+ Ok ( kind_id) if trait_def_id != kind_id => {
982
+ ccx. tcx . sess . span_warn ( span,
983
+ format ! ( "default bound relaxed \
984
+ for a {}, but this does \
985
+ nothing because the given \
986
+ bound is not a default. \
987
+ Only `Sized?` is supported.",
988
+ desc) . as_slice ( ) ) ;
989
+ ty:: try_add_builtin_trait ( ccx. tcx ,
990
+ kind_id,
991
+ bounds) ;
992
+ }
993
+ _ => { }
994
+ }
995
+ }
996
+ _ if kind_id. is_ok ( ) => {
997
+ ty:: try_add_builtin_trait ( ccx. tcx ,
998
+ kind_id. unwrap ( ) ,
999
+ bounds) ;
1000
+ }
1001
+ // No lang item for Sized, so we can't add it as a bound.
1002
+ _ => { }
1003
+ }
1004
+ }
1005
+
977
1006
fn ty_generics ( ccx : & CrateCtxt ,
978
1007
space : subst:: ParamSpace ,
979
1008
lifetimes : & Vec < ast:: Lifetime > ,
@@ -1016,7 +1045,7 @@ fn ty_generics(ccx: &CrateCtxt,
1016
1045
let bounds = Rc :: new ( compute_bounds ( ccx,
1017
1046
param_ty,
1018
1047
& param. bounds ,
1019
- param. sized ,
1048
+ & param. unbound ,
1020
1049
param. ident ,
1021
1050
param. span ) ) ;
1022
1051
let default = param. default . map ( |path| {
@@ -1056,7 +1085,7 @@ fn ty_generics(ccx: &CrateCtxt,
1056
1085
ccx : & CrateCtxt ,
1057
1086
param_ty : ty:: ParamTy ,
1058
1087
ast_bounds : & OwnedSlice < ast:: TyParamBound > ,
1059
- sized : ast:: Sized ,
1088
+ unbound : & Option < ast:: TyParamBound > ,
1060
1089
ident : ast:: Ident ,
1061
1090
span : Span ) -> ty:: ParamBounds
1062
1091
{
@@ -1113,15 +1142,11 @@ fn ty_generics(ccx: &CrateCtxt,
1113
1142
}
1114
1143
}
1115
1144
1116
- if sized == ast:: StaticSize {
1117
- match ccx. tcx . lang_items . require ( SizedTraitLangItem ) {
1118
- Ok ( def_id) => { ty:: try_add_builtin_trait ( ccx. tcx ,
1119
- def_id,
1120
- & mut param_bounds. builtin_bounds ) ; } ,
1121
- // Fixme(13367) after `type` makes it into the snapshot, we can check this properly
1122
- Err ( _s) => { } , //ccx.tcx.sess.err(s),
1123
- }
1124
- }
1145
+ add_unsized_bound ( ccx,
1146
+ unbound,
1147
+ & mut param_bounds. builtin_bounds ,
1148
+ "type parameter" ,
1149
+ span) ;
1125
1150
1126
1151
check_bounds_compatible ( ccx. tcx , & param_bounds, ident, span) ;
1127
1152
0 commit comments