Use correct BytePos for where when rewriting trait
This commit is contained in:
parent
1f991d00e0
commit
5a81c7d4b0
12
src/items.rs
12
src/items.rs
@ -962,8 +962,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
|
||||
};
|
||||
@ -974,7 +980,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
tests/target/issue-1824.rs
Normal file
5
tests/target/issue-1824.rs
Normal file
@ -0,0 +1,5 @@
|
||||
pub trait Ingredient
|
||||
where
|
||||
Self: Send,
|
||||
{
|
||||
}
|
@ -54,13 +54,13 @@ where
|
||||
|
||||
trait Tttttttttttttttttttttttttttttttttttttttttttttttttttttttttt<T>
|
||||
where
|
||||
T: Foo
|
||||
T: Foo,
|
||||
{
|
||||
}
|
||||
|
||||
trait Ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt<T>
|
||||
where
|
||||
T: Foo
|
||||
T: Foo,
|
||||
{
|
||||
}
|
||||
|
||||
@ -75,6 +75,6 @@ where
|
||||
trait WhereList<T, J>
|
||||
where
|
||||
T: Foo,
|
||||
J: Bar
|
||||
J: Bar,
|
||||
{
|
||||
}
|
||||
|
@ -110,6 +110,6 @@ where
|
||||
+ Display
|
||||
+ Write
|
||||
+ Read
|
||||
+ FromStr
|
||||
+ FromStr,
|
||||
{
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user