diff --git a/src/gen.rs b/src/gen.rs index ffb8795..6c61815 100644 --- a/src/gen.rs +++ b/src/gen.rs @@ -1,4 +1,4 @@ -use proc_macro2::{Span as Span2, TokenStream as TokenStream2}; +use proc_macro2::{Span as Span2, TokenStream as TokenStream2, TokenTree as TokenTree2}; use quote::{ToTokens, TokenStreamExt}; use syn::{ punctuated::Punctuated, spanned::Spanned, Attribute, Error, FnArg, GenericParam, Ident, @@ -246,6 +246,20 @@ fn gen_header( .skip(1) // the opening `<` .collect::>(); tts.pop(); // the closing `>` + + // Pop a trailing comma if there is one + // We'll end up conditionally putting one back in shortly + if tts.last().and_then(|tt| { + if let TokenTree2::Punct(p) = tt { + Some(p.as_char()) + } else { + None + } + }) == Some(',') + { + tts.pop(); + } + params.append_all(&tts); // Append proxy type parameter (if there aren't any parameters so far, diff --git a/tests/compile-fail/super_trait_not_implemented.stderr b/tests/compile-fail/super_trait_not_implemented.stderr index 52513b6..96b16ef 100644 --- a/tests/compile-fail/super_trait_not_implemented.stderr +++ b/tests/compile-fail/super_trait_not_implemented.stderr @@ -1,4 +1,4 @@ -error[E0277]: the trait bound `Box: Supi` is not satisfied +error[E0277]: the trait bound `Box: Foo` is not satisfied --> tests/compile-fail/super_trait_not_implemented.rs:18:18 | 18 | requires_foo(Box::new(Dog)); // shouldn't, because `Box: Supi` is not satisfied @@ -6,7 +6,6 @@ error[E0277]: the trait bound `Box: Supi` is not satisfied | | | required by a bound introduced by this call | - = help: the trait `Supi` is implemented for `Dog` note: required for `Box` to implement `Foo` --> tests/compile-fail/super_trait_not_implemented.rs:5:1 | @@ -20,3 +19,7 @@ note: required by a bound in `requires_foo` 14 | fn requires_foo(_: T) {} | ^^^ required by this bound in `requires_foo` = note: this error originates in the attribute macro `auto_impl` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider dereferencing here + | +18 | requires_foo(*Box::new(Dog)); // shouldn't, because `Box: Supi` is not satisfied + | + diff --git a/tests/compile-pass/trailing_comma.rs b/tests/compile-pass/trailing_comma.rs new file mode 100644 index 0000000..0c805b8 --- /dev/null +++ b/tests/compile-pass/trailing_comma.rs @@ -0,0 +1,6 @@ +use auto_impl::auto_impl; + +#[auto_impl(&)] +trait MyTrait {} + +fn main() { }