Fix clippy lints (#2651)

This commit is contained in:
Jonathan Turner 2020-10-09 10:47:51 +13:00 committed by GitHub
parent 152ba32eb7
commit 1159d3365a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 32 additions and 70 deletions

View File

@ -10,25 +10,16 @@ pub enum AutoPivotMode {
impl AutoPivotMode { impl AutoPivotMode {
pub fn is_auto(&self) -> bool { pub fn is_auto(&self) -> bool {
match &self { matches!(self, AutoPivotMode::Auto)
AutoPivotMode::Auto => true,
_ => false,
}
} }
pub fn is_always(&self) -> bool { pub fn is_always(&self) -> bool {
match &self { matches!(self, AutoPivotMode::Always)
AutoPivotMode::Always => true,
_ => false,
}
} }
#[allow(unused)] #[allow(unused)]
pub fn is_never(&self) -> bool { pub fn is_never(&self) -> bool {
match &self { matches!(self, AutoPivotMode::Never)
AutoPivotMode::Never => true,
_ => false,
}
} }
} }

View File

@ -135,7 +135,7 @@ fn parse_aligned_columns<'a>(
.flat_map(|s| find_indices(*s)) .flat_map(|s| find_indices(*s))
.collect::<Vec<usize>>(); .collect::<Vec<usize>>();
indices.sort(); indices.sort_unstable();
indices.dedup(); indices.dedup();
let headers: Vec<(String, usize)> = indices let headers: Vec<(String, usize)> = indices

View File

@ -218,17 +218,13 @@ fn move_after(
)); ));
}; };
let columns_moved = table let columns_moved = table.data_descriptors().into_iter().map(|name| {
.data_descriptors() if columns.contains(&name) {
.into_iter() None
.map(|name| { } else {
if columns.contains(&name) { Some(name)
None }
} else { });
Some(name)
}
})
.collect::<Vec<_>>();
let mut reordered_columns = vec![]; let mut reordered_columns = vec![];
let mut insert = false; let mut insert = false;
@ -281,17 +277,13 @@ fn move_before(
)); ));
}; };
let columns_moved = table let columns_moved = table.data_descriptors().into_iter().map(|name| {
.data_descriptors() if columns.contains(&name) {
.into_iter() None
.map(|name| { } else {
if columns.contains(&name) { Some(name)
None }
} else { });
Some(name)
}
})
.collect::<Vec<_>>();
let mut reordered_columns = vec![]; let mut reordered_columns = vec![];
let mut inserted = false; let mut inserted = false;

View File

@ -266,11 +266,11 @@ mod tests {
impl SignatureRegistry for VecRegistry { impl SignatureRegistry for VecRegistry {
fn has(&self, name: &str) -> bool { fn has(&self, name: &str) -> bool {
self.0.iter().any(|v| &v.name == name) self.0.iter().any(|v| v.name == name)
} }
fn get(&self, name: &str) -> Option<nu_protocol::Signature> { fn get(&self, name: &str) -> Option<nu_protocol::Signature> {
self.0.iter().find(|v| &v.name == name).map(Clone::clone) self.0.iter().find(|v| v.name == name).map(Clone::clone)
} }
fn clone_box(&self) -> Box<dyn SignatureRegistry> { fn clone_box(&self) -> Box<dyn SignatureRegistry> {

View File

@ -53,15 +53,8 @@ pub fn test_examples(cmd: Command) -> Result<(), ShellError> {
if let Some(expected) = &sample_pipeline.result { if let Some(expected) = &sample_pipeline.result {
let result = block_on(evaluate_block(block, &mut ctx))?; let result = block_on(evaluate_block(block, &mut ctx))?;
ctx.with_errors(|reasons| { ctx.with_errors(|reasons| reasons.iter().cloned().take(1).next())
reasons .map_or(Ok(()), Err)?;
.iter()
.cloned()
.take(1)
.next()
.and_then(|err| Some(err))
})
.map_or(Ok(()), |reason| Err(reason))?;
if expected.len() != result.len() { if expected.len() != result.len() {
let rows_returned = let rows_returned =
@ -115,15 +108,8 @@ pub fn test(cmd: impl WholeStreamCommand + 'static) -> Result<(), ShellError> {
if let Some(expected) = &sample_pipeline.result { if let Some(expected) = &sample_pipeline.result {
let result = block_on(evaluate_block(block, &mut ctx))?; let result = block_on(evaluate_block(block, &mut ctx))?;
ctx.with_errors(|reasons| { ctx.with_errors(|reasons| reasons.iter().cloned().take(1).next())
reasons .map_or(Ok(()), Err)?;
.iter()
.cloned()
.take(1)
.next()
.and_then(|err| Some(err))
})
.map_or(Ok(()), |reason| Err(reason))?;
if expected.len() != result.len() { if expected.len() != result.len() {
let rows_returned = let rows_returned =
@ -180,15 +166,8 @@ pub fn test_anchors(cmd: Command) -> Result<(), ShellError> {
let block = parse_line(&pipeline_with_anchor, &mut ctx)?; let block = parse_line(&pipeline_with_anchor, &mut ctx)?;
let result = block_on(evaluate_block(block, &mut ctx))?; let result = block_on(evaluate_block(block, &mut ctx))?;
ctx.with_errors(|reasons| { ctx.with_errors(|reasons| reasons.iter().cloned().take(1).next())
reasons .map_or(Ok(()), Err)?;
.iter()
.cloned()
.take(1)
.next()
.and_then(|err| Some(err))
})
.map_or(Ok(()), |reason| Err(reason))?;
for actual in result.iter() { for actual in result.iter() {
if !is_anchor_carried(actual, mock_path()) { if !is_anchor_carried(actual, mock_path()) {
@ -366,7 +345,7 @@ impl WholeStreamCommand for MockEcho {
match i.as_string() { match i.as_string() {
Ok(s) => OutputStream::one(Ok(ReturnSuccess::Value(Value { Ok(s) => OutputStream::one(Ok(ReturnSuccess::Value(Value {
value: UntaggedValue::Primitive(Primitive::String(s)), value: UntaggedValue::Primitive(Primitive::String(s)),
tag: base_value.tag.clone(), tag: base_value.tag,
}))), }))),
_ => match i { _ => match i {
Value { Value {
@ -384,7 +363,7 @@ impl WholeStreamCommand for MockEcho {
.to_output_stream(), .to_output_stream(),
_ => OutputStream::one(Ok(ReturnSuccess::Value(Value { _ => OutputStream::one(Ok(ReturnSuccess::Value(Value {
value: i.value.clone(), value: i.value.clone(),
tag: base_value.tag.clone(), tag: base_value.tag,
}))), }))),
}, },
} }

View File

@ -9,7 +9,7 @@ fn into_int_filesize() {
"# "#
)); ));
assert!(actual.out.contains("1")); assert!(actual.out.contains('1'));
} }
#[test] #[test]
@ -21,5 +21,5 @@ fn into_int_int() {
"# "#
)); ));
assert!(actual.out.contains("1")); assert!(actual.out.contains('1'));
} }

View File

@ -1,3 +1,3 @@
mod keep; mod rows;
mod until; mod until;
mod while_; mod while_;

View File

@ -33,5 +33,5 @@ fn generates_0() {
"# "#
)); ));
assert!(actual.out.contains("0")); assert!(actual.out.contains('0'));
} }