Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc error message prose style in "recursive type T has infinite size" #31683

Closed
jorendorff opened this issue Feb 15, 2016 · 6 comments
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@jorendorff
Copy link
Contributor

Stable (1.6):

<anon>:1:1: 3:2 error: invalid recursive struct type [E0072]
<anon>:1 struct T {
<anon>:2     t: T
<anon>:3 }
<anon>:1:1: 3:2 help: see the detailed explanation for E0072
<anon>:1:1: 3:2 help: wrap the inner value in a box to make it representable

Nightly (1.8):

<anon>:1:1: 3:2 error: recursive type `T` has infinite size [E0072]
<anon>:1 struct T {
<anon>:2     t: T
<anon>:3 }
<anon>:1:1: 3:2 help: see the detailed explanation for E0072
<anon>:1:1: 3:2 help: insert indirection (e.g., a `Box`, `Rc`, or `&`) at some point to make `T` representable

Proposed:

<anon>:2:5: 2:9 error: field `t` of struct `T` can't have type `T` [E0072]
<anon>:2     t: T
<anon>       ^~~
<anon>:2:5: 2:9 help: see the detailed explanation for E0072

In the indirect case, it could say field fooof structTcan't contain a nested value of typeT (t.foo.bar.t).

My objection to the version in Nightly is that "infinite size" (a) feels a little jargony, (b) attributes to the user (i.e. me) (or at least my code) the ridiculous motive of wanting infinitely large, infinitely nested values.

I guess I would leave the "help" to the detailed explanation. Nightly suggests using Box or Rc or &, which would fix one problem but create others, right? Without also adding an Option, you'd have to use unsafe code to create values of such types.

@jorendorff
Copy link
Contributor Author

I would not recommend adding:

<anon>:1:1: 3:2 help: "Big `T`s have little `T`s,
<anon>:1:1: 3:2 help: Upon their backs to bite 'em,
<anon>:1:1: 3:2 help: And little `T`s have lesser `T`s,
<anon>:1:1: 3:2 help: and so, ad infinitum."

but it's not like I can stop you.

@arielb1
Copy link
Contributor

arielb1 commented Feb 15, 2016

The cycle can also contain enums - in which case an Option would not be needed. I'm generally against adding lots of special-case error messages - as you can see in this case, they have an annoying tendency of

OTOH, I see the point of adding the relevant field (and variant) to the backtrace of structural traits/default traits/OIBITs, as ADTs can get quite large.

@arielb1
Copy link
Contributor

arielb1 commented Feb 15, 2016

A possible example:

<anon>:1:1: 3:2 error: recursive type `T` has infinite size [E0072]
<anon>:1 struct T {
<anon>:2     t: T
<anon>:3 }
<anon>:1:1: 3:2 help: see the detailed explanation for E0072
<anon>:1:1: 3:2 note: field `t` of `T` has the same type as its container
<anon>:1:1: 3:2 help: insert indirection (e.g., a `Box`, `Rc`, or `&`) at some point to make `T` representable

or for more complicated cases

<anon>:1:1: 3:2 error: recursive type `T` has infinite size [E0072]
<anon>:1 enum Foo {
<anon>:2     Bar(T)
<anon>:3 }
<anon>:1:1: 3:2 help: see the detailed explanation for E0072
<anon>:1:1: 3:2 note: field #0 of the variant `Foo::Bar` has the type `T`
<anon>:1:1: 3:2 note: field `t` of the struct `T` has the type `Foo`, completing the cycle
<anon>:1:1: 3:2 help: insert indirection (e.g., a `Box`, `Rc`, or `&`) at some point to make `T` representable

@nagisa nagisa added the A-diagnostics Area: Messages for errors, warnings, and lints label Feb 16, 2016
@strega-nil
Copy link
Contributor

I quite like this error. At least keeping around the spirit of the message would be nice. When I was building my compiler, I saw this error and it made me stop for a second and smile :)

@jorendorff
Copy link
Contributor Author

OK, this is clearly not something worth changing.

@cengiz-io
Copy link
Contributor

Sorry for commenting on this but I think this is currently broken: #32417

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

No branches or pull requests

5 participants