1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

Merge pull request #2699 from jfinkels/lint-fixes

ls,more,csplit,sort,od,dd: fix clippy complaints
This commit is contained in:
Sylvestre Ledru 2021-10-03 10:35:13 +02:00 committed by GitHub
commit 20becf8166
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 41 deletions

View file

@ -320,18 +320,19 @@ impl<'a> SplitWriter<'a> {
let l = line?;
match n.cmp(&(&ln + 1)) {
Ordering::Less => {
if input_iter.add_line_to_buffer(ln, l).is_some() {
panic!("the buffer is big enough to contain 1 line");
}
assert!(
input_iter.add_line_to_buffer(ln, l).is_none(),
"the buffer is big enough to contain 1 line"
);
ret = Ok(());
break;
}
Ordering::Equal => {
if !self.options.suppress_matched
&& input_iter.add_line_to_buffer(ln, l).is_some()
{
panic!("the buffer is big enough to contain 1 line");
}
assert!(
self.options.suppress_matched
|| input_iter.add_line_to_buffer(ln, l).is_none(),
"the buffer is big enough to contain 1 line"
);
ret = Ok(());
break;
}
@ -378,9 +379,10 @@ impl<'a> SplitWriter<'a> {
match (self.options.suppress_matched, offset) {
// no offset, add the line to the next split
(false, 0) => {
if input_iter.add_line_to_buffer(ln, l).is_some() {
panic!("the buffer is big enough to contain 1 line");
}
assert!(
input_iter.add_line_to_buffer(ln, l).is_none(),
"the buffer is big enough to contain 1 line"
);
}
// a positive offset, some more lines need to be added to the current split
(false, _) => self.writeln(l)?,
@ -425,9 +427,10 @@ impl<'a> SplitWriter<'a> {
if !self.options.suppress_matched {
// add 1 to the buffer size to make place for the matched line
input_iter.set_size_of_buffer(offset_usize + 1);
if input_iter.add_line_to_buffer(ln, l).is_some() {
panic!("should be big enough to hold every lines");
}
assert!(
input_iter.add_line_to_buffer(ln, l).is_none(),
"should be big enough to hold every lines"
);
}
self.finish_split();
if input_iter.buffer_len() < offset_usize {

View file

@ -35,12 +35,11 @@ fn unimplemented_flags_should_error_non_linux() {
}
}
if !succeeded.is_empty() {
panic!(
assert!(
succeeded.is_empty(),
"The following flags did not panic as expected: {:?}",
succeeded
);
}
}
#[test]
@ -64,12 +63,11 @@ fn unimplemented_flags_should_error() {
}
}
if !succeeded.is_empty() {
panic!(
assert!(
succeeded.is_empty(),
"The following flags did not panic as expected: {:?}",
succeeded
);
}
}
#[test]

View file

@ -1967,11 +1967,7 @@ fn display_file_name(
#[cfg(unix)]
{
if config.format != Format::Long && config.inode {
name = path
.md()
.map_or_else(|| "?".to_string(), |md| get_inode(md))
+ " "
+ &name;
name = path.md().map_or_else(|| "?".to_string(), get_inode) + " " + &name;
}
}

View file

@ -210,7 +210,7 @@ fn reset_term(stdout: &mut std::io::Stdout) {
#[inline(always)]
fn reset_term(_: &mut usize) {}
fn more(buff: &str, mut stdout: &mut Stdout, next_file: Option<&str>, silent: bool) {
fn more(buff: &str, stdout: &mut Stdout, next_file: Option<&str>, silent: bool) {
let (cols, rows) = terminal::size().unwrap();
let lines = break_buff(buff, usize::from(cols));
@ -232,7 +232,7 @@ fn more(buff: &str, mut stdout: &mut Stdout, next_file: Option<&str>, silent: bo
code: KeyCode::Char('c'),
modifiers: KeyModifiers::CONTROL,
}) => {
reset_term(&mut stdout);
reset_term(stdout);
std::process::exit(0);
}
Event::Key(KeyEvent {

View file

@ -145,13 +145,12 @@ impl OutputInfo {
byte_size_block: usize,
print_width_block: usize,
) -> [usize; MAX_BYTES_PER_UNIT] {
if byte_size_block > MAX_BYTES_PER_UNIT {
panic!(
assert!(
byte_size_block <= MAX_BYTES_PER_UNIT,
"{}-bits types are unsupported. Current max={}-bits.",
8 * byte_size_block,
8 * MAX_BYTES_PER_UNIT
);
}
let mut spacing = [0; MAX_BYTES_PER_UNIT];
let mut byte_size = sf.byte_size();

View file

@ -825,7 +825,7 @@ impl FieldSelector {
fn parse(key: &str, global_settings: &GlobalSettings) -> UResult<Self> {
let mut from_to = key.split(',');
let (from, from_options) = Self::split_key_options(from_to.next().unwrap());
let to = from_to.next().map(|to| Self::split_key_options(to));
let to = from_to.next().map(Self::split_key_options);
let options_are_empty = from_options.is_empty() && matches!(to, None | Some((_, "")));
if options_are_empty {