Skip to content

Commit a3db4ad

Browse files
committed
treewide: apply fixable clippy lints
1 parent e9737f1 commit a3db4ad

File tree

12 files changed

+85
-92
lines changed

12 files changed

+85
-92
lines changed

src/clean.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use regex::Regex;
1515
use tracing::{debug, info, instrument, span, warn, Level};
1616
use uzers::os::unix::UserExt;
1717

18-
use crate::{commands::Command, *};
18+
use crate::{commands::Command, Result, interface};
1919

2020
// Nix impl:
2121
// https://github.com/NixOS/nix/blob/master/src/nix-collect-garbage/nix-collect-garbage.cc
@@ -42,12 +42,12 @@ impl interface::CleanMode {
4242
// What profiles to clean depending on the call mode
4343
let uid = nix::unistd::Uid::effective();
4444
let args = match self {
45-
interface::CleanMode::Profile(args) => {
45+
Self::Profile(args) => {
4646
profiles.push(args.profile.clone());
4747
is_profile_clean = true;
4848
&args.common
4949
}
50-
interface::CleanMode::All(args) => {
50+
Self::All(args) => {
5151
if !uid.is_root() {
5252
crate::self_elevate();
5353
}
@@ -72,7 +72,7 @@ impl interface::CleanMode {
7272
}
7373
args
7474
}
75-
interface::CleanMode::User(args) => {
75+
Self::User(args) => {
7676
if uid.is_root() {
7777
bail!("nh clean user: don't run me as root!");
7878
}
@@ -129,7 +129,7 @@ impl interface::CleanMode {
129129
AccessFlags::F_OK | AccessFlags::W_OK,
130130
AtFlags::AT_SYMLINK_NOFOLLOW,
131131
) {
132-
Ok(_) => true,
132+
Ok(()) => true,
133133
Err(errno) => match errno {
134134
Errno::EACCES | Errno::ENOENT => false,
135135
_ => {
@@ -191,7 +191,7 @@ impl interface::CleanMode {
191191
}
192192
println!();
193193
}
194-
for (profile, generations_tagged) in profiles_tagged.iter() {
194+
for (profile, generations_tagged) in &profiles_tagged {
195195
println!("{}", profile.to_string_lossy().blue().bold());
196196
for (gen, tbr) in generations_tagged.iter().rev() {
197197
if *tbr {
@@ -218,7 +218,7 @@ impl interface::CleanMode {
218218
}
219219
}
220220

221-
for (_, generations_tagged) in profiles_tagged.iter() {
221+
for generations_tagged in profiles_tagged.values() {
222222
for (gen, tbr) in generations_tagged.iter().rev() {
223223
if *tbr {
224224
remove_path_nofail(&gen.path);
@@ -324,7 +324,7 @@ fn cleanable_generations(
324324
}
325325

326326
let now = SystemTime::now();
327-
for (gen, tbr) in result.iter_mut() {
327+
for (gen, tbr) in &mut result {
328328
match now.duration_since(gen.last_modified) {
329329
Err(err) => {
330330
warn!(?err, ?now, ?gen, "Failed to compare time!");

src/commands.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ impl Command {
4343
}
4444
}
4545

46-
pub fn elevate(mut self, elevate: bool) -> Self {
46+
pub const fn elevate(mut self, elevate: bool) -> Self {
4747
self.elevate = elevate;
4848
self
4949
}
5050

51-
pub fn dry(mut self, dry: bool) -> Self {
51+
pub const fn dry(mut self, dry: bool) -> Self {
5252
self.dry = dry;
5353
self
5454
}
@@ -163,7 +163,7 @@ pub struct Build {
163163
}
164164

165165
impl Build {
166-
pub fn new(installable: Installable) -> Self {
166+
pub const fn new(installable: Installable) -> Self {
167167
Self {
168168
message: None,
169169
installable,
@@ -183,7 +183,7 @@ impl Build {
183183
self
184184
}
185185

186-
pub fn nom(mut self, yes: bool) -> Self {
186+
pub const fn nom(mut self, yes: bool) -> Self {
187187
self.nom = yes;
188188
self
189189
}

src/completion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use color_eyre::Result;
33
use tracing::instrument;
44

55
use crate::interface::Main;
6-
use crate::*;
6+
use crate::interface;
77

88
impl interface::CompletionArgs {
99
#[instrument(ret, level = "trace")]

src/darwin.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const CURRENT_PROFILE: &str = "/run/current-system";
1717

1818
impl DarwinArgs {
1919
pub fn run(self) -> Result<()> {
20-
use DarwinRebuildVariant::*;
20+
use DarwinRebuildVariant::{Build, Switch};
2121
match self.subcommand {
2222
DarwinSubcommand::Switch(args) => args.rebuild(Switch),
2323
DarwinSubcommand::Build(args) => {
@@ -38,7 +38,7 @@ enum DarwinRebuildVariant {
3838

3939
impl DarwinRebuildArgs {
4040
fn rebuild(self, variant: DarwinRebuildVariant) -> Result<()> {
41-
use DarwinRebuildVariant::*;
41+
use DarwinRebuildVariant::{Build, Switch};
4242

4343
if nix::unistd::Uid::effective().is_root() {
4444
bail!("Don't run nh os as root. I will call sudo internally as needed");
@@ -121,7 +121,7 @@ impl DarwinRebuildArgs {
121121
}
122122
}
123123

124-
if let Switch = variant {
124+
if matches!(variant, Switch) {
125125
Command::new("nix")
126126
.args(["build", "--no-link", "--profile", SYSTEM_PROFILE])
127127
.arg(out_path.get_path())

src/generations.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub struct GenerationInfo {
1414
/// Date on switch a generation was built
1515
pub date: String,
1616

17-
/// NixOS version derived from `nixos-version`
17+
/// `NixOS` version derived from `nixos-version`
1818
pub nixos_version: String,
1919

2020
/// Version of the bootable kernel for a given generation
@@ -66,7 +66,7 @@ pub fn describe(generation_dir: &Path, current_profile: &Path) -> Option<Generat
6666
.join("kernel")
6767
.canonicalize()
6868
.ok()
69-
.and_then(|path| path.parent().map(|p| p.to_path_buf()))
69+
.and_then(|path| path.parent().map(std::path::Path::to_path_buf))
7070
.unwrap_or_else(|| PathBuf::from("Unknown"));
7171

7272
let kernel_modules_dir = kernel_dir.join("lib/modules");
@@ -195,9 +195,7 @@ pub fn print_info(mut generations: Vec<GenerationInfo>) {
195195
// Parse all dates at once and cache them
196196
let mut parsed_dates = HashMap::with_capacity(generations.len());
197197
for gen in &generations {
198-
let date = DateTime::parse_from_rfc3339(&gen.date)
199-
.map(|dt| dt.with_timezone(&Local))
200-
.unwrap_or_else(|_| Local.timestamp_opt(0, 0).unwrap());
198+
let date = DateTime::parse_from_rfc3339(&gen.date).map_or_else(|_| Local.timestamp_opt(0, 0).unwrap(), |dt| dt.with_timezone(&Local));
201199
parsed_dates.insert(
202200
gen.date.clone(),
203201
date.format("%Y-%m-%d %H:%M:%S").to_string(),
@@ -216,7 +214,7 @@ pub fn print_info(mut generations: Vec<GenerationInfo>) {
216214
println!("Error getting current generation!");
217215
}
218216

219-
println!("Closure Size: {}", closure);
217+
println!("Closure Size: {closure}");
220218
println!();
221219

222220
// Determine column widths for pretty printing
@@ -256,7 +254,7 @@ pub fn print_info(mut generations: Vec<GenerationInfo>) {
256254
generation
257255
.specialisations
258256
.iter()
259-
.map(|s| format!("*{}", s))
257+
.map(|s| format!("*{s}"))
260258
.collect::<Vec<String>>()
261259
.join(" ")
262260
};

src/home.rs

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::util::get_hostname;
1515

1616
impl interface::HomeArgs {
1717
pub fn run(self) -> Result<()> {
18-
use HomeRebuildVariant::*;
18+
use HomeRebuildVariant::{Build, Switch};
1919
match self.subcommand {
2020
HomeSubcommand::Switch(args) => args.rebuild(Switch),
2121
HomeSubcommand::Build(args) => {
@@ -37,7 +37,7 @@ enum HomeRebuildVariant {
3737

3838
impl HomeRebuildArgs {
3939
fn rebuild(self, variant: HomeRebuildVariant) -> Result<()> {
40-
use HomeRebuildVariant::*;
40+
use HomeRebuildVariant::Build;
4141

4242
if self.update_args.update {
4343
update(&self.common.installable, self.update_args.update_input)?;
@@ -170,10 +170,10 @@ where
170170
I: IntoIterator<Item = S>,
171171
S: AsRef<std::ffi::OsStr>,
172172
{
173-
let mut res = installable.clone();
173+
let mut res = installable;
174174
let extra_args: Vec<OsString> = {
175175
let mut vec = Vec::new();
176-
for elem in extra_args.into_iter() {
176+
for elem in extra_args {
177177
vec.push(elem.as_ref().to_owned());
178178
}
179179
vec
@@ -206,7 +206,7 @@ where
206206
// Check if an explicit configuration name was provided via the flag
207207
if let Some(config_name) = configuration_name {
208208
// Verify the provided configuration exists
209-
let func = format!(r#" x: x ? "{}" "#, config_name);
209+
let func = format!(r#" x: x ? "{config_name}" "#);
210210
let check_res = commands::Command::new("nix")
211211
.arg("eval")
212212
.args(&extra_args)
@@ -228,29 +228,26 @@ where
228228
)
229229
})?;
230230

231-
match check_res.map(|s| s.trim().to_owned()).as_deref() {
232-
Some("true") => {
233-
debug!("Using explicit configuration from flag: {}", config_name);
234-
attribute.push(config_name.clone());
235-
if push_drv {
236-
attribute.extend(toplevel.clone());
237-
}
238-
found_config = true;
239-
}
240-
_ => {
241-
// Explicit config provided but not found
242-
let tried_attr_path = {
243-
let mut attr_path = attribute.clone();
244-
attr_path.push(config_name.clone());
245-
Installable::Flake {
246-
reference: flake_reference.clone(),
247-
attribute: attr_path,
248-
}
249-
.to_args()
250-
.join(" ")
251-
};
252-
bail!("Explicitly specified home-manager configuration not found: {tried_attr_path}");
231+
if check_res.map(|s| s.trim().to_owned()).as_deref() == Some("true") {
232+
debug!("Using explicit configuration from flag: {}", config_name);
233+
attribute.push(config_name);
234+
if push_drv {
235+
attribute.extend(toplevel.clone());
253236
}
237+
found_config = true;
238+
} else {
239+
// Explicit config provided but not found
240+
let tried_attr_path = {
241+
let mut attr_path = attribute.clone();
242+
attr_path.push(config_name);
243+
Installable::Flake {
244+
reference: flake_reference,
245+
attribute: attr_path,
246+
}
247+
.to_args()
248+
.join(" ")
249+
};
250+
bail!("Explicitly specified home-manager configuration not found: {tried_attr_path}");
254251
}
255252
}
256253

@@ -260,8 +257,8 @@ where
260257
let hostname = get_hostname()?;
261258
let mut tried = vec![];
262259

263-
for attr_name in [format!("{username}@{hostname}"), username.to_string()] {
264-
let func = format!(r#" x: x ? "{}" "#, attr_name);
260+
for attr_name in [format!("{username}@{hostname}"), username] {
261+
let func = format!(r#" x: x ? "{attr_name}" "#);
265262
let check_res = commands::Command::new("nix")
266263
.arg("eval")
267264
.args(&extra_args)
@@ -293,7 +290,7 @@ where
293290
match check_res.map(|s| s.trim().to_owned()).as_deref() {
294291
Some("true") => {
295292
debug!("Using automatically detected configuration: {}", attr_name);
296-
attribute.push(attr_name.clone());
293+
attribute.push(attr_name);
297294
if push_drv {
298295
attribute.extend(toplevel.clone());
299296
}

0 commit comments

Comments
 (0)