@@ -5,7 +5,7 @@ use bevy_macro_utils::BevyManifest;
5
5
use bit_set:: BitSet ;
6
6
use proc_macro2:: { Ident , Span } ;
7
7
use quote:: { quote, ToTokens } ;
8
- use syn:: { spanned:: Spanned , LitStr , Member , Path , Type , WhereClause } ;
8
+ use syn:: { spanned:: Spanned , Lifetime , LitStr , Member , Path , Type , WhereClause } ;
9
9
10
10
/// Returns the correct path for `bevy_reflect`.
11
11
pub ( crate ) fn get_bevy_reflect_path ( ) -> Path {
@@ -60,6 +60,10 @@ pub(crate) fn ident_or_index(ident: Option<&Ident>, index: usize) -> Member {
60
60
61
61
/// Options defining how to extend the `where` clause in reflection with any additional bounds needed.
62
62
pub ( crate ) struct WhereClauseOptions {
63
+ /// Lifetime parameters that need extra trait bounds.
64
+ pub ( crate ) parameter_lifetimes : Box < [ Lifetime ] > ,
65
+ /// Bounds to add to the lifetime parameters.
66
+ pub ( crate ) parameter_lifetime_bounds : proc_macro2:: TokenStream ,
63
67
/// Type parameters that need extra trait bounds.
64
68
pub ( crate ) parameter_types : Box < [ Ident ] > ,
65
69
/// Trait bounds to add to the type parameters.
@@ -79,6 +83,13 @@ impl WhereClauseOptions {
79
83
pub fn type_path_bounds ( meta : & ReflectMeta ) -> Self {
80
84
let bevy_reflect_path = meta. bevy_reflect_path ( ) ;
81
85
Self {
86
+ parameter_lifetimes : meta
87
+ . type_path ( )
88
+ . generics ( )
89
+ . lifetimes ( )
90
+ . map ( |param| param. lifetime . clone ( ) )
91
+ . collect ( ) ,
92
+ parameter_lifetime_bounds : quote ! { ' static } ,
82
93
parameter_types : meta
83
94
. type_path ( )
84
95
. generics ( )
@@ -95,10 +106,12 @@ impl Default for WhereClauseOptions {
95
106
/// By default, don't add any additional bounds to the `where` clause
96
107
fn default ( ) -> Self {
97
108
Self {
109
+ parameter_lifetimes : Box :: new ( [ ] ) ,
98
110
parameter_types : Box :: new ( [ ] ) ,
99
111
active_types : Box :: new ( [ ] ) ,
100
112
ignored_types : Box :: new ( [ ] ) ,
101
113
parameter_trait_bounds : quote ! { } ,
114
+ parameter_lifetime_bounds : quote ! { } ,
102
115
active_trait_bounds : quote ! { } ,
103
116
ignored_trait_bounds : quote ! { } ,
104
117
}
@@ -140,17 +153,23 @@ pub(crate) fn extend_where_clause(
140
153
where_clause : Option < & WhereClause > ,
141
154
where_clause_options : & WhereClauseOptions ,
142
155
) -> proc_macro2:: TokenStream {
156
+ let parameter_lifetimes = & where_clause_options. parameter_lifetimes ;
143
157
let parameter_types = & where_clause_options. parameter_types ;
144
158
let active_types = & where_clause_options. active_types ;
145
159
let ignored_types = & where_clause_options. ignored_types ;
160
+ let parameter_lifetime_bounds = & where_clause_options. parameter_lifetime_bounds ;
146
161
let parameter_trait_bounds = & where_clause_options. parameter_trait_bounds ;
147
162
let active_trait_bounds = & where_clause_options. active_trait_bounds ;
148
163
let ignored_trait_bounds = & where_clause_options. ignored_trait_bounds ;
149
164
150
165
let mut generic_where_clause = if let Some ( where_clause) = where_clause {
151
166
let predicates = where_clause. predicates . iter ( ) ;
152
167
quote ! { where #( #predicates, ) * }
153
- } else if !( parameter_types. is_empty ( ) && active_types. is_empty ( ) && ignored_types. is_empty ( ) ) {
168
+ } else if !( parameter_lifetimes. is_empty ( )
169
+ && parameter_types. is_empty ( )
170
+ && active_types. is_empty ( )
171
+ && ignored_types. is_empty ( ) )
172
+ {
154
173
quote ! { where }
155
174
} else {
156
175
quote ! ( )
@@ -161,6 +180,7 @@ pub(crate) fn extend_where_clause(
161
180
// the whole bound by default, resulting in a failure to prove trait
162
181
// adherence.
163
182
generic_where_clause. extend ( quote ! {
183
+ #( #parameter_lifetimes: #parameter_lifetime_bounds, ) *
164
184
#( ( #active_types) : #active_trait_bounds, ) *
165
185
#( ( #ignored_types) : #ignored_trait_bounds, ) *
166
186
// Leave parameter bounds to the end for more sane error messages.
0 commit comments