diff --git a/src/items.rs b/src/items.rs index 302d15ee8aa..0eed4204d45 100644 --- a/src/items.rs +++ b/src/items.rs @@ -1551,7 +1551,8 @@ pub fn rewrite_associated_type( let prefix = format!("type {}", ident); 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 bound_str = try_opt!( bounds diff --git a/tests/source/associated-types-bounds-wrapping.rs b/tests/source/associated-types-bounds-wrapping.rs new file mode 100644 index 00000000000..8f5e2172569 --- /dev/null +++ b/tests/source/associated-types-bounds-wrapping.rs @@ -0,0 +1,6 @@ +// rustfmt-max_width: 100 +// Test proper wrapping of long associated type bounds + +pub trait HttpService { + type WsService: 'static + Service; +} diff --git a/tests/target/associated-types-bounds-wrapping.rs b/tests/target/associated-types-bounds-wrapping.rs new file mode 100644 index 00000000000..d5b94a5e869 --- /dev/null +++ b/tests/target/associated-types-bounds-wrapping.rs @@ -0,0 +1,7 @@ +// rustfmt-max_width: 100 +// Test proper wrapping of long associated type bounds + +pub trait HttpService { + type WsService: 'static + + Service; +}