File tree Expand file tree Collapse file tree 2 files changed +26
-10
lines changed Expand file tree Collapse file tree 2 files changed +26
-10
lines changed Original file line number Diff line number Diff line change @@ -52,13 +52,36 @@ impl<'de> serde::de::Deserialize<'de> for RustdocExternMode {
5252 }
5353}
5454
55- #[ derive( serde:: Deserialize , Debug , Default ) ]
55+ #[ derive( serde:: Deserialize , Debug ) ]
5656#[ serde( default ) ]
5757pub struct RustdocExternMap {
58+ #[ serde( deserialize_with = "default_crates_io_to_docs_rs" ) ]
5859 pub ( crate ) registries : HashMap < String , String > ,
5960 std : Option < RustdocExternMode > ,
6061}
6162
63+ impl Default for RustdocExternMap {
64+ fn default ( ) -> Self {
65+ let mut registries = HashMap :: new ( ) ;
66+ registries. insert ( "crates-io" . into ( ) , "https://docs.rs/" . into ( ) ) ;
67+ Self {
68+ registries,
69+ std : None ,
70+ }
71+ }
72+ }
73+
74+ fn default_crates_io_to_docs_rs < ' de , D : serde:: Deserializer < ' de > > (
75+ de : D ,
76+ ) -> Result < HashMap < String , String > , D :: Error > {
77+ use serde:: Deserialize ;
78+ let mut registries = HashMap :: deserialize ( de) ?;
79+ if !registries. contains_key ( "crates-io" ) {
80+ registries. insert ( "crates-io" . into ( ) , "https://docs.rs/" . into ( ) ) ;
81+ }
82+ Ok ( registries)
83+ }
84+
6285impl hash:: Hash for RustdocExternMap {
6386 fn hash < H : hash:: Hasher > ( & self , into : & mut H ) {
6487 self . std . hash ( into) ;
Original file line number Diff line number Diff line change @@ -1217,15 +1217,8 @@ impl Config {
12171217 // Note: This does not support environment variables. The `Unit`
12181218 // fundamentally does not have access to the registry name, so there is
12191219 // nothing to query. Plumbing the name into SourceId is quite challenging.
1220- self . doc_extern_map . try_borrow_with ( || {
1221- let mut extern_map = self . get :: < RustdocExternMap > ( "doc.extern-map" ) ;
1222- if let Ok ( map) = & mut extern_map {
1223- map. registries
1224- . entry ( "crates-io" . into ( ) )
1225- . or_insert ( "https://docs.rs/" . into ( ) ) ;
1226- }
1227- extern_map
1228- } )
1220+ self . doc_extern_map
1221+ . try_borrow_with ( || self . get :: < RustdocExternMap > ( "doc.extern-map" ) )
12291222 }
12301223
12311224 /// Returns the `[target]` table definition for the given target triple.
You can’t perform that action at this time.
0 commit comments