Skip to content

Commit

Permalink
fix clippy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nightmared committed Feb 27, 2021
1 parent 1bd8a87 commit b00c9f1
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions tracing-attributes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,18 +328,16 @@ fn instrument_handle_recent_async_trait(
let mut variable_rebindings = Vec::with_capacity(pre_statements.len());
for stmt in pre_statements.iter() {
if let Stmt::Local(Local {
pat,
pat: Pat::Ident(PatIdent { ident, .. }),
init: Some((_, source_path)),
..
}) = stmt
{
if let Pat::Ident(PatIdent { ident, .. }) = pat {
if let Expr::Path(source_path) = source_path.as_ref() {
variable_rebindings.push((
ident.clone(),
Ident::new(&path_to_string(&source_path.path), source_path.span()),
));
}
if let Expr::Path(source_path) = source_path.as_ref() {
variable_rebindings.push((
ident.clone(),
Ident::new(&path_to_string(&source_path.path), source_path.span()),
));
}
}
}
Expand Down Expand Up @@ -395,8 +393,8 @@ fn instrument_handle_recent_async_trait(
}

// given an existing function, generate an instrumented version of that function
fn gen_function<'a>(
input: &'a ItemFn,
fn gen_function(
input: &ItemFn,
args: InstrumentArgs,
instrumented_function_name: String,
variables_rebindings: Vec<(Ident, Ident)>,
Expand Down Expand Up @@ -549,7 +547,7 @@ fn gen_block<'a>(
// eplace every use of a variable by its original name
if let Some(Fields(ref mut fields)) = args.fields {
let mut replacer = KnifeReplacer {
idents: param_names.clone(),
idents: param_names,
types: Vec::new(),
};

Expand Down Expand Up @@ -1149,8 +1147,11 @@ struct KnifeReplacer<'a> {
}

impl<'a> syn::visit_mut::VisitMut for KnifeReplacer<'a> {
#[allow(clippy::cmp_owned)]
fn visit_ident_mut(&mut self, id: &mut Ident) {
for (old_ident, new_ident) in &self.idents {
// we deliberately compare strings because we want to ignore the spans
// If we apply clippy's lint, the behavior changes
if id.to_string() == old_ident.to_string() {
*id = new_ident.clone();
}
Expand Down Expand Up @@ -1184,17 +1185,19 @@ impl<'a> syn::visit::Visit<'a> for AsyncTraitBlockFinder<'a> {
fn visit_block(&mut self, i: &'a Block) {
let mut pre_statements = Vec::new();
for (pos, stmt) in i.stmts.iter().enumerate() {
if let Stmt::Local(Local { pat, .. }) = stmt {
if let Pat::Type(PatType { pat: pat_type, .. }) = pat {
if let Pat::Ident(PatIdent { ident, .. }) = pat_type.as_ref() {
if ident == "__async_trait" {
self.block = Some(AsyncTraitBlock {
block: i,
pre_statements,
post_statements: i.stmts[pos + 1..].iter().collect(),
});
return;
}
if let Stmt::Local(Local {
pat: Pat::Type(PatType { pat: pat_type, .. }),
..
}) = stmt
{
if let Pat::Ident(PatIdent { ident, .. }) = pat_type.as_ref() {
if ident == "__async_trait" {
self.block = Some(AsyncTraitBlock {
block: i,
pre_statements,
post_statements: i.stmts[pos + 1..].iter().collect(),
});
return;
}
}
}
Expand Down

0 comments on commit b00c9f1

Please sign in to comment.