Skip to content

Commit

Permalink
Fixed almost all clippy warning
Browse files Browse the repository at this point in the history
  • Loading branch information
la10736 committed May 24, 2021
1 parent 88e32a5 commit 3e6648a
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 89 deletions.
1 change: 1 addition & 0 deletions checkoutlist.md
Expand Up @@ -2,6 +2,7 @@

- [ ] Update rustup
- [ ] Update dependency `cargo upgrade`
- [ ] Run `cargo clippy`
- [ ] Run all test
- [ ] Stable: `RSTEST_TEST_CHANNEL=stable; cargo +${RSTEST_TEST_CHANNEL} test`
- [ ] Beta: `RSTEST_TEST_CHANNEL=beta; cargo +${RSTEST_TEST_CHANNEL} test`
Expand Down
12 changes: 6 additions & 6 deletions src/error.rs
Expand Up @@ -89,9 +89,9 @@ impl From<Vec<syn::Error>> for ErrorsVec {
}
}

impl Into<Vec<syn::Error>> for ErrorsVec {
fn into(self) -> Vec<syn::Error> {
self.0
impl From<ErrorsVec> for Vec<syn::Error> {
fn from(v: ErrorsVec) -> Self {
v.0
}
}

Expand All @@ -101,10 +101,10 @@ impl quote::ToTokens for ErrorsVec {
}
}

impl Into<proc_macro::TokenStream> for ErrorsVec {
fn into(self) -> proc_macro::TokenStream {
impl From<ErrorsVec> for proc_macro::TokenStream {
fn from(v: ErrorsVec) -> Self {
use quote::ToTokens;
self.into_token_stream().into()
v.into_token_stream().into()
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Expand Up @@ -515,7 +515,7 @@ pub fn fixture(
}

if errors.is_empty() {
render::fixture(fixture, info).into()
render::fixture(fixture, info)
} else {
errors
}
Expand Down Expand Up @@ -578,7 +578,7 @@ pub fn fixture(
/// ```
///
/// If you want to use long and descriptive names for your fixture but prefer to use
/// shorter names inside your tests you use rename feature described in
/// shorter names inside your tests you use rename feature described in
/// [fixture rename](attr.fixture.html#rename):
///
/// ```
Expand Down
8 changes: 4 additions & 4 deletions src/parse/expressions.rs
Expand Up @@ -21,8 +21,8 @@ impl Parse for Expressions {
}
}

impl Into<Vec<Expr>> for Expressions {
fn into(self) -> Vec<Expr> {
self.0
impl From<Expressions> for Vec<Expr> {
fn from(expressions: Expressions) -> Self {
expressions.0
}
}
}
12 changes: 6 additions & 6 deletions src/parse/fixture.rs
Expand Up @@ -174,7 +174,7 @@ impl FixtureData {

pub(crate) fn values(&self) -> impl Iterator<Item = &ArgumentValue> {
self.items.iter().filter_map(|f| match f {
FixtureItem::ArgumentValue(ref value) => Some(value),
FixtureItem::ArgumentValue(ref value) => Some(value.as_ref()),
_ => None,
})
}
Expand Down Expand Up @@ -207,7 +207,7 @@ impl ArgumentValue {
#[derive(PartialEq, Debug)]
pub(crate) enum FixtureItem {
Fixture(Fixture),
ArgumentValue(ArgumentValue),
ArgumentValue(Box<ArgumentValue>),
}

impl From<Fixture> for FixtureItem {
Expand All @@ -230,7 +230,7 @@ impl RefIdent for FixtureItem {
fn ident(&self) -> &Ident {
match self {
FixtureItem::Fixture(Fixture { ref name, .. }) => name,
FixtureItem::ArgumentValue(ArgumentValue { ref name, .. }) => name,
FixtureItem::ArgumentValue(ref av) => &av.name,
}
}
}
Expand All @@ -243,7 +243,7 @@ impl ToTokens for FixtureItem {

impl From<ArgumentValue> for FixtureItem {
fn from(av: ArgumentValue) -> Self {
FixtureItem::ArgumentValue(av)
FixtureItem::ArgumentValue(Box::new(av))
}
}

Expand Down Expand Up @@ -273,14 +273,14 @@ impl FixtureModifiers {
pub(crate) fn set_default_return_type(&mut self, return_type: syn::Type) {
self.inner.attributes.push(Attribute::Type(
format_ident!("{}", Self::DEFAULT_RET_ATTR),
return_type,
Box::new(return_type),
))
}

pub(crate) fn set_partial_return_type(&mut self, id: usize, return_type: syn::Type) {
self.inner.attributes.push(Attribute::Type(
format_ident!("{}{}", Self::PARTIAL_RET_ATTR, id),
return_type,
Box::new(return_type),
))
}

Expand Down
4 changes: 2 additions & 2 deletions src/parse/future.rs
Expand Up @@ -61,7 +61,7 @@ impl VisitMut for ReplaceFutureAttribute {
self.errors.extend(futures.iter().skip(1).map(|attr| {
syn::Error::new_spanned(
attr.into_token_stream(),
format!("Cannot use #[future] more than once."),
"Cannot use #[future] more than once.".to_owned(),
)
}));
return;
Expand All @@ -73,7 +73,7 @@ impl VisitMut for ReplaceFutureAttribute {
| TraitObject(_) | Verbatim(_) => {
self.errors.push(syn::Error::new_spanned(
ty.into_token_stream(),
format!("This type cannot used to generete impl Future."),
"This type cannot used to generete impl Future.".to_owned(),
));
return;
}
Expand Down
43 changes: 21 additions & 22 deletions src/parse/mod.rs
Expand Up @@ -57,7 +57,7 @@ impl Parse for Attributes {
pub(crate) enum Attribute {
Attr(Ident),
Tagged(Ident, Vec<Ident>),
Type(Ident, syn::Type),
Type(Ident, Box<syn::Type>),
}

impl Parse for Attribute {
Expand Down Expand Up @@ -96,11 +96,11 @@ where
if input_tokens.is_empty() || input_tokens.peek(Token![::]) {
Ok(None)
} else {
T::parse(input_tokens).map(|inner| Some(inner))
T::parse(input_tokens).map(Some)
}
})?
.into_iter()
.filter_map(|it| it)
.flatten()
.collect(),
)
}
Expand Down Expand Up @@ -190,21 +190,21 @@ pub(crate) fn extract_fixtures(item_fn: &mut ItemFn) -> Result<Vec<Fixture>, Err
let mut fixtures_extractor = FixturesFunctionExtractor::default();
fixtures_extractor.visit_item_fn_mut(item_fn);

if fixtures_extractor.1.len() > 0 {
Err(fixtures_extractor.1.into())
} else {
if fixtures_extractor.1.is_empty() {
Ok(fixtures_extractor.0)
} else {
Err(fixtures_extractor.1.into())
}
}

pub(crate) fn extract_defaults(item_fn: &mut ItemFn) -> Result<Vec<ArgumentValue>, ErrorsVec> {
let mut defaults_extractor = DefaultsFunctionExtractor::default();
defaults_extractor.visit_item_fn_mut(item_fn);

if defaults_extractor.1.len() > 0 {
Err(defaults_extractor.1.into())
} else {
if defaults_extractor.1.is_empty() {
Ok(defaults_extractor.0)
} else {
Err(defaults_extractor.1.into())
}
}

Expand Down Expand Up @@ -277,7 +277,7 @@ impl VisitMut for DefaultTypeFunctionExtractor {
let mut defaults = defaults.into_iter();
let mut data = None;
let mut errors = ErrorsVec::default();
match defaults.nth(0).map(|def| def.parse_args::<syn::Type>()) {
match defaults.next().map(|def| def.parse_args::<syn::Type>()) {
Some(Ok(t)) => data = Some(t),
Some(Err(e)) => errors.push(e),
None => {}
Expand Down Expand Up @@ -376,10 +376,10 @@ pub(crate) fn extract_case_args(item_fn: &mut ItemFn) -> Result<Vec<Ident>, Erro
let mut case_args_extractor = CaseArgsFunctionExtractor::default();
case_args_extractor.visit_item_fn_mut(item_fn);

if case_args_extractor.1.len() > 0 {
Err(case_args_extractor.1.into())
} else {
if case_args_extractor.1.is_empty() {
Ok(case_args_extractor.0)
} else {
Err(case_args_extractor.1.into())
}
}

Expand Down Expand Up @@ -419,10 +419,10 @@ pub(crate) fn extract_cases(item_fn: &mut ItemFn) -> Result<Vec<TestCase>, Error
let mut cases_extractor = CasesFunctionExtractor::default();
cases_extractor.visit_item_fn_mut(item_fn);

if cases_extractor.1.len() > 0 {
Err(cases_extractor.1.into())
} else {
if cases_extractor.1.is_empty() {
Ok(cases_extractor.0)
} else {
Err(cases_extractor.1.into())
}
}

Expand Down Expand Up @@ -457,10 +457,10 @@ pub(crate) fn extract_value_list(item_fn: &mut ItemFn) -> Result<Vec<ValueList>,
let mut vlist_extractor = ValueListFunctionExtractor::default();
vlist_extractor.visit_item_fn_mut(item_fn);

if vlist_extractor.1.len() > 0 {
Err(vlist_extractor.1.into())
} else {
if vlist_extractor.1.is_empty() {
Ok(vlist_extractor.0)
} else {
Err(vlist_extractor.1.into())
}
}

Expand All @@ -483,13 +483,12 @@ impl ExcludedTraceAttributesFunctionExtractor {
Ok(_) => self.0 = Err(errors),
Err(err) => err.append(&mut errors),
}
.into()
}

fn update_excluded(&mut self, value: Ident) {
self.0.iter_mut().next().map(|inner| {
if let Some(inner) = self.0.iter_mut().next() {
inner.push(value);
});
}
}
}

Expand Down
22 changes: 6 additions & 16 deletions src/parse/rstest.rs
Expand Up @@ -212,10 +212,7 @@ impl RsTestAttributes {

pub(crate) fn trace_me(&self, ident: &Ident) -> bool {
if self.should_trace() {
self.iter()
.filter(|&m| Self::is_notrace(ident, m))
.next()
.is_none()
!self.iter().any(|m| Self::is_notrace(ident, m))
} else {
false
}
Expand All @@ -224,14 +221,14 @@ impl RsTestAttributes {
fn is_notrace(ident: &Ident, m: &Attribute) -> bool {
match m {
Attribute::Tagged(i, args) if i == Self::NOTRACE_VARIABLE_ATTR => {
args.iter().find(|&a| a == ident).is_some()
args.iter().any(|a| a == ident)
}
_ => false,
}
}

pub(crate) fn should_trace(&self) -> bool {
self.iter().filter(|&m| Self::is_trace(m)).next().is_some()
self.iter().any(Self::is_trace)
}

pub(crate) fn add_trace(&mut self, trace: Ident) {
Expand All @@ -249,10 +246,7 @@ impl RsTestAttributes {
}

fn is_trace(m: &Attribute) -> bool {
match m {
Attribute::Attr(i) if i == Self::TRACE_VARIABLE_ATTR => true,
_ => false,
}
matches!(m, Attribute::Attr(i) if i == Self::TRACE_VARIABLE_ATTR)
}
}

Expand Down Expand Up @@ -362,7 +356,7 @@ mod test {
fixture("short", &["42", r#""other""#])
.with_resolve("long_fixture_name")
.into(),
fixture("s", &[]).with_resolve("simple").into()
fixture("s", &[]).with_resolve("simple").into(),
]
.into(),
..Default::default()
Expand All @@ -374,7 +368,6 @@ mod test {

assert_eq!(expected, data);
}


#[test]
fn defined_via_with_attributes() {
Expand Down Expand Up @@ -493,10 +486,7 @@ mod test {
let data = info.data;
let fixtures = data.fixtures().cloned().collect::<Vec<_>>();

assert_eq!(
vec![fixture("my_fixture", &["42", r#""foo""#])],
fixtures
);
assert_eq!(vec![fixture("my_fixture", &["42", r#""foo""#])], fixtures);
assert_eq!(
to_strs!(vec!["arg1", "arg2", "arg3"]),
data.case_args()
Expand Down
2 changes: 1 addition & 1 deletion src/parse/vlist.rs
Expand Up @@ -27,7 +27,7 @@ impl Parse for ValueList {
arg,
values: values.take(),
};
if ret.values.len() == 0 {
if ret.values.is_empty() {
Err(syn::Error::new(
paren.span,
"Values list should not be empty",
Expand Down
6 changes: 3 additions & 3 deletions src/render/fixture.rs
Expand Up @@ -8,7 +8,7 @@ use crate::resolver::{self, Resolver};
use crate::utils::{fn_args, fn_args_idents};
use crate::{parse::fixture::FixtureInfo, utils::generics_clean_up};

pub(crate) fn render<'a>(fixture: ItemFn, info: FixtureInfo) -> TokenStream {
pub(crate) fn render(fixture: ItemFn, info: FixtureInfo) -> TokenStream {
let name = &fixture.sig.ident;
let asyncness = &fixture.sig.asyncness.clone();
let vargs = fn_args_idents(&fixture).cloned().collect::<Vec<_>>();
Expand All @@ -19,7 +19,7 @@ pub(crate) fn render<'a>(fixture: ItemFn, info: FixtureInfo) -> TokenStream {
let default_output = info
.attributes
.extract_default_type()
.unwrap_or(fixture.sig.output.clone());
.unwrap_or_else(|| fixture.sig.output.clone());
let default_generics =
generics_clean_up(&fixture.sig.generics, std::iter::empty(), &default_output);
let default_where_clause = &default_generics.where_clause;
Expand Down Expand Up @@ -75,7 +75,7 @@ fn render_partial_impl(
let output = info
.attributes
.extract_partial_type(n)
.unwrap_or(fixture.sig.output.clone());
.unwrap_or_else(|| fixture.sig.output.clone());

let generics = generics_clean_up(&fixture.sig.generics, fn_args(fixture).take(n), &output);
let where_clause = &generics.where_clause;
Expand Down
3 changes: 1 addition & 2 deletions src/render/inject.rs
Expand Up @@ -54,7 +54,6 @@ where
let mut fixture = self
.resolver
.resolve(&fixture_name)
.map(|e| e.clone())
.unwrap_or_else(|| default_fixture_resolve(&fixture_name));

if fixture.is_literal() && self.type_can_be_get_from_literal_str(arg_type) {
Expand All @@ -68,7 +67,7 @@ where

fn fixture_name<'a>(&self, ident: &'a Ident) -> Cow<'a, Ident> {
let id_str = ident.to_string();
if id_str.starts_with("_") && !id_str.starts_with("__") {
if id_str.starts_with('_') && !id_str.starts_with("__") {
Cow::Owned(Ident::new(&id_str[1..], ident.span()))
} else {
Cow::Borrowed(ident)
Expand Down

0 comments on commit 3e6648a

Please sign in to comment.