Fix wrapping of bounds in associated types
Bounds were wrapped to the full width of the line rather then the width available after the "type ...: ", resulting in rustfmt unnecessarily producing lines that were longer than the maximum width.
This commit is contained in:
parent
c166004e6d
commit
baafa4f011
@ -1551,7 +1551,8 @@ pub fn rewrite_associated_type(
|
|||||||
let prefix = format!("type {}", ident);
|
let prefix = format!("type {}", ident);
|
||||||
|
|
||||||
let type_bounds_str = if let Some(ty_param_bounds) = ty_param_bounds_opt {
|
let type_bounds_str = if let Some(ty_param_bounds) = ty_param_bounds_opt {
|
||||||
let shape = Shape::indented(indent, context.config);
|
// 2 = ": ".len()
|
||||||
|
let shape = try_opt!(Shape::indented(indent, context.config).offset_left(prefix.len() + 2));
|
||||||
let bounds: &[_] = ty_param_bounds;
|
let bounds: &[_] = ty_param_bounds;
|
||||||
let bound_str = try_opt!(
|
let bound_str = try_opt!(
|
||||||
bounds
|
bounds
|
||||||
|
6
tests/source/associated-types-bounds-wrapping.rs
Normal file
6
tests/source/associated-types-bounds-wrapping.rs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
// rustfmt-max_width: 100
|
||||||
|
// Test proper wrapping of long associated type bounds
|
||||||
|
|
||||||
|
pub trait HttpService {
|
||||||
|
type WsService: 'static + Service<Request = WsCommand, Response = WsResponse, Error = ServerError>;
|
||||||
|
}
|
7
tests/target/associated-types-bounds-wrapping.rs
Normal file
7
tests/target/associated-types-bounds-wrapping.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
// rustfmt-max_width: 100
|
||||||
|
// Test proper wrapping of long associated type bounds
|
||||||
|
|
||||||
|
pub trait HttpService {
|
||||||
|
type WsService: 'static
|
||||||
|
+ Service<Request = WsCommand, Response = WsResponse, Error = ServerError>;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user