Skip to content

Commit 6675a84

Browse files
authored
Merge pull request #101 from KodrAus/fix/trailing-commas
Allow trailing commas in type definitions
2 parents 15d8337 + e4a14fd commit 6675a84

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

src/gen.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use proc_macro2::{Span as Span2, TokenStream as TokenStream2};
1+
use proc_macro2::{Span as Span2, TokenStream as TokenStream2, TokenTree as TokenTree2};
22
use quote::{ToTokens, TokenStreamExt};
33
use syn::{
44
punctuated::Punctuated, spanned::Spanned, Attribute, Error, FnArg, GenericParam, Ident,
@@ -246,6 +246,20 @@ fn gen_header(
246246
.skip(1) // the opening `<`
247247
.collect::<Vec<_>>();
248248
tts.pop(); // the closing `>`
249+
250+
// Pop a trailing comma if there is one
251+
// We'll end up conditionally putting one back in shortly
252+
if tts.last().and_then(|tt| {
253+
if let TokenTree2::Punct(p) = tt {
254+
Some(p.as_char())
255+
} else {
256+
None
257+
}
258+
}) == Some(',')
259+
{
260+
tts.pop();
261+
}
262+
249263
params.append_all(&tts);
250264

251265
// Append proxy type parameter (if there aren't any parameters so far,

tests/compile-fail/super_trait_not_implemented.stderr

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
error[E0277]: the trait bound `Box<Dog>: Supi` is not satisfied
1+
error[E0277]: the trait bound `Box<Dog>: Foo` is not satisfied
22
--> tests/compile-fail/super_trait_not_implemented.rs:18:18
33
|
44
18 | requires_foo(Box::new(Dog)); // shouldn't, because `Box<Dog>: Supi` is not satisfied
55
| ------------ ^^^^^^^^^^^^^ the trait `Supi` is not implemented for `Box<Dog>`
66
| |
77
| required by a bound introduced by this call
88
|
9-
= help: the trait `Supi` is implemented for `Dog`
109
note: required for `Box<Dog>` to implement `Foo`
1110
--> tests/compile-fail/super_trait_not_implemented.rs:5:1
1211
|
@@ -20,3 +19,7 @@ note: required by a bound in `requires_foo`
2019
14 | fn requires_foo<T: Foo>(_: T) {}
2120
| ^^^ required by this bound in `requires_foo`
2221
= note: this error originates in the attribute macro `auto_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
22+
help: consider dereferencing here
23+
|
24+
18 | requires_foo(*Box::new(Dog)); // shouldn't, because `Box<Dog>: Supi` is not satisfied
25+
| +

tests/compile-pass/trailing_comma.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use auto_impl::auto_impl;
2+
3+
#[auto_impl(&)]
4+
trait MyTrait<T,> {}
5+
6+
fn main() { }

0 commit comments

Comments
 (0)