Skip to content

Commit

Permalink
Merge pull request #22 from MingweiSamuel/supertrait
Browse files Browse the repository at this point in the history
Fix handling of supertraits, fix #21
  • Loading branch information
jmg-duarte authored Aug 15, 2024
2 parents cd857a3 + d7177c3 commit b9fe92b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,11 @@ pub fn sealed(args: TokenStream, input: TokenStream) -> TokenStream {
fn parse_sealed_trait(mut item_trait: syn::ItemTrait, args: TraitArguments) -> TokenStream2 {
let trait_ident = &item_trait.ident.unraw();
let trait_generics = &item_trait.generics;
let trait_supertraits = &item_trait.supertraits;
let seal = seal_name(trait_ident);
let vis = &args.visibility;

let (_, ty_generics, where_clause) = trait_generics.split_for_impl();
item_trait
.supertraits
.push(parse_quote!( #seal::Sealed #ty_generics ));

let mod_code = if args.erased {
let lifetimes = trait_generics.lifetimes();
Expand All @@ -174,10 +172,13 @@ fn parse_sealed_trait(mut item_trait: syn::ItemTrait, args: TraitArguments) -> T
// to supertraits in the middle). So we output them separately.
quote! {
use super::*;
pub trait Sealed #trait_generics #where_clause {}
pub trait Sealed #trait_generics : #trait_supertraits #where_clause {}
}
};

item_trait
.supertraits
.push(parse_quote!( #seal::Sealed #ty_generics ));
quote! {
#[automatically_derived]
#vis mod #seal {
Expand Down
10 changes: 10 additions & 0 deletions tests/pass/14-supertrait.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use sealed::sealed;

#[sealed]
pub trait CopyIterator: Iterator
where
Self::Item: Copy,
{
}

fn main() {}

0 comments on commit b9fe92b

Please sign in to comment.