rust icon indicating copy to clipboard operation
rust copied to clipboard

internal compiler error with self-referential struct definition

Open ttaubert opened this issue 13 years ago • 4 comments

Trying to implement a tree-like structure:

extern mod core(vers = "0.5");

priv struct Node<K, V> {
  left: core::Option<Node<K, V>>
}

I hit the following compiler error:

rust: task 7f3b6c105dd0 ran out of stack
/usr/local/bin/../lib/librustrt.so(_ZN9rust_task13begin_failureEPKcS1_m+0x4b)[0x7f3b73b0e45b]
/usr/local/bin/../lib/librustrt.so(_ZN9rust_task9new_stackEm+0x158)[0x7f3b73b0e928]
/usr/local/bin/../lib/librustrt.so(+0x30229)[0x7f3b73b22229]
/usr/local/bin/../lib/librustrt.so(upcall_new_stack+0x280)[0x7f3b73b12040]
/usr/local/bin/../lib/librustc-c84825241471686d-0.5.so(+0x767fa2)[0x7f3b742bbfa2]
/usr/local/bin/../lib/librustc-c84825241471686d-0.5.so(+0x2f2c59)[0x7f3b73e46c59]
/usr/local/bin/../lib/librustc-c84825241471686d-0.5.so(_ZN6middle2ty14__extensions__10meth_3526010iter_bytes15_abfbbb3dea17df3_05E+0xc3f)[0x7f3b73e1bc3f]
/usr/local/bin/../lib/librustc-c84825241471686d-0.5.so(_ZN6middle2ty14__extensions__10meth_3525510iter_bytes15_abfbbb3dea17df3_05E+0x85)[0x7f3b73e1adb5]
/usr/local/bin/../lib/librustc-c84825241471686d-0.5.so(+0x2d6ebf)[0x7f3b73e2aebf]
/usr/local/bin/../lib/librustc-c84825241471686d-0.5.so(+0x2d62ef)[0x7f3b73e2a2ef]
/usr/local/bin/../lib/librustc-c84825241471686d-0.5.so(_ZN6middle2ty9mk_struct16_beb59be6919256b3_05E+0x11e)[0x7f3b73e311de]
/usr/local/bin/../lib/librustc-c84825241471686d-0.5.so(_ZN6middle2ty19fold_regions_and_ty17_4c9b12843e648dc73_05E+0x93a)[0x7f3b73e33dfa]
/usr/local/bin/../lib/librustc-c84825241471686d-0.5.so(+0x2e1f54)[0x7f3b73e35f54]
/usr/local/bin/../lib/librustc-c84825241471686d-0.5.so(+0x111321)[0x7f3b73c65321]
/usr/local/bin/../lib/librustc-c84825241471686d-0.5.so(+0x2e03ea)[0x7f3b73e343ea]
/usr/local/bin/../lib/librustc-c84825241471686d-0.5.so(_ZN6middle2ty19fold_regions_and_ty17_4c9b12843e648dc73_05E+0x26a)[0x7f3b73e3372a]
/usr/local/bin/../lib/librustc-c84825241471686d-0.5.so(+0x2e1f54)[0x7f3b73e35f54]
/usr/local/bin/../lib/librustc-c84825241471686d-0.5.so(_ZN6middle2ty5subst16_b2fc4a1db6bca5d3_05E+0x2fb)[0x7f3b73d0772b]
/usr/local/bin/../lib/librustc-c84825241471686d-0.5.so(_ZN6middle2ty17lookup_field_type17_f6b5a6d1e0e9fa5f3_05E+0x1bb)[0x7f3b73d6472b]

ttaubert avatar Dec 18 '12 21:12 ttaubert

Seems to be caused by recursive type_size() calls.

ttaubert avatar Dec 18 '12 23:12 ttaubert

I just realized that what I'm doing is quite dumb because a struct on the stack clearly can't contain itself and needs a pointer here. We should have an error message saying that.

ttaubert avatar Dec 18 '12 23:12 ttaubert

I was sure there was already another issue open about this, but I couldn't find one. Hmmm.

catamorphism avatar Dec 27 '12 23:12 catamorphism

The most extensive discussion on this is in issue #4363 so closing this variant, it's a duplicate.

graydon avatar Feb 04 '13 20:02 graydon