Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 7cde07e

Browse files
committed
review comments: only suggest one substitution
1 parent c29b3fa commit 7cde07e

22 files changed

+38
-155
lines changed

src/librustc_trait_selection/traits/error_reporting/mod.rs

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,48 +1759,27 @@ pub fn recursive_type_with_infinite_size_error(
17591759
for &span in &spans {
17601760
err.span_label(span, "recursive without indirection");
17611761
}
1762-
let short_msg = format!("insert some indirection to make `{}` representable", path);
17631762
let msg = format!(
17641763
"insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `{}` representable",
17651764
path,
17661765
);
1767-
match &spans[..] {
1768-
[span] => {
1769-
err.multipart_suggestions(
1770-
&short_msg,
1771-
vec![
1766+
if spans.len() <= 4 {
1767+
err.multipart_suggestion(
1768+
&msg,
1769+
spans
1770+
.iter()
1771+
.flat_map(|&span| {
17721772
vec![
17731773
(span.shrink_to_lo(), "Box<".to_string()),
17741774
(span.shrink_to_hi(), ">".to_string()),
1775-
],
1776-
vec![
1777-
(span.shrink_to_lo(), "Rc<".to_string()),
1778-
(span.shrink_to_hi(), ">".to_string()),
1779-
],
1780-
vec![(span.shrink_to_lo(), "&".to_string())],
1781-
],
1782-
Applicability::HasPlaceholders,
1783-
);
1784-
}
1785-
_ if spans.len() <= 4 => {
1786-
err.multipart_suggestion(
1787-
&msg,
1788-
spans
1789-
.iter()
1790-
.flat_map(|&span| {
1791-
vec![
1792-
(span.shrink_to_lo(), "Box<".to_string()),
1793-
(span.shrink_to_hi(), ">".to_string()),
1794-
]
1795-
.into_iter()
1796-
})
1797-
.collect(),
1798-
Applicability::HasPlaceholders,
1799-
);
1800-
}
1801-
_ => {
1802-
err.help(&msg);
1803-
}
1775+
]
1776+
.into_iter()
1777+
})
1778+
.collect(),
1779+
Applicability::HasPlaceholders,
1780+
);
1781+
} else {
1782+
err.help(&msg);
18041783
}
18051784
err.emit();
18061785
}

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

Lines changed: 1 addition & 5 deletions
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 computing drop-check constraints for `MList`
1915
--> $DIR/infinite-tag-type-recursion.rs:1:1

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

Lines changed: 1 addition & 5 deletions
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

Lines changed: 2 additions & 10 deletions
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

Lines changed: 1 addition & 5 deletions
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

Lines changed: 1 addition & 5 deletions
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

Lines changed: 1 addition & 5 deletions
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

Lines changed: 1 addition & 5 deletions
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

Lines changed: 1 addition & 5 deletions
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

Lines changed: 1 addition & 5 deletions
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

0 commit comments

Comments
 (0)