diff --git a/src/cargo/core/features.rs b/src/cargo/core/features.rs index d86f3dfc454..93dfb5d359c 100644 --- a/src/cargo/core/features.rs +++ b/src/cargo/core/features.rs @@ -530,15 +530,9 @@ impl Features { } let see_docs = || { - let url_channel = match channel().as_str() { - "dev" | "nightly" => "nightly/", - "beta" => "beta/", - _ => "", - }; format!( - "See https://doc.rust-lang.org/{}cargo/{} for more information \ - about using this feature.", - url_channel, feature.docs + "See {} for more information about using this feature.", + cargo_docs_link(feature.docs) ) }; @@ -1231,3 +1225,14 @@ pub fn channel() -> String { fn cargo_use_gitoxide_instead_of_git2() -> bool { std::env::var_os("__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2").map_or(false, |value| value == "1") } + +/// Generate a link to Cargo documentation for the current release channel +/// `path` is the URL component after `https://doc.rust-lang.org/{channel}/cargo/` +pub fn cargo_docs_link(path: &str) -> String { + let url_channel = match channel().as_str() { + "dev" | "nightly" => "nightly/", + "beta" => "beta/", + _ => "", + }; + format!("https://doc.rust-lang.org/{url_channel}cargo/{path}") +} diff --git a/src/cargo/util/auth/mod.rs b/src/cargo/util/auth/mod.rs index d60a0624f7f..7f60fe7085f 100644 --- a/src/cargo/util/auth/mod.rs +++ b/src/cargo/util/auth/mod.rs @@ -1,6 +1,7 @@ //! Registry authentication support. use crate::{ + core::features::cargo_docs_link, sources::CRATES_IO_REGISTRY, util::{config::ConfigKey, CanonicalUrl, CargoResult, Config, IntoUrl}, }; @@ -219,7 +220,8 @@ fn credential_provider( if !global_provider_defined && require_cred_provider_config { bail!( "authenticated registries require a credential-provider to be configured\n\ - see https://doc.rust-lang.org/cargo/reference/registry-authentication.html for details" + see {} for details", + cargo_docs_link("reference/registry-authentication.html") ); } Ok(global_providers)