Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cargo clippy warning and error #351

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion strum_macros/src/helpers/case_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ pub fn snakify(s: &str) -> String {
let mut output: Vec<char> = s.to_string().to_snake_case().chars().collect();
let mut num_starts = vec![];
for (pos, c) in output.iter().enumerate() {
if c.is_digit(10) && pos != 0 && !output[pos - 1].is_digit(10) {
if c.is_ascii_digit() && pos != 0 && !output[pos - 1].is_ascii_digit() {
num_starts.push(pos);
}
}
Expand Down
2 changes: 1 addition & 1 deletion strum_macros/src/macros/enum_try_as.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn enum_try_as_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
})
},
_ => {
return None;
None
}
}

Expand Down
2 changes: 1 addition & 1 deletion strum_macros/src/macros/strings/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ fn capture_format_string_idents(string_literal: &LitStr) -> syn::Result<Vec<Iden
))?;

let inside_brackets = &format_str[start_index + 1..i];
let ident_str = inside_brackets.split(":").next().unwrap();
let ident_str = inside_brackets.split(':').next().unwrap();
let ident = syn::parse_str::<Ident>(ident_str).map_err(|_| {
syn::Error::new_spanned(
string_literal,
Expand Down
28 changes: 14 additions & 14 deletions strum_tests/tests/enum_is.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ enum Foo {
}
#[test]
fn generics_test() {
let foo = LifeTimeTest::One(Cow::Borrowed("Hello"));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was clippy complaining about this? It doesn't on my machine, and I prefer we avoid changing variables names based on personal preference

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it complains about foo only in nightly. I agree it could be ignored for now.

assert!(foo.is_one());
let foo = LifeTimeTest::Two("Hello");
assert!(foo.is_two());
let foo = LifeTimeTest::One(Cow::Owned("Hello".to_string()));
assert!(foo.is_one());
let foouname = LifeTimeTest::One(Cow::Borrowed("Hello"));
assert!(foouname.is_one());
let foouname = LifeTimeTest::Two("Hello");
assert!(foouname.is_two());
let foouname = LifeTimeTest::One(Cow::Owned("Hello".to_string()));
assert!(foouname.is_one());
}
#[test]
fn simple_test() {
Expand All @@ -47,19 +47,19 @@ fn named_0() {

#[test]
fn named_1() {
let foo = Foo::Named1 {
let foouname = Foo::Named1 {
_a: Default::default(),
};
assert!(foo.is_named_1());
assert!(foouname.is_named_1());
}

#[test]
fn named_2() {
let foo = Foo::Named2 {
let foouname = Foo::Named2 {
_a: Default::default(),
_b: Default::default(),
};
assert!(foo.is_named_2());
assert!(foouname.is_named_2());
}

#[test]
Expand All @@ -69,14 +69,14 @@ fn unnamed_0() {

#[test]
fn unnamed_1() {
let foo = Foo::Unnamed1(Default::default());
assert!(foo.is_unnamed_1());
let foouname = Foo::Unnamed1(Default::default());
assert!(foouname.is_unnamed_1());
}

#[test]
fn unnamed_2() {
let foo = Foo::Unnamed2(Default::default(), Default::default());
assert!(foo.is_unnamed_2());
let foouname = Foo::Unnamed2(Default::default(), Default::default());
assert!(foouname.is_unnamed_2());
}

#[test]
Expand Down
22 changes: 11 additions & 11 deletions strum_tests/tests/enum_try_as.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,33 @@ enum Foo {

#[test]
fn unnamed_0() {
let foo = Foo::Unnamed0();
assert_eq!(Some(()), foo.try_as_unnamed_0());
let foouname = Foo::Unnamed0();
assert_eq!(Some(()), foouname.try_as_unnamed_0());
}

#[test]
fn unnamed_1() {
let foo = Foo::Unnamed1(128);
assert_eq!(Some(&128), foo.try_as_unnamed_1_ref());
let foouname = Foo::Unnamed1(128);
assert_eq!(Some(&128), foouname.try_as_unnamed_1_ref());
}

#[test]
fn unnamed_2() {
let foo = Foo::Unnamed2(true, String::from("Hay"));
assert_eq!(Some((true, String::from("Hay"))), foo.try_as_unnamed_2());
let foouname = Foo::Unnamed2(true, String::from("Hay"));
assert_eq!(Some((true, String::from("Hay"))), foouname.try_as_unnamed_2());
}

#[test]
fn can_mutate() {
let mut foo = Foo::Unnamed1(128);
if let Some(value) = foo.try_as_unnamed_1_mut() {
let mut foouname = Foo::Unnamed1(128);
if let Some(value) = foouname.try_as_unnamed_1_mut() {
*value = 44_u128;
}
assert_eq!(foo.try_as_unnamed_1(), Some(44));
assert_eq!(foouname.try_as_unnamed_1(), Some(44));
}

#[test]
fn doesnt_match_other_variations() {
let foo = Foo::Unnamed1(66);
assert_eq!(None, foo.try_as_unnamed_0());
let foouname = Foo::Unnamed1(66);
assert_eq!(None, foouname.try_as_unnamed_0());
}