Rust 1.49 Clippy Fixes (#2835)

This commit is contained in:
Joseph T. Lyons
2020-12-31 21:13:59 -05:00
committed by GitHub
parent 3ef53fe2cd
commit 15d49e4096
19 changed files with 25 additions and 28 deletions

View File

@ -238,6 +238,7 @@ pub trait WholeStreamCommand: Send + Sync {
// Custom commands are blocks, so we can use the information in the block to also
// implement a WholeStreamCommand
#[allow(clippy::suspicious_else_formatting)]
#[async_trait]
impl WholeStreamCommand for Block {
fn name(&self) -> &str {

View File

@ -35,7 +35,7 @@ fn from_attributes_to_value(attributes: &[roxmltree::Attribute], tag: impl Into<
collected.into_value()
}
fn from_node_to_value<'a, 'd>(n: &roxmltree::Node<'a, 'd>, tag: impl Into<Tag>) -> Value {
fn from_node_to_value(n: &roxmltree::Node, tag: impl Into<Tag>) -> Value {
let tag = tag.into();
if n.is_element() {

View File

@ -59,7 +59,7 @@ pub async fn bool_command(args: CommandArgs) -> Result<OutputStream, ShellError>
if let Some(prob) = bias {
probability = *prob as f64;
let probability_is_valid = 0.0 <= probability && probability <= 1.0;
let probability_is_valid = (0.0..=1.0).contains(&probability);
if !probability_is_valid {
return Err(ShellError::labeled_error(

View File

@ -197,7 +197,7 @@ async fn seq_dates(args: CommandArgs) -> Result<OutputStream, ShellError> {
let clone = i.clone();
i.to_value(clone.tag)
}
_ => (1 as i64).to_value_create_tag(),
_ => (1_i64).to_value_create_tag(),
};
let day_count: Option<Value> = match days {

View File

@ -251,7 +251,7 @@ fn process_arguments(range: Value, name: impl Into<Tag>) -> Result<(isize, isize
}?;
let start = match &search {
SubstringText(start, _) if start == "" || start == "_" => 0,
SubstringText(start, _) if start.is_empty() || start == "_" => 0,
SubstringText(start, _) => start.trim().parse().map_err(|_| {
ShellError::labeled_error(
"could not perform substring",
@ -262,7 +262,7 @@ fn process_arguments(range: Value, name: impl Into<Tag>) -> Result<(isize, isize
};
let end = match &search {
SubstringText(_, end) if end == "" || end == "_" => isize::max_value(),
SubstringText(_, end) if end.is_empty() || end == "_" => isize::max_value(),
SubstringText(_, end) => end.trim().parse().map_err(|_| {
ShellError::labeled_error(
"could not perform substring",

View File

@ -75,7 +75,7 @@ fn values_to_entries(
let mut row: Vec<StyledString> = headers
.iter()
.map(|d: &StyledString| {
if d.contents == "" {
if d.contents.is_empty() {
match value {
Value {
value: UntaggedValue::Row(..),

View File

@ -284,7 +284,7 @@ async fn to_html(args: CommandArgs) -> Result<OutputStream, ShellError> {
let input: Vec<Value> = input.collect().await;
let headers = nu_protocol::merge_descriptors(&input);
let headers = Some(headers)
.filter(|headers| !headers.is_empty() && (headers.len() > 1 || headers[0] != ""));
.filter(|headers| !headers.is_empty() && (headers.len() > 1 || !headers[0].is_empty()));
let mut output_string = String::new();
let mut regex_hm: HashMap<u32, (&str, String)> = HashMap::new();

View File

@ -59,7 +59,7 @@ async fn to_md(args: CommandArgs) -> Result<OutputStream, ShellError> {
let mut escaped_headers: Vec<String> = Vec::new();
let mut column_widths: Vec<usize> = Vec::new();
if !headers.is_empty() && (headers.len() > 1 || headers[0] != "") {
if !headers.is_empty() && (headers.len() > 1 || !headers[0].is_empty()) {
for header in &headers {
let escaped_header_string = htmlescape::encode_minimal(&header);
column_widths.push(escaped_header_string.len());

View File

@ -7,7 +7,6 @@ use quick_xml::events::{BytesEnd, BytesStart, BytesText, Event};
use std::collections::HashSet;
use std::io::Cursor;
use std::io::Write;
use std::iter::FromIterator;
pub struct ToXML;
@ -77,7 +76,7 @@ pub fn get_children(row: &Value) -> Option<&Vec<Value>> {
pub fn is_xml_row(row: &Value) -> bool {
if let UntaggedValue::Row(r) = &row.value {
let keys: HashSet<&String> = HashSet::from_iter(r.keys());
let keys: HashSet<&String> = r.keys().collect();
let children: String = "children".to_string();
let attributes: String = "attributes".to_string();
return keys.contains(&children) && keys.contains(&attributes) && keys.len() == 2;

View File

@ -38,7 +38,7 @@ impl Completer for CommandCompleter {
})
.collect();
if partial != "" {
if !partial.is_empty() {
let path_completer = crate::completion::path::PathCompleter;
let path_results = path_completer.path_suggestions(partial, matcher);
let iter = path_results.into_iter().filter_map(|path_suggestion| {

View File

@ -22,7 +22,7 @@ impl PathCompleter {
None => ("", expanded),
};
let base_dir = if base_dir_name == "" {
let base_dir = if base_dir_name.is_empty() {
PathBuf::from(".")
} else {
#[cfg(feature = "directories")]