Skip to content

Commit c209040

Browse files
committed
review comments: only suggest one substitution
1 parent f6dfbbb commit c209040

22 files changed

+38
-155
lines changed

src/librustc_trait_selection/traits/error_reporting/mod.rs

+14-35
Original file line numberDiff line numberDiff line change
@@ -1737,48 +1737,27 @@ pub fn recursive_type_with_infinite_size_error(
17371737
for &span in &spans {
17381738
err.span_label(span, "recursive without indirection");
17391739
}
1740-
let short_msg = format!("insert some indirection to make `{}` representable", path);
17411740
let msg = format!(
17421741
"insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `{}` representable",
17431742
path,
17441743
);
1745-
match &spans[..] {
1746-
[span] => {
1747-
err.multipart_suggestions(
1748-
&short_msg,
1749-
vec![
1744+
if spans.len() <= 4 {
1745+
err.multipart_suggestion(
1746+
&msg,
1747+
spans
1748+
.iter()
1749+
.flat_map(|&span| {
17501750
vec![
17511751
(span.shrink_to_lo(), "Box<".to_string()),
17521752
(span.shrink_to_hi(), ">".to_string()),
1753-
],
1754-
vec![
1755-
(span.shrink_to_lo(), "Rc<".to_string()),
1756-
(span.shrink_to_hi(), ">".to_string()),
1757-
],
1758-
vec![(span.shrink_to_lo(), "&".to_string())],
1759-
],
1760-
Applicability::HasPlaceholders,
1761-
);
1762-
}
1763-
_ if spans.len() <= 4 => {
1764-
err.multipart_suggestion(
1765-
&msg,
1766-
spans
1767-
.iter()
1768-
.flat_map(|&span| {
1769-
vec![
1770-
(span.shrink_to_lo(), "Box<".to_string()),
1771-
(span.shrink_to_hi(), ">".to_string()),
1772-
]
1773-
.into_iter()
1774-
})
1775-
.collect(),
1776-
Applicability::HasPlaceholders,
1777-
);
1778-
}
1779-
_ => {
1780-
err.help(&msg);
1781-
}
1753+
]
1754+
.into_iter()
1755+
})
1756+
.collect(),
1757+
Applicability::HasPlaceholders,
1758+
);
1759+
} else {
1760+
err.help(&msg);
17821761
}
17831762
err.emit();
17841763
}

src/test/ui/infinite/infinite-tag-type-recursion.stderr

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@ LL | enum MList { Cons(isize, MList), Nil }
66
| |
77
| recursive type has infinite size
88
|
9-
help: insert some indirection to make `MList` representable
9+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `MList` representable
1010
|
1111
LL | enum MList { Cons(isize, Box<MList>), Nil }
1212
| ^^^^ ^
13-
LL | enum MList { Cons(isize, Rc<MList>), Nil }
14-
| ^^^ ^
15-
LL | enum MList { Cons(isize, &MList), Nil }
16-
| ^
1713

1814
error[E0391]: cycle detected when processing `MList`
1915
--> $DIR/infinite-tag-type-recursion.rs:1:1

src/test/ui/issues/issue-17431-1.stderr

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@ LL | struct Foo { foo: Option<Option<Foo>> }
66
| |
77
| recursive type has infinite size
88
|
9-
help: insert some indirection to make `Foo` representable
9+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
1010
|
1111
LL | struct Foo { foo: Box<Option<Option<Foo>>> }
1212
| ^^^^ ^
13-
LL | struct Foo { foo: Rc<Option<Option<Foo>>> }
14-
| ^^^ ^
15-
LL | struct Foo { foo: &Option<Option<Foo>> }
16-
| ^
1713

1814
error: aborting due to previous error
1915

src/test/ui/issues/issue-17431-2.stderr

+2-10
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@ LL | struct Baz { q: Option<Foo> }
66
| |
77
| recursive type has infinite size
88
|
9-
help: insert some indirection to make `Baz` representable
9+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Baz` representable
1010
|
1111
LL | struct Baz { q: Box<Option<Foo>> }
1212
| ^^^^ ^
13-
LL | struct Baz { q: Rc<Option<Foo>> }
14-
| ^^^ ^
15-
LL | struct Baz { q: &Option<Foo> }
16-
| ^
1713

1814
error[E0072]: recursive type `Foo` has infinite size
1915
--> $DIR/issue-17431-2.rs:4:1
@@ -23,14 +19,10 @@ LL | struct Foo { q: Option<Baz> }
2319
| |
2420
| recursive type has infinite size
2521
|
26-
help: insert some indirection to make `Foo` representable
22+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
2723
|
2824
LL | struct Foo { q: Box<Option<Baz>> }
2925
| ^^^^ ^
30-
LL | struct Foo { q: Rc<Option<Baz>> }
31-
| ^^^ ^
32-
LL | struct Foo { q: &Option<Baz> }
33-
| ^
3426

3527
error: aborting due to 2 previous errors
3628

src/test/ui/issues/issue-17431-3.stderr

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@ LL | struct Foo { foo: Mutex<Option<Foo>> }
66
| |
77
| recursive type has infinite size
88
|
9-
help: insert some indirection to make `Foo` representable
9+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
1010
|
1111
LL | struct Foo { foo: Box<Mutex<Option<Foo>>> }
1212
| ^^^^ ^
13-
LL | struct Foo { foo: Rc<Mutex<Option<Foo>>> }
14-
| ^^^ ^
15-
LL | struct Foo { foo: &Mutex<Option<Foo>> }
16-
| ^
1713

1814
error: aborting due to previous error
1915

src/test/ui/issues/issue-17431-4.stderr

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@ LL | struct Foo<T> { foo: Option<Option<Foo<T>>>, marker: marker::PhantomData<T>
66
| |
77
| recursive type has infinite size
88
|
9-
help: insert some indirection to make `Foo` representable
9+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
1010
|
1111
LL | struct Foo<T> { foo: Box<Option<Option<Foo<T>>>>, marker: marker::PhantomData<T> }
1212
| ^^^^ ^
13-
LL | struct Foo<T> { foo: Rc<Option<Option<Foo<T>>>>, marker: marker::PhantomData<T> }
14-
| ^^^ ^
15-
LL | struct Foo<T> { foo: &Option<Option<Foo<T>>>, marker: marker::PhantomData<T> }
16-
| ^
1713

1814
error: aborting due to previous error
1915

src/test/ui/issues/issue-17431-5.stderr

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@ LL | struct Bar<T> { x: Bar<Foo> , marker: marker::PhantomData<T> }
66
| |
77
| recursive type has infinite size
88
|
9-
help: insert some indirection to make `Bar` representable
9+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Bar` representable
1010
|
1111
LL | struct Bar<T> { x: Box<Bar<Foo>> , marker: marker::PhantomData<T> }
1212
| ^^^^ ^
13-
LL | struct Bar<T> { x: Rc<Bar<Foo>> , marker: marker::PhantomData<T> }
14-
| ^^^ ^
15-
LL | struct Bar<T> { x: &Bar<Foo> , marker: marker::PhantomData<T> }
16-
| ^
1713

1814
error: aborting due to previous error
1915

src/test/ui/issues/issue-17431-6.stderr

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@ LL | enum Foo { X(Mutex<Option<Foo>>) }
66
| |
77
| recursive type has infinite size
88
|
9-
help: insert some indirection to make `Foo` representable
9+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
1010
|
1111
LL | enum Foo { X(Box<Mutex<Option<Foo>>>) }
1212
| ^^^^ ^
13-
LL | enum Foo { X(Rc<Mutex<Option<Foo>>>) }
14-
| ^^^ ^
15-
LL | enum Foo { X(&Mutex<Option<Foo>>) }
16-
| ^
1713

1814
error: aborting due to previous error
1915

