Skip to content

Commit

Permalink
Merge #889
Browse files Browse the repository at this point in the history
889: Don't insert a duplicate trailing comma in `gluon_codegen` r=Marwes a=Aaron1011

Currently, `gluon_codegen` unconditionall inserts a comma after the
user-provided `where` clause. However, the `where` clause may already
have a trailing comma, which will result in an unparsable `TokenStream`
being generated.

The `AliasRef` struct would be affected by this bug, but a rustc bug
causes the exact parsed `TokenStream` to be lost in some cases
(see rust-lang/rust#43081) - in this case, due
to the presence of `#[cfg_attr]`.

When PR rust-lang/rust#76130 is merged, the
exact parsed `TokenStream` will be passed to proc-macros in more cases,
exposing this bug.

Co-authored-by: Aaron Hill <[email protected]>
  • Loading branch information
bors[bot] and Aaron1011 authored Sep 24, 2020
2 parents c313ab8 + 787c43c commit 112263e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion codegen/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ pub fn split_for_impl<'a>(
let (_, ty_generics, where_clause) = generics.split_for_impl();
let ty_generics = ty_generics.clone();
let where_clause = where_clause
.map(|clause| quote! { #clause, })
.map(|clause| {
if clause.predicates.empty_or_trailing() {
quote! { #clause }
} else {
quote! { #clause, }
}
})
.unwrap_or(quote! { where });

// generate the generic params for the impl block
Expand Down

0 comments on commit 112263e

Please sign in to comment.