Skip to content

Commit

Permalink
Auto merge of #45930 - jplatte:generics_refactoring, r=eddyb
Browse files Browse the repository at this point in the history
Generics refactoring (groundwork for const generics)

These changes were suggested by @eddyb.

After this change, the `Generics` contain one `Vec` of an enum for the generic parameters, rather than two separate `Vec`s for lifetime and type parameters. Type params and const params will need to be in a shared `Vec` to preserve their ordering, and moving lifetimes into the same `Vec` should simplify the code that processes `Generics`.
  • Loading branch information
bors committed Dec 21, 2017
2 parents b7b52cc + 78493ed commit 250b492
Show file tree
Hide file tree
Showing 51 changed files with 1,024 additions and 836 deletions.
42 changes: 23 additions & 19 deletions src/librustc/hir/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ pub trait Visitor<'v> : Sized {
fn visit_ty(&mut self, t: &'v Ty) {
walk_ty(self, t)
}
fn visit_generic_param(&mut self, p: &'v GenericParam) {
walk_generic_param(self, p)
}
fn visit_generics(&mut self, g: &'v Generics) {
walk_generics(self, g)
}
Expand Down Expand Up @@ -336,9 +339,6 @@ pub trait Visitor<'v> : Sized {
fn visit_lifetime(&mut self, lifetime: &'v Lifetime) {
walk_lifetime(self, lifetime)
}
fn visit_lifetime_def(&mut self, lifetime: &'v LifetimeDef) {
walk_lifetime_def(self, lifetime)
}
fn visit_qpath(&mut self, qpath: &'v QPath, id: NodeId, span: Span) {
walk_qpath(self, qpath, id, span)
}
Expand Down Expand Up @@ -430,17 +430,12 @@ pub fn walk_lifetime<'v, V: Visitor<'v>>(visitor: &mut V, lifetime: &'v Lifetime
}
}

pub fn walk_lifetime_def<'v, V: Visitor<'v>>(visitor: &mut V, lifetime_def: &'v LifetimeDef) {
visitor.visit_lifetime(&lifetime_def.lifetime);
walk_list!(visitor, visit_lifetime, &lifetime_def.bounds);
}

pub fn walk_poly_trait_ref<'v, V>(visitor: &mut V,
trait_ref: &'v PolyTraitRef,
_modifier: TraitBoundModifier)
where V: Visitor<'v>
{
walk_list!(visitor, visit_lifetime_def, &trait_ref.bound_lifetimes);
walk_list!(visitor, visit_generic_param, &trait_ref.bound_generic_params);
visitor.visit_trait_ref(&trait_ref.trait_ref);
}

Expand Down Expand Up @@ -581,7 +576,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
}
TyBareFn(ref function_declaration) => {
visitor.visit_fn_decl(&function_declaration.decl);
walk_list!(visitor, visit_lifetime_def, &function_declaration.lifetimes);
walk_list!(visitor, visit_generic_param, &function_declaration.generic_params);
}
TyPath(ref qpath) => {
visitor.visit_qpath(qpath, typ.id, typ.span);
Expand Down Expand Up @@ -729,14 +724,23 @@ pub fn walk_ty_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v TyPar
}
}

pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics) {
for param in &generics.ty_params {
visitor.visit_id(param.id);
visitor.visit_name(param.span, param.name);
walk_list!(visitor, visit_ty_param_bound, &param.bounds);
walk_list!(visitor, visit_ty, &param.default);
pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v GenericParam) {
match *param {
GenericParam::Lifetime(ref ld) => {
visitor.visit_lifetime(&ld.lifetime);
walk_list!(visitor, visit_lifetime, &ld.bounds);
}
GenericParam::Type(ref ty_param) => {
visitor.visit_id(ty_param.id);
visitor.visit_name(ty_param.span, ty_param.name);
walk_list!(visitor, visit_ty_param_bound, &ty_param.bounds);
walk_list!(visitor, visit_ty, &ty_param.default);
}
}
walk_list!(visitor, visit_lifetime_def, &generics.lifetimes);
}

pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics) {
walk_list!(visitor, visit_generic_param, &generics.params);
visitor.visit_id(generics.where_clause.id);
walk_list!(visitor, visit_where_predicate, &generics.where_clause.predicates);
}
Expand All @@ -748,11 +752,11 @@ pub fn walk_where_predicate<'v, V: Visitor<'v>>(
match predicate {
&WherePredicate::BoundPredicate(WhereBoundPredicate{ref bounded_ty,
ref bounds,
ref bound_lifetimes,
ref bound_generic_params,
..}) => {
visitor.visit_ty(bounded_ty);
walk_list!(visitor, visit_ty_param_bound, bounds);
walk_list!(visitor, visit_lifetime_def, bound_lifetimes);
walk_list!(visitor, visit_generic_param, bound_generic_params);
}
&WherePredicate::RegionPredicate(WhereRegionPredicate{ref lifetime,
ref bounds,
Expand Down
Loading

0 comments on commit 250b492

Please sign in to comment.