src/test/ui/issues/issue-17431-7.stderr

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@ LL | enum Foo { Voo(Option<Option<Foo>>) }
66
| |
77
| recursive type has infinite size
88
|
9-
help: insert some indirection to make `Foo` representable
9+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
1010
|
1111
LL | enum Foo { Voo(Box<Option<Option<Foo>>>) }
1212
| ^^^^ ^
13-
LL | enum Foo { Voo(Rc<Option<Option<Foo>>>) }
14-
| ^^^ ^
15-
LL | enum Foo { Voo(&Option<Option<Foo>>) }
16-
| ^
1713

1814
error: aborting due to previous error
1915

src/test/ui/issues/issue-2718-a.stderr

+1-5
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,10 @@ LL | pub struct Pong(SendPacket<Ping>);
77
| | recursive without indirection
88
| recursive type has infinite size
99
|
10-
help: insert some indirection to make `pingpong::Pong` representable
10+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `pingpong::Pong` representable
1111
|
1212
LL | pub struct Pong(Box<SendPacket<Ping>>);
1313
| ^^^^ ^
14-
LL | pub struct Pong(Rc<SendPacket<Ping>>);
15-
| ^^^ ^
16-
LL | pub struct Pong(&SendPacket<Ping>);
17-
| ^
1814

1915
error: aborting due to previous error
2016

src/test/ui/issues/issue-3008-1.stderr

