Skip to content

Commit

Permalink
attributes: check if a skipped parameter exists (#600)
Browse files Browse the repository at this point in the history
This PR adds a check to the `#[instrument]` macro to emit a compiler
error if the user tries to skip non-existing parameters.

Fixes: #562
  • Loading branch information
Kobzol authored Feb 25, 2020
1 parent 503d936 commit d533f90
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tracing-attributes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,19 @@ pub fn instrument(args: TokenStream, item: TokenStream) -> TokenStream {
FnArg::Typed(PatType { pat, .. }) => param_names(*pat),
FnArg::Receiver(_) => Box::new(iter::once(Ident::new("self", param.span()))),
})
.collect();

for skip in &skips {
if !param_names.contains(skip) {
return quote_spanned!(skip.span()=>
compile_error!("attempting to skip non-existent parameter")
)
.into();
}
}

let param_names: Vec<Ident> = param_names
.into_iter()
.filter(|ident| !skips.contains(ident))
.collect();

Expand Down

0 comments on commit d533f90

Please sign in to comment.