Skip to content

Commit

Permalink
rename IntoOverflowableItem to satisfy clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
kadiwa4 committed Oct 22, 2023
1 parent 547577f commit ef5a09e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
8 changes: 4 additions & 4 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::lists::{
};
use crate::macros::{rewrite_macro, MacroPosition};
use crate::matches::rewrite_match;
use crate::overflow::{self, IntoOverflowableItem, OverflowableItem};
use crate::overflow::{self, OverflowableItem, ToOverflowableItem};
use crate::pairs::{rewrite_all_pairs, rewrite_pair, PairParts};
use crate::rewrite::{Rewrite, RewriteContext};
use crate::shape::{Indent, Shape};
Expand Down Expand Up @@ -420,7 +420,7 @@ pub(crate) fn format_expr(
})
}

pub(crate) fn rewrite_array<'a, T: 'a + IntoOverflowableItem<'a>>(
pub(crate) fn rewrite_array<'a, T: 'a + ToOverflowableItem<'a>>(
name: &'a str,
exprs: impl Iterator<Item = &'a T>,
span: Span,
Expand Down Expand Up @@ -1786,7 +1786,7 @@ pub(crate) fn rewrite_field(
}
}

fn rewrite_tuple_in_visual_indent_style<'a, T: 'a + IntoOverflowableItem<'a>>(
fn rewrite_tuple_in_visual_indent_style<'a, T: 'a + ToOverflowableItem<'a>>(
context: &RewriteContext<'_>,
mut items: impl Iterator<Item = &'a T>,
span: Span,
Expand Down Expand Up @@ -1868,7 +1868,7 @@ fn rewrite_let(
)
}

pub(crate) fn rewrite_tuple<'a, T: 'a + IntoOverflowableItem<'a>>(
pub(crate) fn rewrite_tuple<'a, T: 'a + ToOverflowableItem<'a>>(
context: &'a RewriteContext<'_>,
items: impl Iterator<Item = &'a T>,
span: Span,
Expand Down
44 changes: 22 additions & 22 deletions src/overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl<'a> OverflowableItem<'a> {

pub(crate) fn map<F, T>(&self, f: F) -> T
where
F: Fn(&dyn IntoOverflowableItem<'a>) -> T,
F: Fn(&dyn ToOverflowableItem<'a>) -> T,
{
match self {
OverflowableItem::Expr(expr) => f(*expr),
Expand Down Expand Up @@ -191,60 +191,60 @@ impl<'a> OverflowableItem<'a> {
}
}

pub(crate) trait IntoOverflowableItem<'a>: Rewrite + Spanned {
fn into_overflowable_item(&'a self) -> OverflowableItem<'a>;
pub(crate) trait ToOverflowableItem<'a>: Rewrite + Spanned {
fn to_overflowable_item(&'a self) -> OverflowableItem<'a>;
}

impl<'a, T: 'a + IntoOverflowableItem<'a>> IntoOverflowableItem<'a> for ptr::P<T> {
fn into_overflowable_item(&'a self) -> OverflowableItem<'a> {
(**self).into_overflowable_item()
impl<'a, T: 'a + ToOverflowableItem<'a>> ToOverflowableItem<'a> for ptr::P<T> {
fn to_overflowable_item(&'a self) -> OverflowableItem<'a> {
(**self).to_overflowable_item()
}
}

macro_rules! impl_into_overflowable_item_for_ast_node {
macro_rules! impl_to_overflowable_item_for_ast_node {
($($ast_node:ident),*) => {
$(
impl<'a> IntoOverflowableItem<'a> for ast::$ast_node {
fn into_overflowable_item(&'a self) -> OverflowableItem<'a> {
impl<'a> ToOverflowableItem<'a> for ast::$ast_node {
fn to_overflowable_item(&'a self) -> OverflowableItem<'a> {
OverflowableItem::$ast_node(self)
}
}
)*
}
}

macro_rules! impl_into_overflowable_item_for_rustfmt_types {
macro_rules! impl_to_overflowable_item_for_rustfmt_types {
([$($ty:ident),*], [$($ty_with_lifetime:ident),*]) => {
$(
impl<'a> IntoOverflowableItem<'a> for $ty {
fn into_overflowable_item(&'a self) -> OverflowableItem<'a> {
impl<'a> ToOverflowableItem<'a> for $ty {
fn to_overflowable_item(&'a self) -> OverflowableItem<'a> {
OverflowableItem::$ty(self)
}
}
)*
$(
impl<'a> IntoOverflowableItem<'a> for $ty_with_lifetime<'a> {
fn into_overflowable_item(&'a self) -> OverflowableItem<'a> {
impl<'a> ToOverflowableItem<'a> for $ty_with_lifetime<'a> {
fn to_overflowable_item(&'a self) -> OverflowableItem<'a> {
OverflowableItem::$ty_with_lifetime(self)
}
}
)*
}
}

impl_into_overflowable_item_for_ast_node!(Expr, GenericParam, NestedMetaItem, FieldDef, Ty, Pat);
impl_into_overflowable_item_for_rustfmt_types!([MacroArg], [SegmentParam, TuplePatField]);
impl_to_overflowable_item_for_ast_node!(Expr, GenericParam, NestedMetaItem, FieldDef, Ty, Pat);
impl_to_overflowable_item_for_rustfmt_types!([MacroArg], [SegmentParam, TuplePatField]);

pub(crate) fn into_overflowable_list<'a, T>(
iter: impl Iterator<Item = &'a T>,
) -> impl Iterator<Item = OverflowableItem<'a>>
where
T: 'a + IntoOverflowableItem<'a>,
T: 'a + ToOverflowableItem<'a>,
{
iter.map(|x| IntoOverflowableItem::into_overflowable_item(x))
iter.map(|x| ToOverflowableItem::to_overflowable_item(x))
}

pub(crate) fn rewrite_with_parens<'a, T: 'a + IntoOverflowableItem<'a>>(
pub(crate) fn rewrite_with_parens<'a, T: 'a + ToOverflowableItem<'a>>(
context: &'a RewriteContext<'_>,
ident: &'a str,
items: impl Iterator<Item = &'a T>,
Expand All @@ -268,7 +268,7 @@ pub(crate) fn rewrite_with_parens<'a, T: 'a + IntoOverflowableItem<'a>>(
.rewrite(shape)
}

pub(crate) fn rewrite_with_angle_brackets<'a, T: 'a + IntoOverflowableItem<'a>>(
pub(crate) fn rewrite_with_angle_brackets<'a, T: 'a + ToOverflowableItem<'a>>(
context: &'a RewriteContext<'_>,
ident: &'a str,
items: impl Iterator<Item = &'a T>,
Expand All @@ -290,7 +290,7 @@ pub(crate) fn rewrite_with_angle_brackets<'a, T: 'a + IntoOverflowableItem<'a>>(
.rewrite(shape)
}

pub(crate) fn rewrite_with_square_brackets<'a, T: 'a + IntoOverflowableItem<'a>>(
pub(crate) fn rewrite_with_square_brackets<'a, T: 'a + ToOverflowableItem<'a>>(
context: &'a RewriteContext<'_>,
name: &'a str,
items: impl Iterator<Item = &'a T>,
Expand Down Expand Up @@ -335,7 +335,7 @@ struct Context<'a> {
}

impl<'a> Context<'a> {
fn new<T: 'a + IntoOverflowableItem<'a>>(
fn new<T: 'a + ToOverflowableItem<'a>>(
context: &'a RewriteContext<'_>,
items: impl Iterator<Item = &'a T>,
ident: &'a str,
Expand Down

0 comments on commit ef5a09e

Please sign in to comment.