Skip to content

Commit 77e9228

Browse files
committed
Improve invalid recursive types diagnostic
1 parent 55ede7e commit 77e9228

17 files changed

+20
-22
lines changed

src/librustc_typeck/check/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4273,10 +4273,8 @@ pub fn check_representable(tcx: &ty::ctxt,
42734273
// caught by case 1.
42744274
match rty.is_representable(tcx, sp) {
42754275
ty::SelfRecursive => {
4276-
span_err!(tcx.sess, sp, E0072,
4277-
"illegal recursive {} type; \
4278-
wrap the inner value in a box to make it representable",
4279-
designation);
4276+
span_err!(tcx.sess, sp, E0072, "invalid recursive {} type", designation);
4277+
tcx.sess.fileline_help(sp, "wrap the inner value in a box to make it representable");
42804278
return false
42814279
}
42824280
ty::Representable | ty::ContainsRecursive => (),

src/librustc_typeck/diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ the pointer the size of the type would need to be unbounded.
778778
Consider the following erroneous definition of a type for a list of bytes:
779779
780780
```
781-
// error, illegal recursive struct type
781+
// error, invalid recursive struct type
782782
struct ListNode {
783783
head: u8,
784784
tail: Option<ListNode>,
@@ -2345,7 +2345,7 @@ register_diagnostics! {
23452345
E0241,
23462346
E0242, // internal error looking up a definition
23472347
E0245, // not a trait
2348-
E0246, // illegal recursive type
2348+
E0246, // invalid recursive type
23492349
E0247, // found module name used as a type
23502350
E0248, // found value name used as a type
23512351
E0319, // trait impls for defaulted traits allowed just for structs/enums

src/test/compile-fail/infinite-tag-type-recursion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111

12-
// error-pattern: illegal recursive enum type; wrap the inner value in a box
12+
// error-pattern: invalid recursive enum type
1313

1414
enum mlist { cons(isize, mlist), nil, }
1515

src/test/compile-fail/issue-17431-1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
struct Foo { foo: Option<Option<Foo>> }
12-
//~^ ERROR illegal recursive struct type; wrap the inner value in a box to make it representable
12+
//~^ ERROR invalid recursive struct type
1313

1414
impl Foo { fn bar(&self) {} }
1515

src/test/compile-fail/issue-17431-2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
// except according to those terms.
1010

1111
struct Baz { q: Option<Foo> }
12-
//~^ ERROR illegal recursive struct type; wrap the inner value in a box to make it representable
12+
//~^ ERROR invalid recursive struct type
1313

1414
struct Foo { q: Option<Baz> }
15-
//~^ ERROR illegal recursive struct type; wrap the inner value in a box to make it representable
15+
//~^ ERROR invalid recursive struct type
1616

1717
impl Foo { fn bar(&self) {} }
1818

src/test/compile-fail/issue-17431-3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use std::sync::Mutex;
1212

1313
struct Foo { foo: Mutex<Option<Foo>> }
14-
//~^ ERROR illegal recursive struct type; wrap the inner value in a box to make it representable
14+
//~^ ERROR invalid recursive struct type
1515

1616
impl Foo { fn bar(&self) {} }
1717

src/test/compile-fail/issue-17431-4.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use std::marker;
1212

1313
struct Foo<T> { foo: Option<Option<Foo<T>>>, marker: marker::PhantomData<T> }
14-
//~^ ERROR illegal recursive struct type; wrap the inner value in a box to make it representable
14+
//~^ ERROR invalid recursive struct type
1515

1616
impl<T> Foo<T> { fn bar(&self) {} }
1717

src/test/compile-fail/issue-17431-5.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::marker;
1212

1313
struct Foo { foo: Bar<Foo> }
1414
struct Bar<T> { x: Bar<Foo> , marker: marker::PhantomData<T> }
15-
//~^ ERROR illegal recursive struct type; wrap the inner value in a box to make it representable
15+
//~^ ERROR invalid recursive struct type
1616

1717
impl Foo { fn foo(&self) {} }
1818

src/test/compile-fail/issue-17431-6.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use std::sync::Mutex;
1212

1313
enum Foo { X(Mutex<Option<Foo>>) }
14-
//~^ ERROR illegal recursive enum type; wrap the inner value in a box to make it representable
14+
//~^ ERROR invalid recursive enum type
1515

1616
impl Foo { fn bar(self) {} }
1717

src/test/compile-fail/issue-17431-7.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
enum Foo { Voo(Option<Option<Foo>>) }
12-
//~^ ERROR illegal recursive enum type; wrap the inner value in a box to make it representable
12+
//~^ ERROR invalid recursive enum type
1313

1414
impl Foo { fn bar(&self) {} }
1515

src/test/compile-fail/issue-2718-a.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ mod pingpong {
1616
use send_packet;
1717
pub type ping = send_packet<pong>;
1818
pub struct pong(send_packet<ping>);
19-
//~^ ERROR illegal recursive struct type; wrap the inner value in a box to make it representable
19+
//~^ ERROR invalid recursive struct type
2020
}
2121

2222
fn main() {}

src/test/compile-fail/issue-3008-1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
enum foo { foo_(bar) }
1212
enum bar { bar_none, bar_some(bar) }
13-
//~^ ERROR illegal recursive enum type; wrap the inner value in a box to make it representable
13+
//~^ ERROR invalid recursive enum type
1414

1515
fn main() {
1616
}

src/test/compile-fail/issue-3008-2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
enum foo { foo_(bar) }
1414
struct bar { x: bar }
15-
//~^ ERROR illegal recursive struct type; wrap the inner value in a box to make it representable
15+
//~^ ERROR invalid recursive struct type
1616

1717
fn main() {
1818
}

src/test/compile-fail/issue-3008-3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::marker;
1212

1313
enum E1 { V1(E2<E1>), }
1414
enum E2<T> { V2(E2<E1>, marker::PhantomData<T>), }
15-
//~^ ERROR illegal recursive enum type; wrap the inner value in a box to make it representable
15+
//~^ ERROR invalid recursive enum type
1616

1717
impl E1 { fn foo(&self) {} }
1818

src/test/compile-fail/issue-3779.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
struct S {
12-
//~^ ERROR illegal recursive struct type; wrap the inner value in a box to make it representable
12+
//~^ ERROR invalid recursive struct type
1313
element: Option<S>
1414
}
1515

src/test/compile-fail/recursive-enum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern: illegal recursive enum type
11+
// error-pattern: invalid recursive enum type
1212

1313
enum list<T> { cons(T, list<T>), nil }
1414

src/test/compile-fail/type-recursive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern:illegal recursive struct type
11+
// error-pattern:invalid recursive struct type
1212
struct t1 {
1313
foo: isize,
1414
foolish: t1

0 commit comments

Comments
 (0)