+1-5
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,10 @@ LL | enum Bar {
77
LL | BarSome(Bar)
88
| --- recursive without indirection
99
|
10-
help: insert some indirection to make `Bar` representable
10+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Bar` representable
1111
|
1212
LL | BarSome(Box<Bar>)
1313
| ^^^^ ^
14-
LL | BarSome(Rc<Bar>)
15-
| ^^^ ^
16-
LL | BarSome(&Bar)
17-
| ^
1814

1915
error: aborting due to previous error
2016

src/test/ui/issues/issue-3008-2.stderr

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@ LL | struct Bar { x: Bar }
66
| |
77
| recursive type has infinite size
88
|
9-
help: insert some indirection to make `Bar` representable
9+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Bar` representable
1010
|
1111
LL | struct Bar { x: Box<Bar> }
1212
| ^^^^ ^
13-
LL | struct Bar { x: Rc<Bar> }
14-
| ^^^ ^
15-
LL | struct Bar { x: &Bar }
16-
| ^
1713

1814
error: aborting due to previous error
1915

src/test/ui/issues/issue-3008-3.stderr

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@ LL | enum E2<T> { V2(E2<E1>, marker::PhantomData<T>), }
66
| |
77
| recursive type has infinite size
88
|
9-
help: insert some indirection to make `E2` representable
9+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `E2` representable
1010
|
1111
LL | enum E2<T> { V2(Box<E2<E1>>, marker::PhantomData<T>), }
1212
| ^^^^ ^
13-
LL | enum E2<T> { V2(Rc<E2<E1>>, marker::PhantomData<T>), }
14-
| ^^^ ^
15-
LL | enum E2<T> { V2(&E2<E1>, marker::PhantomData<T>), }
16-
| ^
1713

1814
error: aborting due to previous error
1915

src/test/ui/issues/issue-3779.stderr

+1-5
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,10 @@ LL |
77
LL | element: Option<S>
88
| --------- recursive without indirection
99
|
10-
help: insert some indirection to make `S` representable
10+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `S` representable
1111
|
1212
LL | element: Box<Option<S>>
1313
| ^^^^ ^
14-
LL | element: Rc<Option<S>>
15-
| ^^^ ^
16-
LL | element: &Option<S>
17-
| ^
1814

1915
error: aborting due to previous error
2016

src/test/ui/issues/issue-57271.stderr

+2-10
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,10 @@ LL | Class(ClassTypeSignature),
77
LL | Array(TypeSignature),
88
| ------------- recursive without indirection
99
|
10-
help: insert some indirection to make `ObjectType` representable
10+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `ObjectType` representable
1111
|
1212
LL | Array(Box<TypeSignature>),
1313
| ^^^^ ^
14-
LL | Array(Rc<TypeSignature>),
15-
| ^^^ ^
16-
LL | Array(&TypeSignature),
17-
| ^
1814

1915
error[E0072]: recursive type `TypeSignature` has infinite size
2016
--> $DIR/issue-57271.rs:19:1
@@ -25,14 +21,10 @@ LL | Base(BaseType),
2521
LL | Object(ObjectType),
2622
| ---------- recursive without indirection
2723
|
28-
help: insert some indirection to make `TypeSignature` representable
24+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `TypeSignature` representable
2925
|
3026
LL | Object(Box<ObjectType>),
3127
| ^^^^ ^
32-
LL | Object(Rc<ObjectType>),
33-
| ^^^ ^
34-
LL | Object(&ObjectType),
35-
| ^
3628

3729
error: aborting due to 2 previous errors
3830

src/test/ui/recursion/recursive-enum.stderr

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@ LL | enum List<T> { Cons(T, List<T>), Nil }
66
| |
77
| recursive type has infinite size
88
|
9-
help: insert some indirection to make `List` representable
9+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `List` representable
1010
|
1111
LL | enum List<T> { Cons(T, Box<List<T>>), Nil }
1212
| ^^^^ ^
13-
LL | enum List<T> { Cons(T, Rc<List<T>>), Nil }
14-
| ^^^ ^
15-
LL | enum List<T> { Cons(T, &List<T>), Nil }
16-
| ^
1713

1814
error: aborting due to previous error
1915

src/test/ui/sized-cycle-note.stderr

+2-10
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@ LL | struct Baz { q: Option<Foo> }
66
| |
77
| recursive type has infinite size
88
|
9-
help: insert some indirection to make `Baz` representable
9+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Baz` representable
1010
|
1111
LL | struct Baz { q: Box<Option<Foo>> }
1212
| ^^^^ ^
13-
LL | struct Baz { q: Rc<Option<Foo>> }
14-
| ^^^ ^
15-
LL | struct Baz { q: &Option<Foo> }
16-
| ^
1713

1814
error[E0072]: recursive type `Foo` has infinite size
1915
--> $DIR/sized-cycle-note.rs:11:1
@@ -23,14 +19,10 @@ LL | struct Foo { q: Option<Baz> }
2319
| |
2420
| recursive type has infinite size
2521
|
26-
help: insert some indirection to make `Foo` representable
22+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
2723
|
2824
LL | struct Foo { q: Box<Option<Baz>> }
2925
| ^^^^ ^
30-
LL | struct Foo { q: Rc<Option<Baz>> }
31-
| ^^^ ^
32-
LL | struct Foo { q: &Option<Baz> }
33-
| ^
3426

3527
error: aborting due to 2 previous errors
3628

src/test/ui/span/E0072.stderr

+1-5
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,10 @@ LL | head: u8,
77
LL | tail: Option<ListNode>,
88
| ---------------- recursive without indirection
99
|
10-
help: insert some indirection to make `ListNode` representable
10+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `ListNode` representable
1111
|
1212
LL | tail: Box<Option<ListNode>>,
1313
| ^^^^ ^
14-
LL | tail: Rc<Option<ListNode>>,
15-
| ^^^ ^
16-
LL | tail: &Option<ListNode>,
17-
| ^
1814

1915
error: aborting due to previous error
2016

src/test/ui/span/multiline-span-E0072.stderr

+1-5
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@ LL | | tail: Option<ListNode>,
1010
LL | | }
1111
| |_^ recursive type has infinite size
1212
|
13-
help: insert some indirection to make `ListNode` representable
13+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `ListNode` representable
1414
|
1515
LL | tail: Box<Option<ListNode>>,
1616
| ^^^^ ^
17-
LL | tail: Rc<Option<ListNode>>,
18-
| ^^^ ^
19-
LL | tail: &Option<ListNode>,
20-
| ^
2117

2218
error: aborting due to previous error
2319

0 commit comments

Comments
 (0)