Skip to content

Commit c1496d2

Browse files
committed
Undo vis removal for generated wrapper type
We need to provide a way for users to reference their wrapper type for use in #[reflect(remote = ...)] attributes
1 parent f898f0b commit c1496d2

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

crates/bevy_reflect/derive/src/remote.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ pub(crate) fn reflect_remote(args: TokenStream, input: TokenStream) -> TokenStre
106106
/// ```
107107
fn generate_remote_wrapper(input: &DeriveInput, remote_ty: &TypePath) -> proc_macro2::TokenStream {
108108
let ident = &input.ident;
109+
let vis = &input.vis;
109110
let ty_generics = &input.generics;
110111
let where_clause = &input.generics.where_clause;
111112
let attrs = input
@@ -117,7 +118,7 @@ fn generate_remote_wrapper(input: &DeriveInput, remote_ty: &TypePath) -> proc_ma
117118
#(#attrs)*
118119
#[repr(transparent)]
119120
#[doc(hidden)]
120-
struct #ident #ty_generics (pub #remote_ty) #where_clause;
121+
#vis struct #ident #ty_generics (pub #remote_ty) #where_clause;
121122
}
122123
}
123124

crates/bevy_reflect/src/lib.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2554,6 +2554,34 @@ bevy_reflect::tests::Test {
25542554
assert_eq!("Goodbye", data.0.value);
25552555
}
25562556

2557+
#[test]
2558+
fn should_reflect_remote_type_from_module() {
2559+
mod wrapper {
2560+
use super::*;
2561+
2562+
// We have to place this module internally to this one to get around the following error:
2563+
// ```
2564+
// error[E0433]: failed to resolve: use of undeclared crate or module `external_crate`
2565+
// ```
2566+
pub mod external_crate {
2567+
pub struct TheirType {
2568+
pub value: String,
2569+
}
2570+
}
2571+
2572+
#[reflect_remote(external_crate::TheirType)]
2573+
pub struct MyType {
2574+
pub value: String,
2575+
}
2576+
}
2577+
2578+
#[derive(Reflect)]
2579+
struct ContainerStruct {
2580+
#[reflect(remote = wrapper::MyType)]
2581+
their_type: wrapper::external_crate::TheirType,
2582+
}
2583+
}
2584+
25572585
#[test]
25582586
fn should_reflect_remote_enum() {
25592587
mod external_crate {

0 commit comments

Comments
 (0)