Merge pull request #1826 from topecongiro/issue-1824

Use correct BytePos for where when rewriting trait
This commit is contained in:
Nick Cameron
2017-07-29 12:11:17 +12:00
committed by GitHub
4 changed files with 18 additions and 7 deletions
+9 -3
View File
@@ -963,8 +963,14 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
.checked_sub(last_line_width(&result))
);
let pos_before_where = if type_param_bounds.is_empty() {
// We do not use this, so it does not matter
generics.span.hi
if generics.where_clause.predicates.is_empty() {
// We do not use this, so it does not matter
item.span.lo
} else {
let snippet = context.snippet(item.span);
let where_pos = snippet.find_uncommented("where");
item.span.lo + where_pos.map_or(BytePos(0), |p| BytePos(p as u32))
}
} else {
type_param_bounds[type_param_bounds.len() - 1].span().hi
};
@@ -975,7 +981,7 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
Shape::legacy(where_budget, offset.block_only()),
where_density,
"{",
!has_body,
false,
trait_bound_str.is_empty() && last_line_width(&generics_str) == 1,
None,
item.span,
+5
View File
@@ -0,0 +1,5 @@
pub trait Ingredient
where
Self: Send,
{
}
+3 -3
View File
@@ -54,13 +54,13 @@ trait ConstCheck<T>: Foo
trait Tttttttttttttttttttttttttttttttttttttttttttttttttttttttttt<T>
where
T: Foo
T: Foo,
{
}
trait Ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt<T>
where
T: Foo
T: Foo,
{
}
@@ -75,6 +75,6 @@ trait FooBar<T>
trait WhereList<T, J>
where
T: Foo,
J: Bar
J: Bar,
{
}
+1 -1
View File
@@ -110,6 +110,6 @@ pub trait SomeTrait<T>
+ Display
+ Write
+ Read
+ FromStr
+ FromStr,
{
}