Skip to content

Commit 4bfed40

Browse files
committed
don't need mut
1 parent 7a3ec1d commit 4bfed40

File tree

7 files changed

+19
-31
lines changed

7 files changed

+19
-31
lines changed

crates/mdman/src/hbs.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@ pub fn expand(file: &Path, formatter: FormatterRef) -> Result<String, Error> {
2424
handlebars.register_template_file("template", file)?;
2525
let includes = file.parent().unwrap().join("includes");
2626
handlebars.register_templates_directory(".md", includes)?;
27-
let mut data: HashMap<String, String> = HashMap::new();
2827
let man_name = file
2928
.file_stem()
3029
.expect("expected filename")
3130
.to_str()
3231
.expect("utf8 filename")
3332
.to_string();
34-
data.insert("man_name".to_string(), man_name);
33+
let data: HashMap<String, String> = [("man_name", man_name)].into();
3534
let expanded = handlebars.render("template", &data)?;
3635
Ok(expanded)
3736
}

src/bin/cargo/commands/verify_project.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ pub fn cli() -> App {
1313

1414
pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
1515
if let Err(e) = args.workspace(config) {
16-
let mut h = HashMap::new();
17-
h.insert("invalid".to_string(), e.to_string());
16+
let h: HashMap<_, _> = [("invalid", e.to_string())].into();
1817
config.shell().print_json(&h)?;
1918
process::exit(1)
2019
}
2120

22-
let mut h = HashMap::new();
23-
h.insert("success".to_string(), "true".to_string());
21+
let h: HashMap<_, _> = [("success", "true")].into();
2422
config.shell().print_json(&h)?;
2523
Ok(())
2624
}

src/cargo/core/compiler/rustdoc.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ pub struct RustdocExternMap {
6464

6565
impl Default for RustdocExternMap {
6666
fn default() -> Self {
67-
let mut registries = HashMap::new();
68-
registries.insert(CRATES_IO_REGISTRY.into(), DOCS_RS_URL.into());
67+
let registries = [(CRATES_IO_REGISTRY.into(), DOCS_RS_URL.into())].into();
6968
Self {
7069
registries,
7170
std: None,

src/cargo/core/compiler/standard_lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ pub fn resolve_std<'cfg>(
5353
})
5454
.collect::<CargoResult<Vec<_>>>()?;
5555
let crates_io_url = crate::sources::CRATES_IO_INDEX.parse().unwrap();
56-
let mut patch = HashMap::new();
57-
patch.insert(crates_io_url, patches);
56+
let patch = [(crates_io_url, patches)].into();
5857
let members = vec![
5958
String::from("library/std"),
6059
String::from("library/core"),

src/cargo/core/profiles.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,12 @@ impl Profiles {
139139

140140
/// Returns the hard-coded directory names for built-in profiles.
141141
fn predefined_dir_names() -> HashMap<InternedString, InternedString> {
142-
let mut dir_names = HashMap::new();
143-
dir_names.insert(InternedString::new("dev"), InternedString::new("debug"));
144-
dir_names.insert(InternedString::new("test"), InternedString::new("debug"));
145-
dir_names.insert(InternedString::new("bench"), InternedString::new("release"));
146-
dir_names
142+
[
143+
(InternedString::new("dev"), InternedString::new("debug")),
144+
(InternedString::new("test"), InternedString::new("debug")),
145+
(InternedString::new("bench"), InternedString::new("release")),
146+
]
147+
.into()
147148
}
148149

149150
/// Initialize `by_name` with the two "root" profiles, `dev`, and

src/cargo/util/config/mod.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,8 +1053,7 @@ impl Config {
10531053
}
10541054

10551055
fn load_file(&self, path: &Path, includes: bool) -> CargoResult<ConfigValue> {
1056-
let mut seen = HashSet::new();
1057-
self._load_file(path, &mut seen, includes)
1056+
self._load_file(path, &mut HashSet::new(), includes)
10581057
}
10591058

10601059
fn _load_file(
@@ -1171,9 +1170,8 @@ impl Config {
11711170
anyhow::format_err!("config path {:?} is not utf-8", arg_as_path)
11721171
})?
11731172
.to_string();
1174-
let mut map = HashMap::new();
11751173
let value = CV::String(str_path, Definition::Cli);
1176-
map.insert("include".to_string(), value);
1174+
let map = [("include".to_string(), value)].into();
11771175
CV::Table(map, Definition::Cli)
11781176
} else {
11791177
// We only want to allow "dotted key" (see https://toml.io/en/v1.0.0#keys)
@@ -1253,9 +1251,8 @@ impl Config {
12531251
CV::from_toml(Definition::Cli, toml_v)
12541252
.with_context(|| format!("failed to convert --config argument `{arg}`"))?
12551253
};
1256-
let mut seen = HashSet::new();
12571254
let tmp_table = self
1258-
.load_includes(tmp_table, &mut seen)
1255+
.load_includes(tmp_table, &mut HashSet::new())
12591256
.with_context(|| "failed to load --config include".to_string())?;
12601257
loaded_args
12611258
.merge(tmp_table, true)
@@ -1419,8 +1416,7 @@ impl Config {
14191416

14201417
if let Some(token) = value_map.remove("token") {
14211418
if let Vacant(entry) = value_map.entry("registry".into()) {
1422-
let mut map = HashMap::new();
1423-
map.insert("token".into(), token);
1419+
let map = [("token".into(), token)].into();
14241420
let table = CV::Table(map, def.clone());
14251421
entry.insert(table);
14261422
}
@@ -1994,8 +1990,7 @@ pub fn save_credentials(
19941990

19951991
// Move the old token location to the new one.
19961992
if let Some(token) = toml.as_table_mut().unwrap().remove("token") {
1997-
let mut map = HashMap::new();
1998-
map.insert("token".to_string(), token);
1993+
let map: HashMap<_, _> = [("token".to_string(), token)].into();
19991994
toml.as_table_mut()
20001995
.unwrap()
20011996
.insert("registry".into(), map.into());
@@ -2006,13 +2001,11 @@ pub fn save_credentials(
20062001
let (key, mut value) = {
20072002
let key = "token".to_string();
20082003
let value = ConfigValue::String(token, Definition::Path(file.path().to_path_buf()));
2009-
let mut map = HashMap::new();
2010-
map.insert(key, value);
2004+
let map = [(key, value)].into();
20112005
let table = CV::Table(map, Definition::Path(file.path().to_path_buf()));
20122006

20132007
if let Some(registry) = registry {
2014-
let mut map = HashMap::new();
2015-
map.insert(registry.to_string(), table);
2008+
let map = [(registry.to_string(), table)].into();
20162009
(
20172010
"registries".into(),
20182011
CV::Table(map, Definition::Path(file.path().to_path_buf())),

src/cargo/util/diagnostic_server.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@ impl Message {
7575
.shutdown(Shutdown::Write)
7676
.context("failed to shutdown")?;
7777

78-
let mut tmp = Vec::new();
7978
client
80-
.read_to_end(&mut tmp)
79+
.read_to_end(&mut Vec::new())
8180
.context("failed to receive a disconnect")?;
8281

8382
Ok(())

0 commit comments

Comments
 (0)