@@ -24,6 +24,7 @@ use syntax::codemap::Pos;
24
24
use rustc:: metadata:: cstore;
25
25
use rustc:: metadata:: csearch;
26
26
use rustc:: metadata:: decoder;
27
+ use rustc:: middle:: ty;
27
28
28
29
use std;
29
30
use std:: hashmap:: HashMap ;
@@ -182,6 +183,7 @@ pub enum ItemEnum {
182
183
VariantItem ( Variant ) ,
183
184
ForeignFunctionItem ( Function ) ,
184
185
ForeignStaticItem ( Static ) ,
186
+ PrimitiveType ( ast:: PrimTy ) ,
185
187
}
186
188
187
189
#[ deriving( Clone , Encodable , Decodable ) ]
@@ -196,6 +198,8 @@ impl Clean<Item> for doctree::Module {
196
198
} else {
197
199
~""
198
200
} ;
201
+ let impls = self . impls . clean ( ) ;
202
+ let impls = impls. move_iter ( ) . flat_map ( |i| i. move_iter ( ) ) . collect ( ) ;
199
203
Item {
200
204
name : Some ( name) ,
201
205
attrs : self . attrs . clean ( ) ,
@@ -207,7 +211,7 @@ impl Clean<Item> for doctree::Module {
207
211
self . fns . clean ( ) , self . foreigns . clean ( ) . concat_vec ( ) ,
208
212
self . mods . clean ( ) , self . typedefs . clean ( ) ,
209
213
self . statics . clean ( ) , self . traits . clean ( ) ,
210
- self . impls . clean ( ) , self . view_items . clean ( ) ] . concat_vec ( )
214
+ impls, self . view_items . clean ( ) ] . concat_vec ( )
211
215
} )
212
216
}
213
217
}
@@ -615,6 +619,7 @@ pub enum TypeKind {
615
619
TypeEnum ,
616
620
TypeTrait ,
617
621
TypeFunction ,
622
+ TypePrimitive ,
618
623
}
619
624
620
625
impl Clean < Type > for ast:: Ty {
@@ -961,23 +966,100 @@ pub struct Impl {
961
966
trait_ : Option < Type > ,
962
967
for_ : Type ,
963
968
methods : ~[ Item ] ,
969
+ is_primitive_impl : bool ,
964
970
}
965
971
966
- impl Clean < Item > for doctree:: Impl {
967
- fn clean ( & self ) -> Item {
968
- Item {
972
+ impl Clean < ~[ Item ] > for doctree:: Impl {
973
+ fn clean ( & self ) -> ~[ Item ] {
974
+ let tcx = local_data:: get ( super :: ctxtkey, |x| * x. unwrap ( ) ) . tycx ;
975
+ let is_primitive_impl = match tcx {
976
+ Some ( tcx) => {
977
+ let did = Some ( ast:: DefId {
978
+ node : self . id ,
979
+ crate : ast:: LOCAL_CRATE ,
980
+ } ) ;
981
+ did == tcx. lang_items . char_impl ( ) ||
982
+ did == tcx. lang_items . bool_impl ( ) ||
983
+ did == tcx. lang_items . u8_impl ( ) ||
984
+ did == tcx. lang_items . u16_impl ( ) ||
985
+ did == tcx. lang_items . u32_impl ( ) ||
986
+ did == tcx. lang_items . u64_impl ( ) ||
987
+ did == tcx. lang_items . uint_impl ( ) ||
988
+ did == tcx. lang_items . i8_impl ( ) ||
989
+ did == tcx. lang_items . i16_impl ( ) ||
990
+ did == tcx. lang_items . i32_impl ( ) ||
991
+ did == tcx. lang_items . i64_impl ( ) ||
992
+ did == tcx. lang_items . int_impl ( ) ||
993
+ did == tcx. lang_items . f32_impl ( ) ||
994
+ did == tcx. lang_items . f64_impl ( )
995
+ }
996
+ None => false
997
+ } ;
998
+ let mut items = ~[ ] ;
999
+ if is_primitive_impl {
1000
+ items. push ( primitive_item ( self ) ) ;
1001
+ }
1002
+ items. push ( Item {
969
1003
name : None ,
970
- attrs : self . attrs . clean ( ) ,
1004
+ attrs : if is_primitive_impl { ~ [ ] } else { self . attrs . clean ( ) } ,
971
1005
source : self . where . clean ( ) ,
972
1006
id : self . id ,
973
1007
visibility : self . vis . clean ( ) ,
974
1008
inner : ImplItem ( Impl {
1009
+ is_primitive_impl : is_primitive_impl,
975
1010
generics : self . generics . clean ( ) ,
976
1011
trait_ : self . trait_ . clean ( ) ,
977
1012
for_ : self . for_ . clean ( ) ,
978
1013
methods : self . methods . clean ( ) ,
979
1014
} ) ,
1015
+ } ) ;
1016
+ return items;
1017
+ }
1018
+ }
1019
+
1020
+ fn primitive_item ( imp : & doctree:: Impl ) -> Item {
1021
+ let tcx = local_data:: get ( super :: ctxtkey, |x| * x. unwrap ( ) ) . tycx . unwrap ( ) ;
1022
+ let def_map = tcx. def_map . borrow ( ) ;
1023
+ let id = match imp. for_ . node {
1024
+ ast:: TyPath ( _, _, id) => id,
1025
+ _ => fail ! ( "not a primitive path" ) ,
1026
+ } ;
1027
+ let d = def_map. get ( ) . get ( & id) ;
1028
+
1029
+ macro_rules! primitive( ( $li: ident, $prim: expr) => ( {
1030
+ match tycx. lang_items. $li( ) {
1031
+ Some ( did) => ( did, TypePrimitive ) ,
1032
+ None => return if $prim == ast:: TyBool { Bool } else { Primitive ( $prim) }
980
1033
}
1034
+ } ) )
1035
+
1036
+ let ( ty, name, prim_ty) = match * d {
1037
+ ast:: DefPrimTy ( p) => match p {
1038
+ ast:: TyBool => ( ty:: mk_bool ( ) , "bool" , p) ,
1039
+ ast:: TyChar => ( ty:: mk_char ( ) , "char" , p) ,
1040
+ ast:: TyFloat ( ast:: TyF32 ) => ( ty:: mk_f32 ( ) , "f32" , p) ,
1041
+ ast:: TyFloat ( ast:: TyF64 ) => ( ty:: mk_f64 ( ) , "f64" , p) ,
1042
+ ast:: TyUint ( ast:: TyU ) => ( ty:: mk_uint ( ) , "uint" , p) ,
1043
+ ast:: TyUint ( ast:: TyU8 ) => ( ty:: mk_u8 ( ) , "u8" , p) ,
1044
+ ast:: TyUint ( ast:: TyU16 ) => ( ty:: mk_u16 ( ) , "u16" , p) ,
1045
+ ast:: TyUint ( ast:: TyU32 ) => ( ty:: mk_u32 ( ) , "u32" , p) ,
1046
+ ast:: TyUint ( ast:: TyU64 ) => ( ty:: mk_u64 ( ) , "u64" , p) ,
1047
+ ast:: TyInt ( ast:: TyI ) => ( ty:: mk_int ( ) , "int" , p) ,
1048
+ ast:: TyInt ( ast:: TyI8 ) => ( ty:: mk_i8 ( ) , "i8" , p) ,
1049
+ ast:: TyInt ( ast:: TyI16 ) => ( ty:: mk_i16 ( ) , "i16" , p) ,
1050
+ ast:: TyInt ( ast:: TyI32 ) => ( ty:: mk_i32 ( ) , "i32" , p) ,
1051
+ ast:: TyInt ( ast:: TyI64 ) => ( ty:: mk_i64 ( ) , "i64" , p) ,
1052
+ ast:: TyStr => fail ! ( "can't handle string primitive yet" ) ,
1053
+ } ,
1054
+ x => fail ! ( "resolved type maps to not a primitive {:?}" , x) ,
1055
+ } ;
1056
+ Item {
1057
+ name : Some ( name. to_owned ( ) ) ,
1058
+ attrs : imp. attrs . clean ( ) ,
1059
+ source : imp. where . clean ( ) ,
1060
+ id : ty:: maybe_prim_did ( tcx, ty) . unwrap ( ) . node ,
1061
+ visibility : ast:: Public . clean ( ) ,
1062
+ inner : PrimitiveType ( prim_ty) ,
981
1063
}
982
1064
}
983
1065
@@ -1176,6 +1258,15 @@ fn resolve_type(path: Path, tpbs: Option<~[TyParamBound]>,
1176
1258
}
1177
1259
} ;
1178
1260
1261
+ macro_rules! primitive( ( $ty: expr, $prim: expr) => ( {
1262
+ match ty:: maybe_prim_did( tycx, $ty) {
1263
+ Some ( did) => ( did, TypePrimitive ) ,
1264
+ None => {
1265
+ return if $prim == ast:: TyBool { Bool } else { Primitive ( $prim) }
1266
+ }
1267
+ }
1268
+ } ) )
1269
+
1179
1270
let ( def_id, kind) = match * d {
1180
1271
ast:: DefFn ( i, _) => ( i, TypeFunction ) ,
1181
1272
ast:: DefSelf ( i, _) | ast:: DefSelfTy ( i) => return Self ( i) ,
@@ -1186,8 +1277,20 @@ fn resolve_type(path: Path, tpbs: Option<~[TyParamBound]>,
1186
1277
} ,
1187
1278
ast:: DefPrimTy ( p) => match p {
1188
1279
ast:: TyStr => return String ,
1189
- ast:: TyBool => return Bool ,
1190
- _ => return Primitive ( p)
1280
+ ast:: TyBool => primitive!( ty:: mk_bool( ) , p) ,
1281
+ ast:: TyChar => primitive!( ty:: mk_char( ) , p) ,
1282
+ ast:: TyFloat ( ast:: TyF32 ) => primitive!( ty:: mk_f32( ) , p) ,
1283
+ ast:: TyFloat ( ast:: TyF64 ) => primitive!( ty:: mk_f64( ) , p) ,
1284
+ ast:: TyUint ( ast:: TyU ) => primitive!( ty:: mk_uint( ) , p) ,
1285
+ ast:: TyUint ( ast:: TyU8 ) => primitive!( ty:: mk_u8( ) , p) ,
1286
+ ast:: TyUint ( ast:: TyU16 ) => primitive!( ty:: mk_u16( ) , p) ,
1287
+ ast:: TyUint ( ast:: TyU32 ) => primitive!( ty:: mk_u32( ) , p) ,
1288
+ ast:: TyUint ( ast:: TyU64 ) => primitive!( ty:: mk_u64( ) , p) ,
1289
+ ast:: TyInt ( ast:: TyI ) => primitive!( ty:: mk_int( ) , p) ,
1290
+ ast:: TyInt ( ast:: TyI8 ) => primitive!( ty:: mk_i8( ) , p) ,
1291
+ ast:: TyInt ( ast:: TyI16 ) => primitive!( ty:: mk_i16( ) , p) ,
1292
+ ast:: TyInt ( ast:: TyI32 ) => primitive!( ty:: mk_i32( ) , p) ,
1293
+ ast:: TyInt ( ast:: TyI64 ) => primitive!( ty:: mk_i64( ) , p) ,
1191
1294
} ,
1192
1295
ast:: DefTyParam ( i, _) => return Generic ( i. node) ,
1193
1296
ast:: DefStruct ( i) => ( i, TypeStruct ) ,
@@ -1200,7 +1303,30 @@ fn resolve_type(path: Path, tpbs: Option<~[TyParamBound]>,
1200
1303
if ast_util:: is_local( def_id) {
1201
1304
ResolvedPath { path: path, typarams: tpbs, id: def_id. node }
1202
1305
} else {
1203
- let fqn = csearch:: get_item_path( tycx, def_id) ;
1306
+ let fqn = match * d {
1307
+ ast:: DefPrimTy ( p) => {
1308
+ let did = match p {
1309
+ ast:: TyBool => tycx. lang_items. bool_impl( ) ,
1310
+ ast:: TyChar => tycx. lang_items. char_impl( ) ,
1311
+ ast:: TyFloat ( ast:: TyF32 ) => tycx. lang_items. f32_impl( ) ,
1312
+ ast:: TyFloat ( ast:: TyF64 ) => tycx. lang_items. f64_impl( ) ,
1313
+ ast:: TyInt ( ast:: TyI ) => tycx. lang_items. int_impl( ) ,
1314
+ ast:: TyInt ( ast:: TyI8 ) => tycx. lang_items. i8_impl( ) ,
1315
+ ast:: TyInt ( ast:: TyI16 ) => tycx. lang_items. i16_impl( ) ,
1316
+ ast:: TyInt ( ast:: TyI32 ) => tycx. lang_items. i32_impl( ) ,
1317
+ ast:: TyInt ( ast:: TyI64 ) => tycx. lang_items. i64_impl( ) ,
1318
+ ast:: TyUint ( ast:: TyU ) => tycx. lang_items. uint_impl( ) ,
1319
+ ast:: TyUint ( ast:: TyU8 ) => tycx. lang_items. u8_impl( ) ,
1320
+ ast:: TyUint ( ast:: TyU16 ) => tycx. lang_items. u16_impl( ) ,
1321
+ ast:: TyUint ( ast:: TyU32 ) => tycx. lang_items. u32_impl( ) ,
1322
+ ast:: TyUint ( ast:: TyU64 ) => tycx. lang_items. u64_impl( ) ,
1323
+
1324
+ _ => None ,
1325
+ } ;
1326
+ csearch:: get_item_path( tycx, did. unwrap( ) )
1327
+ }
1328
+ _ => csearch:: get_item_path( tycx, def_id)
1329
+ } ;
1204
1330
let fqn = fqn. move_iter( ) . map( |i| {
1205
1331
match i {
1206
1332
ast_map:: PathMod ( id) | ast_map:: PathName ( id) |
0 commit comments