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