@@ -27,17 +27,17 @@ use lists::{
27
27
definitive_tactic, itemize_list, shape_for_tactic, struct_lit_formatting, struct_lit_shape,
28
28
struct_lit_tactic, write_list, ListFormatting , ListItem , Separator ,
29
29
} ;
30
- use macros:: { rewrite_macro, MacroArg , MacroPosition } ;
30
+ use macros:: { rewrite_macro, MacroPosition } ;
31
31
use matches:: rewrite_match;
32
- use overflow;
32
+ use overflow:: { self , IntoOverflowableItem , OverflowableItem } ;
33
33
use pairs:: { rewrite_all_pairs, rewrite_pair, PairParts } ;
34
- use patterns:: { can_be_overflowed_pat , is_short_pattern, TuplePatField } ;
34
+ use patterns:: is_short_pattern;
35
35
use rewrite:: { Rewrite , RewriteContext } ;
36
36
use shape:: { Indent , Shape } ;
37
37
use source_map:: { LineRangeUtils , SpanUtils } ;
38
38
use spanned:: Spanned ;
39
39
use string:: { rewrite_string, StringFormat } ;
40
- use types:: { can_be_overflowed_type , rewrite_path, PathContext } ;
40
+ use types:: { rewrite_path, PathContext } ;
41
41
use utils:: {
42
42
colon_spaces, contains_skip, count_newlines, first_line_ends_with, first_line_width,
43
43
inner_attributes, last_line_extendable, last_line_width, mk_sp, outer_attributes,
@@ -391,18 +391,15 @@ pub fn format_expr(
391
391
} )
392
392
}
393
393
394
- pub fn rewrite_array < ' a , T : ' a > (
394
+ pub fn rewrite_array < ' a , T : ' a + IntoOverflowableItem < ' a > > (
395
395
name : & ' a str ,
396
396
exprs : impl Iterator < Item = & ' a T > ,
397
397
span : Span ,
398
398
context : & ' a RewriteContext ,
399
399
shape : Shape ,
400
400
force_separator_tactic : Option < SeparatorTactic > ,
401
401
delim_token : Option < DelimToken > ,
402
- ) -> Option < String >
403
- where
404
- T : Rewrite + Spanned + ToExpr ,
405
- {
402
+ ) -> Option < String > {
406
403
overflow:: rewrite_with_square_brackets (
407
404
context,
408
405
name,
@@ -1263,7 +1260,7 @@ fn rewrite_string_lit(context: &RewriteContext, span: Span, shape: Shape) -> Opt
1263
1260
}
1264
1261
1265
1262
/// In case special-case style is required, returns an offset from which we start horizontal layout.
1266
- pub fn maybe_get_args_offset < T : ToExpr > ( callee_str : & str , args : & [ & T ] ) -> Option < ( bool , usize ) > {
1263
+ pub fn maybe_get_args_offset ( callee_str : & str , args : & [ OverflowableItem ] ) -> Option < ( bool , usize ) > {
1267
1264
if let Some ( & ( _, num_args_before) ) = SPECIAL_MACRO_WHITELIST
1268
1265
. iter ( )
1269
1266
. find ( |& & ( s, _) | s == callee_str)
@@ -1358,7 +1355,7 @@ fn is_simple_expr(expr: &ast::Expr) -> bool {
1358
1355
}
1359
1356
}
1360
1357
1361
- pub fn is_every_expr_simple < T : ToExpr > ( lists : & [ & T ] ) -> bool {
1358
+ pub fn is_every_expr_simple ( lists : & [ OverflowableItem ] ) -> bool {
1362
1359
lists
1363
1360
. iter ( )
1364
1361
. all ( |arg| arg. to_expr ( ) . map_or ( false , is_simple_expr) )
@@ -1723,16 +1720,13 @@ pub fn rewrite_field(
1723
1720
}
1724
1721
}
1725
1722
1726
- fn rewrite_tuple_in_visual_indent_style < ' a , T > (
1723
+ fn rewrite_tuple_in_visual_indent_style < ' a , T : ' a + IntoOverflowableItem < ' a > > (
1727
1724
context : & RewriteContext ,
1728
1725
mut items : impl Iterator < Item = & ' a T > ,
1729
1726
span : Span ,
1730
1727
shape : Shape ,
1731
1728
is_singleton_tuple : bool ,
1732
- ) -> Option < String >
1733
- where
1734
- T : Rewrite + Spanned + ToExpr + ' a ,
1735
- {
1729
+ ) -> Option < String > {
1736
1730
// In case of length 1, need a trailing comma
1737
1731
debug ! ( "rewrite_tuple_in_visual_indent_style {:?}" , shape) ;
1738
1732
if is_singleton_tuple {
@@ -1774,16 +1768,13 @@ where
1774
1768
Some ( format ! ( "({})" , list_str) )
1775
1769
}
1776
1770
1777
- pub fn rewrite_tuple < ' a , T > (
1771
+ pub fn rewrite_tuple < ' a , T : ' a + IntoOverflowableItem < ' a > > (
1778
1772
context : & ' a RewriteContext ,
1779
1773
items : impl Iterator < Item = & ' a T > ,
1780
1774
span : Span ,
1781
1775
shape : Shape ,
1782
1776
is_singleton_tuple : bool ,
1783
- ) -> Option < String >
1784
- where
1785
- T : Rewrite + Spanned + ToExpr + ' a ,
1786
- {
1777
+ ) -> Option < String > {
1787
1778
debug ! ( "rewrite_tuple {:?}" , shape) ;
1788
1779
if context. use_block_indent ( ) {
1789
1780
// We use the same rule as function calls for rewriting tuples.
@@ -1999,89 +1990,6 @@ fn rewrite_expr_addrof(
1999
1990
rewrite_unary_prefix ( context, operator_str, expr, shape)
2000
1991
}
2001
1992
2002
- pub trait ToExpr {
2003
- fn to_expr ( & self ) -> Option < & ast:: Expr > ;
2004
- fn can_be_overflowed ( & self , context : & RewriteContext , len : usize ) -> bool ;
2005
- }
2006
-
2007
- impl ToExpr for ast:: Expr {
2008
- fn to_expr ( & self ) -> Option < & ast:: Expr > {
2009
- Some ( self )
2010
- }
2011
-
2012
- fn can_be_overflowed ( & self , context : & RewriteContext , len : usize ) -> bool {
2013
- can_be_overflowed_expr ( context, self , len)
2014
- }
2015
- }
2016
-
2017
- impl ToExpr for ast:: Ty {
2018
- fn to_expr ( & self ) -> Option < & ast:: Expr > {
2019
- None
2020
- }
2021
-
2022
- fn can_be_overflowed ( & self , context : & RewriteContext , len : usize ) -> bool {
2023
- can_be_overflowed_type ( context, self , len)
2024
- }
2025
- }
2026
-
2027
- impl < ' a > ToExpr for TuplePatField < ' a > {
2028
- fn to_expr ( & self ) -> Option < & ast:: Expr > {
2029
- None
2030
- }
2031
-
2032
- fn can_be_overflowed ( & self , context : & RewriteContext , len : usize ) -> bool {
2033
- can_be_overflowed_pat ( context, self , len)
2034
- }
2035
- }
2036
-
2037
- impl < ' a > ToExpr for ast:: StructField {
2038
- fn to_expr ( & self ) -> Option < & ast:: Expr > {
2039
- None
2040
- }
2041
-
2042
- fn can_be_overflowed ( & self , _: & RewriteContext , _: usize ) -> bool {
2043
- false
2044
- }
2045
- }
2046
-
2047
- impl < ' a > ToExpr for MacroArg {
2048
- fn to_expr ( & self ) -> Option < & ast:: Expr > {
2049
- match * self {
2050
- MacroArg :: Expr ( ref expr) => Some ( expr) ,
2051
- _ => None ,
2052
- }
2053
- }
2054
-
2055
- fn can_be_overflowed ( & self , context : & RewriteContext , len : usize ) -> bool {
2056
- match * self {
2057
- MacroArg :: Expr ( ref expr) => can_be_overflowed_expr ( context, expr, len) ,
2058
- MacroArg :: Ty ( ref ty) => can_be_overflowed_type ( context, ty, len) ,
2059
- MacroArg :: Pat ( ..) => false ,
2060
- MacroArg :: Item ( ..) => len == 1 ,
2061
- }
2062
- }
2063
- }
2064
-
2065
- impl ToExpr for ast:: GenericParam {
2066
- fn to_expr ( & self ) -> Option < & ast:: Expr > {
2067
- None
2068
- }
2069
-
2070
- fn can_be_overflowed ( & self , _: & RewriteContext , _: usize ) -> bool {
2071
- false
2072
- }
2073
- }
2074
-
2075
- impl < T : ToExpr > ToExpr for ptr:: P < T > {
2076
- fn to_expr ( & self ) -> Option < & ast:: Expr > {
2077
- ( * * self ) . to_expr ( )
2078
- }
2079
-
2080
- fn can_be_overflowed ( & self , context : & RewriteContext , len : usize ) -> bool {
2081
- ( * * self ) . can_be_overflowed ( context, len)
2082
- }
2083
- }
2084
-
2085
1993
pub fn is_method_call ( expr : & ast:: Expr ) -> bool {
2086
1994
match expr. node {
2087
1995
ast:: ExprKind :: MethodCall ( ..) => true ,
0 commit comments