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:
Michael Smith 2017-08-19 14:57:01 -07:00
parent c166004e6d
commit baafa4f011
No known key found for this signature in database
GPG Key ID: 8645BDF574E8F755
3 changed files with 15 additions and 1 deletions

View File

@ -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

View 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>;
}

View 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>;
}