Skip to content

Commit

Permalink
review comments: only suggest one substitution
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed May 31, 2020
1 parent f6dfbbb commit c209040
Show file tree
Hide file tree
Showing 22 changed files with 38 additions and 155 deletions.
49 changes: 14 additions & 35 deletions src/librustc_trait_selection/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1737,48 +1737,27 @@ pub fn recursive_type_with_infinite_size_error(
for &span in &spans {
err.span_label(span, "recursive without indirection");
}
let short_msg = format!("insert some indirection to make `{}` representable", path);
let msg = format!(
"insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `{}` representable",
path,
);
match &spans[..] {
[span] => {
err.multipart_suggestions(
&short_msg,
vec![
if spans.len() <= 4 {
err.multipart_suggestion(
&msg,
spans
.iter()
.flat_map(|&span| {
vec![
(span.shrink_to_lo(), "Box<".to_string()),
(span.shrink_to_hi(), ">".to_string()),
],
vec![
(span.shrink_to_lo(), "Rc<".to_string()),
(span.shrink_to_hi(), ">".to_string()),
],
vec![(span.shrink_to_lo(), "&".to_string())],
],
Applicability::HasPlaceholders,
);
}
_ if spans.len() <= 4 => {
err.multipart_suggestion(
&msg,
spans
.iter()
.flat_map(|&span| {
vec![
(span.shrink_to_lo(), "Box<".to_string()),
(span.shrink_to_hi(), ">".to_string()),
]
.into_iter()
})
.collect(),
Applicability::HasPlaceholders,
);
}
_ => {
err.help(&msg);
}
]
.into_iter()
})
.collect(),
Applicability::HasPlaceholders,
);
} else {
err.help(&msg);
}
err.emit();
}
Expand Down
6 changes: 1 addition & 5 deletions src/test/ui/infinite/infinite-tag-type-recursion.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ LL | enum MList { Cons(isize, MList), Nil }
| |
| recursive type has infinite size
|
help: insert some indirection to make `MList` representable
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `MList` representable
|
LL | enum MList { Cons(isize, Box<MList>), Nil }
| ^^^^ ^
LL | enum MList { Cons(isize, Rc<MList>), Nil }
| ^^^ ^
LL | enum MList { Cons(isize, &MList), Nil }
| ^

error[E0391]: cycle detected when processing `MList`
--> $DIR/infinite-tag-type-recursion.rs:1:1
Expand Down
6 changes: 1 addition & 5 deletions src/test/ui/issues/issue-17431-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ LL | struct Foo { foo: Option<Option<Foo>> }
| |
| recursive type has infinite size
|
help: insert some indirection to make `Foo` representable
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
|
LL | struct Foo { foo: Box<Option<Option<Foo>>> }
| ^^^^ ^
LL | struct Foo { foo: Rc<Option<Option<Foo>>> }
| ^^^ ^
LL | struct Foo { foo: &Option<Option<Foo>> }
| ^

error: aborting due to previous error

Expand Down
12 changes: 2 additions & 10 deletions src/test/ui/issues/issue-17431-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ LL | struct Baz { q: Option<Foo> }
| |
| recursive type has infinite size
|
help: insert some indirection to make `Baz` representable
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Baz` representable
|
LL | struct Baz { q: Box<Option<Foo>> }
| ^^^^ ^
LL | struct Baz { q: Rc<Option<Foo>> }
| ^^^ ^
LL | struct Baz { q: &Option<Foo> }
| ^

error[E0072]: recursive type `Foo` has infinite size
--> $DIR/issue-17431-2.rs:4:1
Expand All @@ -23,14 +19,10 @@ LL | struct Foo { q: Option<Baz> }
| |
| recursive type has infinite size
|
help: insert some indirection to make `Foo` representable
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
|
LL | struct Foo { q: Box<Option<Baz>> }
| ^^^^ ^
LL | struct Foo { q: Rc<Option<Baz>> }
| ^^^ ^
LL | struct Foo { q: &Option<Baz> }
| ^

error: aborting due to 2 previous errors

Expand Down
6 changes: 1 addition & 5 deletions src/test/ui/issues/issue-17431-3.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ LL | struct Foo { foo: Mutex<Option<Foo>> }
| |
| recursive type has infinite size
|
help: insert some indirection to make `Foo` representable
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
|
LL | struct Foo { foo: Box<Mutex<Option<Foo>>> }
| ^^^^ ^
LL | struct Foo { foo: Rc<Mutex<Option<Foo>>> }
| ^^^ ^
LL | struct Foo { foo: &Mutex<Option<Foo>> }
| ^

error: aborting due to previous error

Expand Down
6 changes: 1 addition & 5 deletions src/test/ui/issues/issue-17431-4.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ LL | struct Foo<T> { foo: Option<Option<Foo<T>>>, marker: marker::PhantomData<T>
| |
| recursive type has infinite size
|
help: insert some indirection to make `Foo` representable
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
|
LL | struct Foo<T> { foo: Box<Option<Option<Foo<T>>>>, marker: marker::PhantomData<T> }
| ^^^^ ^
LL | struct Foo<T> { foo: Rc<Option<Option<Foo<T>>>>, marker: marker::PhantomData<T> }
| ^^^ ^
LL | struct Foo<T> { foo: &Option<Option<Foo<T>>>, marker: marker::PhantomData<T> }
| ^

error: aborting due to previous error

Expand Down
6 changes: 1 addition & 5 deletions src/test/ui/issues/issue-17431-5.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ LL | struct Bar<T> { x: Bar<Foo> , marker: marker::PhantomData<T> }
| |
| recursive type has infinite size
|
help: insert some indirection to make `Bar` representable
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Bar` representable
|
LL | struct Bar<T> { x: Box<Bar<Foo>> , marker: marker::PhantomData<T> }
| ^^^^ ^
LL | struct Bar<T> { x: Rc<Bar<Foo>> , marker: marker::PhantomData<T> }
| ^^^ ^
LL | struct Bar<T> { x: &Bar<Foo> , marker: marker::PhantomData<T> }
| ^

error: aborting due to previous error

Expand Down
6 changes: 1 addition & 5 deletions src/test/ui/issues/issue-17431-6.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ LL | enum Foo { X(Mutex<Option<Foo>>) }
| |
| recursive type has infinite size
|
help: insert some indirection to make `Foo` representable
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
|
LL | enum Foo { X(Box<Mutex<Option<Foo>>>) }
| ^^^^ ^
LL | enum Foo { X(Rc<Mutex<Option<Foo>>>) }
| ^^^ ^
LL | enum Foo { X(&Mutex<Option<Foo>>) }
| ^

error: aborting due to previous error

Expand Down
6 changes: 1 addition & 5 deletions src/test/ui/issues/issue-17431-7.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ LL | enum Foo { Voo(Option<Option<Foo>>) }
| |
| recursive type has infinite size
|
help: insert some indirection to make `Foo` representable
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
|
LL | enum Foo { Voo(Box<Option<Option<Foo>>>) }
| ^^^^ ^
LL | enum Foo { Voo(Rc<Option<Option<Foo>>>) }
| ^^^ ^
LL | enum Foo { Voo(&Option<Option<Foo>>) }
| ^

error: aborting due to previous error

Expand Down
6 changes: 1 addition & 5 deletions src/test/ui/issues/issue-2718-a.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ LL | pub struct Pong(SendPacket<Ping>);
| | recursive without indirection
| recursive type has infinite size
|
help: insert some indirection to make `pingpong::Pong` representable
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `pingpong::Pong` representable
|
LL | pub struct Pong(Box<SendPacket<Ping>>);
| ^^^^ ^
LL | pub struct Pong(Rc<SendPacket<Ping>>);
| ^^^ ^
LL | pub struct Pong(&SendPacket<Ping>);
| ^

error: aborting due to previous error

