From a15e97f1e92b3621ab8c2f1585f27e8de583f74b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Campinas?= Date: Fri, 11 Oct 2019 11:19:44 +0200 Subject: [PATCH] do not indent impl generics (#3856) --- src/items.rs | 20 +++++++------- .../issue-3840/version-one_hard-tabs.rs | 15 +++++++++++ .../issue-3840/version-one_soft-tabs.rs | 13 ++++++++++ .../issue-3840/version-two_hard-tabs.rs | 16 ++++++++++++ .../issue-3840/version-two_soft-tabs.rs | 15 +++++++++++ .../issue-3840/version-one_hard-tabs.rs | 25 ++++++++++++++++++ .../issue-3840/version-one_soft-tabs.rs | 23 ++++++++++++++++ .../issue-3840/version-two_hard-tabs.rs | 26 +++++++++++++++++++ .../issue-3840/version-two_soft-tabs.rs | 25 ++++++++++++++++++ 9 files changed, 168 insertions(+), 10 deletions(-) create mode 100644 tests/source/issue-3840/version-one_hard-tabs.rs create mode 100644 tests/source/issue-3840/version-one_soft-tabs.rs create mode 100644 tests/source/issue-3840/version-two_hard-tabs.rs create mode 100644 tests/source/issue-3840/version-two_soft-tabs.rs create mode 100644 tests/target/issue-3840/version-one_hard-tabs.rs create mode 100644 tests/target/issue-3840/version-one_soft-tabs.rs create mode 100644 tests/target/issue-3840/version-two_hard-tabs.rs create mode 100644 tests/target/issue-3840/version-two_soft-tabs.rs 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; + } +}