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

Consider lifetime when adding trait bounds. #61

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
14 changes: 12 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ use syn::parse::{ParseStream, Parser};
use syn::visit::{self, Visit};
use syn::{
braced, punctuated, token, Attribute, Data, DeriveInput, Error, Expr, Field, Fields,
FieldsNamed, FieldsUnnamed, GenericParam, Generics, Ident, PredicateType, Result, Token,
TraitBound, Type, TypeMacro, TypeParamBound, TypePath, WhereClause, WherePredicate,
FieldsNamed, FieldsUnnamed, GenericParam, Generics, Ident, Lifetime, PredicateType, Result,
Token, TraitBound, Type, TypeMacro, TypeParamBound, TypePath, WhereClause, WherePredicate,
};

use quote::{format_ident, quote_spanned, ToTokens};
Expand Down Expand Up @@ -476,6 +476,16 @@ fn get_ty_params(field: &Field, generics: &Generics) -> Vec<bool> {
}
}

fn visit_lifetime(&mut self, id: &'a Lifetime) {
for (idx, i) in self.generics.params.iter().enumerate() {
if let GenericParam::Lifetime(lparam) = i {
if lparam.lifetime == *id {
self.result[idx] = true;
}
}
}
}

fn visit_type_macro(&mut self, x: &'a TypeMacro) {
// If we see a type_mac declaration, then we can't know what type parameters
// it might be binding, so we presume it binds all of them.
Expand Down