Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of supertraits, fix #21 #22

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {}