Skip to content

Commit 733e1ef

Browse files
committed
fix panic on failure to format generics in enum
- instead of calling unwrap(), restore original snippet when we fail to format generics in enum - we need to propagate this rewrite failure later
1 parent 777e25a commit 733e1ef

File tree

3 files changed

+89
-3
lines changed

3 files changed

+89
-3
lines changed

Diff for: src/items.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -558,9 +558,13 @@ impl<'a> FmtVisitor<'a> {
558558
// make a span that starts right after `enum Foo`
559559
mk_sp(ident.span.hi(), body_start),
560560
last_line_width(&enum_header),
561-
)
562-
.unwrap();
563-
self.push_str(&generics_str);
561+
);
562+
563+
if let Some(generics_str) = generics_str {
564+
self.push_str(&generics_str);
565+
} else {
566+
self.push_str(self.snippet(mk_sp(ident.span.hi(), body_start)));
567+
}
564568

565569
self.last_pos = body_start;
566570

Diff for: tests/source/issue-5738/enum_with_generics.rs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
enum En4<'x1, 'x2, T: Tr1<As1: >> {
2+
V0,
3+
V1,
4+
}
5+
6+
enum _En5<'x1, 'x2, T: Tr1<As1: >> {
7+
_V0,
8+
_V1,
9+
}
10+
11+
enum En6
12+
where
13+
T: Tr1<En2<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S>>>>>>>>>>>>>>>>>>>>>>>>,
14+
{
15+
V0,
16+
V1,
17+
V2,
18+
V3,
19+
}
20+
21+
enum _En7
22+
where
23+
T: ,
24+
{
25+
V0,
26+
V1,
27+
}
28+
29+
fn _make_en7()
30+
where
31+
T: ,
32+
{
33+
34+
}
35+
36+
enum EnSelf<T> where Self: Tr1<As1: > {
37+
V0(T),
38+
V1,
39+
V2,
40+
}

Diff for: tests/target/issue-5738/enum_with_generics.rs

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
enum En4<'x1, 'x2, T: Tr1<As1: >> {
2+
V0,
3+
V1,
4+
}
5+
6+
enum _En5<'x1, 'x2, T: Tr1<As1: >> {
7+
_V0,
8+
_V1,
9+
}
10+
11+
enum En6
12+
where
13+
T: Tr1<En2<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S>>>>>>>>>>>>>>>>>>>>>>>>,
14+
{
15+
V0,
16+
V1,
17+
V2,
18+
V3,
19+
}
20+
21+
enum _En7
22+
where
23+
T:,
24+
{
25+
V0,
26+
V1,
27+
}
28+
29+
fn _make_en7()
30+
where
31+
T:,
32+
{
33+
}
34+
35+
enum EnSelf<T>
36+
where
37+
Self: Tr1<As1: >,
38+
{
39+
V0(T),
40+
V1,
41+
V2,
42+
}

0 commit comments

Comments
 (0)