You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Attached #[derive(SystemParam)] to a type that is not fully public (private, crate-private, or otherwise restricted). For instance:
mod private {
use bevy::ecs::system::SystemParam;
use bevy::prelude::*;
#[derive(SystemParam)]
struct Foo<'a> {
some_resource: Res<'a, i32>,
}
}
What you expected to happen
I would get an implementation of SystemParam for my private type.
What actually happened
error[E0446]: private type Foo<'a> in public interface
--> src/main.rs:6:14
|
6 | #[derive(SystemParam)]
| ^^^^^^^^^^^ can't leak private type
7 | struct Foo<'a> {
| -------------- Foo<'a> declared as private
|
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
Here's the macroexpansion (click to expand):
```
mod private {
use bevy::ecs::system::SystemParam;
use bevy::prelude::*;
struct Foo<'a> {
some_resource: Res<'a, i32>,
}
impl <'a> bevy::ecs::system::SystemParam for Foo<'a> {
type Fetch = FooState<( as SystemParam>::Fetch,)>;
}
pub struct FooState {
state: TSystemParamState,
marker: std::marker::PhantomData<()>,
}
unsafe impl
bevy::ecs::system::SystemParamState for FooState {
type Config = TSystemParamState::Config;
fn init(world: &mut bevy::ecs::world::World,
system_state: &mut bevy::ecs::system::SystemState,
config: Self::Config) -> Self {
Self{state: TSystemParamState::init(world, system_state, config),
marker: std::marker::PhantomData,}
}
fn new_archetype(&mut self,
archetype: &bevy::ecs::archetype::Archetype,
system_state: &mut bevy::ecs::system::SystemState) {
self.state.new_archetype(archetype, system_state)
}
fn default_config() -> TSystemParamState::Config {
TSystemParamState::default_config()
}
}
impl <'a> bevy::ecs::system::SystemParamFetch<'a> for
FooState<( as SystemParam>::Fetch,)> {
type Item = Foo<'a>;
unsafe fn get_param(state: &'a mut Self,
system_state: &'a bevy::ecs::system::SystemState,
world: &'a bevy::ecs::world::World,
change_tick: u32) -> Self::Item {
Foo{some_resource:
< as SystemParam>::Fetch as
bevy::ecs::system::SystemParamFetch>::get_param(&mut state.state.0,
system_state,
world,
change_tick),}
}
}
}
```
The macro is defining pub struct FooState<TSystemParamState>, then implementing SystemParamFetch on it. The SystemParamFetch declares type Item = Foo, which is what "leaks" Foo.
I think that this would be resolved if the derive macro copied the visibility attribute of the input struct onto the State struct. Each of the structs references the other in a trait impl, so they need to be equally visible.
The text was updated successfully, but these errors were encountered:
Examples creating a public type to derive `SystemParam` on were updated
to create a private type where a public one is no longer needed.
Resolvesbevyengine#1869
Bevy version
0.5
Operating system & version
Debian GNU/Linux "buster"
What you did
Attached
#[derive(SystemParam)]
to a type that is not fully public (private, crate-private, or otherwise restricted). For instance:What you expected to happen
I would get an implementation of
SystemParam
for my private type.What actually happened
error[E0446]: private type
Foo<'a>
in public interface--> src/main.rs:6:14
|
6 | #[derive(SystemParam)]
| ^^^^^^^^^^^ can't leak private type
7 | struct Foo<'a> {
| --------------
Foo<'a>
declared as private|
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
Here's the macroexpansion (click to expand):
The macro is defining
pub struct FooState<TSystemParamState>
, then implementingSystemParamFetch
on it. TheSystemParamFetch
declarestype Item = Foo
, which is what "leaks"Foo
.I think that this would be resolved if the
derive
macro copied the visibility attribute of the input struct onto theState
struct. Each of the structs references the other in a trait impl, so they need to be equally visible.The text was updated successfully, but these errors were encountered: