Skip to content

Commit

Permalink
document new helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
japaric committed Dec 15, 2020
1 parent 95e0914 commit 659442e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ use syn::{
WhereClause, WherePredicate,
};

fn reject_attributes(
// appears in the error message
/// Checks if any attribute in `attrs_to_check` is in `reject_list` and returns a compiler error if there's a match
///
/// The compiler error will indicate that the attribute conflicts with `attr_name`
fn check_attribute_conflicts(
attr_name: &str,
attrs_to_check: &[Attribute],
reject_list: &[&str],
Expand Down Expand Up @@ -122,7 +124,8 @@ pub fn panic_handler(args: TokenStream, input: TokenStream) -> TokenStream {
}

let attrs = &f.attrs;
if let Err(e) = reject_attributes("panic_handler", attrs, &["export_name", "no_mangle"]) {
if let Err(e) = check_attribute_conflicts("panic_handler", attrs, &["export_name", "no_mangle"])
{
return e.to_compile_error().into();
}
let block = &f.block;
Expand Down Expand Up @@ -173,7 +176,7 @@ pub fn timestamp(args: TokenStream, input: TokenStream) -> TokenStream {
}

let attrs = &f.attrs;
if let Err(e) = reject_attributes("timestamp", attrs, &["export_name", "no_mangle"]) {
if let Err(e) = check_attribute_conflicts("timestamp", attrs, &["export_name", "no_mangle"]) {
return e.to_compile_error().into();
}
let block = &f.block;
Expand Down

0 comments on commit 659442e

Please sign in to comment.