Skip to content

Commit a15e97f

Browse files
scampitopecongiro
authored andcommitted
do not indent impl generics (#3856)
1 parent 8210cc1 commit a15e97f

9 files changed

+168
-10
lines changed

Diff for: src/items.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -802,11 +802,15 @@ fn format_impl_ref_and_type(
802802
result.push_str(format_defaultness(defaultness));
803803
result.push_str(format_unsafety(unsafety));
804804

805-
let shape = generics_shape_from_config(
806-
context.config,
807-
Shape::indented(offset + last_line_width(&result), context.config),
808-
0,
809-
)?;
805+
let shape = if context.config.version() == Version::Two {
806+
Shape::indented(offset + last_line_width(&result), context.config)
807+
} else {
808+
generics_shape_from_config(
809+
context.config,
810+
Shape::indented(offset + last_line_width(&result), context.config),
811+
0,
812+
)?
813+
};
810814
let generics_str = rewrite_generics(context, "impl", generics, shape)?;
811815
result.push_str(&generics_str);
812816

@@ -2609,11 +2613,7 @@ fn rewrite_generics(
26092613
overflow::rewrite_with_angle_brackets(context, ident, params, shape, generics.span)
26102614
}
26112615

2612-
pub(crate) fn generics_shape_from_config(
2613-
config: &Config,
2614-
shape: Shape,
2615-
offset: usize,
2616-
) -> Option<Shape> {
2616+
fn generics_shape_from_config(config: &Config, shape: Shape, offset: usize) -> Option<Shape> {
26172617
match config.indent_style() {
26182618
IndentStyle::Visual => shape.visual_indent(1 + offset).sub_width(offset + 2),
26192619
IndentStyle::Block => {

Diff for: tests/source/issue-3840/version-one_hard-tabs.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// rustfmt-hard_tabs: true
2+
3+
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>
4+
{
5+
type Ctx = C;
6+
type Event = Vec<Target>;
7+
}
8+
9+
mod foo {
10+
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>
11+
{
12+
type Ctx = C;
13+
type Event = Vec<Target>;
14+
}
15+
}

Diff for: tests/source/issue-3840/version-one_soft-tabs.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
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>
2+
{
3+
type Ctx = C;
4+
type Event = Vec<Target>;
5+
}
6+
7+
mod foo {
8+
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>
9+
{
10+
type Ctx = C;
11+
type Event = Vec<Target>;
12+
}
13+
}

Diff for: tests/source/issue-3840/version-two_hard-tabs.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// rustfmt-hard_tabs: true
2+
// rustfmt-version: Two
3+
4+
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>
5+
{
6+
type Ctx = C;
7+
type Event = Vec<Target>;
8+
}
9+
10+
mod foo {
11+
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>
12+
{
13+
type Ctx = C;
14+
type Event = Vec<Target>;
15+
}
16+
}

Diff for: tests/source/issue-3840/version-two_soft-tabs.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// rustfmt-version: Two
2+
3+
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>
4+
{
5+
type Ctx = C;
6+
type Event = Vec<Target>;
7+
}
8+
9+
mod foo {
10+
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>
11+
{
12+
type Ctx = C;
13+
type Event = Vec<Target>;
14+
}
15+
}

Diff for: tests/target/issue-3840/version-one_hard-tabs.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// rustfmt-hard_tabs: true
2+
3+
impl<
4+
Target: FromEvent<A> + FromEvent<B>,
5+
A: Widget2<Ctx = C>,
6+
B: Widget2<Ctx = C>,
7+
C: for<'a> CtxFamily<'a>,
8+
> Widget2 for WidgetEventLifter<Target, A, B>
9+
{
10+
type Ctx = C;
11+
type Event = Vec<Target>;
12+
}
13+
14+
mod foo {
15+
impl<
16+
Target: FromEvent<A> + FromEvent<B>,
17+
A: Widget2<Ctx = C>,
18+
B: Widget2<Ctx = C>,
19+
C: for<'a> CtxFamily<'a>,
20+
> Widget2 for WidgetEventLifter<Target, A, B>
21+
{
22+
type Ctx = C;
23+
type Event = Vec<Target>;
24+
}
25+
}

Diff for: tests/target/issue-3840/version-one_soft-tabs.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
impl<
2+
Target: FromEvent<A> + FromEvent<B>,
3+
A: Widget2<Ctx = C>,
4+
B: Widget2<Ctx = C>,
5+
C: for<'a> CtxFamily<'a>,
6+
> Widget2 for WidgetEventLifter<Target, A, B>
7+
{
8+
type Ctx = C;
9+
type Event = Vec<Target>;
10+
}
11+
12+
mod foo {
13+
impl<
14+
Target: FromEvent<A> + FromEvent<B>,
15+
A: Widget2<Ctx = C>,
16+
B: Widget2<Ctx = C>,
17+
C: for<'a> CtxFamily<'a>,
18+
> Widget2 for WidgetEventLifter<Target, A, B>
19+
{
20+
type Ctx = C;
21+
type Event = Vec<Target>;
22+
}
23+
}

Diff for: tests/target/issue-3840/version-two_hard-tabs.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// rustfmt-hard_tabs: true
2+
// rustfmt-version: Two
3+
4+
impl<
5+
Target: FromEvent<A> + FromEvent<B>,
6+
A: Widget2<Ctx = C>,
7+
B: Widget2<Ctx = C>,
8+
C: for<'a> CtxFamily<'a>,
9+
> Widget2 for WidgetEventLifter<Target, A, B>
10+
{
11+
type Ctx = C;
12+
type Event = Vec<Target>;
13+
}
14+
15+
mod foo {
16+
impl<
17+
Target: FromEvent<A> + FromEvent<B>,
18+
A: Widget2<Ctx = C>,
19+
B: Widget2<Ctx = C>,
20+
C: for<'a> CtxFamily<'a>,
21+
> Widget2 for WidgetEventLifter<Target, A, B>
22+
{
23+
type Ctx = C;
24+
type Event = Vec<Target>;
25+
}
26+
}

Diff for: tests/target/issue-3840/version-two_soft-tabs.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// rustfmt-version: Two
2+
3+
impl<
4+
Target: FromEvent<A> + FromEvent<B>,
5+
A: Widget2<Ctx = C>,
6+
B: Widget2<Ctx = C>,
7+
C: for<'a> CtxFamily<'a>,
8+
> Widget2 for WidgetEventLifter<Target, A, B>
9+
{
10+
type Ctx = C;
11+
type Event = Vec<Target>;
12+
}
13+
14+
mod foo {
15+
impl<
16+
Target: FromEvent<A> + FromEvent<B>,
17+
A: Widget2<Ctx = C>,
18+
B: Widget2<Ctx = C>,
19+
C: for<'a> CtxFamily<'a>,
20+
> Widget2 for WidgetEventLifter<Target, A, B>
21+
{
22+
type Ctx = C;
23+
type Event = Vec<Target>;
24+
}
25+
}

0 commit comments

Comments
 (0)