-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set docs.rs as the default extern-map for crates.io #8877
Conversation
docs.rs
as the default extern-map for crates.ioLocally, the output looks like `'bar=...'`, but in CI the quotes are missing. Allow either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks and seems reasonable to me! Instead of manually adding this after deserializing, though, could this update the Deserialize
integration to add this in if it wasn't found previously? I think that would be a bit more natural to integrate with what we already have.
I'm not sure what you mean - |
I believe |
So, this is what I have so far for diff --git a/src/cargo/core/compiler/rustdoc.rs b/src/cargo/core/compiler/rustdoc.rs
index 18c6898ee..1008652c2 100644
--- a/src/cargo/core/compiler/rustdoc.rs
+++ b/src/cargo/core/compiler/rustdoc.rs
@@ -55,10 +55,32 @@ impl<'de> serde::de::Deserialize<'de> for RustdocExternMode {
#[derive(serde::Deserialize, Debug, Default)]
#[serde(default)]
pub struct RustdocExternMap {
+ #[serde(deserialize_with = "default_crates_io_to_docs_rs")]
pub(crate) registries: HashMap<String, String>,
std: Option<RustdocExternMode>,
}
+fn default_crates_io_to_docs_rs<'de, D: serde::Deserializer<'de>>(de: D) -> Result<HashMap<String, String>, D::Error> {
+ struct DocsrsDeserializer;
+ impl<'de> serde::de::Visitor<'de> for DocsrsDeserializer {
+ type Value = HashMap<String, String>;
+
+ fn expecting(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ Ok(())
+ }
+
+ fn visit_map<A: serde::de::MapAccess<'de>>(self, mut a: A) -> Result<Self::Value, A::Error> {
+ let mut map = HashMap::new();
+ while let Some((k, v)) = a.next_entry()? {
+ map.insert(k, v);
+ }
+ map.entry("crates-io".into()).or_insert("https://docs.rs/".into());
+ Ok(map)
+ }
+ }
+ de.deserialize_map(DocsrsDeserializer)
+}
+
impl hash::Hash for RustdocExternMap {
fn hash<H: hash::Hasher>(&self, into: &mut H) {
self.std.hash(into);
diff --git a/src/cargo/util/config/mod.rs b/src/cargo/util/config/mod.rs
index 24ac86e83..24a4e41c7 100644
--- a/src/cargo/util/config/mod.rs
+++ b/src/cargo/util/config/mod.rs
@@ -1218,13 +1218,7 @@ impl Config {
// fundamentally does not have access to the registry name, so there is
// nothing to query. Plumbing the name into SourceId is quite challenging.
self.doc_extern_map.try_borrow_with(|| {
- let mut extern_map = self.get::<RustdocExternMap>("doc.extern-map");
- if let Ok(map) = &mut extern_map {
- map.registries
- .entry("crates-io".into())
- .or_insert("https://docs.rs/".into());
- }
- extern_map
+ self.get::<RustdocExternMap>("doc.extern-map")
})
}
which fails with
and I'm starting to wonder whether this is worth it :/ It seems a lot more complicated than before. What's the reason for going through Deserialize directly? Is the idea that it will be consistent even if you use |
I don't think you need to deal with let map = HashMap::deserialize(d)?;
if !map.contains_key(...) {
map.insert(...);
} The reason I'm asking for the change is that it feels more idiomatic to fix this at the source rather than have it fixed after-the-fact once we've deserialized. That should ideally make future refactorings easier. |
Ok, I finally got this working with serde - the issue was that |
@bors: r+ 👍 |
📌 Commit 8a48c87 has been approved by |
☀️ Test successful - checks-actions |
Thanks for all the help getting this to work! You could probably tell this was my first time working with serde 😅 |
Update cargo 12 commits in bfca1cd22bf514d5f2b6c1089b0ded0ba7dfaa6e..63d0fe43449adcb316d34d98a982b597faca4178 2020-11-24 16:33:21 +0000 to 2020-12-02 01:44:30 +0000 - Add "--workspace" to update command (rust-lang/cargo#8725) - Add an FAQ for "Why is my crate rebuilt?" (rust-lang/cargo#8927) - Set docs.rs as the default extern-map for crates.io (rust-lang/cargo#8877) - remove extra whitespace when running cargo -Z help (rust-lang/cargo#8924) - Remove version from dev-dependencies to make it easier to publish. (rust-lang/cargo#8920) - update dependency queue to consider cost for each node (rust-lang/cargo#8908) - Fix some rustdoc warnings. (rust-lang/cargo#8911) - Bump miow dependency to not invalidly assume memory layout (rust-lang/cargo#8909) - Remove unnecessary trailing semicolons (rust-lang/cargo#8906) - Fix custom_target_dependency test. (rust-lang/cargo#8907) - fix: we don't ignore `version` for `git`/`path` deps now (rust-lang/cargo#8900) - doc (book): add "Getting Started" subsection: "Essential Terminology" (rust-lang/cargo#8855)
Helps address #8296, specifically the bit needed for rust-lang/docs.rs#1177.
r? @ehuss