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 Sep 2, 2024
1 parent 40909b4 commit 578d753
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, RewriteError, RewriteErrorExt, RewriteResult};
use crate::shape::{Indent, Shape};
Expand Down Expand Up @@ -448,7 +448,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 @@ -1867,7 +1867,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 @@ -1957,7 +1957,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 @@ -116,7 +116,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 @@ -216,48 +216,48 @@ 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!(
impl_to_overflowable_item_for_ast_node!(
Expr,
GenericParam,
NestedMetaItem,
Expand All @@ -266,18 +266,18 @@ impl_into_overflowable_item_for_ast_node!(
Pat,
PreciseCapturingArg
);
impl_into_overflowable_item_for_rustfmt_types!([MacroArg], [SegmentParam, TuplePatField]);
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 @@ -301,7 +301,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 @@ -323,7 +323,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 @@ -368,7 +368,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 578d753

Please sign in to comment.