@@ -342,3 +342,85 @@ fn rebuilds_when_changing() {
342342        ) 
343343        . run ( ) ; 
344344} 
345+ 
346+ #[ cargo_test( nightly,  reason = "--extern-html-root-url is unstable" ) ]  
347+ fn  alt_sparse_registry ( )  { 
348+     // Supports other registry names. 
349+ 
350+     registry:: init ( ) ; 
351+     let  _registry = registry:: RegistryBuilder :: new ( ) 
352+         . http_index ( ) 
353+         . alternative ( ) 
354+         . build ( ) ; 
355+ 
356+     Package :: new ( "bar" ,  "1.0.0" ) 
357+         . alternative ( true ) 
358+         . file ( 
359+             "src/lib.rs" , 
360+             r#" 
361+                 extern crate baz; 
362+                 pub struct Queen; 
363+                 pub use baz::King; 
364+             "# , 
365+         ) 
366+         . registry_dep ( "baz" ,  "1.0" ) 
367+         . publish ( ) ; 
368+     Package :: new ( "baz" ,  "1.0.0" ) 
369+         . alternative ( true ) 
370+         . file ( "src/lib.rs" ,  "pub struct King;" ) 
371+         . publish ( ) ; 
372+     Package :: new ( "grimm" ,  "1.0.0" ) 
373+         . file ( "src/lib.rs" ,  "pub struct Gold;" ) 
374+         . publish ( ) ; 
375+ 
376+     let  p = project ( ) 
377+         . file ( 
378+             "Cargo.toml" , 
379+             r#" 
380+                 [package] 
381+                 name = "foo" 
382+                 version = "0.1.0" 
383+                 edition = "2018" 
384+ 
385+                 [dependencies] 
386+                 bar = { version = "1.0", registry="alternative" } 
387+                 grimm = "1.0" 
388+             "# , 
389+         ) 
390+         . file ( 
391+             "src/lib.rs" , 
392+             r#" 
393+                 pub fn queen() -> bar::Queen { bar::Queen } 
394+                 pub fn king() -> bar::King { bar::King } 
395+                 pub fn gold() -> grimm::Gold { grimm::Gold } 
396+             "# , 
397+         ) 
398+         . file ( 
399+             ".cargo/config" , 
400+             r#" 
401+                 [doc.extern-map.registries] 
402+                 alternative = "https://example.com/{pkg_name}/{version}/" 
403+                 crates-io = "https://docs.rs/" 
404+             "# , 
405+         ) 
406+         . build ( ) ; 
407+     p. cargo ( "doc -v --no-deps -Zrustdoc-map -Zsparse-registry" ) 
408+         . masquerade_as_nightly_cargo ( & [ "rustdoc-map" ,  "sparse-registry" ] ) 
409+         . with_stderr_contains ( 
410+             "[RUNNING] `rustdoc [..]--crate-name foo \  
411+ , 
412+         ) 
413+         . run ( ) ; 
414+     let  queen = p. read_file ( "target/doc/foo/fn.queen.html" ) ; 
415+     assert ! ( queen. contains( r#"href="https://example.com/bar/1.0.0/bar/struct.Queen.html""# ) ) ; 
416+     // The king example fails to link. Rustdoc seems to want the origin crate 
417+     // name (baz) for re-exports. There are many issues in the issue tracker 
418+     // for rustdoc re-exports, so I'm not sure, but I think this is maybe a 
419+     // rustdoc issue. Alternatively, Cargo could provide mappings for all 
420+     // transitive dependencies to fix this. 
421+     let  king = p. read_file ( "target/doc/foo/fn.king.html" ) ; 
422+     assert ! ( king. contains( r#"-> King"# ) ) ; 
423+ 
424+     let  gold = p. read_file ( "target/doc/foo/fn.gold.html" ) ; 
425+     assert ! ( gold. contains( r#"href="https://docs.rs/grimm/1.0.0/grimm/struct.Gold.html""# ) ) ; 
426+ } 
0 commit comments