@@ -670,15 +670,7 @@ pub enum Type {
670670 ResolvedPath {
671671 pub path : Path ,
672672 pub typarams : Option < Vec < TyParamBound > > ,
673- pub id : ast:: NodeId ,
674- } ,
675- /// Same as above, but only external variants
676- ExternalPath {
677- pub path : Path ,
678- pub typarams : Option < Vec < TyParamBound > > ,
679- pub fqn : Vec < ~str > ,
680- pub kind : TypeKind ,
681- pub krate : ast:: CrateNum ,
673+ pub did : ast:: DefId ,
682674 } ,
683675 // I have no idea how to usefully use this.
684676 TyParamBinder ( ast:: NodeId ) ,
@@ -715,19 +707,18 @@ pub enum Type {
715707
716708#[ deriving( Clone , Encodable , Decodable ) ]
717709pub enum TypeKind {
718- TypeStruct ,
719710 TypeEnum ,
720- TypeTrait ,
721711 TypeFunction ,
712+ TypeModule ,
713+ TypeStatic ,
714+ TypeStruct ,
715+ TypeTrait ,
716+ TypeVariant ,
722717}
723718
724719impl Clean < Type > for ast:: Ty {
725720 fn clean ( & self ) -> Type {
726721 use syntax:: ast:: * ;
727- debug ! ( "cleaning type `{:?}`" , self ) ;
728- let ctxt = super :: ctxtkey. get ( ) . unwrap ( ) ;
729- let codemap = ctxt. sess ( ) . codemap ( ) ;
730- debug ! ( "span corresponds to `{}`" , codemap. span_to_str( self . span) ) ;
731722 match self . node {
732723 TyNil => Unit ,
733724 TyPtr ( ref m) => RawPointer ( m. mutbl . clean ( ) , box m. ty . clean ( ) ) ,
@@ -1153,7 +1144,7 @@ pub enum ViewPath {
11531144 // use source::*;
11541145 GlobImport ( ImportSource ) ,
11551146 // use source::{a, b, c};
1156- ImportList ( ImportSource , Vec < ViewListIdent > ) ,
1147+ ImportList ( ImportSource , Vec < ViewListIdent > ) ,
11571148}
11581149
11591150#[ deriving( Clone , Encodable , Decodable ) ]
@@ -1298,48 +1289,47 @@ fn resolve_type(path: Path, tpbs: Option<Vec<TyParamBound> >,
12981289 core:: NotTyped ( _) => return Bool
12991290 } ;
13001291 debug ! ( "searching for {:?} in defmap" , id) ;
1301- let d = match tycx. def_map . borrow ( ) . find ( & id) {
1292+ let def = match tycx. def_map . borrow ( ) . find ( & id) {
13021293 Some ( & k) => k,
1303- None => {
1304- debug ! ( "could not find {:?} in defmap (`{}`)" , id, tycx. map. node_to_str( id) ) ;
1305- fail ! ( "Unexpected failure: unresolved id not in defmap (this is a bug!)" )
1306- }
1294+ None => fail ! ( "unresolved id not in defmap" )
13071295 } ;
13081296
1309- let ( def_id, kind) = match d {
1310- ast:: DefFn ( i, _) => ( i, TypeFunction ) ,
1297+ match def {
13111298 ast:: DefSelfTy ( i) => return Self ( i) ,
1312- ast:: DefTy ( i) => ( i, TypeEnum ) ,
1313- ast:: DefTrait ( i) => {
1314- debug ! ( "saw DefTrait in def_to_id" ) ;
1315- ( i, TypeTrait )
1316- } ,
13171299 ast:: DefPrimTy ( p) => match p {
13181300 ast:: TyStr => return String ,
13191301 ast:: TyBool => return Bool ,
13201302 _ => return Primitive ( p)
13211303 } ,
13221304 ast:: DefTyParam ( i, _) => return Generic ( i. node ) ,
1305+ ast:: DefTyParamBinder ( i) => return TyParamBinder ( i) ,
1306+ _ => { }
1307+ } ;
1308+ let did = register_def ( & * * cx, def) ;
1309+ ResolvedPath { path : path, typarams : tpbs, did : did }
1310+ }
1311+
1312+ fn register_def ( cx : & core:: DocContext , def : ast:: Def ) -> ast:: DefId {
1313+ let ( did, kind) = match def {
1314+ ast:: DefFn ( i, _) => ( i, TypeFunction ) ,
1315+ ast:: DefTy ( i) => ( i, TypeEnum ) ,
1316+ ast:: DefTrait ( i) => ( i, TypeTrait ) ,
13231317 ast:: DefStruct ( i) => ( i, TypeStruct ) ,
1324- ast:: DefTyParamBinder ( i) => {
1325- debug ! ( "found a typaram_binder, what is it? {}" , i) ;
1326- return TyParamBinder ( i) ;
1327- } ,
1328- x => fail ! ( "resolved type maps to a weird def {:?}" , x) ,
1318+ ast:: DefMod ( i) => ( i, TypeModule ) ,
1319+ ast:: DefStatic ( i, _) => ( i, TypeStatic ) ,
1320+ ast:: DefVariant ( i, _, _) => ( i, TypeEnum ) ,
1321+ _ => return ast_util:: def_id_of_def ( def) ,
13291322 } ;
1330- if ast_util:: is_local ( def_id) {
1331- ResolvedPath { path : path, typarams : tpbs, id : def_id. node }
1332- } else {
1333- let fqn = csearch:: get_item_path ( tycx, def_id) ;
1334- let fqn = fqn. move_iter ( ) . map ( |i| i. to_str ( ) ) . collect ( ) ;
1335- ExternalPath {
1336- path : path,
1337- typarams : tpbs,
1338- fqn : fqn,
1339- kind : kind,
1340- krate : def_id. krate ,
1341- }
1342- }
1323+ if ast_util:: is_local ( did) { return did }
1324+ let tcx = match cx. maybe_typed {
1325+ core:: Typed ( ref t) => t,
1326+ core:: NotTyped ( _) => return did
1327+ } ;
1328+ let fqn = csearch:: get_item_path ( tcx, did) ;
1329+ let fqn = fqn. move_iter ( ) . map ( |i| i. to_str ( ) ) . collect ( ) ;
1330+ debug ! ( "recording {} => {}" , did, fqn) ;
1331+ cx. external_paths . borrow_mut ( ) . get_mut_ref ( ) . insert ( did, ( fqn, kind) ) ;
1332+ return did;
13431333}
13441334
13451335fn resolve_use_source ( path : Path , id : ast:: NodeId ) -> ImportSource {
@@ -1353,7 +1343,7 @@ fn resolve_def(id: ast::NodeId) -> Option<ast::DefId> {
13531343 let cx = super :: ctxtkey. get ( ) . unwrap ( ) ;
13541344 match cx. maybe_typed {
13551345 core:: Typed ( ref tcx) => {
1356- tcx. def_map . borrow ( ) . find ( & id) . map ( |& d| ast_util :: def_id_of_def ( d ) )
1346+ tcx. def_map . borrow ( ) . find ( & id) . map ( |& def| register_def ( & * * cx , def ) )
13571347 }
13581348 core:: NotTyped ( _) => None
13591349 }
0 commit comments