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

View file

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

View file

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

View file

@ -854,7 +854,7 @@ impl EnvStackImpl {
if val.exports() {
let mut node_ref = node.borrow_mut();
// 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.changed_exported();

View file

@ -4,6 +4,9 @@ use crate::wchar::prelude::*;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering;
#[cfg(test)]
use std::cell::RefCell;
/// The list of flags.
#[repr(u8)]
#[derive(Clone, Copy)]
@ -97,7 +100,7 @@ pub const METADATA: &[FeatureMetadata] = &[
thread_local!(
#[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.

View file

@ -296,12 +296,8 @@ fn autosuggest_parse_command(
);
// Find the first statement.
let Some(jc) = ast.top().as_job_list().unwrap().get(0) else {
return None;
};
let Some(first_statement) = jc.job.statement.contents.as_decorated_statement() else {
return None;
};
let jc = ast.top().as_job_list().unwrap().get(0)?;
let first_statement = jc.job.statement.contents.as_decorated_statement()?;
if let Some(expanded_command) = statement_get_expanded_command(buff, first_statement, ctx) {
let mut arg = WString::new();
@ -1491,9 +1487,7 @@ fn statement_get_expanded_command(
ctx: &OperationContext<'_>,
) -> Option<WString> {
// Get the command. Try expanding it. If we cannot, it's an error.
let Some(cmd) = stmt.command.try_source(src) else {
return None;
};
let cmd = stmt.command.try_source(src)?;
let mut out_cmd = WString::new();
let err = expand_to_command_and_args(cmd, ctx, &mut out_cmd, None, None, false);
(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;
}
let Some(mut result) = path_get_data() else {
return None;
};
let mut result = path_get_data()?;
result.push('/');
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> {
let (advance, line) = read_line(data);
let line = trim_start(line);
let Some((key, value)) = extract_prefix_and_unescape_yaml(line) else {
return None;
};
let (key, value) = extract_prefix_and_unescape_yaml(line)?;
if key != b"- cmd" {
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.
fn parse_timestamp(s: &[u8]) -> Option<SystemTime> {
let s = trim_start(s);
let Some(s) = s.strip_prefix(b"when:") else {
return None;
};
let s = s.strip_prefix(b"when:")?;
let s = trim_start(s);
std::str::from_utf8(s)
.ok()
.and_then(|s| s.parse().ok())
.map(time_from_seconds)
let t = std::str::from_utf8(s).ok()?.parse().ok()?;
Some(time_from_seconds(t))
}
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()],
EnvVarFlags::EXPORT,
);
assert!(v1 == v2 && !(v1 != v2));
assert!(v1 != v3 && !(v1 == v3));
assert!(v1 != v4 && !(v1 == v4));
assert_eq!(v1, v2);
assert_ne!(v1, v3);
assert_ne!(v1, v4);
}
#[test]

View file

@ -34,7 +34,7 @@ fn test_is_potential_path() {
std::fs::write("test/is_potential_path_test/gamma", []).unwrap();
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 ctx = OperationContext::background(&*vars, EXPANSION_LIMIT_DEFAULT);

View file

@ -4,7 +4,6 @@ use crate::pager::{Pager, SelectionMotion};
use crate::termsize::Termsize;
use crate::tests::prelude::*;
use crate::wchar::prelude::*;
use crate::wchar_ext::WExt;
use crate::wcstringutil::StringFuzzyMatch;
#[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::tests::prelude::*;
use crate::wchar::prelude::*;
use crate::wchar_ext::WExt;
#[test]
#[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
// automatically if the returned join handle is dropped.
let result = match std::thread::Builder::new().spawn(move || {
(callback)();
}) {
let result = match std::thread::Builder::new().spawn(callback) {
Ok(handle) => {
let thread_id = handle.thread().id();
FLOG!(iothread, "rust thread", thread_id, "spawned");