Expand Down
6 changes: 1 addition & 5 deletions src/test/ui/issues/issue-3008-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ LL | enum Bar {
LL | BarSome(Bar)
| --- recursive without indirection
|
help: insert some indirection to make `Bar` representable
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Bar` representable
|
LL | BarSome(Box<Bar>)
| ^^^^ ^
LL | BarSome(Rc<Bar>)
| ^^^ ^
LL | BarSome(&Bar)
| ^

error: aborting due to previous error

Expand Down
6 changes: 1 addition & 5 deletions src/test/ui/issues/issue-3008-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ LL | struct Bar { x: Bar }
| |
| recursive type has infinite size
|
help: insert some indirection to make `Bar` representable
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Bar` representable
|
LL | struct Bar { x: Box<Bar> }
| ^^^^ ^
LL | struct Bar { x: Rc<Bar> }
| ^^^ ^
LL | struct Bar { x: &Bar }
| ^

error: aborting due to previous error

Expand Down
6 changes: 1 addition & 5 deletions src/test/ui/issues/issue-3008-3.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ LL | enum E2<T> { V2(E2<E1>, marker::PhantomData<T>), }
| |
| recursive type has infinite size
|
help: insert some indirection to make `E2` representable
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `E2` representable
|
LL | enum E2<T> { V2(Box<E2<E1>>, marker::PhantomData<T>), }
| ^^^^ ^
LL | enum E2<T> { V2(Rc<E2<E1>>, marker::PhantomData<T>), }
| ^^^ ^
LL | enum E2<T> { V2(&E2<E1>, marker::PhantomData<T>), }
| ^

error: aborting due to previous error

Expand Down
6 changes: 1 addition & 5 deletions src/test/ui/issues/issue-3779.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ LL |
LL | element: Option<S>
| --------- recursive without indirection
|
help: insert some indirection to make `S` representable
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `S` representable
|
LL | element: Box<Option<S>>
| ^^^^ ^
LL | element: Rc<Option<S>>
| ^^^ ^
LL | element: &Option<S>
| ^

error: aborting due to previous error

Expand Down
12 changes: 2 additions & 10 deletions src/test/ui/issues/issue-57271.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ LL | Class(ClassTypeSignature),
LL | Array(TypeSignature),
| ------------- recursive without indirection
|
help: insert some indirection to make `ObjectType` representable
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `ObjectType` representable
|
LL | Array(Box<TypeSignature>),
| ^^^^ ^
LL | Array(Rc<TypeSignature>),
| ^^^ ^
LL | Array(&TypeSignature),
| ^

error[E0072]: recursive type `TypeSignature` has infinite size
--> $DIR/issue-57271.rs:19:1
Expand All @@ -25,14 +21,10 @@ LL | Base(BaseType),
LL | Object(ObjectType),
| ---------- recursive without indirection
|
help: insert some indirection to make `TypeSignature` representable
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `TypeSignature` representable
|
LL | Object(Box<ObjectType>),
| ^^^^ ^
LL | Object(Rc<ObjectType>),
| ^^^ ^
LL | Object(&ObjectType),
| ^

error: aborting due to 2 previous errors

Expand Down
6 changes: 1 addition & 5 deletions src/test/ui/recursion/recursive-enum.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ LL | enum List<T> { Cons(T, List<T>), Nil }
| |
| recursive type has infinite size
|
help: insert some indirection to make `List` representable
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `List` representable
|
LL | enum List<T> { Cons(T, Box<List<T>>), Nil }
| ^^^^ ^
LL | enum List<T> { Cons(T, Rc<List<T>>), Nil }
| ^^^ ^
LL | enum List<T> { Cons(T, &List<T>), Nil }
| ^

error: aborting due to previous error

Expand Down
12 changes: 2 additions & 10 deletions src/test/ui/sized-cycle-note.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ LL | struct Baz { q: Option<Foo> }
| |
| recursive type has infinite size
|
help: insert some indirection to make `Baz` representable
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Baz` representable
|
LL | struct Baz { q: Box<Option<Foo>> }
| ^^^^ ^
LL | struct Baz { q: Rc<Option<Foo>> }
| ^^^ ^
LL | struct Baz { q: &Option<Foo> }
| ^

error[E0072]: recursive type `Foo` has infinite size
--> $DIR/sized-cycle-note.rs:11:1
Expand All @@ -23,14 +19,10 @@ LL | struct Foo { q: Option<Baz> }
| |
| recursive type has infinite size
|
help: insert some indirection to make `Foo` representable
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
|
LL | struct Foo { q: Box<Option<Baz>> }
| ^^^^ ^
LL | struct Foo { q: Rc<Option<Baz>> }
| ^^^ ^
LL | struct Foo { q: &Option<Baz> }
| ^

error: aborting due to 2 previous errors

Expand Down
6 changes: 1 addition & 5 deletions src/test/ui/span/E0072.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ LL | head: u8,
LL | tail: Option<ListNode>,
| ---------------- recursive without indirection
|
help: insert some indirection to make `ListNode` representable
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `ListNode` representable
|
LL | tail: Box<Option<ListNode>>,
| ^^^^ ^
LL | tail: Rc<Option<ListNode>>,
| ^^^ ^
LL | tail: &Option<ListNode>,
| ^

error: aborting due to previous error

Expand Down
6 changes: 1 addition & 5 deletions src/test/ui/span/multiline-span-E0072.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ LL | | tail: Option<ListNode>,
LL | | }
| |_^ recursive type has infinite size
|
help: insert some indirection to make `ListNode` representable
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `ListNode` representable
|
LL | tail: Box<Option<ListNode>>,
| ^^^^ ^
LL | tail: Rc<Option<ListNode>>,
| ^^^ ^
LL | tail: &Option<ListNode>,
| ^

error: aborting due to previous error

Expand Down
Loading

0 comments on commit c209040

Please sign in to comment.