don't need mut

This commit is contained in:
Jacob Finkelman 2022-02-23 20:46:51 +00:00
parent 7a3ec1d274
commit 4bfed40178
7 changed files with 19 additions and 31 deletions

View File

@ -24,14 +24,13 @@ pub fn expand(file: &Path, formatter: FormatterRef) -> Result<String, Error> {
handlebars.register_template_file("template", file)?;
let includes = file.parent().unwrap().join("includes");
handlebars.register_templates_directory(".md", includes)?;
let mut data: HashMap<String, String> = HashMap::new();
let man_name = file
.file_stem()
.expect("expected filename")
.to_str()
.expect("utf8 filename")
.to_string();
data.insert("man_name".to_string(), man_name);
let data: HashMap<String, String> = [("man_name", man_name)].into();
let expanded = handlebars.render("template", &data)?;
Ok(expanded)
}

View File

@ -13,14 +13,12 @@ pub fn cli() -> App {
pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
if let Err(e) = args.workspace(config) {
let mut h = HashMap::new();
h.insert("invalid".to_string(), e.to_string());
let h: HashMap<_, _> = [("invalid", e.to_string())].into();
config.shell().print_json(&h)?;
process::exit(1)
}
let mut h = HashMap::new();
h.insert("success".to_string(), "true".to_string());
let h: HashMap<_, _> = [("success", "true")].into();
config.shell().print_json(&h)?;
Ok(())
}

View File

@ -64,8 +64,7 @@ pub struct RustdocExternMap {
impl Default for RustdocExternMap {
fn default() -> Self {
let mut registries = HashMap::new();
registries.insert(CRATES_IO_REGISTRY.into(), DOCS_RS_URL.into());
let registries = [(CRATES_IO_REGISTRY.into(), DOCS_RS_URL.into())].into();
Self {
registries,
std: None,

View File

@ -53,8 +53,7 @@ pub fn resolve_std<'cfg>(
})
.collect::<CargoResult<Vec<_>>>()?;
let crates_io_url = crate::sources::CRATES_IO_INDEX.parse().unwrap();
let mut patch = HashMap::new();
patch.insert(crates_io_url, patches);
let patch = [(crates_io_url, patches)].into();
let members = vec![
String::from("library/std"),
String::from("library/core"),

View File

@ -139,11 +139,12 @@ impl Profiles {
/// Returns the hard-coded directory names for built-in profiles.
fn predefined_dir_names() -> HashMap<InternedString, InternedString> {
let mut dir_names = HashMap::new();
dir_names.insert(InternedString::new("dev"), InternedString::new("debug"));
dir_names.insert(InternedString::new("test"), InternedString::new("debug"));
dir_names.insert(InternedString::new("bench"), InternedString::new("release"));
dir_names
[
(InternedString::new("dev"), InternedString::new("debug")),
(InternedString::new("test"), InternedString::new("debug")),
(InternedString::new("bench"), InternedString::new("release")),
]
.into()
}
/// Initialize `by_name` with the two "root" profiles, `dev`, and

View File

@ -1053,8 +1053,7 @@ impl Config {
}
fn load_file(&self, path: &Path, includes: bool) -> CargoResult<ConfigValue> {
let mut seen = HashSet::new();
self._load_file(path, &mut seen, includes)
self._load_file(path, &mut HashSet::new(), includes)
}
fn _load_file(
@ -1171,9 +1170,8 @@ impl Config {
anyhow::format_err!("config path {:?} is not utf-8", arg_as_path)
})?
.to_string();
let mut map = HashMap::new();
let value = CV::String(str_path, Definition::Cli);
map.insert("include".to_string(), value);
let map = [("include".to_string(), value)].into();
CV::Table(map, Definition::Cli)
} else {
// 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)
.with_context(|| format!("failed to convert --config argument `{arg}`"))?
};
let mut seen = HashSet::new();
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())?;
loaded_args
.merge(tmp_table, true)
@ -1419,8 +1416,7 @@ impl Config {
if let Some(token) = value_map.remove("token") {
if let Vacant(entry) = value_map.entry("registry".into()) {
let mut map = HashMap::new();
map.insert("token".into(), token);
let map = [("token".into(), token)].into();
let table = CV::Table(map, def.clone());
entry.insert(table);
}
@ -1994,8 +1990,7 @@ pub fn save_credentials(
// Move the old token location to the new one.
if let Some(token) = toml.as_table_mut().unwrap().remove("token") {
let mut map = HashMap::new();
map.insert("token".to_string(), token);
let map: HashMap<_, _> = [("token".to_string(), token)].into();
toml.as_table_mut()
.unwrap()
.insert("registry".into(), map.into());
@ -2006,13 +2001,11 @@ pub fn save_credentials(
let (key, mut value) = {
let key = "token".to_string();
let value = ConfigValue::String(token, Definition::Path(file.path().to_path_buf()));
let mut map = HashMap::new();
map.insert(key, value);
let map = [(key, value)].into();
let table = CV::Table(map, Definition::Path(file.path().to_path_buf()));
if let Some(registry) = registry {
let mut map = HashMap::new();
map.insert(registry.to_string(), table);
let map = [(registry.to_string(), table)].into();
(
"registries".into(),
CV::Table(map, Definition::Path(file.path().to_path_buf())),

View File

@ -75,9 +75,8 @@ impl Message {
.shutdown(Shutdown::Write)
.context("failed to shutdown")?;
let mut tmp = Vec::new();
client
.read_to_end(&mut tmp)
.read_to_end(&mut Vec::new())
.context("failed to receive a disconnect")?;
Ok(())