Skip to content

Commit

Permalink
style: Make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Oct 12, 2023
1 parent e597616 commit 55f95c7
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 68 deletions.
15 changes: 3 additions & 12 deletions crates/toml/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ impl<'de> serde::de::VariantAccess<'de> for MapEnumDeserializer {
}
}
Value::Table(values) => {
let tuple_values = values
let tuple_values: Result<Vec<_>, _> = values
.into_iter()
.enumerate()
.map(|(index, (key, value))| match key.parse::<usize>() {
Expand All @@ -822,17 +822,8 @@ impl<'de> serde::de::VariantAccess<'de> for MapEnumDeserializer {
index, key
))),
})
// Fold all values into a `Vec`, or return the first error.
.fold(Ok(Vec::with_capacity(len)), |result, value_result| {
result.and_then(move |mut tuple_values| match value_result {
Ok(value) => {
tuple_values.push(value);
Ok(tuple_values)
}
// `Result<de::Value, Self::Error>` to `Result<Vec<_>, Self::Error>`
Err(e) => Err(e),
})
})?;
.collect();
let tuple_values = tuple_values?;

if tuple_values.len() == len {
serde::de::Deserializer::deserialize_seq(
Expand Down
12 changes: 6 additions & 6 deletions crates/toml/tests/testsuite/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn pretty_std() {
assert_eq(toml, &result);
}

const PRETTY_TRICKY: &str = r##"[example]
const PRETTY_TRICKY: &str = r#"[example]
f = "\f"
glass = """
Nothing too unusual, except that I can eat glass in:
Expand All @@ -72,7 +72,7 @@ This has a ''' in it and \"\"\" cuz it's tricky yo
Also ' and \" because why not
this is the fourth line
"""
"##;
"#;

#[test]
fn pretty_tricky() {
Expand All @@ -85,7 +85,7 @@ fn pretty_tricky() {
assert_eq(toml, &result);
}

const PRETTY_TABLE_ARRAY: &str = r##"[[array]]
const PRETTY_TABLE_ARRAY: &str = r#"[[array]]
key = "foo"
[[array]]
Expand All @@ -96,7 +96,7 @@ doc = "this is a table"
[example]
single = "this is a single line string"
"##;
"#;

#[test]
fn pretty_table_array() {
Expand All @@ -109,7 +109,7 @@ fn pretty_table_array() {
assert_eq(toml, &result);
}

const TABLE_ARRAY: &str = r##"[[array]]
const TABLE_ARRAY: &str = r#"[[array]]
key = "foo"
[[array]]
Expand All @@ -120,7 +120,7 @@ doc = "this is a table"
[example]
single = "this is a single line string"
"##;
"#;

#[test]
fn table_array() {
Expand Down
2 changes: 1 addition & 1 deletion crates/toml_datetime/src/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ impl FromStr for Datetime {

fn digit(chars: &mut str::Chars<'_>) -> Result<u8, DatetimeParseError> {
match chars.next() {
Some(c) if ('0'..='9').contains(&c) => Ok(c as u8 - b'0'),
Some(c) if c.is_ascii_digit() => Ok(c as u8 - b'0'),
_ => Err(DatetimeParseError {}),
}
}
Expand Down
30 changes: 6 additions & 24 deletions crates/toml_edit/src/de/table_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl<'de> serde::de::VariantAccess<'de> for TableEnumDeserializer {
}
crate::Item::Table(values) => {
let values_span = values.span();
let tuple_values = values
let tuple_values: Result<Vec<_>, _> = values
.items
.into_iter()
.enumerate()
Expand All @@ -114,17 +114,8 @@ impl<'de> serde::de::VariantAccess<'de> for TableEnumDeserializer {
)),
},
)
// Fold all values into a `Vec`, or return the first error.
.fold(Ok(Vec::with_capacity(len)), |result, value_result| {
result.and_then(move |mut tuple_values| match value_result {
Ok(value) => {
tuple_values.push(value);
Ok(tuple_values)
}
// `Result<de::Value, Self::Error>` to `Result<Vec<_>, Self::Error>`
Err(e) => Err(e),
})
})?;
.collect();
let tuple_values = tuple_values?;

if tuple_values.len() == len {
serde::de::Deserializer::deserialize_seq(
Expand All @@ -140,7 +131,7 @@ impl<'de> serde::de::VariantAccess<'de> for TableEnumDeserializer {
}
crate::Item::Value(crate::Value::InlineTable(values)) => {
let values_span = values.span();
let tuple_values = values
let tuple_values: Result<Vec<_>, _> = values
.items
.into_iter()
.enumerate()
Expand All @@ -157,17 +148,8 @@ impl<'de> serde::de::VariantAccess<'de> for TableEnumDeserializer {
)),
},
)
// Fold all values into a `Vec`, or return the first error.
.fold(Ok(Vec::with_capacity(len)), |result, value_result| {
result.and_then(move |mut tuple_values| match value_result {
Ok(value) => {
tuple_values.push(value);
Ok(tuple_values)
}
// `Result<de::Value, Self::Error>` to `Result<Vec<_>, Self::Error>`
Err(e) => Err(e),
})
})?;
.collect();
let tuple_values = tuple_values?;

if tuple_values.len() == len {
serde::de::Deserializer::deserialize_seq(
Expand Down
6 changes: 3 additions & 3 deletions crates/toml_edit/src/inline_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ impl InlineTable {
values
}

pub(crate) fn append_values<'s, 'c>(
pub(crate) fn append_values<'s>(
&'s self,
parent: &[&'s Key],
values: &'c mut Vec<(Vec<&'s Key>, &'s Value)>,
values: &mut Vec<(Vec<&'s Key>, &'s Value)>,
) {
for value in self.items.values() {
let mut path = parent.to_vec();
Expand Down Expand Up @@ -467,7 +467,7 @@ fn decorate_inline_table(table: &mut InlineTable) {
for (key_decor, value) in table
.items
.iter_mut()
.filter(|&(_, ref kv)| kv.value.is_value())
.filter(|(_, kv)| kv.value.is_value())
.map(|(_, kv)| (&mut kv.key.decor, kv.value.as_value_mut().unwrap()))
{
key_decor.clear();
Expand Down
9 changes: 2 additions & 7 deletions crates/toml_edit/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ use crate::table::TableLike;
use crate::{Array, InlineTable, Table, Value};

/// Type representing either a value, a table, an array of tables, or none.
#[derive(Debug)]
#[derive(Debug, Default)]
pub enum Item {
/// Type representing none.
#[default]
None,
/// Type representing value.
Value(Value),
Expand Down Expand Up @@ -328,12 +329,6 @@ impl Clone for Item {
}
}

impl Default for Item {
fn default() -> Self {
Item::None
}
}

impl FromStr for Item {
type Err = crate::TomlError;

Expand Down
1 change: 0 additions & 1 deletion crates/toml_edit/src/parser/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ fn translate_position(input: &[u8], index: usize) -> (usize, usize) {
None => 0,
};
let line = input[0..line_start].iter().filter(|b| **b == b'\n').count();
let line = line;

let column = std::str::from_utf8(&input[line_start..=index])
.map(|s| s.chars().count() - 1)
Expand Down
2 changes: 1 addition & 1 deletion crates/toml_edit/src/parser/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ mod test {
let cases = [
("a", "a"),
(r#""hello\n ""#, "hello\n "),
(r#"'hello\n '"#, "hello\\n "),
(r"'hello\n '", "hello\\n "),
];

for (input, expected) in cases {
Expand Down
4 changes: 2 additions & 2 deletions crates/toml_edit/src/parser/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ impl ParseState {
Ok(())
}

pub(crate) fn descend_path<'t, 'k>(
pub(crate) fn descend_path<'t>(
mut table: &'t mut Table,
path: &'k [Key],
path: &[Key],
dotted: bool,
) -> Result<&'t mut Table, CustomError> {
for (i, key) in path.iter().enumerate() {
Expand Down
8 changes: 4 additions & 4 deletions crates/toml_edit/src/parser/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,10 @@ The quick brown \
#[test]
fn literal_string() {
let inputs = [
r#"'C:\Users\nodejs\templates'"#,
r#"'\\ServerX\admin$\system32\'"#,
r"'C:\Users\nodejs\templates'",
r"'\\ServerX\admin$\system32\'",
r#"'Tom "Dubs" Preston-Werner'"#,
r#"'<\i\c*\s*>'"#,
r"'<\i\c*\s*>'",
];

for input in &inputs {
Expand All @@ -456,7 +456,7 @@ The quick brown \
#[test]
fn ml_literal_string() {
let inputs = [
r#"'''I [dw]on't need \d{2} apples'''"#,
r"'''I [dw]on't need \d{2} apples'''",
r#"''''one_quote''''"#,
];
for input in &inputs {
Expand Down
2 changes: 1 addition & 1 deletion crates/toml_edit/src/parser/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ mod test {
"-239",
"1e200",
"9_224_617.445_991_228_313",
r#"'''I [dw]on't need \d{2} apples'''"#,
r"'''I [dw]on't need \d{2} apples'''",
r#"'''
The first newline is
trimmed in raw strings.
Expand Down
6 changes: 3 additions & 3 deletions crates/toml_edit/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ impl Table {
values
}

fn append_values<'s, 'c>(
fn append_values<'s>(
&'s self,
parent: &[&'s Key],
values: &'c mut Vec<(Vec<&'s Key>, &'s Value)>,
values: &mut Vec<(Vec<&'s Key>, &'s Value)>,
) {
for value in self.items.values() {
let mut path = parent.to_vec();
Expand Down Expand Up @@ -474,7 +474,7 @@ fn decorate_table(table: &mut Table) {
for (key_decor, value) in table
.items
.iter_mut()
.filter(|&(_, ref kv)| kv.value.is_value())
.filter(|(_, kv)| kv.value.is_value())
.map(|(_, kv)| (&mut kv.key.decor, kv.value.as_value_mut().unwrap()))
{
key_decor.clear();
Expand Down
6 changes: 3 additions & 3 deletions crates/toml_edit/tests/testsuite/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ multiline basic string
""""#
)
.is_str());
assert!(parse_value!(r#"'literal string\ \'"#).is_str());
assert!(parse_value!(r"'literal string\ \'").is_str());
assert!(parse_value!(
r#"'''multiline
r"'''multiline
literal \ \
string'''"#
string'''"
)
.is_str());
assert!(parse_value!(r#"{ hello = "world", a = 1}"#).is_inline_table());
Expand Down

0 comments on commit 55f95c7

Please sign in to comment.