Skip to content

Commit 182b46e

Browse files
committed
Simplify join_bounds()
1 parent ccd134e commit 182b46e

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

src/types.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use syntax::symbol::keywords;
1818

1919
use codemap::SpanUtils;
2020
use config::{IndentStyle, TypeDensity};
21-
use expr::{rewrite_assign_rhs, rewrite_pair, rewrite_tuple, rewrite_unary_prefix,
22-
PairParts, ToExpr};
21+
use expr::{rewrite_assign_rhs, rewrite_pair, rewrite_tuple, rewrite_unary_prefix, PairParts,
22+
ToExpr};
2323
use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, Separator};
2424
use macros::{rewrite_macro, MacroPosition};
2525
use overflow;
@@ -485,17 +485,13 @@ fn rewrite_bounded_lifetime(
485485
if bounds.len() == 0 {
486486
Some(result)
487487
} else {
488-
let appendix = bounds
489-
.iter()
490-
.map(|b| b.rewrite(context, shape))
491-
.collect::<Option<Vec<_>>>()?;
492488
let colon = type_bound_colon(context);
493489
let overhead = last_line_width(&result) + colon.len();
494490
let result = format!(
495491
"{}{}{}",
496492
result,
497493
colon,
498-
join_bounds(context, shape.sub_width(overhead)?, bounds, &appendix, true)?
494+
join_bounds(context, shape.sub_width(overhead)?, bounds, true)?
499495
);
500496
Some(result)
501497
}
@@ -529,20 +525,13 @@ pub struct TraitTyParamBounds<'a> {
529525

530526
impl<'a> Rewrite for TraitTyParamBounds<'a> {
531527
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
532-
let strs = self.inner
533-
.iter()
534-
.map(|b| b.rewrite(context, shape))
535-
.collect::<Option<Vec<_>>>()?;
536-
join_bounds(context, shape, self.inner, &strs, false)
528+
join_bounds(context, shape, self.inner, false)
537529
}
538530
}
539531

540532
impl Rewrite for ast::TyParamBounds {
541533
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
542-
let strs = self.iter()
543-
.map(|b| b.rewrite(context, shape))
544-
.collect::<Option<Vec<_>>>()?;
545-
join_bounds(context, shape, self, &strs, true)
534+
join_bounds(context, shape, self, true)
546535
}
547536
}
548537

@@ -779,7 +768,6 @@ fn join_bounds<T>(
779768
context: &RewriteContext,
780769
shape: Shape,
781770
items: &[T],
782-
type_strs: &[String],
783771
need_indent: bool,
784772
) -> Option<String>
785773
where
@@ -790,6 +778,10 @@ where
790778
TypeDensity::Compressed => "+",
791779
TypeDensity::Wide => " + ",
792780
};
781+
let type_strs = items
782+
.iter()
783+
.map(|item| item.rewrite(context, shape))
784+
.collect::<Option<Vec<_>>>()?;
793785
let result = type_strs.join(joiner);
794786
if items.len() == 1 || (!result.contains('\n') && result.len() <= shape.width) {
795787
return Some(result);
@@ -805,7 +797,7 @@ where
805797
.collect::<Option<Vec<_>>>()?;
806798
(type_strs, nested_shape.indent)
807799
} else {
808-
(type_strs.to_vec(), shape.indent)
800+
(type_strs, shape.indent)
809801
};
810802

811803
let joiner = format!("{}+ ", offset.to_string_with_newline(context.config));

tests/target/trait.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ where
6565
{
6666
}
6767

68-
trait FooBar<T>:
69-
Tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt
68+
trait FooBar<T>: Tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt
7069
where
7170
J: Bar,
7271
{

0 commit comments

Comments
 (0)