Improve naming in WherePredicate

This commit is contained in:
David Tolnay 2018-01-01 20:13:24 -08:00
parent bdafb10843
commit d4add859c2
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
6 changed files with 113 additions and 113 deletions

View File

@ -314,6 +314,12 @@ fn fold_path_segment(&mut self, i: PathSegment) -> PathSegment { fold_path_segme
fn fold_poly_trait_ref(&mut self, i: PolyTraitRef) -> PolyTraitRef { fold_poly_trait_ref(self, i) }
fn fold_predicate_eq(&mut self, i: PredicateEq) -> PredicateEq { fold_predicate_eq(self, i) }
fn fold_predicate_lifetime(&mut self, i: PredicateLifetime) -> PredicateLifetime { fold_predicate_lifetime(self, i) }
fn fold_predicate_type(&mut self, i: PredicateType) -> PredicateType { fold_predicate_type(self, i) }
fn fold_qself(&mut self, i: QSelf) -> QSelf { fold_qself(self, i) }
# [ cfg ( feature = "full" ) ]
fn fold_range_limits(&mut self, i: RangeLimits) -> RangeLimits { fold_range_limits(self, i) }
@ -394,16 +400,10 @@ fn fold_vis_restricted(&mut self, i: VisRestricted) -> VisRestricted { fold_vis_
fn fold_visibility(&mut self, i: Visibility) -> Visibility { fold_visibility(self, i) }
fn fold_where_bound_predicate(&mut self, i: WhereBoundPredicate) -> WhereBoundPredicate { fold_where_bound_predicate(self, i) }
fn fold_where_clause(&mut self, i: WhereClause) -> WhereClause { fold_where_clause(self, i) }
fn fold_where_eq_predicate(&mut self, i: WhereEqPredicate) -> WhereEqPredicate { fold_where_eq_predicate(self, i) }
fn fold_where_predicate(&mut self, i: WherePredicate) -> WherePredicate { fold_where_predicate(self, i) }
fn fold_where_region_predicate(&mut self, i: WhereRegionPredicate) -> WhereRegionPredicate { fold_where_region_predicate(self, i) }
}
pub fn fold_ident<V: Folder + ?Sized>(_visitor: &mut V, mut _i: Ident) -> Ident {
@ -2314,6 +2314,31 @@ pub fn fold_poly_trait_ref<V: Folder + ?Sized>(_visitor: &mut V, _i: PolyTraitRe
}
}
pub fn fold_predicate_eq<V: Folder + ?Sized>(_visitor: &mut V, _i: PredicateEq) -> PredicateEq {
PredicateEq {
lhs_ty: _visitor.fold_type(_i . lhs_ty),
eq_token: Token ! [ = ](tokens_helper(_visitor, &(_i . eq_token).0)),
rhs_ty: _visitor.fold_type(_i . rhs_ty),
}
}
pub fn fold_predicate_lifetime<V: Folder + ?Sized>(_visitor: &mut V, _i: PredicateLifetime) -> PredicateLifetime {
PredicateLifetime {
lifetime: _visitor.fold_lifetime(_i . lifetime),
colon_token: (_i . colon_token).map(|it| { Token ! [ : ](tokens_helper(_visitor, &(it).0)) }),
bounds: FoldHelper::lift(_i . bounds, |it| { _visitor.fold_lifetime(it) }),
}
}
pub fn fold_predicate_type<V: Folder + ?Sized>(_visitor: &mut V, _i: PredicateType) -> PredicateType {
PredicateType {
bound_lifetimes: (_i . bound_lifetimes).map(|it| { _visitor.fold_bound_lifetimes(it) }),
bounded_ty: _visitor.fold_type(_i . bounded_ty),
colon_token: Token ! [ : ](tokens_helper(_visitor, &(_i . colon_token).0)),
bounds: FoldHelper::lift(_i . bounds, |it| { _visitor.fold_type_param_bound(it) }),
}
}
pub fn fold_qself<V: Folder + ?Sized>(_visitor: &mut V, _i: QSelf) -> QSelf {
QSelf {
lt_token: Token ! [ < ](tokens_helper(_visitor, &(_i . lt_token).0)),
@ -2815,15 +2840,6 @@ pub fn fold_visibility<V: Folder + ?Sized>(_visitor: &mut V, _i: Visibility) ->
}
}
pub fn fold_where_bound_predicate<V: Folder + ?Sized>(_visitor: &mut V, _i: WhereBoundPredicate) -> WhereBoundPredicate {
WhereBoundPredicate {
bound_lifetimes: (_i . bound_lifetimes).map(|it| { _visitor.fold_bound_lifetimes(it) }),
bounded_ty: _visitor.fold_type(_i . bounded_ty),
colon_token: Token ! [ : ](tokens_helper(_visitor, &(_i . colon_token).0)),
bounds: FoldHelper::lift(_i . bounds, |it| { _visitor.fold_type_param_bound(it) }),
}
}
pub fn fold_where_clause<V: Folder + ?Sized>(_visitor: &mut V, _i: WhereClause) -> WhereClause {
WhereClause {
where_token: Token ! [ where ](tokens_helper(_visitor, &(_i . where_token).0)),
@ -2831,39 +2847,23 @@ pub fn fold_where_clause<V: Folder + ?Sized>(_visitor: &mut V, _i: WhereClause)
}
}
pub fn fold_where_eq_predicate<V: Folder + ?Sized>(_visitor: &mut V, _i: WhereEqPredicate) -> WhereEqPredicate {
WhereEqPredicate {
lhs_ty: _visitor.fold_type(_i . lhs_ty),
eq_token: Token ! [ = ](tokens_helper(_visitor, &(_i . eq_token).0)),
rhs_ty: _visitor.fold_type(_i . rhs_ty),
}
}
pub fn fold_where_predicate<V: Folder + ?Sized>(_visitor: &mut V, _i: WherePredicate) -> WherePredicate {
match _i {
WherePredicate::BoundPredicate(_binding_0, ) => {
WherePredicate::BoundPredicate (
_visitor.fold_where_bound_predicate(_binding_0),
WherePredicate::Type(_binding_0, ) => {
WherePredicate::Type (
_visitor.fold_predicate_type(_binding_0),
)
}
WherePredicate::RegionPredicate(_binding_0, ) => {
WherePredicate::RegionPredicate (
_visitor.fold_where_region_predicate(_binding_0),
WherePredicate::Lifetime(_binding_0, ) => {
WherePredicate::Lifetime (
_visitor.fold_predicate_lifetime(_binding_0),
)
}
WherePredicate::EqPredicate(_binding_0, ) => {
WherePredicate::EqPredicate (
_visitor.fold_where_eq_predicate(_binding_0),
WherePredicate::Eq(_binding_0, ) => {
WherePredicate::Eq (
_visitor.fold_predicate_eq(_binding_0),
)
}
}
}
pub fn fold_where_region_predicate<V: Folder + ?Sized>(_visitor: &mut V, _i: WhereRegionPredicate) -> WhereRegionPredicate {
WhereRegionPredicate {
lifetime: _visitor.fold_lifetime(_i . lifetime),
colon_token: (_i . colon_token).map(|it| { Token ! [ : ](tokens_helper(_visitor, &(it).0)) }),
bounds: FoldHelper::lift(_i . bounds, |it| { _visitor.fold_lifetime(it) }),
}
}

View File

@ -310,6 +310,12 @@ fn visit_path_segment(&mut self, i: &'ast PathSegment) { visit_path_segment(self
fn visit_poly_trait_ref(&mut self, i: &'ast PolyTraitRef) { visit_poly_trait_ref(self, i) }
fn visit_predicate_eq(&mut self, i: &'ast PredicateEq) { visit_predicate_eq(self, i) }
fn visit_predicate_lifetime(&mut self, i: &'ast PredicateLifetime) { visit_predicate_lifetime(self, i) }
fn visit_predicate_type(&mut self, i: &'ast PredicateType) { visit_predicate_type(self, i) }
fn visit_qself(&mut self, i: &'ast QSelf) { visit_qself(self, i) }
# [ cfg ( feature = "full" ) ]
fn visit_range_limits(&mut self, i: &'ast RangeLimits) { visit_range_limits(self, i) }
@ -390,16 +396,10 @@ fn visit_vis_restricted(&mut self, i: &'ast VisRestricted) { visit_vis_restricte
fn visit_visibility(&mut self, i: &'ast Visibility) { visit_visibility(self, i) }
fn visit_where_bound_predicate(&mut self, i: &'ast WhereBoundPredicate) { visit_where_bound_predicate(self, i) }
fn visit_where_clause(&mut self, i: &'ast WhereClause) { visit_where_clause(self, i) }
fn visit_where_eq_predicate(&mut self, i: &'ast WhereEqPredicate) { visit_where_eq_predicate(self, i) }
fn visit_where_predicate(&mut self, i: &'ast WherePredicate) { visit_where_predicate(self, i) }
fn visit_where_region_predicate(&mut self, i: &'ast WhereRegionPredicate) { visit_where_region_predicate(self, i) }
}
@ -1798,6 +1798,25 @@ pub fn visit_poly_trait_ref<'ast, V: Visitor<'ast> + ?Sized>(_visitor: &mut V, _
_visitor.visit_path(& _i . trait_ref);
}
pub fn visit_predicate_eq<'ast, V: Visitor<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast PredicateEq) {
_visitor.visit_type(& _i . lhs_ty);
tokens_helper(_visitor, &(& _i . eq_token).0);
_visitor.visit_type(& _i . rhs_ty);
}
pub fn visit_predicate_lifetime<'ast, V: Visitor<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast PredicateLifetime) {
_visitor.visit_lifetime(& _i . lifetime);
if let Some(ref it) = _i . colon_token { tokens_helper(_visitor, &(it).0) };
for el in & _i . bounds { let it = el.item(); _visitor.visit_lifetime(it) };
}
pub fn visit_predicate_type<'ast, V: Visitor<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast PredicateType) {
if let Some(ref it) = _i . bound_lifetimes { _visitor.visit_bound_lifetimes(it) };
_visitor.visit_type(& _i . bounded_ty);
tokens_helper(_visitor, &(& _i . colon_token).0);
for el in & _i . bounds { let it = el.item(); _visitor.visit_type_param_bound(it) };
}
pub fn visit_qself<'ast, V: Visitor<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast QSelf) {
tokens_helper(_visitor, &(& _i . lt_token).0);
_visitor.visit_type(& * _i . ty);
@ -2162,41 +2181,22 @@ pub fn visit_visibility<'ast, V: Visitor<'ast> + ?Sized>(_visitor: &mut V, _i: &
}
}
pub fn visit_where_bound_predicate<'ast, V: Visitor<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast WhereBoundPredicate) {
if let Some(ref it) = _i . bound_lifetimes { _visitor.visit_bound_lifetimes(it) };
_visitor.visit_type(& _i . bounded_ty);
tokens_helper(_visitor, &(& _i . colon_token).0);
for el in & _i . bounds { let it = el.item(); _visitor.visit_type_param_bound(it) };
}
pub fn visit_where_clause<'ast, V: Visitor<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast WhereClause) {
tokens_helper(_visitor, &(& _i . where_token).0);
for el in & _i . predicates { let it = el.item(); _visitor.visit_where_predicate(it) };
}
pub fn visit_where_eq_predicate<'ast, V: Visitor<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast WhereEqPredicate) {
_visitor.visit_type(& _i . lhs_ty);
tokens_helper(_visitor, &(& _i . eq_token).0);
_visitor.visit_type(& _i . rhs_ty);
}
pub fn visit_where_predicate<'ast, V: Visitor<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast WherePredicate) {
match *_i {
WherePredicate::BoundPredicate(ref _binding_0, ) => {
_visitor.visit_where_bound_predicate(_binding_0);
WherePredicate::Type(ref _binding_0, ) => {
_visitor.visit_predicate_type(_binding_0);
}
WherePredicate::RegionPredicate(ref _binding_0, ) => {
_visitor.visit_where_region_predicate(_binding_0);
WherePredicate::Lifetime(ref _binding_0, ) => {
_visitor.visit_predicate_lifetime(_binding_0);
}
WherePredicate::EqPredicate(ref _binding_0, ) => {
_visitor.visit_where_eq_predicate(_binding_0);
WherePredicate::Eq(ref _binding_0, ) => {
_visitor.visit_predicate_eq(_binding_0);
}
}
}
pub fn visit_where_region_predicate<'ast, V: Visitor<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast WhereRegionPredicate) {
_visitor.visit_lifetime(& _i . lifetime);
if let Some(ref it) = _i . colon_token { tokens_helper(_visitor, &(it).0) };
for el in & _i . bounds { let it = el.item(); _visitor.visit_lifetime(it) };
}

View File

@ -310,6 +310,12 @@ fn visit_path_segment_mut(&mut self, i: &mut PathSegment) { visit_path_segment_m
fn visit_poly_trait_ref_mut(&mut self, i: &mut PolyTraitRef) { visit_poly_trait_ref_mut(self, i) }
fn visit_predicate_eq_mut(&mut self, i: &mut PredicateEq) { visit_predicate_eq_mut(self, i) }
fn visit_predicate_lifetime_mut(&mut self, i: &mut PredicateLifetime) { visit_predicate_lifetime_mut(self, i) }
fn visit_predicate_type_mut(&mut self, i: &mut PredicateType) { visit_predicate_type_mut(self, i) }
fn visit_qself_mut(&mut self, i: &mut QSelf) { visit_qself_mut(self, i) }
# [ cfg ( feature = "full" ) ]
fn visit_range_limits_mut(&mut self, i: &mut RangeLimits) { visit_range_limits_mut(self, i) }
@ -390,16 +396,10 @@ fn visit_vis_restricted_mut(&mut self, i: &mut VisRestricted) { visit_vis_restri
fn visit_visibility_mut(&mut self, i: &mut Visibility) { visit_visibility_mut(self, i) }
fn visit_where_bound_predicate_mut(&mut self, i: &mut WhereBoundPredicate) { visit_where_bound_predicate_mut(self, i) }
fn visit_where_clause_mut(&mut self, i: &mut WhereClause) { visit_where_clause_mut(self, i) }
fn visit_where_eq_predicate_mut(&mut self, i: &mut WhereEqPredicate) { visit_where_eq_predicate_mut(self, i) }
fn visit_where_predicate_mut(&mut self, i: &mut WherePredicate) { visit_where_predicate_mut(self, i) }
fn visit_where_region_predicate_mut(&mut self, i: &mut WhereRegionPredicate) { visit_where_region_predicate_mut(self, i) }
}
@ -1798,6 +1798,25 @@ pub fn visit_poly_trait_ref_mut<V: VisitorMut + ?Sized>(_visitor: &mut V, _i: &m
_visitor.visit_path_mut(& mut _i . trait_ref);
}
pub fn visit_predicate_eq_mut<V: VisitorMut + ?Sized>(_visitor: &mut V, _i: &mut PredicateEq) {
_visitor.visit_type_mut(& mut _i . lhs_ty);
tokens_helper(_visitor, &mut (& mut _i . eq_token).0);
_visitor.visit_type_mut(& mut _i . rhs_ty);
}
pub fn visit_predicate_lifetime_mut<V: VisitorMut + ?Sized>(_visitor: &mut V, _i: &mut PredicateLifetime) {
_visitor.visit_lifetime_mut(& mut _i . lifetime);
if let Some(ref mut it) = _i . colon_token { tokens_helper(_visitor, &mut (it).0) };
for mut el in & mut _i . bounds { let it = el.item_mut(); _visitor.visit_lifetime_mut(it) };
}
pub fn visit_predicate_type_mut<V: VisitorMut + ?Sized>(_visitor: &mut V, _i: &mut PredicateType) {
if let Some(ref mut it) = _i . bound_lifetimes { _visitor.visit_bound_lifetimes_mut(it) };
_visitor.visit_type_mut(& mut _i . bounded_ty);
tokens_helper(_visitor, &mut (& mut _i . colon_token).0);
for mut el in & mut _i . bounds { let it = el.item_mut(); _visitor.visit_type_param_bound_mut(it) };
}
pub fn visit_qself_mut<V: VisitorMut + ?Sized>(_visitor: &mut V, _i: &mut QSelf) {
tokens_helper(_visitor, &mut (& mut _i . lt_token).0);
_visitor.visit_type_mut(& mut * _i . ty);
@ -2162,41 +2181,22 @@ pub fn visit_visibility_mut<V: VisitorMut + ?Sized>(_visitor: &mut V, _i: &mut V
}
}
pub fn visit_where_bound_predicate_mut<V: VisitorMut + ?Sized>(_visitor: &mut V, _i: &mut WhereBoundPredicate) {
if let Some(ref mut it) = _i . bound_lifetimes { _visitor.visit_bound_lifetimes_mut(it) };
_visitor.visit_type_mut(& mut _i . bounded_ty);
tokens_helper(_visitor, &mut (& mut _i . colon_token).0);
for mut el in & mut _i . bounds { let it = el.item_mut(); _visitor.visit_type_param_bound_mut(it) };
}
pub fn visit_where_clause_mut<V: VisitorMut + ?Sized>(_visitor: &mut V, _i: &mut WhereClause) {
tokens_helper(_visitor, &mut (& mut _i . where_token).0);
for mut el in & mut _i . predicates { let it = el.item_mut(); _visitor.visit_where_predicate_mut(it) };
}
pub fn visit_where_eq_predicate_mut<V: VisitorMut + ?Sized>(_visitor: &mut V, _i: &mut WhereEqPredicate) {
_visitor.visit_type_mut(& mut _i . lhs_ty);
tokens_helper(_visitor, &mut (& mut _i . eq_token).0);
_visitor.visit_type_mut(& mut _i . rhs_ty);
}
pub fn visit_where_predicate_mut<V: VisitorMut + ?Sized>(_visitor: &mut V, _i: &mut WherePredicate) {
match *_i {
WherePredicate::BoundPredicate(ref mut _binding_0, ) => {
_visitor.visit_where_bound_predicate_mut(_binding_0);
WherePredicate::Type(ref mut _binding_0, ) => {
_visitor.visit_predicate_type_mut(_binding_0);
}
WherePredicate::RegionPredicate(ref mut _binding_0, ) => {
_visitor.visit_where_region_predicate_mut(_binding_0);
WherePredicate::Lifetime(ref mut _binding_0, ) => {
_visitor.visit_predicate_lifetime_mut(_binding_0);
}
WherePredicate::EqPredicate(ref mut _binding_0, ) => {
_visitor.visit_where_eq_predicate_mut(_binding_0);
WherePredicate::Eq(ref mut _binding_0, ) => {
_visitor.visit_predicate_eq_mut(_binding_0);
}
}
}
pub fn visit_where_region_predicate_mut<V: VisitorMut + ?Sized>(_visitor: &mut V, _i: &mut WhereRegionPredicate) {
_visitor.visit_lifetime_mut(& mut _i . lifetime);
if let Some(ref mut it) = _i . colon_token { tokens_helper(_visitor, &mut (it).0) };
for mut el in & mut _i . bounds { let it = el.item_mut(); _visitor.visit_lifetime_mut(it) };
}

View File

@ -164,7 +164,7 @@ ast_enum_of_structs! {
/// A single predicate in a `where` clause
pub enum WherePredicate {
/// A type binding, e.g. `for<'c> Foo: Send+Clone+'c`
pub BoundPredicate(WhereBoundPredicate {
pub Type(PredicateType {
/// Any lifetimes from a `for` binding
pub bound_lifetimes: Option<BoundLifetimes>,
/// The type being bounded
@ -175,14 +175,14 @@ ast_enum_of_structs! {
}),
/// A lifetime predicate, e.g. `'a: 'b+'c`
pub RegionPredicate(WhereRegionPredicate {
pub Lifetime(PredicateLifetime {
pub lifetime: Lifetime,
pub colon_token: Option<Token![:]>,
pub bounds: Punctuated<Lifetime, Token![+]>,
}),
/// An equality predicate (unsupported)
pub EqPredicate(WhereEqPredicate {
pub Eq(PredicateEq {
pub lhs_ty: Type,
pub eq_token: Token![=],
pub rhs_ty: Type,
@ -381,7 +381,7 @@ pub mod parsing {
colon.is_some(),
Punctuated::parse_separated
) >>
(WherePredicate::RegionPredicate(WhereRegionPredicate {
(WherePredicate::Lifetime(PredicateLifetime {
lifetime: ident,
bounds: bounds.unwrap_or_default(),
colon_token: colon,
@ -393,7 +393,7 @@ pub mod parsing {
bounded_ty: syn!(Type) >>
colon: punct!(:) >>
bounds: call!(Punctuated::parse_separated_nonempty) >>
(WherePredicate::BoundPredicate(WhereBoundPredicate {
(WherePredicate::Type(PredicateType {
bound_lifetimes: bound_lifetimes,
bounded_ty: bounded_ty,
bounds: bounds,
@ -581,7 +581,7 @@ mod printing {
}
}
impl ToTokens for WhereBoundPredicate {
impl ToTokens for PredicateType {
fn to_tokens(&self, tokens: &mut Tokens) {
self.bound_lifetimes.to_tokens(tokens);
self.bounded_ty.to_tokens(tokens);
@ -590,7 +590,7 @@ mod printing {
}
}
impl ToTokens for WhereRegionPredicate {
impl ToTokens for PredicateLifetime {
fn to_tokens(&self, tokens: &mut Tokens) {
self.lifetime.to_tokens(tokens);
if !self.bounds.is_empty() {
@ -600,7 +600,7 @@ mod printing {
}
}
impl ToTokens for WhereEqPredicate {
impl ToTokens for PredicateEq {
fn to_tokens(&self, tokens: &mut Tokens) {
self.lhs_ty.to_tokens(tokens);
self.eq_token.to_tokens(tokens);

View File

@ -42,8 +42,8 @@ pub use expr::{Arm, Block, FieldPat, FieldValue, GenericMethodArgument, Label, L
mod generics;
pub use generics::{BoundLifetimes, ConstParam, GenericParam, Generics, LifetimeDef,
TraitBoundModifier, TypeParam, TypeParamBound, WhereBoundPredicate,
WhereClause, WhereEqPredicate, WherePredicate, WhereRegionPredicate};
PredicateEq, PredicateLifetime, PredicateType, TraitBoundModifier,
TypeParam, TypeParamBound, WhereClause, WherePredicate};
#[cfg(feature = "printing")]
pub use generics::{ImplGenerics, Turbofish, TypeGenerics};

View File

@ -62,7 +62,7 @@ fn test_split_for_impl() {
where_clause: Some(WhereClause {
where_token: Default::default(),
predicates: punctuated![
WherePredicate::BoundPredicate(WhereBoundPredicate {
WherePredicate::Type(PredicateType {
bound_lifetimes: None,
colon_token: Default::default(),
bounded_ty: TypePath {