Skip to content

Commit 7c676d9

Browse files
committed
clippy fixes
1 parent d17db68 commit 7c676d9

File tree

20 files changed

+78
-94
lines changed

20 files changed

+78
-94
lines changed

file/file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ fn get_magic_files(args: &Args) -> Vec<PathBuf> {
110110
magic_files
111111
}
112112

113-
fn analyze_file(mut path: String, args: &Args, magic_files: &Vec<PathBuf>) {
113+
fn analyze_file(mut path: String, args: &Args, magic_files: &[PathBuf]) {
114114
if path == "-" {
115115
path = String::new();
116116
io::stdin().read_line(&mut path).unwrap();

mailx/mailbox.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ impl Mailbox {
232232
let address_field = if show_to && msg.from().contains(&user) {
233233
format!("To {}", truncate(msg.to(), 18))
234234
} else {
235-
msg.from_short()
235+
msg.short_from()
236236
};
237237

238238
let date = msg.short_date();

mailx/message.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl Message {
186186
}
187187

188188
/// Extract the sender's name or address for header display
189-
pub fn from_short(&self) -> String {
189+
pub fn short_from(&self) -> String {
190190
let from = self.from();
191191
// Try to extract name from "Name <email>" format
192192
if let Some(start) = from.find('<') {

mailx/msglist.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,22 +163,22 @@ fn parse_single_spec(
163163
}
164164
_ => {
165165
// Could be a number, /string, :c, or address
166-
if spec.starts_with('/') {
166+
if let Some(suffix) = spec.strip_prefix('/') {
167167
// Search subject
168-
let search = &spec[1..].to_lowercase();
168+
let search = suffix.to_lowercase();
169169
let matches: Vec<usize> = mb
170170
.messages
171171
.iter()
172172
.enumerate()
173173
.filter(|(_, m)| {
174174
(for_undelete || m.state != MessageState::Deleted)
175-
&& m.subject().to_lowercase().contains(search)
175+
&& m.subject().to_lowercase().contains(&search)
176176
})
177177
.map(|(i, _)| i + 1)
178178
.collect();
179179

180180
if matches.is_empty() {
181-
Err(format!("No messages matching /{}", &spec[1..]))
181+
Err(format!("No messages matching /{}", suffix))
182182
} else {
183183
Ok(matches)
184184
}

pax/subst.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,7 @@ impl Substitution {
124124
let mut pos = 0;
125125
let mut any_match = false;
126126

127-
loop {
128-
// Try to match at or after current position
129-
let matches = match self.regex.captures_at(&result, pos) {
130-
Some(m) => m,
131-
None => break,
132-
};
133-
127+
while let Some(matches) = self.regex.captures_at(&result, pos) {
134128
any_match = true;
135129

136130
// Build the replacement string

sh/builtin/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ mod unalias;
7171
mod unset;
7272
mod wait;
7373

74+
#[allow(clippy::enum_variant_names)]
7475
pub enum BuiltinError {
7576
CustomError(String),
7677
AssignmentError(CannotModifyReadonly),

sh/builtin/ulimit.rs

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -144,38 +144,34 @@ impl UlimitArgs {
144144
return Err("ulimit: cannot set limit for all resources".to_string());
145145
}
146146

147-
if limit.is_none() && resource_limit.is_some() {
148-
if newlimit.is_some() {
149-
return Ok(UlimitArgs {
150-
limit: LimitType::Both,
151-
resource: resource_limit.unwrap(),
152-
newlimit,
153-
});
147+
match (limit, resource_limit) {
148+
(None, Some(resource)) => {
149+
if newlimit.is_some() {
150+
Ok(UlimitArgs {
151+
limit: LimitType::Both,
152+
resource,
153+
newlimit,
154+
})
155+
} else {
156+
Ok(UlimitArgs {
157+
limit: LimitType::Soft,
158+
resource,
159+
newlimit: None,
160+
})
161+
}
154162
}
155-
return Ok(UlimitArgs {
156-
limit: LimitType::Soft,
157-
resource: resource_limit.unwrap(),
158-
newlimit: None,
159-
});
160-
}
161-
162-
if limit.is_some() && resource_limit.is_none() {
163-
return Ok(UlimitArgs {
164-
limit: limit.unwrap(),
163+
(Some(lim), None) => Ok(UlimitArgs {
164+
limit: lim,
165165
resource: ResourceLimit::FSize,
166166
newlimit,
167-
});
168-
}
169-
170-
if limit.is_some() && resource_limit.is_some() {
171-
return Ok(UlimitArgs {
172-
limit: limit.unwrap(),
173-
resource: resource_limit.unwrap(),
167+
}),
168+
(Some(lim), Some(resource)) => Ok(UlimitArgs {
169+
limit: lim,
170+
resource,
174171
newlimit,
175-
});
172+
}),
173+
(None, None) => Err("ulimit: invalid arguments".to_string()),
176174
}
177-
178-
Err("ulimit: invalid arguments".to_string())
179175
}
180176
}
181177

sh/cli/terminal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl Terminal {
4343
/// # Panic
4444
/// Panics if the current process is not attached to a terminal.
4545
pub fn set_nonblocking_no_echo(&self) {
46-
let mut termios = self.base_settings.clone().unwrap();
46+
let mut termios = self.base_settings.unwrap();
4747
termios.c_lflag &= !(libc::ECHO | libc::ICANON);
4848
termios.c_cc[libc::VMIN] = 0;
4949
termios.c_cc[libc::VTIME] = 0;
@@ -53,7 +53,7 @@ impl Terminal {
5353
/// # Panic
5454
/// Panics if the current process is not attached to a terminal.
5555
pub fn set_nonblocking(&self) {
56-
let mut termios = self.base_settings.clone().unwrap();
56+
let mut termios = self.base_settings.unwrap();
5757
termios.c_lflag &= !libc::ICANON;
5858
termios.c_cc[libc::VMIN] = 0;
5959
termios.c_cc[libc::VTIME] = 0;

sh/os/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ pub enum ForkResult {
8686
Parent { child: Pid },
8787
}
8888

89+
#[allow(clippy::comparison_chain)]
8990
pub fn fork() -> OsResult<ForkResult> {
9091
// fork in general is not safe for multithreaded programs, but all code in this module is single
9192
// threaded, so this is safe

sh/os/signals.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ impl FromStr for Signal {
118118
}
119119
}
120120

121-
impl Into<i32> for Signal {
122-
fn into(self) -> i32 {
123-
match self {
121+
impl From<Signal> for i32 {
122+
fn from(value: Signal) -> i32 {
123+
match value {
124124
Signal::SigHup => libc::SIGHUP,
125125
Signal::SigInt => libc::SIGINT,
126126
Signal::SigQuit => libc::SIGQUIT,

0 commit comments

Comments
 (0)