Address clippy lints

This commit is contained in:
The0x539 2024-03-09 04:08:16 -06:00 committed by Johannes Altmanninger
parent 6869b14fb5
commit 4c3e814a50
13 changed files with 21 additions and 44 deletions

View File

@ -2288,9 +2288,7 @@ impl<'a> Traversal<'a> {
impl<'a> Iterator for Traversal<'a> { impl<'a> Iterator for Traversal<'a> {
type Item = &'a dyn Node; type Item = &'a dyn Node;
fn next(&mut self) -> Option<&'a dyn Node> { fn next(&mut self) -> Option<&'a dyn Node> {
let Some(node) = self.stack.pop() else { let node = self.stack.pop()?;
return None;
};
// We want to visit in reverse order so the first child ends up on top of the stack. // We want to visit in reverse order so the first child ends up on top of the stack.
node.accept(self, true /* reverse */); node.accept(self, true /* reverse */);
Some(node) Some(node)

View File

@ -140,9 +140,7 @@ impl Autoload {
} }
// Do we have an entry to load? // Do we have an entry to load?
let Some(file) = self.cache.check(cmd, false) else { let file = self.cache.check(cmd, false)?;
return None;
};
// Is this file the same as what we previously autoloaded? // Is this file the same as what we previously autoloaded?
if let Some(loaded_file) = self.autoloaded_files.get(cmd) { if let Some(loaded_file) = self.autoloaded_files.get(cmd) {

View File

@ -545,9 +545,7 @@ mod test_expressions {
} }
// Parse a subexpression. // Parse a subexpression.
let Some(subexpr) = self.parse_expression(start + 1, end) else { let subexpr = self.parse_expression(start + 1, end)?;
return None;
};
// Parse a close paren. // Parse a close paren.
let close_index = subexpr.range().end; let close_index = subexpr.range().end;

View File

@ -854,7 +854,7 @@ impl EnvStackImpl {
if val.exports() { if val.exports() {
let mut node_ref = node.borrow_mut(); let mut node_ref = node.borrow_mut();
// Do NOT overwrite existing values, since we go from inner scopes outwards. // Do NOT overwrite existing values, since we go from inner scopes outwards.
if node_ref.env.get(key).is_none() { if !node_ref.env.contains_key(key) {
node_ref.env.insert(key.clone(), val.clone()); node_ref.env.insert(key.clone(), val.clone());
} }
node_ref.changed_exported(); node_ref.changed_exported();

View File

@ -4,6 +4,9 @@ use crate::wchar::prelude::*;
use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering; use std::sync::atomic::Ordering;
#[cfg(test)]
use std::cell::RefCell;
/// The list of flags. /// The list of flags.
#[repr(u8)] #[repr(u8)]
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
@ -97,7 +100,7 @@ pub const METADATA: &[FeatureMetadata] = &[
thread_local!( thread_local!(
#[cfg(test)] #[cfg(test)]
static LOCAL_FEATURES: std::cell::RefCell<Option<Features>> = std::cell::RefCell::new(None); static LOCAL_FEATURES: RefCell<Option<Features>> = const { RefCell::new(None) };
); );
/// The singleton shared feature set. /// The singleton shared feature set.

View File

@ -296,12 +296,8 @@ fn autosuggest_parse_command(
); );
// Find the first statement. // Find the first statement.
let Some(jc) = ast.top().as_job_list().unwrap().get(0) else { let jc = ast.top().as_job_list().unwrap().get(0)?;
return None; let first_statement = jc.job.statement.contents.as_decorated_statement()?;
};
let Some(first_statement) = jc.job.statement.contents.as_decorated_statement() else {
return None;
};
if let Some(expanded_command) = statement_get_expanded_command(buff, first_statement, ctx) { if let Some(expanded_command) = statement_get_expanded_command(buff, first_statement, ctx) {
let mut arg = WString::new(); let mut arg = WString::new();
@ -1491,9 +1487,7 @@ fn statement_get_expanded_command(
ctx: &OperationContext<'_>, ctx: &OperationContext<'_>,
) -> Option<WString> { ) -> Option<WString> {
// Get the command. Try expanding it. If we cannot, it's an error. // Get the command. Try expanding it. If we cannot, it's an error.
let Some(cmd) = stmt.command.try_source(src) else { let cmd = stmt.command.try_source(src)?;
return None;
};
let mut out_cmd = WString::new(); let mut out_cmd = WString::new();
let err = expand_to_command_and_args(cmd, ctx, &mut out_cmd, None, None, false); let err = expand_to_command_and_args(cmd, ctx, &mut out_cmd, None, None, false);
(err == ExpandResultCode::ok).then_some(out_cmd) (err == ExpandResultCode::ok).then_some(out_cmd)

View File

@ -205,9 +205,7 @@ fn history_filename(session_id: &wstr, suffix: &wstr) -> Option<WString> {
return None; return None;
} }
let Some(mut result) = path_get_data() else { let mut result = path_get_data()?;
return None;
};
result.push('/'); result.push('/');
result.push_utfstr(session_id); result.push_utfstr(session_id);

View File

@ -340,9 +340,7 @@ fn extract_prefix_and_unescape_yaml(line: &[u8]) -> Option<(Vec<u8>, Vec<u8>)> {
fn decode_item_fish_2_0(mut data: &[u8]) -> Option<HistoryItem> { fn decode_item_fish_2_0(mut data: &[u8]) -> Option<HistoryItem> {
let (advance, line) = read_line(data); let (advance, line) = read_line(data);
let line = trim_start(line); let line = trim_start(line);
let Some((key, value)) = extract_prefix_and_unescape_yaml(line) else { let (key, value) = extract_prefix_and_unescape_yaml(line)?;
return None;
};
if key != b"- cmd" { if key != b"- cmd" {
return None; return None;
@ -432,17 +430,11 @@ pub fn time_to_seconds(ts: SystemTime) -> i64 {
/// We know the string contains a newline, so stop when we reach it. /// We know the string contains a newline, so stop when we reach it.
fn parse_timestamp(s: &[u8]) -> Option<SystemTime> { fn parse_timestamp(s: &[u8]) -> Option<SystemTime> {
let s = trim_start(s); let s = trim_start(s);
let s = s.strip_prefix(b"when:")?;
let Some(s) = s.strip_prefix(b"when:") else {
return None;
};
let s = trim_start(s); let s = trim_start(s);
std::str::from_utf8(s) let t = std::str::from_utf8(s).ok()?.parse().ok()?;
.ok() Some(time_from_seconds(t))
.and_then(|s| s.parse().ok())
.map(time_from_seconds)
} }
fn complete_lines(s: &[u8]) -> impl Iterator<Item = &[u8]> { fn complete_lines(s: &[u8]) -> impl Iterator<Item = &[u8]> {

View File

@ -102,9 +102,9 @@ fn test_env_vars() {
vec![L!("abc").to_owned(), L!("def").to_owned()], vec![L!("abc").to_owned(), L!("def").to_owned()],
EnvVarFlags::EXPORT, EnvVarFlags::EXPORT,
); );
assert!(v1 == v2 && !(v1 != v2)); assert_eq!(v1, v2);
assert!(v1 != v3 && !(v1 == v3)); assert_ne!(v1, v3);
assert!(v1 != v4 && !(v1 == v4)); assert_ne!(v1, v4);
} }
#[test] #[test]

View File

@ -34,7 +34,7 @@ fn test_is_potential_path() {
std::fs::write("test/is_potential_path_test/gamma", []).unwrap(); std::fs::write("test/is_potential_path_test/gamma", []).unwrap();
let wd = L!("test/is_potential_path_test/").to_owned(); let wd = L!("test/is_potential_path_test/").to_owned();
let wds = vec![L!(".").to_owned(), wd]; let wds = [L!(".").to_owned(), wd];
let vars = EnvStack::principal().clone(); let vars = EnvStack::principal().clone();
let ctx = OperationContext::background(&*vars, EXPANSION_LIMIT_DEFAULT); let ctx = OperationContext::background(&*vars, EXPANSION_LIMIT_DEFAULT);

View File

@ -4,7 +4,6 @@ use crate::pager::{Pager, SelectionMotion};
use crate::termsize::Termsize; use crate::termsize::Termsize;
use crate::tests::prelude::*; use crate::tests::prelude::*;
use crate::wchar::prelude::*; use crate::wchar::prelude::*;
use crate::wchar_ext::WExt;
use crate::wcstringutil::StringFuzzyMatch; use crate::wcstringutil::StringFuzzyMatch;
#[test] #[test]

View File

@ -8,7 +8,6 @@ use crate::parse_constants::{
use crate::parse_util::{parse_util_detect_errors, BOOL_AFTER_BACKGROUND_ERROR_MSG}; use crate::parse_util::{parse_util_detect_errors, BOOL_AFTER_BACKGROUND_ERROR_MSG};
use crate::tests::prelude::*; use crate::tests::prelude::*;
use crate::wchar::prelude::*; use crate::wchar::prelude::*;
use crate::wchar_ext::WExt;
#[test] #[test]
#[serial] #[serial]

View File

@ -180,9 +180,7 @@ pub fn spawn<F: FnOnce() + Send + 'static>(callback: F) -> bool {
// We don't have to port the PTHREAD_CREATE_DETACHED logic. Rust threads are detached // We don't have to port the PTHREAD_CREATE_DETACHED logic. Rust threads are detached
// automatically if the returned join handle is dropped. // automatically if the returned join handle is dropped.
let result = match std::thread::Builder::new().spawn(move || { let result = match std::thread::Builder::new().spawn(callback) {
(callback)();
}) {
Ok(handle) => { Ok(handle) => {
let thread_id = handle.thread().id(); let thread_id = handle.thread().id();
FLOG!(iothread, "rust thread", thread_id, "spawned"); FLOG!(iothread, "rust thread", thread_id, "spawned");