Skip to content

Commit

Permalink
Merge branch 'ijackson-leaking-bounds'
Browse files Browse the repository at this point in the history
  • Loading branch information
magiclen committed Jun 1, 2024
2 parents 47bd92f + 3f98647 commit b867288
Show file tree
Hide file tree
Showing 40 changed files with 127 additions and 89 deletions.
28 changes: 14 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1910,7 +1910,7 @@ use syn::{
#[allow(unused)]
use trait_handlers::{TraitHandler, TraitHandlerMultiple};

fn derive_input_handler(mut ast: DeriveInput) -> syn::Result<proc_macro2::TokenStream> {
fn derive_input_handler(ast: DeriveInput) -> syn::Result<proc_macro2::TokenStream> {
let mut token_stream = proc_macro2::TokenStream::new();
let mut trait_meta_map: HashMap<Trait, Vec<Meta>> = HashMap::new();

Expand Down Expand Up @@ -1960,7 +1960,7 @@ fn derive_input_handler(mut ast: DeriveInput) -> syn::Result<proc_macro2::TokenS
{
if let Some(meta) = trait_meta_map.get(&Trait::Debug) {
trait_handlers::debug::DebugHandler::trait_meta_handler(
&mut ast,
&ast,
&mut token_stream,
&traits,
&meta[0],
Expand All @@ -1972,7 +1972,7 @@ fn derive_input_handler(mut ast: DeriveInput) -> syn::Result<proc_macro2::TokenS
{
if let Some(meta) = trait_meta_map.get(&Trait::Clone) {
trait_handlers::clone::CloneHandler::trait_meta_handler(
&mut ast,
&ast,
&mut token_stream,
&traits,
&meta[0],
Expand All @@ -1984,7 +1984,7 @@ fn derive_input_handler(mut ast: DeriveInput) -> syn::Result<proc_macro2::TokenS
{
if let Some(meta) = trait_meta_map.get(&Trait::Copy) {
trait_handlers::copy::CopyHandler::trait_meta_handler(
&mut ast,
&ast,
&mut token_stream,
&traits,
&meta[0],
Expand All @@ -1996,7 +1996,7 @@ fn derive_input_handler(mut ast: DeriveInput) -> syn::Result<proc_macro2::TokenS
{
if let Some(meta) = trait_meta_map.get(&Trait::PartialEq) {
trait_handlers::partial_eq::PartialEqHandler::trait_meta_handler(
&mut ast,
&ast,
&mut token_stream,
&traits,
&meta[0],
Expand All @@ -2008,7 +2008,7 @@ fn derive_input_handler(mut ast: DeriveInput) -> syn::Result<proc_macro2::TokenS
{
if let Some(meta) = trait_meta_map.get(&Trait::Eq) {
trait_handlers::eq::EqHandler::trait_meta_handler(
&mut ast,
&ast,
&mut token_stream,
&traits,
&meta[0],
Expand All @@ -2020,7 +2020,7 @@ fn derive_input_handler(mut ast: DeriveInput) -> syn::Result<proc_macro2::TokenS
{
if let Some(meta) = trait_meta_map.get(&Trait::PartialOrd) {
trait_handlers::partial_ord::PartialOrdHandler::trait_meta_handler(
&mut ast,
&ast,
&mut token_stream,
&traits,
&meta[0],
Expand All @@ -2032,7 +2032,7 @@ fn derive_input_handler(mut ast: DeriveInput) -> syn::Result<proc_macro2::TokenS
{
if let Some(meta) = trait_meta_map.get(&Trait::Ord) {
trait_handlers::ord::OrdHandler::trait_meta_handler(
&mut ast,
&ast,
&mut token_stream,
&traits,
&meta[0],
Expand All @@ -2044,7 +2044,7 @@ fn derive_input_handler(mut ast: DeriveInput) -> syn::Result<proc_macro2::TokenS
{
if let Some(meta) = trait_meta_map.get(&Trait::Hash) {
trait_handlers::hash::HashHandler::trait_meta_handler(
&mut ast,
&ast,
&mut token_stream,
&traits,
&meta[0],
Expand All @@ -2056,7 +2056,7 @@ fn derive_input_handler(mut ast: DeriveInput) -> syn::Result<proc_macro2::TokenS
{
if let Some(meta) = trait_meta_map.get(&Trait::Default) {
trait_handlers::default::DefaultHandler::trait_meta_handler(
&mut ast,
&ast,
&mut token_stream,
&traits,
&meta[0],
Expand All @@ -2068,7 +2068,7 @@ fn derive_input_handler(mut ast: DeriveInput) -> syn::Result<proc_macro2::TokenS
{
if let Some(meta) = trait_meta_map.get(&Trait::Deref) {
trait_handlers::deref::DerefHandler::trait_meta_handler(
&mut ast,
&ast,
&mut token_stream,
&traits,
&meta[0],
Expand All @@ -2080,7 +2080,7 @@ fn derive_input_handler(mut ast: DeriveInput) -> syn::Result<proc_macro2::TokenS
{
if let Some(meta) = trait_meta_map.get(&Trait::DerefMut) {
trait_handlers::deref_mut::DerefMutHandler::trait_meta_handler(
&mut ast,
&ast,
&mut token_stream,
&traits,
&meta[0],
Expand All @@ -2092,7 +2092,7 @@ fn derive_input_handler(mut ast: DeriveInput) -> syn::Result<proc_macro2::TokenS
{
if let Some(meta) = trait_meta_map.get(&Trait::Into) {
trait_handlers::into::IntoHandler::trait_meta_handler(
&mut ast,
&ast,
&mut token_stream,
&traits,
meta,
Expand All @@ -2102,7 +2102,7 @@ fn derive_input_handler(mut ast: DeriveInput) -> syn::Result<proc_macro2::TokenS

if trait_meta_map.contains_key(&Trait::_Nothing) {
// avoid unused warnings
let _ = &mut ast;
let _ = &ast;
let _ = &mut token_stream;
let _ = traits;
unreachable!();
Expand Down
7 changes: 4 additions & 3 deletions src/trait_handlers/clone/clone_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub(crate) struct CloneEnumHandler;
impl TraitHandler for CloneEnumHandler {
#[inline]
fn trait_meta_handler(
ast: &mut DeriveInput,
ast: &DeriveInput,
token_stream: &mut proc_macro2::TokenStream,
traits: &[Trait],
meta: &Meta,
Expand Down Expand Up @@ -239,13 +239,14 @@ impl TraitHandler for CloneEnumHandler {

let ident = &ast.ident;

let where_clause = ast.generics.make_where_clause();
let mut generics = ast.generics.clone();
let where_clause = generics.make_where_clause();

for where_predicate in bound {
where_clause.predicates.push(where_predicate);
}

let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl();
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();

token_stream.extend(quote! {
impl #impl_generics ::core::clone::Clone for #ident #ty_generics #where_clause {
Expand Down
7 changes: 4 additions & 3 deletions src/trait_handlers/clone/clone_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub(crate) struct CloneStructHandler;
impl TraitHandler for CloneStructHandler {
#[inline]
fn trait_meta_handler(
ast: &mut DeriveInput,
ast: &DeriveInput,
token_stream: &mut proc_macro2::TokenStream,
traits: &[Trait],
meta: &Meta,
Expand Down Expand Up @@ -162,13 +162,14 @@ impl TraitHandler for CloneStructHandler {

let ident = &ast.ident;

let where_clause = ast.generics.make_where_clause();
let mut generics = ast.generics.clone();
let where_clause = generics.make_where_clause();

for where_predicate in bound {
where_clause.predicates.push(where_predicate);
}

let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl();
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();

token_stream.extend(quote! {
impl #impl_generics ::core::clone::Clone for #ident #ty_generics #where_clause {
Expand Down
7 changes: 4 additions & 3 deletions src/trait_handlers/clone/clone_union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub(crate) struct CloneUnionHandler;

impl TraitHandler for CloneUnionHandler {
fn trait_meta_handler(
ast: &mut DeriveInput,
ast: &DeriveInput,
token_stream: &mut proc_macro2::TokenStream,
traits: &[Trait],
meta: &Meta,
Expand Down Expand Up @@ -42,13 +42,14 @@ impl TraitHandler for CloneUnionHandler {
&[],
);

let where_clause = ast.generics.make_where_clause();
let mut generics = ast.generics.clone();
let where_clause = generics.make_where_clause();

for where_predicate in bound {
where_clause.predicates.push(where_predicate);
}

let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl();
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();

token_stream.extend(quote! {
impl #impl_generics ::core::clone::Clone for #ident #ty_generics #where_clause {
Expand Down
2 changes: 1 addition & 1 deletion src/trait_handlers/clone/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub(crate) struct CloneHandler;
impl TraitHandler for CloneHandler {
#[inline]
fn trait_meta_handler(
ast: &mut DeriveInput,
ast: &DeriveInput,
token_stream: &mut proc_macro2::TokenStream,
traits: &[Trait],
meta: &Meta,
Expand Down
7 changes: 4 additions & 3 deletions src/trait_handlers/copy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub(crate) struct CopyHandler;
impl TraitHandler for CopyHandler {
#[inline]
fn trait_meta_handler(
ast: &mut DeriveInput,
ast: &DeriveInput,
token_stream: &mut proc_macro2::TokenStream,
traits: &[Trait],
meta: &Meta,
Expand Down Expand Up @@ -74,13 +74,14 @@ impl TraitHandler for CopyHandler {
&[quote! {::core::clone::Clone}],
);

let where_clause = ast.generics.make_where_clause();
let mut generics = ast.generics.clone();
let where_clause = generics.make_where_clause();

for where_predicate in bound {
where_clause.predicates.push(where_predicate);
}

let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl();
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();

token_stream.extend(quote! {
impl #impl_generics ::core::marker::Copy for #ident #ty_generics #where_clause {
Expand Down
7 changes: 4 additions & 3 deletions src/trait_handlers/debug/debug_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub(crate) struct DebugEnumHandler;

impl TraitHandler for DebugEnumHandler {
fn trait_meta_handler(
ast: &mut DeriveInput,
ast: &DeriveInput,
token_stream: &mut proc_macro2::TokenStream,
traits: &[Trait],
meta: &Meta,
Expand Down Expand Up @@ -339,13 +339,14 @@ impl TraitHandler for DebugEnumHandler {
&[],
);

let where_clause = ast.generics.make_where_clause();
let mut generics = ast.generics.clone();
let where_clause = generics.make_where_clause();

for where_predicate in bound {
where_clause.predicates.push(where_predicate);
}

let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl();
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();

token_stream.extend(quote! {
impl #impl_generics ::core::fmt::Debug for #ident #ty_generics #where_clause {
Expand Down
7 changes: 4 additions & 3 deletions src/trait_handlers/debug/debug_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct DebugStructHandler;

impl TraitHandler for DebugStructHandler {
fn trait_meta_handler(
ast: &mut DeriveInput,
ast: &DeriveInput,
token_stream: &mut proc_macro2::TokenStream,
traits: &[Trait],
meta: &Meta,
Expand Down Expand Up @@ -160,13 +160,14 @@ impl TraitHandler for DebugStructHandler {
&[],
);

let where_clause = ast.generics.make_where_clause();
let mut generics = ast.generics.clone();
let where_clause = generics.make_where_clause();

for where_predicate in bound {
where_clause.predicates.push(where_predicate);
}

let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl();
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();

token_stream.extend(quote! {
impl #impl_generics ::core::fmt::Debug for #ident #ty_generics #where_clause {
Expand Down
2 changes: 1 addition & 1 deletion src/trait_handlers/debug/debug_union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub(crate) struct DebugUnionHandler;

impl TraitHandler for DebugUnionHandler {
fn trait_meta_handler(
ast: &mut DeriveInput,
ast: &DeriveInput,
token_stream: &mut proc_macro2::TokenStream,
traits: &[Trait],
meta: &Meta,
Expand Down
2 changes: 1 addition & 1 deletion src/trait_handlers/debug/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub(crate) struct DebugHandler;
impl TraitHandler for DebugHandler {
#[inline]
fn trait_meta_handler(
ast: &mut DeriveInput,
ast: &DeriveInput,
token_stream: &mut proc_macro2::TokenStream,
traits: &[Trait],
meta: &Meta,
Expand Down
7 changes: 4 additions & 3 deletions src/trait_handlers/default/default_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub(crate) struct DefaultEnumHandler;

impl TraitHandler for DefaultEnumHandler {
fn trait_meta_handler(
ast: &mut DeriveInput,
ast: &DeriveInput,
token_stream: &mut proc_macro2::TokenStream,
traits: &[Trait],
meta: &Meta,
Expand Down Expand Up @@ -169,13 +169,14 @@ impl TraitHandler for DefaultEnumHandler {
&[],
);

let where_clause = ast.generics.make_where_clause();
let mut generics = ast.generics.clone();
let where_clause = generics.make_where_clause();

for where_predicate in bound {
where_clause.predicates.push(where_predicate);
}

let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl();
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();

token_stream.extend(quote! {
impl #impl_generics ::core::default::Default for #ident #ty_generics #where_clause {
Expand Down
7 changes: 4 additions & 3 deletions src/trait_handlers/default/default_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub(crate) struct DefaultStructHandler;

impl TraitHandler for DefaultStructHandler {
fn trait_meta_handler(
ast: &mut DeriveInput,
ast: &DeriveInput,
token_stream: &mut proc_macro2::TokenStream,
traits: &[Trait],
meta: &Meta,
Expand Down Expand Up @@ -114,13 +114,14 @@ impl TraitHandler for DefaultStructHandler {
&[],
);

let where_clause = ast.generics.make_where_clause();
let mut generics = ast.generics.clone();
let where_clause = generics.make_where_clause();

for where_predicate in bound {
where_clause.predicates.push(where_predicate);
}

let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl();
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();

token_stream.extend(quote! {
impl #impl_generics ::core::default::Default for #ident #ty_generics #where_clause {
Expand Down
7 changes: 4 additions & 3 deletions src/trait_handlers/default/default_union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub(crate) struct DefaultUnionHandler;

impl TraitHandler for DefaultUnionHandler {
fn trait_meta_handler(
ast: &mut DeriveInput,
ast: &DeriveInput,
token_stream: &mut proc_macro2::TokenStream,
traits: &[Trait],
meta: &Meta,
Expand Down Expand Up @@ -118,13 +118,14 @@ impl TraitHandler for DefaultUnionHandler {
&[],
);

let where_clause = ast.generics.make_where_clause();
let mut generics = ast.generics.clone();
let where_clause = generics.make_where_clause();

for where_predicate in bound {
where_clause.predicates.push(where_predicate);
}

let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl();
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();

token_stream.extend(quote! {
impl #impl_generics ::core::default::Default for #ident #ty_generics #where_clause {
Expand Down
2 changes: 1 addition & 1 deletion src/trait_handlers/default/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub(crate) struct DefaultHandler;
impl TraitHandler for DefaultHandler {
#[inline]
fn trait_meta_handler(
ast: &mut DeriveInput,
ast: &DeriveInput,
token_stream: &mut proc_macro2::TokenStream,
traits: &[Trait],
meta: &Meta,
Expand Down
Loading

0 comments on commit b867288

Please sign in to comment.