]> git.lizzy.rs Git - rust.git/commitdiff
Merge pull request #2023 from topecongiro/issue-2020
authorNick Cameron <nrc@ncameron.org>
Thu, 5 Oct 2017 10:09:49 +0000 (18:09 +0800)
committerGitHub <noreply@github.com>
Thu, 5 Oct 2017 10:09:49 +0000 (18:09 +0800)
Use a correct budget for where predicate

src/items.rs
src/types.rs
tests/source/where-clause-rfc.rs
tests/target/where-clause-rfc.rs

index e936999ac7d18373c7c431a617df2e451cf29e9d..8678e40ad22a94ace24ab36e181c9ba159b0133d 100644 (file)
@@ -2529,7 +2529,9 @@ fn rewrite_where_clause_rfc_style(
         "\n".to_owned() + &block_shape.indent.to_string(context.config)
     };
 
-    let clause_shape = block_shape.block_indent(context.config.tab_spaces());
+    let clause_shape = try_opt!(block_shape.block_left(context.config.tab_spaces()));
+    // 1 = `,`
+    let clause_shape = try_opt!(clause_shape.sub_width(1));
     // each clause on one line, trailing comma (except if suppress_comma)
     let span_start = where_clause.predicates[0].span().lo();
     // 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(
         terminator,
         |pred| pred.span().lo(),
         |pred| pred.span().hi(),
-        |pred| pred.rewrite(context, block_shape),
+        |pred| pred.rewrite(context, clause_shape),
         span_start,
         span_end,
         false,
index 1d6c80fb9394470a3bedf66e00fcabd4e4385de0..060871df16132e4602be094b1d82ded1e59ba54e 100644 (file)
@@ -438,7 +438,7 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
 
                     // 6 = "for<> ".len()
                     let used_width = lifetime_str.len() + type_str.len() + colon.len() + 6;
-                    let ty_shape = try_opt!(shape.block_left(used_width));
+                    let ty_shape = try_opt!(shape.offset_left(used_width));
                     let bounds: Vec<_> = try_opt!(
                         bounds
                             .iter()
@@ -462,7 +462,7 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
                     let used_width = type_str.len() + colon.len();
                     let ty_shape = match context.config.where_style() {
                         Style::Legacy => try_opt!(shape.block_left(used_width)),
-                        Style::Rfc => shape.block_indent(context.config.tab_spaces()),
+                        Style::Rfc => shape,
                     };
                     let bounds: Vec<_> = try_opt!(
                         bounds
@@ -552,10 +552,9 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
                 tref.rewrite(context, shape)
             }
             ast::TyParamBound::TraitTyParamBound(ref tref, ast::TraitBoundModifier::Maybe) => {
-                let budget = try_opt!(shape.width.checked_sub(1));
                 Some(format!(
                     "?{}",
-                    try_opt!(tref.rewrite(context, Shape::legacy(budget, shape.indent + 1)))
+                    try_opt!(tref.rewrite(context, try_opt!(shape.offset_left(1))))
                 ))
             }
             ast::TyParamBound::RegionTyParamBound(ref l) => l.rewrite(context, shape),
@@ -623,11 +622,10 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
 
             // 6 is "for<> ".len()
             let extra_offset = lifetime_str.len() + 6;
-            let max_path_width = try_opt!(shape.width.checked_sub(extra_offset));
-            let path_str = try_opt!(self.trait_ref.rewrite(
-                context,
-                Shape::legacy(max_path_width, shape.indent + extra_offset),
-            ));
+            let path_str = try_opt!(
+                self.trait_ref
+                    .rewrite(context, try_opt!(shape.offset_left(extra_offset)))
+            );
 
             Some(
                 if context.config.spaces_within_angle_brackets() && !lifetime_str.is_empty() {
index ef822f6bea2f2c6cea83b3d89667b601ef48903d..678b060602e753319694618347d613b6a7308934 100644 (file)
@@ -48,3 +48,12 @@ pub trait SomeTrait<T>
     T: Something + Sync + Send + Display     + Debug     + Copy + Hash + Debug + Display + Write + Read + FromStr
 {
 }
+
+// #2020
+impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
+    fn elaborate_bounds<F>(&mut self, bounds: &[ty::PolyTraitRef<'tcx>], mut mk_cand: F)
+    where F: for<'b> FnMut(&mut ProbeContext<'b, 'gcx, 'tcx>, ty::PolyTraitRef<'tcx>, ty::AssociatedItem),
+    {
+        // ...
+    }
+}
index ebfdc073eaa7b47857f2ca7d2d58e22059081620..f52cf3e220e71f8a2b6779152bee8d3b85ad1d89 100644 (file)
@@ -113,3 +113,17 @@ pub trait SomeTrait<T>
         + FromStr,
 {
 }
+
+// #2020
+impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
+    fn elaborate_bounds<F>(&mut self, bounds: &[ty::PolyTraitRef<'tcx>], mut mk_cand: F)
+    where
+        F: for<'b> FnMut(
+            &mut ProbeContext<'b, 'gcx, 'tcx>,
+            ty::PolyTraitRef<'tcx>,
+            ty::AssociatedItem,
+        ),
+    {
+        // ...
+    }
+}