Skip to content

Commit 250b492

Browse files
committed
Auto merge of #45930 - jplatte:generics_refactoring, r=eddyb
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`.
2 parents b7b52cc + 78493ed commit 250b492

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1024
-836
lines changed

src/librustc/hir/intravisit.rs

+23-19
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ pub trait Visitor<'v> : Sized {
279279
fn visit_ty(&mut self, t: &'v Ty) {
280280
walk_ty(self, t)
281281
}
282+
fn visit_generic_param(&mut self, p: &'v GenericParam) {
283+
walk_generic_param(self, p)
284+
}
282285
fn visit_generics(&mut self, g: &'v Generics) {
283286
walk_generics(self, g)
284287
}
@@ -336,9 +339,6 @@ pub trait Visitor<'v> : Sized {
336339
fn visit_lifetime(&mut self, lifetime: &'v Lifetime) {
337340
walk_lifetime(self, lifetime)
338341
}
339-
fn visit_lifetime_def(&mut self, lifetime: &'v LifetimeDef) {
340-
walk_lifetime_def(self, lifetime)
341-
}
342342
fn visit_qpath(&mut self, qpath: &'v QPath, id: NodeId, span: Span) {
343343
walk_qpath(self, qpath, id, span)
344344
}
@@ -430,17 +430,12 @@ pub fn walk_lifetime<'v, V: Visitor<'v>>(visitor: &mut V, lifetime: &'v Lifetime
430430
}
431431
}
432432

433-
pub fn walk_lifetime_def<'v, V: Visitor<'v>>(visitor: &mut V, lifetime_def: &'v LifetimeDef) {
434-
visitor.visit_lifetime(&lifetime_def.lifetime);
435-
walk_list!(visitor, visit_lifetime, &lifetime_def.bounds);
436-
}
437-
438433
pub fn walk_poly_trait_ref<'v, V>(visitor: &mut V,
439434
trait_ref: &'v PolyTraitRef,
440435
_modifier: TraitBoundModifier)
441436
where V: Visitor<'v>
442437
{
443-
walk_list!(visitor, visit_lifetime_def, &trait_ref.bound_lifetimes);
438+
walk_list!(visitor, visit_generic_param, &trait_ref.bound_generic_params);
444439
visitor.visit_trait_ref(&trait_ref.trait_ref);
445440
}
446441

@@ -581,7 +576,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
581576
}
582577
TyBareFn(ref function_declaration) => {
583578
visitor.visit_fn_decl(&function_declaration.decl);
584-
walk_list!(visitor, visit_lifetime_def, &function_declaration.lifetimes);
579+
walk_list!(visitor, visit_generic_param, &function_declaration.generic_params);
585580
}
586581
TyPath(ref qpath) => {
587582
visitor.visit_qpath(qpath, typ.id, typ.span);
@@ -729,14 +724,23 @@ pub fn walk_ty_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v TyPar
729724
}
730725
}
731726

732-
pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics) {
733-
for param in &generics.ty_params {
734-
visitor.visit_id(param.id);
735-
visitor.visit_name(param.span, param.name);
736-
walk_list!(visitor, visit_ty_param_bound, &param.bounds);
737-
walk_list!(visitor, visit_ty, &param.default);
727+
pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v GenericParam) {
728+
match *param {
729+
GenericParam::Lifetime(ref ld) => {
730+
visitor.visit_lifetime(&ld.lifetime);
731+
walk_list!(visitor, visit_lifetime, &ld.bounds);
732+
}
733+
GenericParam::Type(ref ty_param) => {
734+
visitor.visit_id(ty_param.id);
735+
visitor.visit_name(ty_param.span, ty_param.name);
736+
walk_list!(visitor, visit_ty_param_bound, &ty_param.bounds);
737+
walk_list!(visitor, visit_ty, &ty_param.default);
738+
}
738739
}
739-
walk_list!(visitor, visit_lifetime_def, &generics.lifetimes);
740+
}
741+
742+
pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics) {
743+
walk_list!(visitor, visit_generic_param, &generics.params);
740744
visitor.visit_id(generics.where_clause.id);
741745
walk_list!(visitor, visit_where_predicate, &generics.where_clause.predicates);
742746
}
@@ -748,11 +752,11 @@ pub fn walk_where_predicate<'v, V: Visitor<'v>>(
748752
match predicate {
749753
&WherePredicate::BoundPredicate(WhereBoundPredicate{ref bounded_ty,
750754
ref bounds,
751-
ref bound_lifetimes,
755+
ref bound_generic_params,
752756
..}) => {
753757
visitor.visit_ty(bounded_ty);
754758
walk_list!(visitor, visit_ty_param_bound, bounds);
755-
walk_list!(visitor, visit_lifetime_def, bound_lifetimes);
759+
walk_list!(visitor, visit_generic_param, bound_generic_params);
756760
}
757761
&WherePredicate::RegionPredicate(WhereRegionPredicate{ref lifetime,
758762
ref bounds,

0 commit comments

Comments
 (0)