@@ -193,7 +193,7 @@ pub struct Cache {
193
193
pub implementors : HashMap < ast:: DefId , Vec < Implementor > > ,
194
194
195
195
/// Cache of where external crate documentation can be found.
196
- pub extern_locations : HashMap < ast:: CrateNum , ExternalLocation > ,
196
+ pub extern_locations : HashMap < ast:: CrateNum , ( String , ExternalLocation ) > ,
197
197
198
198
/// Cache of where documentation for primitives can be found.
199
199
pub primitive_locations : HashMap < clean:: PrimitiveType , ast:: CrateNum > ,
@@ -408,7 +408,8 @@ pub fn run(mut krate: clean::Crate,
408
408
409
409
// Cache where all our extern crates are located
410
410
for & ( n, ref e) in & krate. externs {
411
- cache. extern_locations . insert ( n, extern_location ( e, & cx. dst ) ) ;
411
+ cache. extern_locations . insert ( n, ( e. name . clone ( ) ,
412
+ extern_location ( e, & cx. dst ) ) ) ;
412
413
let did = ast:: DefId { krate : n, node : ast:: CRATE_NODE_ID } ;
413
414
cache. paths . insert ( did, ( vec ! [ e. name. to_string( ) ] , ItemType :: Module ) ) ;
414
415
}
@@ -1343,22 +1344,43 @@ impl<'a> Item<'a> {
1343
1344
/// may happen, for example, with externally inlined items where the source
1344
1345
/// of their crate documentation isn't known.
1345
1346
fn href ( & self , cx : & Context ) -> Option < String > {
1347
+ let href = if self . item . source . loline == self . item . source . hiline {
1348
+ format ! ( "{}" , self . item. source. loline)
1349
+ } else {
1350
+ format ! ( "{}-{}" , self . item. source. loline, self . item. source. hiline)
1351
+ } ;
1352
+
1353
+ // First check to see if this is an imported macro source. In this case
1354
+ // we need to handle it specially as cross-crate inlined macros have...
1355
+ // odd locations!
1356
+ let imported_macro_from = match self . item . inner {
1357
+ clean:: MacroItem ( ref m) => m. imported_from . as_ref ( ) ,
1358
+ _ => None ,
1359
+ } ;
1360
+ if let Some ( krate) = imported_macro_from {
1361
+ let cache = cache ( ) ;
1362
+ let root = cache. extern_locations . values ( ) . find ( |& & ( ref n, _) | {
1363
+ * krate == * n
1364
+ } ) . map ( |l| & l. 1 ) ;
1365
+ let root = match root {
1366
+ Some ( & Remote ( ref s) ) => s. to_string ( ) ,
1367
+ Some ( & Local ) => self . cx . root_path . clone ( ) ,
1368
+ None | Some ( & Unknown ) => return None ,
1369
+ } ;
1370
+ Some ( format ! ( "{root}/{krate}/macro.{name}.html?gotomacrosrc=1" ,
1371
+ root = root,
1372
+ krate = krate,
1373
+ name = self . item. name. as_ref( ) . unwrap( ) ) )
1374
+
1346
1375
// If this item is part of the local crate, then we're guaranteed to
1347
1376
// know the span, so we plow forward and generate a proper url. The url
1348
1377
// has anchors for the line numbers that we're linking to.
1349
- if ast_util:: is_local ( self . item . def_id ) {
1378
+ } else if ast_util:: is_local ( self . item . def_id ) {
1350
1379
let mut path = Vec :: new ( ) ;
1351
1380
clean_srcpath ( & cx. src_root , Path :: new ( & self . item . source . filename ) ,
1352
1381
true , |component| {
1353
1382
path. push ( component. to_string ( ) ) ;
1354
1383
} ) ;
1355
- let href = if self . item . source . loline == self . item . source . hiline {
1356
- format ! ( "{}" , self . item. source. loline)
1357
- } else {
1358
- format ! ( "{}-{}" ,
1359
- self . item. source. loline,
1360
- self . item. source. hiline)
1361
- } ;
1362
1384
Some ( format ! ( "{root}src/{krate}/{path}.html#{href}" ,
1363
1385
root = self . cx. root_path,
1364
1386
krate = self . cx. layout. krate,
@@ -1380,9 +1402,9 @@ impl<'a> Item<'a> {
1380
1402
let cache = cache ( ) ;
1381
1403
let path = & cache. external_paths [ & self . item . def_id ] ;
1382
1404
let root = match cache. extern_locations [ & self . item . def_id . krate ] {
1383
- Remote ( ref s) => s. to_string ( ) ,
1384
- Local => self . cx . root_path . clone ( ) ,
1385
- Unknown => return None ,
1405
+ ( _ , Remote ( ref s) ) => s. to_string ( ) ,
1406
+ ( _ , Local ) => self . cx . root_path . clone ( ) ,
1407
+ ( _ , Unknown ) => return None ,
1386
1408
} ;
1387
1409
Some ( format ! ( "{root}{path}/{file}?gotosrc={goto}" ,
1388
1410
root = root,
@@ -1444,7 +1466,8 @@ impl<'a> fmt::Display for Item<'a> {
1444
1466
if self . cx . include_sources && !is_primitive {
1445
1467
match self . href ( self . cx ) {
1446
1468
Some ( l) => {
1447
- try!( write ! ( fmt, "<a id='src-{}' href='{}'>[src]</a>" ,
1469
+ try!( write ! ( fmt, "<a id='src-{}' class='srclink' \
1470
+ href='{}'>[src]</a>",
1448
1471
self . item. def_id. node, l) ) ;
1449
1472
}
1450
1473
None => { }
0 commit comments