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

Overflow on recursive struct #4

Closed
puckipedia opened this issue Jan 9, 2020 · 4 comments
Closed

Overflow on recursive struct #4

puckipedia opened this issue Jan 9, 2020 · 4 comments

Comments

@puckipedia
Copy link

#[derive(gc_arena::Collect)]
#[collect(no_drop)]
struct Test<'gc, T>(Option<gc_arena::Gc<'gc, Test<'gc, T>>>);

This seems to be because Gc<T> requires T to be Collect, but that depends on Gc<T> being Collect. I'm not sure on how this would be fixed, if even possible.

@kyren
Copy link
Owner

kyren commented Jan 10, 2020

Just to be clear (I haven't tried this), is it the automatic Collect implementation that triggers an error? During compilation?

@puckipedia
Copy link
Author

Indeed. Error trace is:

error[E0275]: overflow evaluating the requirement `gc_arena::gc::Gc<'_, Test<'_, T>>: std::marker::Sized`
 --> src/main.rs:3:21
  |
3 | struct Test<'gc, T>(Option<gc_arena::Gc<'gc, Test<'gc, T>>>);
  |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: consider adding a `#![recursion_limit="256"]` attribute to your crate
  = note: required because of the requirements on the impl of `gc_arena::collect::Collect` for `std::option::Option<gc_arena::gc::Gc<'_, Test<'_, T>>>`
  = note: required because of the requirements on the impl of `gc_arena::collect::Collect` for `Test<'_, T>`
  = note: required because of the requirements on the impl of `gc_arena::collect::Collect` for `gc_arena::gc::Gc<'_, Test<'_, T>>`
[... above three lines repeat a bunch of times]
  = note: required because of the requirements on the impl of `gc_arena::collect::Collect` for `std::option::Option<gc_arena::gc::Gc<'_, Test<'_, T>>>`
  = note: required because of the requirements on the impl of `gc_arena::collect::Collect` for `Test<'gc, T>`
  = note: required by `gc_arena::gc::Gc`

@andersk
Copy link

andersk commented Dec 30, 2020

You can work around this by replacing the direct recursion with Self. (I’ve added a T field because T has to be used somewhere.)

#[derive(gc_arena::Collect)]
#[collect(no_drop)]
struct Test<'gc, T>(T, Option<gc_arena::Gc<'gc, Self>>)
where
    T: gc_arena::Collect + 'gc;

Aaron1011 pushed a commit to Aaron1011/gc-arena that referenced this issue Oct 23, 2022
@kyren
Copy link
Owner

kyren commented Nov 25, 2022

I think this is fixed by #23!

@kyren kyren closed this as completed Nov 25, 2022
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

3 participants