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

Trying to iterate &Res<Assets<T>> results in a poor compiler error #16002

Open
JMS55 opened this issue Oct 19, 2024 · 1 comment
Open

Trying to iterate &Res<Assets<T>> results in a poor compiler error #16002

JMS55 opened this issue Oct 19, 2024 · 1 comment
Labels
A-Cross-Cutting Impacts the entire engine C-Bug An unexpected or incorrect behavior C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Blocked This cannot move forward until something else changes

Comments

@JMS55
Copy link
Contributor

JMS55 commented Oct 19, 2024

for mesh in &meshes {}
error[E0275]: overflow evaluating the requirement `&_: IntoIterator`
  |
  = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`scene_viewer`)
  = note: required for `&bevy::prelude::Res<'_, _>` to implement `IntoIterator`
  = note: 126 redundant requirements hidden
  = note: required for `&Res<'_, Res<'_, Res<'_, Res<'_, Res<'_, Res<'_, Res<'_, Res<'_, Res<'_, Res<'_, Res<'_, Res<'_, Res<'_, Res<'_, Res<'_, Res<'_, Res<'_, Res<'_, Res<'_, Res<'_, Res<'_, Res<'_, Res<'_, Res<'_, ...>>>>>>>>>>>>>>>>>>>>>>>>` to implement `IntoIterator`
  = note: the full name for the type has been written to '<redacted>.long-type-3364561052137337366.txt'
  = note: consider using `--verbose` to print the full type name to the console

For more information about this error, try `rustc --explain E0275`.

Increasing the recursion limit to 256 then says it overflows and suggest increasing to 512, ongoing forever.

The correct solution seems to be using meshes.iter(). I'm curious why that is.

@JMS55 JMS55 added the A-Assets Load files from disk to use for things like images, models, and sounds label Oct 19, 2024
@Victoronz
Copy link
Contributor

Victoronz commented Oct 19, 2024

You can treat this as a limitation of the current rust trait solver, it'll go away once -Znext-solver stabilizes (I think coherence is enough? I've run into this kind of error too, and -Znext-solver=coherence fixed it)
This has been reported a couple times, both in bevy #14799 and in rust-lang.

This error happens when there is recursion in the type bounds.
I don't know what triggers it here, but if I were to guess, the 'a lifetime?

As for why .iter() fixes it:
for loops call IntoIterator::into_iter(value)
In contrast, .iter() doesn't exist for Res so the compiler simply derefs/method resolves til something does.

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior S-Blocked This cannot move forward until something else changes C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Cross-Cutting Impacts the entire engine and removed A-Assets Load files from disk to use for things like images, models, and sounds labels Oct 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Cross-Cutting Impacts the entire engine C-Bug An unexpected or incorrect behavior C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Blocked This cannot move forward until something else changes
Projects
None yet
Development

No branches or pull requests

3 participants