Skip to content

Commit

Permalink
Rename WhereClauseItem -> WhereClausePredicate
Browse files Browse the repository at this point in the history
  • Loading branch information
Bromeon committed Feb 19, 2024
1 parent 59b2023 commit 6ec1ad7
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/parse_fn.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::parse_type::{
consume_item_name, consume_field_type, consume_generic_params, consume_where_clause,
consume_field_type, consume_generic_params, consume_item_name, consume_where_clause,
};
use crate::parse_utils::{
consume_any_ident, consume_comma, consume_ident, consume_outer_attributes, consume_punct,
Expand Down
2 changes: 1 addition & 1 deletion src/parse_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::parse_utils::{
};
use crate::types::{Constant, ImplMember, TypeAlias, ValueExpr};
use crate::types_edition::GroupSpan;
use crate::{Attribute, Item, Impl, Trait, TraitMember, TypeExpr, VisMarker};
use crate::{Attribute, Impl, Item, Trait, TraitMember, TypeExpr, VisMarker};
use proc_macro2::{Delimiter, Group, TokenTree};
use quote::ToTokens;
use std::iter::Peekable;
Expand Down
4 changes: 2 additions & 2 deletions src/parse_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ pub(crate) fn parse_mod(
if tokens.peek().is_none() {
break;
}
let item = consume_item(&mut tokens)
.unwrap_or_else(|e| panic!("declaration in mod: {}", e));
let item =
consume_item(&mut tokens).unwrap_or_else(|e| panic!("declaration in mod: {}", e));
mod_members.push(item);
}
members = mod_members;
Expand Down
8 changes: 4 additions & 4 deletions src/parse_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use crate::parse_utils::{
};
use crate::punctuated::Punctuated;
use crate::types::{
EnumVariant, EnumVariantValue, GenericArg, GenericArgList, GenericBound, GenericParam,
GenericParamList, NamedField, NamedFields, Fields, TupleField, TupleFields,
TypeExpr, WhereClause, WhereClauseItem,
EnumVariant, EnumVariantValue, Fields, GenericArg, GenericArgList, GenericBound, GenericParam,
GenericParamList, NamedField, NamedFields, TupleField, TupleFields, TypeExpr, WhereClause,
WhereClausePredicate,
};
use crate::types_edition::GroupSpan;
use proc_macro2::{Delimiter, Group, Ident, Punct, TokenStream, TokenTree};
Expand Down Expand Up @@ -246,7 +246,7 @@ pub(crate) fn consume_where_clause(tokens: &mut TokenIter) -> Option<WhereClause
let comma = consume_comma(tokens);

items.push(
WhereClauseItem {
WhereClausePredicate {
left_side,
bound: GenericBound {
tk_colon: colon,
Expand Down
7 changes: 4 additions & 3 deletions src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{parse_item, Item, GenericParam, Struct, TypeExpr, WhereClauseItem};
use crate::{parse_item, GenericParam, Item, Struct, TypeExpr, WhereClausePredicate};

use crate::parse_type::consume_generic_args;
use crate::types::GenericArgList;
Expand Down Expand Up @@ -1090,9 +1090,10 @@ fn add_where_item() {
}
));

let basic_type = basic_type.with_where_item(WhereClauseItem::parse(quote!(Self: Sized)));
let basic_type =
basic_type.with_where_predicate(WhereClausePredicate::parse(quote!(Self: Sized)));
let type_with_args =
type_with_args.with_where_item(WhereClauseItem::parse(quote!(Self: Sized)));
type_with_args.with_where_predicate(WhereClausePredicate::parse(quote!(Self: Sized)));

assert_quote_snapshot!(basic_type);
assert_quote_snapshot!(type_with_args);
Expand Down
8 changes: 4 additions & 4 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ pub struct InlineGenericArgs<'a>(pub(crate) &'a GenericParamList);
#[derive(Clone)]
pub struct WhereClause {
pub tk_where: Ident,
pub items: Punctuated<WhereClauseItem>,
pub items: Punctuated<WhereClausePredicate>,
}

/// Item in a where clause.
Expand All @@ -635,7 +635,7 @@ pub struct WhereClause {
/// struct MyStruct<T>(T) where T: Clone;
/// ```
#[derive(Clone)]
pub struct WhereClauseItem {
pub struct WhereClausePredicate {
pub left_side: Vec<TokenTree>,
pub bound: GenericBound,
}
Expand Down Expand Up @@ -1026,7 +1026,7 @@ impl std::fmt::Debug for WhereClause {
}
}

impl std::fmt::Debug for WhereClauseItem {
impl std::fmt::Debug for WhereClausePredicate {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut list = f.debug_list();
for token in quote::quote!(#self) {
Expand Down Expand Up @@ -1550,7 +1550,7 @@ impl ToTokens for WhereClause {
}
}

impl ToTokens for WhereClauseItem {
impl ToTokens for WhereClausePredicate {
fn to_tokens(&self, tokens: &mut TokenStream) {
for token in &self.left_side {
tokens.append(token.clone());
Expand Down
34 changes: 17 additions & 17 deletions src/types_edition.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::parse_utils::{consume_path, tokens_from_slice};
pub use crate::types::{
Attribute, AttributeValue, Item, Enum, EnumVariant, EnumVariantValue, Function,
GenericBound, GenericParam, GenericParamList, GroupSpan, InlineGenericArgs, NamedField, Struct,
Fields, TupleField, TypeExpr, Union, VisMarker, WhereClause, WhereClauseItem,
Attribute, AttributeValue, Enum, EnumVariant, EnumVariantValue, Fields, Function, GenericBound,
GenericParam, GenericParamList, GroupSpan, InlineGenericArgs, Item, NamedField, Struct,
TupleField, TypeExpr, Union, VisMarker, WhereClause, WhereClausePredicate,
};
use crate::types::{FnQualifiers, GenericArg, GenericArgList, Impl, Module, Path};
use crate::{Constant, Punctuated, Trait, TypeAlias};
Expand Down Expand Up @@ -346,14 +346,14 @@ macro_rules! implement_common_methods {
self
}

/// Builder method, add a [`WhereClauseItem`] to `self.where_clause`.
/// Builder method, add a [`WhereClausePredicate`] to `self.where_clause`.
///
/// Creates a default [`WhereClause`] if `self.where_clause` is None.
pub fn with_where_item(mut self, item: WhereClauseItem) -> Self {
pub fn with_where_predicate(mut self, pred: WhereClausePredicate) -> Self {
if let Some(where_clause) = self.where_clause {
self.where_clause = Some(where_clause.with_item(item));
self.where_clause = Some(where_clause.with_predicate(pred));
} else {
self.where_clause = Some(WhereClause::from_item(item));
self.where_clause = Some(WhereClause::from_predicate(pred));
}
self
}
Expand Down Expand Up @@ -431,15 +431,15 @@ macro_rules! implement_common_methods {
let mut where_clause = self.where_clause.clone().unwrap_or_default();

for param in self.get_type_params() {
let item = WhereClauseItem {
let pred = WhereClausePredicate {
left_side: vec![param.name.clone().into()],
bound: GenericBound {
tk_colon: Punct::new(':', Spacing::Alone),
tokens: derived_trait.clone().into_iter().collect(),
},
};

where_clause = where_clause.with_item(item);
where_clause = where_clause.with_predicate(pred);
}

where_clause
Expand Down Expand Up @@ -708,19 +708,19 @@ impl<'a> InlineGenericArgs<'a> {
}

impl WhereClause {
/// Create where-clause with a single item.
pub fn from_item(item: WhereClauseItem) -> Self {
Self::default().with_item(item)
/// Create where-clause with a single predicate.
pub fn from_predicate(item: WhereClausePredicate) -> Self {
Self::default().with_predicate(item)
}

/// Builder method, add an item to the where-clause.
pub fn with_item(mut self, item: WhereClauseItem) -> Self {
/// Builder method, add a predicate to the where-clause.
pub fn with_predicate(mut self, item: WhereClausePredicate) -> Self {
self.items.push(item, None);
self
}
}

impl WhereClauseItem {
impl WhereClausePredicate {
/// Helper method to create a WhereClauseItem from a quote.
///
/// # Panics
Expand Down Expand Up @@ -751,7 +751,7 @@ impl WhereClauseItem {

let bound_tokens = tokens.collect();

WhereClauseItem {
WhereClausePredicate {
left_side,
bound: GenericBound {
tk_colon: colon,
Expand Down Expand Up @@ -803,7 +803,7 @@ implement_span!(TypeExpr);
implement_span!(Union);
implement_span!(VisMarker);
implement_span!(WhereClause);
implement_span!(WhereClauseItem);
implement_span!(WhereClausePredicate);

impl InlineGenericArgs<'_> {
/// Returns span of this item.
Expand Down

0 comments on commit 6ec1ad7

Please sign in to comment.