Improve invalid recursive types diagnostic
This commit is contained in:
parent
55ede7ed8e
commit
77e9228b4a
src
librustc_typeck
test/compile-fail
@ -4273,10 +4273,8 @@ pub fn check_representable(tcx: &ty::ctxt,
|
||||
// caught by case 1.
|
||||
match rty.is_representable(tcx, sp) {
|
||||
ty::SelfRecursive => {
|
||||
span_err!(tcx.sess, sp, E0072,
|
||||
"illegal recursive {} type; \
|
||||
wrap the inner value in a box to make it representable",
|
||||
designation);
|
||||
span_err!(tcx.sess, sp, E0072, "invalid recursive {} type", designation);
|
||||
tcx.sess.fileline_help(sp, "wrap the inner value in a box to make it representable");
|
||||
return false
|
||||
}
|
||||
ty::Representable | ty::ContainsRecursive => (),
|
||||
|
@ -778,7 +778,7 @@ the pointer the size of the type would need to be unbounded.
|
||||
Consider the following erroneous definition of a type for a list of bytes:
|
||||
|
||||
```
|
||||
// error, illegal recursive struct type
|
||||
// error, invalid recursive struct type
|
||||
struct ListNode {
|
||||
head: u8,
|
||||
tail: Option<ListNode>,
|
||||
@ -2345,7 +2345,7 @@ register_diagnostics! {
|
||||
E0241,
|
||||
E0242, // internal error looking up a definition
|
||||
E0245, // not a trait
|
||||
E0246, // illegal recursive type
|
||||
E0246, // invalid recursive type
|
||||
E0247, // found module name used as a type
|
||||
E0248, // found value name used as a type
|
||||
E0319, // trait impls for defaulted traits allowed just for structs/enums
|
||||
|
@ -9,7 +9,7 @@
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
// error-pattern: illegal recursive enum type; wrap the inner value in a box
|
||||
// error-pattern: invalid recursive enum type
|
||||
|
||||
enum mlist { cons(isize, mlist), nil, }
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
// except according to those terms.
|
||||
|
||||
struct Foo { foo: Option<Option<Foo>> }
|
||||
//~^ ERROR illegal recursive struct type; wrap the inner value in a box to make it representable
|
||||
//~^ ERROR invalid recursive struct type
|
||||
|
||||
impl Foo { fn bar(&self) {} }
|
||||
|
||||
|
@ -9,10 +9,10 @@
|
||||
// except according to those terms.
|
||||
|
||||
struct Baz { q: Option<Foo> }
|
||||
//~^ ERROR illegal recursive struct type; wrap the inner value in a box to make it representable
|
||||
//~^ ERROR invalid recursive struct type
|
||||
|
||||
struct Foo { q: Option<Baz> }
|
||||
//~^ ERROR illegal recursive struct type; wrap the inner value in a box to make it representable
|
||||
//~^ ERROR invalid recursive struct type
|
||||
|
||||
impl Foo { fn bar(&self) {} }
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
use std::sync::Mutex;
|
||||
|
||||
struct Foo { foo: Mutex<Option<Foo>> }
|
||||
//~^ ERROR illegal recursive struct type; wrap the inner value in a box to make it representable
|
||||
//~^ ERROR invalid recursive struct type
|
||||
|
||||
impl Foo { fn bar(&self) {} }
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
use std::marker;
|
||||
|
||||
struct Foo<T> { foo: Option<Option<Foo<T>>>, marker: marker::PhantomData<T> }
|
||||
//~^ ERROR illegal recursive struct type; wrap the inner value in a box to make it representable
|
||||
//~^ ERROR invalid recursive struct type
|
||||
|
||||
impl<T> Foo<T> { fn bar(&self) {} }
|
||||
|
||||
|
@ -12,7 +12,7 @@ use std::marker;
|
||||
|
||||
struct Foo { foo: Bar<Foo> }
|
||||
struct Bar<T> { x: Bar<Foo> , marker: marker::PhantomData<T> }
|
||||
//~^ ERROR illegal recursive struct type; wrap the inner value in a box to make it representable
|
||||
//~^ ERROR invalid recursive struct type
|
||||
|
||||
impl Foo { fn foo(&self) {} }
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
use std::sync::Mutex;
|
||||
|
||||
enum Foo { X(Mutex<Option<Foo>>) }
|
||||
//~^ ERROR illegal recursive enum type; wrap the inner value in a box to make it representable
|
||||
//~^ ERROR invalid recursive enum type
|
||||
|
||||
impl Foo { fn bar(self) {} }
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
// except according to those terms.
|
||||
|
||||
enum Foo { Voo(Option<Option<Foo>>) }
|
||||
//~^ ERROR illegal recursive enum type; wrap the inner value in a box to make it representable
|
||||
//~^ ERROR invalid recursive enum type
|
||||
|
||||
impl Foo { fn bar(&self) {} }
|
||||
|
||||
|
@ -16,7 +16,7 @@ mod pingpong {
|
||||
use send_packet;
|
||||
pub type ping = send_packet<pong>;
|
||||
pub struct pong(send_packet<ping>);
|
||||
//~^ ERROR illegal recursive struct type; wrap the inner value in a box to make it representable
|
||||
//~^ ERROR invalid recursive struct type
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
enum foo { foo_(bar) }
|
||||
enum bar { bar_none, bar_some(bar) }
|
||||
//~^ ERROR illegal recursive enum type; wrap the inner value in a box to make it representable
|
||||
//~^ ERROR invalid recursive enum type
|
||||
|
||||
fn main() {
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
enum foo { foo_(bar) }
|
||||
struct bar { x: bar }
|
||||
//~^ ERROR illegal recursive struct type; wrap the inner value in a box to make it representable
|
||||
//~^ ERROR invalid recursive struct type
|
||||
|
||||
fn main() {
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ use std::marker;
|
||||
|
||||
enum E1 { V1(E2<E1>), }
|
||||
enum E2<T> { V2(E2<E1>, marker::PhantomData<T>), }
|
||||
//~^ ERROR illegal recursive enum type; wrap the inner value in a box to make it representable
|
||||
//~^ ERROR invalid recursive enum type
|
||||
|
||||
impl E1 { fn foo(&self) {} }
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
// except according to those terms.
|
||||
|
||||
struct S {
|
||||
//~^ ERROR illegal recursive struct type; wrap the inner value in a box to make it representable
|
||||
//~^ ERROR invalid recursive struct type
|
||||
element: Option<S>
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern: illegal recursive enum type
|
||||
// error-pattern: invalid recursive enum type
|
||||
|
||||
enum list<T> { cons(T, list<T>), nil }
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern:illegal recursive struct type
|
||||
// error-pattern:invalid recursive struct type
|
||||
struct t1 {
|
||||
foo: isize,
|
||||
foolish: t1
|
||||
|
Loading…
x
Reference in New Issue
Block a user