Skip to content

Commit

Permalink
do not indent impl generics (rust-lang#3856)
Browse files Browse the repository at this point in the history
  • Loading branch information
scampi authored and topecongiro committed Oct 11, 2019
1 parent 8210cc1 commit a15e97f
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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<Shape> {
fn generics_shape_from_config(config: &Config, shape: Shape, offset: usize) -> Option<Shape> {
match config.indent_style() {
IndentStyle::Visual => shape.visual_indent(1 + offset).sub_width(offset + 2),
IndentStyle::Block => {
Expand Down
15 changes: 15 additions & 0 deletions tests/source/issue-3840/version-one_hard-tabs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// rustfmt-hard_tabs: true

impl<Target: FromEvent<A> + FromEvent<B>, A: Widget2<Ctx = C>, B: Widget2<Ctx = C>, C: for<'a> CtxFamily<'a>> Widget2 for WidgetEventLifter<Target, A, B>
{
type Ctx = C;
type Event = Vec<Target>;
}

mod foo {
impl<Target: FromEvent<A> + FromEvent<B>, A: Widget2<Ctx = C>, B: Widget2<Ctx = C>, C: for<'a> CtxFamily<'a>> Widget2 for WidgetEventLifter<Target, A, B>
{
type Ctx = C;
type Event = Vec<Target>;
}
}
13 changes: 13 additions & 0 deletions tests/source/issue-3840/version-one_soft-tabs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
impl<Target: FromEvent<A> + FromEvent<B>, A: Widget2<Ctx = C>, B: Widget2<Ctx = C>, C: for<'a> CtxFamily<'a>> Widget2 for WidgetEventLifter<Target, A, B>
{
type Ctx = C;
type Event = Vec<Target>;
}

mod foo {
impl<Target: FromEvent<A> + FromEvent<B>, A: Widget2<Ctx = C>, B: Widget2<Ctx = C>, C: for<'a> CtxFamily<'a>> Widget2 for WidgetEventLifter<Target, A, B>
{
type Ctx = C;
type Event = Vec<Target>;
}
}
16 changes: 16 additions & 0 deletions tests/source/issue-3840/version-two_hard-tabs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// rustfmt-hard_tabs: true
// rustfmt-version: Two

impl<Target: FromEvent<A> + FromEvent<B>, A: Widget2<Ctx = C>, B: Widget2<Ctx = C>, C: for<'a> CtxFamily<'a>> Widget2 for WidgetEventLifter<Target, A, B>
{
type Ctx = C;
type Event = Vec<Target>;
}

mod foo {
impl<Target: FromEvent<A> + FromEvent<B>, A: Widget2<Ctx = C>, B: Widget2<Ctx = C>, C: for<'a> CtxFamily<'a>> Widget2 for WidgetEventLifter<Target, A, B>
{
type Ctx = C;
type Event = Vec<Target>;
}
}
15 changes: 15 additions & 0 deletions tests/source/issue-3840/version-two_soft-tabs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// rustfmt-version: Two

impl<Target: FromEvent<A> + FromEvent<B>, A: Widget2<Ctx = C>, B: Widget2<Ctx = C>, C: for<'a> CtxFamily<'a>> Widget2 for WidgetEventLifter<Target, A, B>
{
type Ctx = C;
type Event = Vec<Target>;
}

mod foo {
impl<Target: FromEvent<A> + FromEvent<B>, A: Widget2<Ctx = C>, B: Widget2<Ctx = C>, C: for<'a> CtxFamily<'a>> Widget2 for WidgetEventLifter<Target, A, B>
{
type Ctx = C;
type Event = Vec<Target>;
}
}
25 changes: 25 additions & 0 deletions tests/target/issue-3840/version-one_hard-tabs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// rustfmt-hard_tabs: true

impl<
Target: FromEvent<A> + FromEvent<B>,
A: Widget2<Ctx = C>,
B: Widget2<Ctx = C>,
C: for<'a> CtxFamily<'a>,
> Widget2 for WidgetEventLifter<Target, A, B>
{
type Ctx = C;
type Event = Vec<Target>;
}

mod foo {
impl<
Target: FromEvent<A> + FromEvent<B>,
A: Widget2<Ctx = C>,
B: Widget2<Ctx = C>,
C: for<'a> CtxFamily<'a>,
> Widget2 for WidgetEventLifter<Target, A, B>
{
type Ctx = C;
type Event = Vec<Target>;
}
}
23 changes: 23 additions & 0 deletions tests/target/issue-3840/version-one_soft-tabs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
impl<
Target: FromEvent<A> + FromEvent<B>,
A: Widget2<Ctx = C>,
B: Widget2<Ctx = C>,
C: for<'a> CtxFamily<'a>,
> Widget2 for WidgetEventLifter<Target, A, B>
{
type Ctx = C;
type Event = Vec<Target>;
}

mod foo {
impl<
Target: FromEvent<A> + FromEvent<B>,
A: Widget2<Ctx = C>,
B: Widget2<Ctx = C>,
C: for<'a> CtxFamily<'a>,
> Widget2 for WidgetEventLifter<Target, A, B>
{
type Ctx = C;
type Event = Vec<Target>;
}
}
26 changes: 26 additions & 0 deletions tests/target/issue-3840/version-two_hard-tabs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// rustfmt-hard_tabs: true
// rustfmt-version: Two

impl<
Target: FromEvent<A> + FromEvent<B>,
A: Widget2<Ctx = C>,
B: Widget2<Ctx = C>,
C: for<'a> CtxFamily<'a>,
> Widget2 for WidgetEventLifter<Target, A, B>
{
type Ctx = C;
type Event = Vec<Target>;
}

mod foo {
impl<
Target: FromEvent<A> + FromEvent<B>,
A: Widget2<Ctx = C>,
B: Widget2<Ctx = C>,
C: for<'a> CtxFamily<'a>,
> Widget2 for WidgetEventLifter<Target, A, B>
{
type Ctx = C;
type Event = Vec<Target>;
}
}
25 changes: 25 additions & 0 deletions tests/target/issue-3840/version-two_soft-tabs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// rustfmt-version: Two

impl<
Target: FromEvent<A> + FromEvent<B>,
A: Widget2<Ctx = C>,
B: Widget2<Ctx = C>,
C: for<'a> CtxFamily<'a>,
> Widget2 for WidgetEventLifter<Target, A, B>
{
type Ctx = C;
type Event = Vec<Target>;
}

mod foo {
impl<
Target: FromEvent<A> + FromEvent<B>,
A: Widget2<Ctx = C>,
B: Widget2<Ctx = C>,
C: for<'a> CtxFamily<'a>,
> Widget2 for WidgetEventLifter<Target, A, B>
{
type Ctx = C;
type Event = Vec<Target>;
}
}

0 comments on commit a15e97f

Please sign in to comment.