mirror of
https://github.com/rust-lang/cargo
synced 2024-09-18 07:12:12 +00:00
Auto merge of #10416 - Eh2406:less_mut, r=alexcrichton
Some small clean ups. Just some small changes I noticed while exploring the code base. The only thing nontrivial was noticing that get_registry_index already calls validate_package_name.
This commit is contained in:
commit
c7dbc422bb
|
@ -24,14 +24,13 @@ pub fn expand(file: &Path, formatter: FormatterRef) -> Result<String, Error> {
|
||||||
handlebars.register_template_file("template", file)?;
|
handlebars.register_template_file("template", file)?;
|
||||||
let includes = file.parent().unwrap().join("includes");
|
let includes = file.parent().unwrap().join("includes");
|
||||||
handlebars.register_templates_directory(".md", includes)?;
|
handlebars.register_templates_directory(".md", includes)?;
|
||||||
let mut data: HashMap<String, String> = HashMap::new();
|
|
||||||
let man_name = file
|
let man_name = file
|
||||||
.file_stem()
|
.file_stem()
|
||||||
.expect("expected filename")
|
.expect("expected filename")
|
||||||
.to_str()
|
.to_str()
|
||||||
.expect("utf8 filename")
|
.expect("utf8 filename")
|
||||||
.to_string();
|
.to_string();
|
||||||
data.insert("man_name".to_string(), man_name);
|
let data = HashMap::from([("man_name", man_name)]);
|
||||||
let expanded = handlebars.render("template", &data)?;
|
let expanded = handlebars.render("template", &data)?;
|
||||||
Ok(expanded)
|
Ok(expanded)
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,14 +13,14 @@ pub fn cli() -> App {
|
||||||
|
|
||||||
pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
|
pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
|
||||||
if let Err(e) = args.workspace(config) {
|
if let Err(e) = args.workspace(config) {
|
||||||
let mut h = HashMap::new();
|
config
|
||||||
h.insert("invalid".to_string(), e.to_string());
|
.shell()
|
||||||
config.shell().print_json(&h)?;
|
.print_json(&HashMap::from([("invalid", e.to_string())]))?;
|
||||||
process::exit(1)
|
process::exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut h = HashMap::new();
|
config
|
||||||
h.insert("success".to_string(), "true".to_string());
|
.shell()
|
||||||
config.shell().print_json(&h)?;
|
.print_json(&HashMap::from([("success", "true")]))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,10 +64,8 @@ pub struct RustdocExternMap {
|
||||||
|
|
||||||
impl Default for RustdocExternMap {
|
impl Default for RustdocExternMap {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let mut registries = HashMap::new();
|
|
||||||
registries.insert(CRATES_IO_REGISTRY.into(), DOCS_RS_URL.into());
|
|
||||||
Self {
|
Self {
|
||||||
registries,
|
registries: HashMap::from([(CRATES_IO_REGISTRY.into(), DOCS_RS_URL.into())]),
|
||||||
std: None,
|
std: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,8 +53,7 @@ pub fn resolve_std<'cfg>(
|
||||||
})
|
})
|
||||||
.collect::<CargoResult<Vec<_>>>()?;
|
.collect::<CargoResult<Vec<_>>>()?;
|
||||||
let crates_io_url = crate::sources::CRATES_IO_INDEX.parse().unwrap();
|
let crates_io_url = crate::sources::CRATES_IO_INDEX.parse().unwrap();
|
||||||
let mut patch = HashMap::new();
|
let patch = HashMap::from([(crates_io_url, patches)]);
|
||||||
patch.insert(crates_io_url, patches);
|
|
||||||
let members = vec![
|
let members = vec![
|
||||||
String::from("library/std"),
|
String::from("library/std"),
|
||||||
String::from("library/core"),
|
String::from("library/core"),
|
||||||
|
|
|
@ -139,11 +139,12 @@ impl Profiles {
|
||||||
|
|
||||||
/// Returns the hard-coded directory names for built-in profiles.
|
/// Returns the hard-coded directory names for built-in profiles.
|
||||||
fn predefined_dir_names() -> HashMap<InternedString, InternedString> {
|
fn predefined_dir_names() -> HashMap<InternedString, InternedString> {
|
||||||
let mut dir_names = HashMap::new();
|
[
|
||||||
dir_names.insert(InternedString::new("dev"), InternedString::new("debug"));
|
(InternedString::new("dev"), InternedString::new("debug")),
|
||||||
dir_names.insert(InternedString::new("test"), InternedString::new("debug"));
|
(InternedString::new("test"), InternedString::new("debug")),
|
||||||
dir_names.insert(InternedString::new("bench"), InternedString::new("release"));
|
(InternedString::new("bench"), InternedString::new("release")),
|
||||||
dir_names
|
]
|
||||||
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Initialize `by_name` with the two "root" profiles, `dev`, and
|
/// Initialize `by_name` with the two "root" profiles, `dev`, and
|
||||||
|
|
|
@ -24,7 +24,6 @@ use crate::sources::{RegistrySource, SourceConfigMap, CRATES_IO_DOMAIN, CRATES_I
|
||||||
use crate::util::config::{self, Config, SslVersionConfig, SslVersionConfigRange};
|
use crate::util::config::{self, Config, SslVersionConfig, SslVersionConfigRange};
|
||||||
use crate::util::errors::CargoResult;
|
use crate::util::errors::CargoResult;
|
||||||
use crate::util::important_paths::find_root_manifest_for_wd;
|
use crate::util::important_paths::find_root_manifest_for_wd;
|
||||||
use crate::util::validate_package_name;
|
|
||||||
use crate::util::IntoUrl;
|
use crate::util::IntoUrl;
|
||||||
use crate::{drop_print, drop_println, version};
|
use crate::{drop_print, drop_println, version};
|
||||||
|
|
||||||
|
@ -344,7 +343,6 @@ pub fn registry_configuration(
|
||||||
// `registry.default` is handled in command-line parsing.
|
// `registry.default` is handled in command-line parsing.
|
||||||
let (index, token, process) = match registry {
|
let (index, token, process) = match registry {
|
||||||
Some(registry) => {
|
Some(registry) => {
|
||||||
validate_package_name(registry, "registry name", "")?;
|
|
||||||
let index = Some(config.get_registry_index(registry)?.to_string());
|
let index = Some(config.get_registry_index(registry)?.to_string());
|
||||||
let token_key = format!("registries.{}.token", registry);
|
let token_key = format!("registries.{}.token", registry);
|
||||||
let token = config.get_string(&token_key)?.map(|p| p.val);
|
let token = config.get_string(&token_key)?.map(|p| p.val);
|
||||||
|
@ -418,8 +416,8 @@ fn registry(
|
||||||
}
|
}
|
||||||
// Parse all configuration options
|
// Parse all configuration options
|
||||||
let reg_cfg = registry_configuration(config, registry.as_deref())?;
|
let reg_cfg = registry_configuration(config, registry.as_deref())?;
|
||||||
let opt_index = reg_cfg.index.as_ref().or_else(|| index.as_ref());
|
let opt_index = reg_cfg.index.as_deref().or_else(|| index.as_deref());
|
||||||
let sid = get_source_id(config, opt_index, registry.as_ref())?;
|
let sid = get_source_id(config, opt_index, registry.as_deref())?;
|
||||||
if !sid.is_remote_registry() {
|
if !sid.is_remote_registry() {
|
||||||
bail!(
|
bail!(
|
||||||
"{} does not support API commands.\n\
|
"{} does not support API commands.\n\
|
||||||
|
@ -892,11 +890,7 @@ pub fn yank(
|
||||||
///
|
///
|
||||||
/// The `index` and `reg` values are from the command-line or config settings.
|
/// The `index` and `reg` values are from the command-line or config settings.
|
||||||
/// If both are None, returns the source for crates.io.
|
/// If both are None, returns the source for crates.io.
|
||||||
fn get_source_id(
|
fn get_source_id(config: &Config, index: Option<&str>, reg: Option<&str>) -> CargoResult<SourceId> {
|
||||||
config: &Config,
|
|
||||||
index: Option<&String>,
|
|
||||||
reg: Option<&String>,
|
|
||||||
) -> CargoResult<SourceId> {
|
|
||||||
match (reg, index) {
|
match (reg, index) {
|
||||||
(Some(r), _) => SourceId::alt_registry(config, r),
|
(Some(r), _) => SourceId::alt_registry(config, r),
|
||||||
(_, Some(i)) => SourceId::for_registry(&i.into_url()?),
|
(_, Some(i)) => SourceId::for_registry(&i.into_url()?),
|
||||||
|
|
|
@ -1053,8 +1053,7 @@ impl Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_file(&self, path: &Path, includes: bool) -> CargoResult<ConfigValue> {
|
fn load_file(&self, path: &Path, includes: bool) -> CargoResult<ConfigValue> {
|
||||||
let mut seen = HashSet::new();
|
self._load_file(path, &mut HashSet::new(), includes)
|
||||||
self._load_file(path, &mut seen, includes)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _load_file(
|
fn _load_file(
|
||||||
|
@ -1119,7 +1118,7 @@ impl Config {
|
||||||
cv: &mut CV,
|
cv: &mut CV,
|
||||||
remove: bool,
|
remove: bool,
|
||||||
) -> CargoResult<Vec<(String, PathBuf, Definition)>> {
|
) -> CargoResult<Vec<(String, PathBuf, Definition)>> {
|
||||||
let abs = |path: &String, def: &Definition| -> (String, PathBuf, Definition) {
|
let abs = |path: &str, def: &Definition| -> (String, PathBuf, Definition) {
|
||||||
let abs_path = match def {
|
let abs_path = match def {
|
||||||
Definition::Path(p) => p.parent().unwrap().join(&path),
|
Definition::Path(p) => p.parent().unwrap().join(&path),
|
||||||
Definition::Environment(_) | Definition::Cli => self.cwd().join(&path),
|
Definition::Environment(_) | Definition::Cli => self.cwd().join(&path),
|
||||||
|
@ -1171,9 +1170,8 @@ impl Config {
|
||||||
anyhow::format_err!("config path {:?} is not utf-8", arg_as_path)
|
anyhow::format_err!("config path {:?} is not utf-8", arg_as_path)
|
||||||
})?
|
})?
|
||||||
.to_string();
|
.to_string();
|
||||||
let mut map = HashMap::new();
|
|
||||||
let value = CV::String(str_path, Definition::Cli);
|
let value = CV::String(str_path, Definition::Cli);
|
||||||
map.insert("include".to_string(), value);
|
let map = HashMap::from([("include".to_string(), value)]);
|
||||||
CV::Table(map, Definition::Cli)
|
CV::Table(map, Definition::Cli)
|
||||||
} else {
|
} else {
|
||||||
// We only want to allow "dotted key" (see https://toml.io/en/v1.0.0#keys)
|
// We only want to allow "dotted key" (see https://toml.io/en/v1.0.0#keys)
|
||||||
|
@ -1253,9 +1251,8 @@ impl Config {
|
||||||
CV::from_toml(Definition::Cli, toml_v)
|
CV::from_toml(Definition::Cli, toml_v)
|
||||||
.with_context(|| format!("failed to convert --config argument `{arg}`"))?
|
.with_context(|| format!("failed to convert --config argument `{arg}`"))?
|
||||||
};
|
};
|
||||||
let mut seen = HashSet::new();
|
|
||||||
let tmp_table = self
|
let tmp_table = self
|
||||||
.load_includes(tmp_table, &mut seen)
|
.load_includes(tmp_table, &mut HashSet::new())
|
||||||
.with_context(|| "failed to load --config include".to_string())?;
|
.with_context(|| "failed to load --config include".to_string())?;
|
||||||
loaded_args
|
loaded_args
|
||||||
.merge(tmp_table, true)
|
.merge(tmp_table, true)
|
||||||
|
@ -1419,8 +1416,7 @@ impl Config {
|
||||||
|
|
||||||
if let Some(token) = value_map.remove("token") {
|
if let Some(token) = value_map.remove("token") {
|
||||||
if let Vacant(entry) = value_map.entry("registry".into()) {
|
if let Vacant(entry) = value_map.entry("registry".into()) {
|
||||||
let mut map = HashMap::new();
|
let map = HashMap::from([("token".into(), token)]);
|
||||||
map.insert("token".into(), token);
|
|
||||||
let table = CV::Table(map, def.clone());
|
let table = CV::Table(map, def.clone());
|
||||||
entry.insert(table);
|
entry.insert(table);
|
||||||
}
|
}
|
||||||
|
@ -1994,8 +1990,7 @@ pub fn save_credentials(
|
||||||
|
|
||||||
// Move the old token location to the new one.
|
// Move the old token location to the new one.
|
||||||
if let Some(token) = toml.as_table_mut().unwrap().remove("token") {
|
if let Some(token) = toml.as_table_mut().unwrap().remove("token") {
|
||||||
let mut map = HashMap::new();
|
let map = HashMap::from([("token".to_string(), token)]);
|
||||||
map.insert("token".to_string(), token);
|
|
||||||
toml.as_table_mut()
|
toml.as_table_mut()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.insert("registry".into(), map.into());
|
.insert("registry".into(), map.into());
|
||||||
|
@ -2006,13 +2001,11 @@ pub fn save_credentials(
|
||||||
let (key, mut value) = {
|
let (key, mut value) = {
|
||||||
let key = "token".to_string();
|
let key = "token".to_string();
|
||||||
let value = ConfigValue::String(token, Definition::Path(file.path().to_path_buf()));
|
let value = ConfigValue::String(token, Definition::Path(file.path().to_path_buf()));
|
||||||
let mut map = HashMap::new();
|
let map = HashMap::from([(key, value)]);
|
||||||
map.insert(key, value);
|
|
||||||
let table = CV::Table(map, Definition::Path(file.path().to_path_buf()));
|
let table = CV::Table(map, Definition::Path(file.path().to_path_buf()));
|
||||||
|
|
||||||
if let Some(registry) = registry {
|
if let Some(registry) = registry {
|
||||||
let mut map = HashMap::new();
|
let map = HashMap::from([(registry.to_string(), table)]);
|
||||||
map.insert(registry.to_string(), table);
|
|
||||||
(
|
(
|
||||||
"registries".into(),
|
"registries".into(),
|
||||||
CV::Table(map, Definition::Path(file.path().to_path_buf())),
|
CV::Table(map, Definition::Path(file.path().to_path_buf())),
|
||||||
|
|
|
@ -75,9 +75,8 @@ impl Message {
|
||||||
.shutdown(Shutdown::Write)
|
.shutdown(Shutdown::Write)
|
||||||
.context("failed to shutdown")?;
|
.context("failed to shutdown")?;
|
||||||
|
|
||||||
let mut tmp = Vec::new();
|
|
||||||
client
|
client
|
||||||
.read_to_end(&mut tmp)
|
.read_to_end(&mut Vec::new())
|
||||||
.context("failed to receive a disconnect")?;
|
.context("failed to receive a disconnect")?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue