bevyengine / bevyengine/bevy

bsn: Attempting to use `collect()` as part of a function argument in a `bsn!` macro, suppresses `E0283`

Open
#25,473 1 comment 0 reactions 0 assignees View on GitHub
A-Scenes C-Bug C-Usability D-Macros D-Straightforward S-Ready-For-Implementation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## Bevy version and features
`bevy = { version = "0.19.1", features = ["dynamic_linking"] }`

## What you did

Attempted to use `collect()` as part of a function argument in a `bsn!` macro, neglecting to specify type.

Minimal Repro:

```rust
use bevy::prelude::*;

fn main() { }

pub fn scene() -> impl SceneList {
let data =vec! [ "Test 1", "Test 2", "Test 3" ];

bsn! {
Node
Children [
// 1. Properly produces [E0283]: type annotations needed when uncommented
// {data.iter().map(|t| Text(t.to_string())).collect()}

// 2. Suppresses: E0283
// Produces: [E0275]: overflow evaluating the requirement `&_: IntoIterator`
test(data.iter().map(|t| Text(t.to_string())).collect()),
]
}
}

fn test(_items: impl IntoIterator) -> impl Scene {
bsn!{}
}
```

## What went wrong

Received :

```
error[E0275]: overflow evaluating the requirement `&_: IntoIterator`
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`entity_ref_bug_repro`)
= note: required for `&Res<'_, _>` to implement `IntoIterator`
= note: 126 redundant requirements hidden
= note: required for `&Res<'_, Res<'_, Res<'_, Res<'_, Res<'_, Res<'_, Res<'_, ...>>>>>>>` to implement `IntoIterator`
= note: the full name for the type has been written to 'D:\Projects\rust\entity_ref_bug_repro\target\debug\deps\entity_ref_bug_repro.long-type-6698994408062003872.txt'
= note: consider using `--verbose` to print the full type name to the console
```
Here is the long type log.
[long_type.txt](https://github.com/user-attachments/files/31241081/long_type.txt)

## Additional information

As noted in the comments in the repro code, when not specifying a type for `collect()` when rust cannot infer it, as part of a function argument (`#2` in comments), the normal rust `E0283` is suppressed and it generates the error above.

Its my understanding that the recursion is tied to a rust trait quirk, but I believe this is a bsn bug because if you uncomment `#1` in the repro code, and do the same exact expression, but not as part of a function argument, it works as expected, producing E0283.

Workaround: Write valid rust code to begin with :). Correctly annotating the type on `collect()` works as expected.

Contributor guide

Open the contributing guide

Research direction

Start by compiling the provided minimal reproduction with Bevy 0.19.1 and inspect the bsn! macro expansion around the function argument containing collect(). Compare its diagnostic with the standalone collect() case, using the reported E0283 and E0275 errors as the acceptance criteria.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.