Turbofish is not supported in `bsn!`
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## Bevy version and features
- 0.19.0
## What you did
```rust
use std::any::type_name;
use bevy::prelude::*;
#[derive(Component, Clone, Default)]
struct A {
name: String,
}
impl A {
fn from() -> Self {
A {
name: type_name::().to_string(),
}
}
}
struct B;
fn setup(mut commands: Commands) -> impl Scene {
bsn! {
A::from::()
}
}
fn main() {}
```
## What went wrong
```
Checking bevy-demo v0.1.0 (D:\Projects\demo\bevy-demo)
WARN rustc_trait_selection::error_reporting::infer::need_type_info unexpected path: def=A args=[] path=Path { span: src\main.rs:21:5: 23:6 (#14), res: Def(AssocTy, DefId(18:15592 ~ bevy_ecs[065a]::template::FromTemplate::Template)), segments: [PathSegment { ident: {{root}}#14, hir_id: HirId(DefId(0:10 ~ bevy_demo[e4b7]::setup).52), res: Err, args: None, infer_args: false }, PathSegment { ident: bevy#14, hir_id: HirId(DefId(0:10 ~ bevy_demo[e4b7]::setup).53), res: Def(Mod, DefId(14:0 ~ bevy[78b0])), args: None, infer_args: false }, PathSegment { ident: ecs#14, hir_id: HirId(DefId(0:10 ~ bevy_demo[e4b7]::setup).54), res: Def(Mod, DefId(18:0 ~ bevy_ecs[065a])), args: None, infer_args: false }, PathSegment { ident: template#14, hir_id: HirId(DefId(0:10 ~ bevy_demo[e4b7]::setup).55), res: Def(Mod, DefId(18:15536 ~ bevy_ecs[065a]::template)), args: None, infer_args: false }, PathSegment { ident: FromTemplate#14, hir_id: HirId(DefId(0:10 ~ bevy_demo[e4b7]::setup).56), res: Def(Trait, DefId(18:15591 ~ bevy_ecs[065a]::template::FromTemplate)), args: None, infer_args: false }, PathSegment { ident: Template#14, hir_id: HirId(DefId(0:10 ~ bevy_demo[e4b7]::setup).57), res: Def(AssocTy, DefId(18:15592 ~ bevy_ecs[065a]::template::FromTemplate::Template)), args: None, infer_args: true }] }
error[E0282]: type annotations needed
--> src\main.rs:21:5
|
21 | / bsn! {
22 | | A::from::()
23 | | }
| |_____^ cannot infer type
|
= note: this error originates in the macro `bsn` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0282`.
error: could not compile `bevy-demo` (bin "bevy-demo") due to 1 previous error
```
## Additional information
Use `cargo expand` to expand it:
```rust
fn setup(mut commands: Commands) -> impl Scene {
::bevy::scene::SceneScope({
let _res = ::bevy::scene::SceneFunction(move |_context, _scene| {
let __value = _scene
.get_or_insert_template::<
::Template,
>(_context);
*__value = ::Template::from();
});
_res
})
}
```
The `::`, which is neccessary, is removed after macro expansion.
Contributor guide
Research direction
Start at the bsn! macro entry point and reproduce the example with cargo expand. Compare the expanded A::from::() call with the reported output, then add regression coverage showing that the turbofish is preserved and the example compiles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- game-dev, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100