Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions calc/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,12 @@ fn logop(lhs: &Token, rhs: &Token, is_and: bool) -> Token {
} else {
Token::Integer(0)
}
} else if !lhs_zero {
lhs.clone()
} else if !rhs_zero {
rhs.clone()
} else {
if !lhs_zero {
lhs.clone()
} else if !rhs_zero {
rhs.clone()
} else {
Token::Integer(0)
}
Token::Integer(0)
}
}

Expand Down
2 changes: 1 addition & 1 deletion datetime/cal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// If no arguments are provided, display the current month
if args.month.is_none() && args.year.is_none() {
let now = chrono::Local::now();
args.month = Some(now.month() as u32);
args.month = Some(now.month());
args.year = Some(now.year() as u32);

// If only one argument is provided, assume it is the entire year
Expand Down
2 changes: 1 addition & 1 deletion editors/vi/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2567,7 +2567,7 @@ impl Editor {
if let Some('=') = ztype {
// For '=', print separator line around current line
let cols = self.terminal.size().cols as usize;
let separator: String = std::iter::repeat('-').take(40.min(cols / 2)).collect();
let separator: String = "-".repeat(40.min(cols / 2));
let half = count / 2;
let before_start = target_line.saturating_sub(half).max(1);

Expand Down
2 changes: 1 addition & 1 deletion fs/df.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ impl Mount {
let percentage_used = percentage_used.ceil() as u32;

FieldsData {
fields: fields,
fields,
source: &self.devname,
size: total,
used,
Expand Down
4 changes: 2 additions & 2 deletions ftw/src/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct EntryInternal<'a> {
phantom: PhantomData<&'a libc::dirent>,
}

impl<'a> EntryInternal<'a> {
impl EntryInternal<'_> {
pub fn name_cstr(&self) -> &CStr {
// Avoid dereferencing `dirent` when getting its fields. See note at:
// https://github.com/rust-lang/rust/blob/1.80.1/library/std/src/sys/pal/unix/fs.rs#L725-L742
Expand Down Expand Up @@ -193,7 +193,7 @@ pub struct DeferredDirIterator<'a> {
visited: RefMut<'a, HashSet<libc::ino_t>>,
}

impl<'a> Drop for DeferredDirIterator<'a> {
impl Drop for DeferredDirIterator<'_> {
fn drop(&mut self) {
unsafe {
libc::closedir(self.dirp);
Expand Down
2 changes: 1 addition & 1 deletion mailx/mailbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ impl Mailbox {

// Decide whether to show To or From
let address_field = if show_to && msg.from().contains(&user) {
format!("To {}", truncate(&msg.to().to_string(), 18))
format!("To {}", truncate(msg.to(), 18))
} else {
msg.from_short()
};
Expand Down
2 changes: 1 addition & 1 deletion mailx/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn run_receive_mode(args: &Args) -> i32 {
}

let mailbox_path = if args.read_mbox {
args.file.clone().unwrap_or_else(|| get_mbox_path())
args.file.clone().unwrap_or_else(get_mbox_path)
} else {
args.file.clone().unwrap_or_else(get_system_mailbox)
};
Expand Down
2 changes: 1 addition & 1 deletion process/kill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn send_signal(prog_cfg: &Config, sig_no: i32) -> u32 {
let mut exit_code = 0;

for pid in &prog_cfg.pids {
let res = unsafe { libc::kill(*pid as libc::pid_t, sig_no as i32) };
let res = unsafe { libc::kill(*pid as libc::pid_t, sig_no) };
if res != 0 {
let err = std::io::Error::last_os_error();
eprintln!("kill pid {}: {}", pid, err);
Expand Down
12 changes: 4 additions & 8 deletions text/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,11 @@ fn comm_file(
let mut want2 = true;

loop {
if want1 && buf1.is_empty() {
if rdr1.read_line(&mut buf1)? == 0 {
want1 = false;
}
if want1 && buf1.is_empty() && rdr1.read_line(&mut buf1)? == 0 {
want1 = false;
}
if want2 && buf2.is_empty() {
if rdr2.read_line(&mut buf2)? == 0 {
want2 = false;
}
if want2 && buf2.is_empty() && rdr2.read_line(&mut buf2)? == 0 {
want2 = false;
}

if buf1.is_empty() && buf2.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion tree/chown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ enum ParseOwnerGroupResult {

fn parse_owner_group(owner_group: &str) -> Result<ParseOwnerGroupResult, String> {
if owner_group.is_empty() || owner_group == ":" {
return Ok(ParseOwnerGroupResult::EmptyOrColon);
Ok(ParseOwnerGroupResult::EmptyOrColon)
} else {
match owner_group.split_once(':') {
None => {
Expand Down
10 changes: 4 additions & 6 deletions tree/common/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,10 @@ where
return Ok(CopyResult::Skipped);
}
}
} else {
if cfg.interactive {
let is_affirm = prompt_fn(&gettext!("overwrite '{}'?", target.display()));
if !is_affirm {
return Ok(CopyResult::Skipped);
}
} else if cfg.interactive {
let is_affirm = prompt_fn(&gettext!("overwrite '{}'?", target.display()));
if !is_affirm {
return Ok(CopyResult::Skipped);
}
}

Expand Down
9 changes: 3 additions & 6 deletions tree/touch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,9 @@ fn parse_tm_posix(time: &str) -> Result<DateTime<Utc>, Box<dyn std::error::Error

// split into YYYYMMDDhhmm and [.SS] components
let mut tmp_time = String::new();
match time.split_once('.') {
Some((t, secs)) => {
tmp_time = t.to_string();
seconds = secs.to_string();
}
None => {}
if let Some((t, secs)) = time.split_once('.') {
tmp_time = t.to_string();
seconds = secs.to_string();
}
if !tmp_time.is_empty() {
time = tmp_time;
Expand Down
22 changes: 11 additions & 11 deletions users/newgrp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,18 @@ fn newgrp(args: Args) -> Result<(), io::Error> {
let groups = plib::group::load();

// Retrieve current user information
let pwd = get_password().or_else(|_| {
Err(io::Error::new(
let pwd = get_password().map_err(|_| {
io::Error::new(
io::ErrorKind::NotFound,
"Could not retrieve current user information.",
))
)
})?;
let user_name = unsafe { CStr::from_ptr(pwd.pw_name) }
.to_str()
.unwrap_or_else(|_| "???");
.unwrap_or("???");

if args.login {
set_login_environment(&user_name)?;
set_login_environment(user_name)?;
}

let group_identifier = args.group.trim();
Expand Down Expand Up @@ -126,12 +126,12 @@ fn newgrp(args: Args) -> Result<(), io::Error> {
if new_gid_in_supplementary {
// New GID is also in the supplementary list; change the effective GID
change_effective_gid_and_uid(group.gid, group_identifier)?;
logger(&user_name, group.gid);
logger(user_name, group.gid);
} else {
// New GID is not in the supplementary list; add it if possible
add_gid_to_groups(group.gid);
change_effective_gid_and_uid(group.gid, group_identifier)?;
logger(&user_name, group.gid);
logger(user_name, group.gid);
}
} else {
// The effective GID is not in the supplementary list
Expand All @@ -143,7 +143,7 @@ fn newgrp(args: Args) -> Result<(), io::Error> {
add_gid_to_groups(current_gid);
}
change_gid_and_uid(group.gid, group_identifier)?;
logger(&user_name, group.gid);
logger(user_name, group.gid);
}

Ok(())
Expand Down Expand Up @@ -755,11 +755,11 @@ fn read_password() -> io::Result<String> {
///
fn set_login_environment(user: &str) -> Result<(), io::Error> {
// Get the user's shell from the password entry
let pwd = get_password().or_else(|_| {
Err(io::Error::new(
let pwd = get_password().map_err(|_| {
io::Error::new(
io::ErrorKind::NotFound,
"Could not retrieve user information.",
))
)
})?;

let user_shell = unsafe { CStr::from_ptr(pwd.pw_shell) }
Expand Down
6 changes: 2 additions & 4 deletions users/pwd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ fn dirname_valid(name: &OsStr) -> bool {
if component != Component::RootDir {
return false;
}
} else {
if component == Component::CurDir || component == Component::ParentDir {
return false;
}
} else if component == Component::CurDir || component == Component::ParentDir {
return false;
}
}

Expand Down
2 changes: 1 addition & 1 deletion users/talk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ fn spawn_input_thread(
'\n' => {
if let Err(e) = handle_newline(
&mut line_buffer,
&mut *bottom_line,
&mut bottom_line,
split_row,
&mut handle,
) {
Expand Down