Skip to content

Commit 69ab2b5

Browse files
authored
Merge pull request #2023 from topecongiro/issue-2020
Use a correct budget for where predicate
2 parents 61043e6 + 1752929 commit 69ab2b5

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed

src/items.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2529,7 +2529,9 @@ fn rewrite_where_clause_rfc_style(
25292529
"\n".to_owned() + &block_shape.indent.to_string(context.config)
25302530
};
25312531

2532-
let clause_shape = block_shape.block_indent(context.config.tab_spaces());
2532+
let clause_shape = try_opt!(block_shape.block_left(context.config.tab_spaces()));
2533+
// 1 = `,`
2534+
let clause_shape = try_opt!(clause_shape.sub_width(1));
25332535
// each clause on one line, trailing comma (except if suppress_comma)
25342536
let span_start = where_clause.predicates[0].span().lo();
25352537
// If we don't have the start of the next span, then use the end of the
@@ -2543,7 +2545,7 @@ fn rewrite_where_clause_rfc_style(
25432545
terminator,
25442546
|pred| pred.span().lo(),
25452547
|pred| pred.span().hi(),
2546-
|pred| pred.rewrite(context, block_shape),
2548+
|pred| pred.rewrite(context, clause_shape),
25472549
span_start,
25482550
span_end,
25492551
false,

src/types.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ impl Rewrite for ast::WherePredicate {
438438

439439
// 6 = "for<> ".len()
440440
let used_width = lifetime_str.len() + type_str.len() + colon.len() + 6;
441-
let ty_shape = try_opt!(shape.block_left(used_width));
441+
let ty_shape = try_opt!(shape.offset_left(used_width));
442442
let bounds: Vec<_> = try_opt!(
443443
bounds
444444
.iter()
@@ -462,7 +462,7 @@ impl Rewrite for ast::WherePredicate {
462462
let used_width = type_str.len() + colon.len();
463463
let ty_shape = match context.config.where_style() {
464464
Style::Legacy => try_opt!(shape.block_left(used_width)),
465-
Style::Rfc => shape.block_indent(context.config.tab_spaces()),
465+
Style::Rfc => shape,
466466
};
467467
let bounds: Vec<_> = try_opt!(
468468
bounds
@@ -552,10 +552,9 @@ impl Rewrite for ast::TyParamBound {
552552
tref.rewrite(context, shape)
553553
}
554554
ast::TyParamBound::TraitTyParamBound(ref tref, ast::TraitBoundModifier::Maybe) => {
555-
let budget = try_opt!(shape.width.checked_sub(1));
556555
Some(format!(
557556
"?{}",
558-
try_opt!(tref.rewrite(context, Shape::legacy(budget, shape.indent + 1)))
557+
try_opt!(tref.rewrite(context, try_opt!(shape.offset_left(1))))
559558
))
560559
}
561560
ast::TyParamBound::RegionTyParamBound(ref l) => l.rewrite(context, shape),
@@ -623,11 +622,10 @@ impl Rewrite for ast::PolyTraitRef {
623622

624623
// 6 is "for<> ".len()
625624
let extra_offset = lifetime_str.len() + 6;
626-
let max_path_width = try_opt!(shape.width.checked_sub(extra_offset));
627-
let path_str = try_opt!(self.trait_ref.rewrite(
628-
context,
629-
Shape::legacy(max_path_width, shape.indent + extra_offset),
630-
));
625+
let path_str = try_opt!(
626+
self.trait_ref
627+
.rewrite(context, try_opt!(shape.offset_left(extra_offset)))
628+
);
631629

632630
Some(
633631
if context.config.spaces_within_angle_brackets() && !lifetime_str.is_empty() {

tests/source/where-clause-rfc.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,12 @@ pub trait SomeTrait<T>
4848
T: Something + Sync + Send + Display + Debug + Copy + Hash + Debug + Display + Write + Read + FromStr
4949
{
5050
}
51+
52+
// #2020
53+
impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
54+
fn elaborate_bounds<F>(&mut self, bounds: &[ty::PolyTraitRef<'tcx>], mut mk_cand: F)
55+
where F: for<'b> FnMut(&mut ProbeContext<'b, 'gcx, 'tcx>, ty::PolyTraitRef<'tcx>, ty::AssociatedItem),
56+
{
57+
// ...
58+
}
59+
}

tests/target/where-clause-rfc.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,17 @@ where
113113
+ FromStr,
114114
{
115115
}
116+
117+
// #2020
118+
impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
119+
fn elaborate_bounds<F>(&mut self, bounds: &[ty::PolyTraitRef<'tcx>], mut mk_cand: F)
120+
where
121+
F: for<'b> FnMut(
122+
&mut ProbeContext<'b, 'gcx, 'tcx>,
123+
ty::PolyTraitRef<'tcx>,
124+
ty::AssociatedItem,
125+
),
126+
{
127+
// ...
128+
}
129+
}

0 commit comments

Comments
 (0)