diff --git a/src/items.rs b/src/items.rs index fadf53a57fd1a..7092659158a17 100644 --- a/src/items.rs +++ b/src/items.rs @@ -802,11 +802,15 @@ fn format_impl_ref_and_type( result.push_str(format_defaultness(defaultness)); result.push_str(format_unsafety(unsafety)); - let shape = generics_shape_from_config( - context.config, - Shape::indented(offset + last_line_width(&result), context.config), - 0, - )?; + let shape = if context.config.version() == Version::Two { + Shape::indented(offset + last_line_width(&result), context.config) + } else { + generics_shape_from_config( + context.config, + Shape::indented(offset + last_line_width(&result), context.config), + 0, + )? + }; let generics_str = rewrite_generics(context, "impl", generics, shape)?; result.push_str(&generics_str); @@ -2609,11 +2613,7 @@ fn rewrite_generics( overflow::rewrite_with_angle_brackets(context, ident, params, shape, generics.span) } -pub(crate) fn generics_shape_from_config( - config: &Config, - shape: Shape, - offset: usize, -) -> Option { +fn generics_shape_from_config(config: &Config, shape: Shape, offset: usize) -> Option { match config.indent_style() { IndentStyle::Visual => shape.visual_indent(1 + offset).sub_width(offset + 2), IndentStyle::Block => { diff --git a/tests/source/issue-3840/version-one_hard-tabs.rs b/tests/source/issue-3840/version-one_hard-tabs.rs new file mode 100644 index 0000000000000..bf7ea7da0ebc3 --- /dev/null +++ b/tests/source/issue-3840/version-one_hard-tabs.rs @@ -0,0 +1,15 @@ +// rustfmt-hard_tabs: true + +impl + FromEvent, A: Widget2, B: Widget2, C: for<'a> CtxFamily<'a>> Widget2 for WidgetEventLifter +{ + type Ctx = C; + type Event = Vec; +} + +mod foo { + impl + FromEvent, A: Widget2, B: Widget2, C: for<'a> CtxFamily<'a>> Widget2 for WidgetEventLifter + { + type Ctx = C; + type Event = Vec; + } +} diff --git a/tests/source/issue-3840/version-one_soft-tabs.rs b/tests/source/issue-3840/version-one_soft-tabs.rs new file mode 100644 index 0000000000000..3fc26224d5035 --- /dev/null +++ b/tests/source/issue-3840/version-one_soft-tabs.rs @@ -0,0 +1,13 @@ +impl + FromEvent, A: Widget2, B: Widget2, C: for<'a> CtxFamily<'a>> Widget2 for WidgetEventLifter +{ + type Ctx = C; + type Event = Vec; +} + +mod foo { + impl + FromEvent, A: Widget2, B: Widget2, C: for<'a> CtxFamily<'a>> Widget2 for WidgetEventLifter + { + type Ctx = C; + type Event = Vec; + } +} diff --git a/tests/source/issue-3840/version-two_hard-tabs.rs b/tests/source/issue-3840/version-two_hard-tabs.rs new file mode 100644 index 0000000000000..7b505fda87c2c --- /dev/null +++ b/tests/source/issue-3840/version-two_hard-tabs.rs @@ -0,0 +1,16 @@ +// rustfmt-hard_tabs: true +// rustfmt-version: Two + +impl + FromEvent, A: Widget2, B: Widget2, C: for<'a> CtxFamily<'a>> Widget2 for WidgetEventLifter +{ + type Ctx = C; + type Event = Vec; +} + +mod foo { + impl + FromEvent, A: Widget2, B: Widget2, C: for<'a> CtxFamily<'a>> Widget2 for WidgetEventLifter + { + type Ctx = C; + type Event = Vec; + } +} diff --git a/tests/source/issue-3840/version-two_soft-tabs.rs b/tests/source/issue-3840/version-two_soft-tabs.rs new file mode 100644 index 0000000000000..39c8ef31292ca --- /dev/null +++ b/tests/source/issue-3840/version-two_soft-tabs.rs @@ -0,0 +1,15 @@ +// rustfmt-version: Two + +impl + FromEvent, A: Widget2, B: Widget2, C: for<'a> CtxFamily<'a>> Widget2 for WidgetEventLifter +{ + type Ctx = C; + type Event = Vec; +} + +mod foo { + impl + FromEvent, A: Widget2, B: Widget2, C: for<'a> CtxFamily<'a>> Widget2 for WidgetEventLifter + { + type Ctx = C; + type Event = Vec; + } +} diff --git a/tests/target/issue-3840/version-one_hard-tabs.rs b/tests/target/issue-3840/version-one_hard-tabs.rs new file mode 100644 index 0000000000000..4aa905ce9e5a6 --- /dev/null +++ b/tests/target/issue-3840/version-one_hard-tabs.rs @@ -0,0 +1,25 @@ +// rustfmt-hard_tabs: true + +impl< + Target: FromEvent + FromEvent, + A: Widget2, + B: Widget2, + C: for<'a> CtxFamily<'a>, + > Widget2 for WidgetEventLifter +{ + type Ctx = C; + type Event = Vec; +} + +mod foo { + impl< + Target: FromEvent + FromEvent, + A: Widget2, + B: Widget2, + C: for<'a> CtxFamily<'a>, + > Widget2 for WidgetEventLifter + { + type Ctx = C; + type Event = Vec; + } +} diff --git a/tests/target/issue-3840/version-one_soft-tabs.rs b/tests/target/issue-3840/version-one_soft-tabs.rs new file mode 100644 index 0000000000000..099e68018230c --- /dev/null +++ b/tests/target/issue-3840/version-one_soft-tabs.rs @@ -0,0 +1,23 @@ +impl< + Target: FromEvent + FromEvent, + A: Widget2, + B: Widget2, + C: for<'a> CtxFamily<'a>, + > Widget2 for WidgetEventLifter +{ + type Ctx = C; + type Event = Vec; +} + +mod foo { + impl< + Target: FromEvent + FromEvent, + A: Widget2, + B: Widget2, + C: for<'a> CtxFamily<'a>, + > Widget2 for WidgetEventLifter + { + type Ctx = C; + type Event = Vec; + } +} diff --git a/tests/target/issue-3840/version-two_hard-tabs.rs b/tests/target/issue-3840/version-two_hard-tabs.rs new file mode 100644 index 0000000000000..084db3d146561 --- /dev/null +++ b/tests/target/issue-3840/version-two_hard-tabs.rs @@ -0,0 +1,26 @@ +// rustfmt-hard_tabs: true +// rustfmt-version: Two + +impl< + Target: FromEvent + FromEvent, + A: Widget2, + B: Widget2, + C: for<'a> CtxFamily<'a>, +> Widget2 for WidgetEventLifter +{ + type Ctx = C; + type Event = Vec; +} + +mod foo { + impl< + Target: FromEvent + FromEvent, + A: Widget2, + B: Widget2, + C: for<'a> CtxFamily<'a>, + > Widget2 for WidgetEventLifter + { + type Ctx = C; + type Event = Vec; + } +} diff --git a/tests/target/issue-3840/version-two_soft-tabs.rs b/tests/target/issue-3840/version-two_soft-tabs.rs new file mode 100644 index 0000000000000..bc59b0baa56c4 --- /dev/null +++ b/tests/target/issue-3840/version-two_soft-tabs.rs @@ -0,0 +1,25 @@ +// rustfmt-version: Two + +impl< + Target: FromEvent + FromEvent, + A: Widget2, + B: Widget2, + C: for<'a> CtxFamily<'a>, +> Widget2 for WidgetEventLifter +{ + type Ctx = C; + type Event = Vec; +} + +mod foo { + impl< + Target: FromEvent + FromEvent, + A: Widget2, + B: Widget2, + C: for<'a> CtxFamily<'a>, + > Widget2 for WidgetEventLifter + { + type Ctx = C; + type Event = Vec; + } +}