bevyengine / bevyengine/bevy

"Type annotations needed" when using system piping to a system that returns a Result

Open
#22,330 2 comments 1 reaction 0 assignees View on GitHub
A-ECS C-Bug I-Regression S-Needs-Investigation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## Bevy version and features

Bevy 0.17, default features

## What you did

This code fails to compile with a "type annotations needed" error:
```rust
use bevy::prelude::*;

fn main() {
App::new().add_systems(Update, foo.pipe(bar));
}

fn foo() -> i32 {
42
}

fn bar(_: In) -> Result {
Ok(())
}
```

## What went wrong

The code above gives this error:
```
error[E0283]: type annotations needed
--> src/main.rs:4:40
|
4 | App::new().add_systems(Update, foo.pipe(bar));
| ^^^^ cannot infer type of the type parameter `BOut` declared on the method `pipe`
|
= note: multiple `impl`s satisfying `std::result::Result<(), BevyError>: IntoResult<_>` found in the `bevy_ecs` crate:
- impl IntoResult for T;
- impl IntoResult for std::result::Result;
= note: required for `fn(In) -> Result<(), BevyError> {bar}` to implement `IntoSystem, _, (IsFunctionSystem, ...)>`
note: required by a bound in `bevy::prelude::IntoSystem::pipe`
--> /home/nate/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bevy_ecs-0.17.3/src/system/mod.rs:199:12
|
196 | fn pipe(self, system: B) -> IntoPipeSystem
| ---- required by a bound in this associated function
...
199 | B: IntoSystem,

```

## Additional information

The code works fine in Bevy 0.16.

Changing the contents of `main()` to either of these makes it compile:
```App::new().add_systems(Update, foo.pipe::<_, _, Result, _>(bar));```
```App::new().add_systems(Update, foo.pipe::<_, _, (), _>(bar));```

I'm not sure whether these give the same behavior.

This looks similar to a new required type annotation in the migration guide, so it's possible this isn't a bug, but even then, this is probably common enough that I think it might be worth looking for ways to avoid the newly required type annotations.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.