Skip to content

Avoid repeated trait bounds in derived impls #27134

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

Merged
merged 1 commit into from
Aug 3, 2015
Merged
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
11 changes: 11 additions & 0 deletions src/libsyntax/ext/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ pub use self::SubstructureFields::*;
use self::StructType::*;

use std::cell::RefCell;
use std::collections::HashSet;
use std::vec;

use abi::Abi;
Expand Down Expand Up @@ -549,10 +550,20 @@ impl<'a> TraitDef<'a> {
.map(|ty_param| ty_param.ident.name)
.collect();

let mut processed_field_types = HashSet::new();
for field_ty in field_tys {
let tys = find_type_parameters(&*field_ty, &ty_param_names);

for ty in tys {
// if we have already handled this type, skip it
if let ast::TyPath(_, ref p) = ty.node {
if p.segments.len() == 1
&& ty_param_names.contains(&p.segments[0].identifier.name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could just add these to the process_fields_types HashSet to begin with; processed_field_types.extend(ty_param_names.iter().cloned()).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, unless I'm misunderstanding your comment. ty_param_names are ast::Names, while the elements of processed_field_types are Vec<ast::PathSegment>. It's not clear to me that we can somehow convert one into the other for comparison.

|| processed_field_types.contains(&p.segments) {
continue;
};
processed_field_types.insert(p.segments.clone());
}
let mut bounds: Vec<_> = self.additional_bounds.iter().map(|p| {
cx.typarambound(p.to_path(cx, self.span, type_ident, generics))
}).collect();
Expand Down