mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
rust: fix issues reported by clippy
This commit is contained in:
parent
c2df63f586
commit
853649f8dc
11 changed files with 86 additions and 88 deletions
|
@ -38,7 +38,7 @@ fn main() -> miette::Result<()> {
|
|||
// Emit autocxx junk.
|
||||
// This allows "C++ to be used from Rust."
|
||||
let include_paths = [&fish_src_dir, &fish_build_dir, &cxx_include_dir];
|
||||
let mut b = autocxx_build::Builder::new("src/ffi.rs", &include_paths)
|
||||
let mut b = autocxx_build::Builder::new("src/ffi.rs", include_paths)
|
||||
.custom_gendir(autocxx_gen_dir.into())
|
||||
.build()?;
|
||||
b.flag_if_supported("-std=c++11")
|
||||
|
|
|
@ -158,7 +158,7 @@ impl fd_readable_set_t {
|
|||
self.pollfds_.insert(
|
||||
pos,
|
||||
libc::pollfd {
|
||||
fd: fd,
|
||||
fd,
|
||||
events: libc::POLLIN,
|
||||
revents: 0,
|
||||
},
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
|
||||
#[cfg(all(feature = "fish-ffi-tests", not(test)))]
|
||||
mod ffi_tests_impl {
|
||||
use inventory;
|
||||
|
||||
/// A test which needs to cross the FFI.
|
||||
#[derive(Debug)]
|
||||
pub struct FFITest {
|
||||
|
|
|
@ -169,13 +169,13 @@ fn apply_one_wildcard(wc_esc: &wstr, sense: bool) {
|
|||
let wc = parse_util_unescape_wildcards(&wc_esc.to_ffi());
|
||||
let mut match_found = false;
|
||||
for cat in categories::all_categories() {
|
||||
if wildcard_match(&cat.name.to_ffi(), &*wc, false) {
|
||||
if wildcard_match(&cat.name.to_ffi(), &wc, false) {
|
||||
cat.enabled.store(sense, Ordering::Relaxed);
|
||||
match_found = true;
|
||||
}
|
||||
}
|
||||
if !match_found {
|
||||
eprintln!("Failed to match debug category: {}\n", wc_esc);
|
||||
eprintln!("Failed to match debug category: {wc_esc}\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -377,7 +377,7 @@ static mut s_principal: *const topic_monitor_t = std::ptr::null();
|
|||
|
||||
/// Create a new topic monitor. Exposed for the FFI.
|
||||
pub fn new_topic_monitor() -> Box<topic_monitor_t> {
|
||||
Box::new(topic_monitor_t::default())
|
||||
Box::default()
|
||||
}
|
||||
|
||||
impl topic_monitor_t {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use crate::ffi::wcharz_t;
|
||||
use crate::wchar::wstr;
|
||||
use std::cmp::Ordering;
|
||||
use std::time;
|
||||
|
||||
#[cxx::bridge]
|
||||
|
@ -80,15 +81,19 @@ pub fn wcsfilecmp(a: wcharz_t, b: wcharz_t) -> i32 {
|
|||
acl = acl.to_uppercase().next().unwrap();
|
||||
bcl = bcl.to_uppercase().next().unwrap();
|
||||
|
||||
if acl < bcl {
|
||||
retval = -1;
|
||||
break;
|
||||
} else if acl > bcl {
|
||||
retval = 1;
|
||||
break;
|
||||
} else {
|
||||
ai += 1;
|
||||
bi += 1;
|
||||
match acl.cmp(&bcl) {
|
||||
Ordering::Less => {
|
||||
retval = -1;
|
||||
break;
|
||||
}
|
||||
Ordering::Equal => {
|
||||
ai += 1;
|
||||
bi += 1;
|
||||
}
|
||||
Ordering::Greater => {
|
||||
retval = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,15 +157,19 @@ pub fn wcsfilecmp_glob(a: wcharz_t, b: wcharz_t) -> i32 {
|
|||
// TODO Compare the tail (enabled by Rust's Unicode support).
|
||||
let acl = ac.to_lowercase().next().unwrap();
|
||||
let bcl = bc.to_lowercase().next().unwrap();
|
||||
if acl < bcl {
|
||||
retval = -1;
|
||||
break;
|
||||
} else if acl > bcl {
|
||||
retval = 1;
|
||||
break;
|
||||
} else {
|
||||
ai += 1;
|
||||
bi += 1;
|
||||
match acl.cmp(&bcl) {
|
||||
Ordering::Less => {
|
||||
retval = -1;
|
||||
break;
|
||||
}
|
||||
Ordering::Equal => {
|
||||
ai += 1;
|
||||
bi += 1;
|
||||
}
|
||||
Ordering::Greater => {
|
||||
retval = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,18 +32,18 @@ impl<'a> CharPrefixSuffix for &'a wstr {
|
|||
impl<'a> CharPrefixSuffix for &'a WString {
|
||||
type Iter = CharsUtf32<'a>;
|
||||
fn chars(self) -> Self::Iter {
|
||||
wstr::chars(&*self)
|
||||
wstr::chars(self)
|
||||
}
|
||||
}
|
||||
|
||||
/// \return true if \p prefix is a prefix of \p contents.
|
||||
fn iter_prefixes_iter<Prefix, Contents>(mut prefix: Prefix, mut contents: Contents) -> bool
|
||||
fn iter_prefixes_iter<Prefix, Contents>(prefix: Prefix, mut contents: Contents) -> bool
|
||||
where
|
||||
Prefix: Iterator,
|
||||
Contents: Iterator,
|
||||
Prefix::Item: PartialEq<Contents::Item>,
|
||||
{
|
||||
while let Some(c1) = prefix.next() {
|
||||
for c1 in prefix {
|
||||
match contents.next() {
|
||||
Some(c2) if c1 == c2 => {}
|
||||
_ => return false,
|
||||
|
|
|
@ -149,7 +149,7 @@ pub struct woption<'a> {
|
|||
}
|
||||
|
||||
/// Helper function to create a woption.
|
||||
pub const fn wopt<'a>(name: &'a wstr, has_arg: woption_argument_t, val: char) -> woption<'a> {
|
||||
pub const fn wopt(name: &wstr, has_arg: woption_argument_t, val: char) -> woption<'_> {
|
||||
woption { name, has_arg, val }
|
||||
}
|
||||
|
||||
|
@ -368,7 +368,7 @@ impl<'opts, 'args, 'argarray> wgetopter_t<'opts, 'args, 'argarray> {
|
|||
if temp.char_at(2) == ':' {
|
||||
// This is an option that accepts an argument optionally.
|
||||
if !self.nextchar.is_empty() {
|
||||
self.woptarg = Some(self.nextchar.clone());
|
||||
self.woptarg = Some(self.nextchar);
|
||||
self.woptind += 1;
|
||||
} else {
|
||||
self.woptarg = None;
|
||||
|
@ -377,7 +377,7 @@ impl<'opts, 'args, 'argarray> wgetopter_t<'opts, 'args, 'argarray> {
|
|||
} else {
|
||||
// This is an option that requires an argument.
|
||||
if !self.nextchar.is_empty() {
|
||||
self.woptarg = Some(self.nextchar.clone());
|
||||
self.woptarg = Some(self.nextchar);
|
||||
// If we end this ARGV-element by taking the rest as an arg, we must advance to
|
||||
// the next element now.
|
||||
self.woptind += 1;
|
||||
|
@ -447,10 +447,9 @@ impl<'opts, 'args, 'argarray> wgetopter_t<'opts, 'args, 'argarray> {
|
|||
indfound: &mut usize,
|
||||
) -> Option<woption<'opts>> {
|
||||
let mut pfound: Option<woption> = None;
|
||||
let mut option_index = 0;
|
||||
|
||||
// Test all long options for either exact match or abbreviated matches.
|
||||
for p in self.longopts.iter() {
|
||||
for (option_index, p) in self.longopts.iter().enumerate() {
|
||||
if p.name.starts_with(&self.nextchar[..nameend]) {
|
||||
// Exact match found.
|
||||
pfound = Some(*p);
|
||||
|
@ -465,7 +464,6 @@ impl<'opts, 'args, 'argarray> wgetopter_t<'opts, 'args, 'argarray> {
|
|||
// Second or later nonexact match found.
|
||||
*ambig = true;
|
||||
}
|
||||
option_index += 1;
|
||||
}
|
||||
return pfound;
|
||||
}
|
||||
|
@ -586,17 +584,20 @@ impl<'opts, 'args, 'argarray> wgetopter_t<'opts, 'args, 'argarray> {
|
|||
// This distinction seems to be the most useful approach.
|
||||
if !self.longopts.is_empty() && self.woptind < self.argc() {
|
||||
let arg = self.argv[self.woptind];
|
||||
let mut try_long = false;
|
||||
if arg.char_at(0) == '-' && arg.char_at(1) == '-' {
|
||||
|
||||
let try_long = if arg.char_at(0) == '-' && arg.char_at(1) == '-' {
|
||||
// Like --foo
|
||||
try_long = true;
|
||||
true
|
||||
} else if long_only && arg.len() >= 3 {
|
||||
// Like -fu
|
||||
try_long = true;
|
||||
true
|
||||
} else if !self.shortopts.as_char_slice().contains(&arg.char_at(1)) {
|
||||
// Like -f, but f is not a short arg.
|
||||
try_long = true;
|
||||
}
|
||||
true
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
if try_long {
|
||||
let mut retval = '\0';
|
||||
if self._handle_long_opt(longind, long_only, &mut retval) {
|
||||
|
|
|
@ -94,7 +94,7 @@ impl Printf for u64 {
|
|||
.try_into()
|
||||
.unwrap_or_default();
|
||||
let formatted = if spec.left_adj {
|
||||
let mut num_str = prefix.clone();
|
||||
let mut num_str = prefix;
|
||||
num_str.extend(rev_num.chars().rev());
|
||||
while num_str.len() < width {
|
||||
num_str.push(' ');
|
||||
|
@ -104,11 +104,11 @@ impl Printf for u64 {
|
|||
while prefix.len() + rev_num.len() < width {
|
||||
rev_num.push('0');
|
||||
}
|
||||
let mut num_str = prefix.clone();
|
||||
let mut num_str = prefix;
|
||||
num_str.extend(rev_num.chars().rev());
|
||||
num_str
|
||||
} else {
|
||||
let mut num_str = prefix.clone();
|
||||
let mut num_str = prefix;
|
||||
num_str.extend(rev_num.chars().rev());
|
||||
while num_str.len() < width {
|
||||
num_str.insert(0, ' ');
|
||||
|
@ -359,7 +359,7 @@ impl Printf for f64 {
|
|||
rev_tail_str.push((b'0' + (tail % 10) as u8) as char);
|
||||
tail /= 10;
|
||||
}
|
||||
number.push_str(&format!("{}", int_part));
|
||||
number.push_str(&int_part.to_string());
|
||||
number.push('.');
|
||||
number.extend(rev_tail_str.chars().rev());
|
||||
if strip_trailing_0s {
|
||||
|
@ -371,35 +371,33 @@ impl Printf for f64 {
|
|||
number.push_str(&format!("{}", normal.round()));
|
||||
}
|
||||
number.push(exp_symb);
|
||||
number.push_str(&format!("{:+03}", exponent));
|
||||
} else {
|
||||
if precision > 0 {
|
||||
let mut int_part = abs.trunc();
|
||||
let exp_factor = 10.0_f64.powf(precision as f64);
|
||||
let mut tail = ((abs - int_part) * exp_factor).round() as u64;
|
||||
let mut rev_tail_str = WString::new();
|
||||
if tail >= exp_factor as u64 {
|
||||
// overflow - we must round up
|
||||
int_part += 1.0;
|
||||
tail -= exp_factor as u64;
|
||||
// no need to change the exponent as we don't have one
|
||||
// (not scientific notation)
|
||||
}
|
||||
for _ in 0..precision {
|
||||
rev_tail_str.push((b'0' + (tail % 10) as u8) as char);
|
||||
tail /= 10;
|
||||
}
|
||||
number.push_str(&format!("{}", int_part));
|
||||
number.push('.');
|
||||
number.extend(rev_tail_str.chars().rev());
|
||||
if strip_trailing_0s {
|
||||
while number.ends_with('0') {
|
||||
number.pop();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
number.push_str(&format!("{}", abs.round()));
|
||||
number.push_str(&format!("{exponent:+03}"));
|
||||
} else if precision > 0 {
|
||||
let mut int_part = abs.trunc();
|
||||
let exp_factor = 10.0_f64.powf(precision as f64);
|
||||
let mut tail = ((abs - int_part) * exp_factor).round() as u64;
|
||||
let mut rev_tail_str = WString::new();
|
||||
if tail >= exp_factor as u64 {
|
||||
// overflow - we must round up
|
||||
int_part += 1.0;
|
||||
tail -= exp_factor as u64;
|
||||
// no need to change the exponent as we don't have one
|
||||
// (not scientific notation)
|
||||
}
|
||||
for _ in 0..precision {
|
||||
rev_tail_str.push((b'0' + (tail % 10) as u8) as char);
|
||||
tail /= 10;
|
||||
}
|
||||
number.push_str(&int_part.to_string());
|
||||
number.push('.');
|
||||
number.extend(rev_tail_str.chars().rev());
|
||||
if strip_trailing_0s {
|
||||
while number.ends_with('0') {
|
||||
number.pop();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
number.push_str(&format!("{}", abs.round()));
|
||||
}
|
||||
} else {
|
||||
// not finite
|
||||
|
|
|
@ -6,10 +6,7 @@ use crate::wchar_ffi::wcslen;
|
|||
|
||||
/// Implementation detail for wgettext!.
|
||||
pub fn wgettext_impl_do_not_use_directly(text: &[wchar_t]) -> &'static wstr {
|
||||
assert!(
|
||||
text.len() > 0 && text[text.len() - 1] == 0,
|
||||
"should be nul-terminated"
|
||||
);
|
||||
assert_eq!(text.last(), Some(&0), "should be nul-terminated");
|
||||
let res: *const wchar_t = ffi::wgettext_ptr(text.as_ptr());
|
||||
let slice = unsafe { std::slice::from_raw_parts(res as *const u32, wcslen(res)) };
|
||||
wstr::from_slice(slice).expect("Invalid UTF-32")
|
||||
|
|
|
@ -35,11 +35,7 @@ where
|
|||
Chars: Iterator<Item = char>,
|
||||
{
|
||||
if let Some(r) = mradix {
|
||||
assert!(
|
||||
(2..=36).contains(&r),
|
||||
"fish_parse_radix: invalid radix {}",
|
||||
r
|
||||
);
|
||||
assert!((2..=36).contains(&r), "fish_parse_radix: invalid radix {r}");
|
||||
}
|
||||
let chars = &mut ichars.peekable();
|
||||
|
||||
|
@ -63,17 +59,16 @@ where
|
|||
}
|
||||
|
||||
// Determine the radix.
|
||||
let radix;
|
||||
if mradix.is_some() {
|
||||
radix = mradix.unwrap();
|
||||
let radix = if let Some(radix) = mradix {
|
||||
radix
|
||||
} else if current(chars) == '0' {
|
||||
chars.next();
|
||||
match current(chars) {
|
||||
'x' | 'X' => {
|
||||
chars.next();
|
||||
radix = 16;
|
||||
16
|
||||
}
|
||||
c if '0' <= c && c <= '9' => radix = 8,
|
||||
c if ('0'..='9').contains(&c) => 8,
|
||||
_ => {
|
||||
// Just a 0.
|
||||
return Ok(ParseResult {
|
||||
|
@ -83,8 +78,8 @@ where
|
|||
}
|
||||
}
|
||||
} else {
|
||||
radix = 10;
|
||||
}
|
||||
10
|
||||
};
|
||||
|
||||
// Compute as u64.
|
||||
let mut consumed1 = false;
|
||||
|
|
Loading…
Reference in a new issue