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

Creating a struct that includes a self-referential type causes an internal compiler error #4548

Closed
martica opened this issue Jan 20, 2013 · 2 comments

Comments

@martica
Copy link
Contributor

martica commented Jan 20, 2013

Creating a struct that includes a self-referential type causes an internal compiler error. It clearly needs to be boxed, but hopefully there could be an error message instead. This appears to be similar to #742, the closed ticket for a similar issues with enums (nee tags).

Starting with a naïve implementation such as:

struct RecursiveType {
    self_reference: RecursiveType
}

You get:

crash.rs:3:0: 5:1 error: this type cannot be instantiated without an instance of itself; consider using `option<RecursiveType>`
crash.rs:3 struct RecursiveType {
crash.rs:4     self_reference: RecursiveType
crash.rs:5 }

Switching to option doesn't work, as it should be Option:

crash.rs:4:20: 4:41 error: found type name used as a variable
crash.rs:4     self_reference: option<RecursiveType>
                               ^~~~~~~~~~~~~~~~~~~~~

Switching to Option triggers the error:

struct RecursiveType {
    self_reference: Option<RecursiveType>
}
$ RUST_LOG=rustc=1,::rt::backtrace rustc crash.rs
rust: task 7fa823d01170 ran out of stack
error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug
note: try running with RUST_LOG=rustc=1,::rt::backtrace to get further details and report the results to github.com/mozilla/rust/issues
rust: task failed at 'explicit failure', /private/tmp/rust-3z40/rust-0.5/src/librustc/rustc.rc:425
rust: domain main @0x7fa824800010 root task failed
rust: task failed at 'killed', /private/tmp/rust-3z40/rust-0.5/src/libcore/task/mod.rs:570

I've tested this in the released 0.5 and the current master branch version of 0.6.

@jdm
Copy link
Contributor

jdm commented Jan 20, 2013

Presumably the same issue as #4218.

@martica
Copy link
Contributor Author

martica commented Jan 20, 2013

That it is. Curses. I found all the old issues about enums and missed the current one about structs. Sigh.

@jdm jdm closed this as completed Jan 20, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants