@@ -8,6 +8,7 @@ use crate::context::{Ctxt, FieldKind, FieldSpec};
8
8
pub ( crate ) fn implement ( cx : & Ctxt < ' _ > , en : & DataEnum ) -> Result < TokenStream , ( ) > {
9
9
let vis = & cx. ast . vis ;
10
10
let ident = & cx. ast . ident ;
11
+ let lt = cx. lt ;
11
12
12
13
let clone = & cx. toks . clone ;
13
14
let copy = & cx. toks . copy ;
@@ -192,11 +193,11 @@ pub(crate) fn implement(cx: &Ctxt<'_>, en: &DataEnum) -> Result<TokenStream, ()>
192
193
193
194
#[ automatically_derived]
194
195
impl <V > #storage_trait<#ident, V > for Storage <V > {
195
- type Iter <' this > = Iter <' this , V > where Self : ' this ;
196
- type Keys <' this > = Keys <' this , V > where Self : ' this ;
197
- type Values <' this > = Values <' this , V > where Self : ' this ;
198
- type IterMut <' this > = IterMut <' this , V > where Self : ' this ;
199
- type ValuesMut <' this > = ValuesMut <' this , V > where Self : ' this ;
196
+ type Iter <#lt > = Iter <#lt , V > where V : #lt ;
197
+ type Keys <#lt > = Keys <#lt , V > where V : #lt ;
198
+ type Values <#lt > = Values <#lt , V > where V : #lt ;
199
+ type IterMut <#lt > = IterMut <#lt , V > where V : #lt ;
200
+ type ValuesMut <#lt > = ValuesMut <#lt , V > where V : #lt ;
200
201
type IntoIter = IntoIter <V >;
201
202
202
203
#[ inline]
@@ -356,15 +357,15 @@ fn build_iter_next(
356
357
FieldKind :: Simple => {
357
358
step_forward. next . push ( quote ! {
358
359
#index => {
359
- if let #option:: Some ( value) = self . #name. take ( ) {
360
+ if let #option:: Some ( value) = #option :: take ( & mut self . #name) {
360
361
return #option:: Some ( ( #ident:: #var, value) ) ;
361
362
}
362
363
}
363
364
} ) ;
364
365
365
366
step_backward. next . push ( quote ! {
366
367
#index => {
367
- if let #option:: Some ( value) = self . #name. take ( ) {
368
+ if let #option:: Some ( value) = #option :: take ( & mut self . #name) {
368
369
return #option:: Some ( ( #ident:: #var, value) ) ;
369
370
}
370
371
}
@@ -681,15 +682,15 @@ fn build_values_impl(
681
682
682
683
step_forward. next . push ( quote ! {
683
684
#index => {
684
- if let #option:: Some ( value) = self . #name. take ( ) {
685
+ if let #option:: Some ( value) = #option :: take ( & mut self . #name) {
685
686
return #option:: Some ( value) ;
686
687
}
687
688
}
688
689
} ) ;
689
690
690
691
step_backward. next . push ( quote ! {
691
692
#index => {
692
- if let #option:: Some ( value) = self . #name. take ( ) {
693
+ if let #option:: Some ( value) = #option :: take ( & mut self . #name) {
693
694
return #option:: Some ( value) ;
694
695
}
695
696
}
@@ -900,16 +901,16 @@ fn build_values_mut_impl(
900
901
901
902
step_forward. next . push ( quote ! {
902
903
#index => {
903
- if let #option:: Some ( v ) = self . #name. take ( ) {
904
- return #option:: Some ( v ) ;
904
+ if let #option:: Some ( value ) = #option :: take ( & mut self . #name) {
905
+ return #option:: Some ( value ) ;
905
906
}
906
907
}
907
908
} ) ;
908
909
909
910
step_backward. next . push ( quote ! {
910
911
#index => {
911
- if let #option:: Some ( v ) = self . #name. take ( ) {
912
- return #option:: Some ( v ) ;
912
+ if let #option:: Some ( value ) = #option :: take ( & mut self . #name) {
913
+ return #option:: Some ( value ) ;
913
914
}
914
915
}
915
916
} ) ;
@@ -1141,6 +1142,7 @@ impl ToTokens for IteratorNextBack {
1141
1142
fn build_entry_impl ( cx : & Ctxt < ' _ > , field_specs : & [ FieldSpec < ' _ > ] ) -> Result < TokenStream , ( ) > {
1142
1143
let ident = & cx. ast . ident ;
1143
1144
let vis = & cx. ast . vis ;
1145
+ let lt = cx. lt ;
1144
1146
let option = & cx. toks . option ;
1145
1147
let storage_entry_trait = & cx. toks . storage_entry_trait ;
1146
1148
let occupied_entry_trait = & cx. toks . occupied_entry_trait ;
@@ -1179,8 +1181,8 @@ fn build_entry_impl(cx: &Ctxt<'_>, field_specs: &[FieldSpec<'_>]) -> Result<Toke
1179
1181
} => {
1180
1182
let as_storage_entry = quote ! ( <#storage as #storage_entry_trait<#element, V >>) ;
1181
1183
1182
- occupied_variant. push ( quote ! ( #name( #as_storage_entry:: Occupied <' this >) ) ) ;
1183
- vacant_variant. push ( quote ! ( #name( #as_storage_entry:: Vacant <' this >) ) ) ;
1184
+ occupied_variant. push ( quote ! ( #name( #as_storage_entry:: Occupied <#lt >) ) ) ;
1185
+ vacant_variant. push ( quote ! ( #name( #as_storage_entry:: Vacant <#lt >) ) ) ;
1184
1186
1185
1187
init. push ( quote ! {
1186
1188
#pattern( key) => match #storage_entry_trait:: entry( & mut self . #name, key) {
@@ -1189,7 +1191,7 @@ fn build_entry_impl(cx: &Ctxt<'_>, field_specs: &[FieldSpec<'_>]) -> Result<Toke
1189
1191
}
1190
1192
} ) ;
1191
1193
1192
- let as_vacant_entry = quote ! ( <#as_storage_entry:: Vacant <' this > as #vacant_entry_trait<' this , #element, V >>) ;
1194
+ let as_vacant_entry = quote ! ( <#as_storage_entry:: Vacant <#lt > as #vacant_entry_trait<#lt , #element, V >>) ;
1193
1195
1194
1196
vacant_key. push (
1195
1197
quote ! ( VacantEntry :: #name( entry) => #pattern( #as_vacant_entry:: key( entry) ) ) ,
@@ -1198,7 +1200,7 @@ fn build_entry_impl(cx: &Ctxt<'_>, field_specs: &[FieldSpec<'_>]) -> Result<Toke
1198
1200
quote ! ( VacantEntry :: #name( entry) => #as_vacant_entry:: insert( entry, value) ) ,
1199
1201
) ;
1200
1202
1201
- let as_occupied_entry = quote ! ( <#as_storage_entry:: Occupied <' this > as #occupied_entry_trait<' this , #element, V >>) ;
1203
+ let as_occupied_entry = quote ! ( <#as_storage_entry:: Occupied <#lt > as #occupied_entry_trait<#lt , #element, V >>) ;
1202
1204
1203
1205
occupied_key. push ( quote ! ( OccupiedEntry :: #name( entry) => #pattern( #as_occupied_entry:: key( entry) ) ) ) ;
1204
1206
occupied_get
@@ -1218,82 +1220,72 @@ fn build_entry_impl(cx: &Ctxt<'_>, field_specs: &[FieldSpec<'_>]) -> Result<Toke
1218
1220
}
1219
1221
1220
1222
let entry_impl = quote ! {
1221
- #vis struct SimpleVacantEntry <' this, V > {
1222
- key: #ident,
1223
- inner: #option_bucket_none<' this, V >,
1224
- }
1225
-
1226
- #vis struct SimpleOccupiedEntry <' this, V > {
1223
+ #vis struct SimpleVacantEntry <#lt, V > {
1227
1224
key: #ident,
1228
- inner: #option_bucket_some< ' this , V >,
1225
+ inner: #option_bucket_none<#lt , V >,
1229
1226
}
1230
1227
1231
- #vis enum VacantEntry <' this, V > {
1232
- Simple ( SimpleVacantEntry <' this, V >) ,
1233
- #( #vacant_variant, ) *
1234
- }
1235
-
1236
- #vis enum OccupiedEntry <' this, V > {
1237
- Simple ( SimpleOccupiedEntry <' this, V >) ,
1238
- #( #occupied_variant, ) *
1239
- }
1240
-
1241
- impl <' this, V > SimpleVacantEntry <' this, V > {
1242
- #[ inline]
1243
- fn key( & self ) -> #ident {
1244
- self . key
1245
- }
1246
-
1228
+ impl <#lt, V > SimpleVacantEntry <#lt, V > {
1247
1229
#[ inline]
1248
- fn insert( self , value: V ) -> & ' this mut V {
1249
- self . inner. insert ( value)
1230
+ fn insert( self , value: V ) -> & #lt mut V {
1231
+ #option_bucket_none :: insert ( self . inner, value)
1250
1232
}
1251
1233
}
1252
1234
1253
- impl <' this, V > SimpleOccupiedEntry <' this, V > {
1254
- #[ inline]
1255
- fn key( & self ) -> #ident {
1256
- self . key
1257
- }
1235
+ #vis struct SimpleOccupiedEntry <#lt, V > {
1236
+ key: #ident,
1237
+ inner: #option_bucket_some<#lt, V >,
1238
+ }
1258
1239
1240
+ impl <#lt, V > SimpleOccupiedEntry <#lt, V > {
1259
1241
#[ inline]
1260
1242
fn get( & self ) -> & V {
1261
- self . inner. as_ref ( )
1243
+ #option_bucket_some :: as_ref ( & self . inner)
1262
1244
}
1263
1245
1264
1246
#[ inline]
1265
1247
fn get_mut( & mut self ) -> & mut V {
1266
- self . inner. as_mut ( )
1248
+ #option_bucket_some :: as_mut ( & mut self . inner)
1267
1249
}
1268
1250
1269
1251
#[ inline]
1270
- fn into_mut( self ) -> & ' this mut V {
1271
- self . inner. into_mut ( )
1252
+ fn into_mut( self ) -> & #lt mut V {
1253
+ #option_bucket_some :: into_mut ( self . inner)
1272
1254
}
1273
1255
1274
1256
#[ inline]
1275
1257
fn insert( & mut self , value: V ) -> V {
1276
- self . inner. replace ( value)
1258
+ #option_bucket_some :: replace ( & mut self . inner, value)
1277
1259
}
1278
1260
1279
1261
#[ inline]
1280
1262
fn remove( self ) -> V {
1281
- self . inner. take ( )
1263
+ #option_bucket_some :: take ( self . inner)
1282
1264
}
1283
1265
}
1284
1266
1267
+ #vis enum VacantEntry <#lt, V > {
1268
+ Simple ( SimpleVacantEntry <#lt, V >) ,
1269
+ #( #vacant_variant, ) *
1270
+ }
1271
+
1272
+ #vis enum OccupiedEntry <#lt, V > {
1273
+ Simple ( SimpleOccupiedEntry <#lt, V >) ,
1274
+ #( #occupied_variant, ) *
1275
+ }
1276
+
1285
1277
#[ automatically_derived]
1286
- impl <' this , V > #vacant_entry_trait<' this , #ident, V > for VacantEntry <' this , V > {
1278
+ impl <#lt , V > #vacant_entry_trait<#lt , #ident, V > for VacantEntry <#lt , V > {
1287
1279
#[ inline]
1288
1280
fn key( & self ) -> #ident {
1289
1281
match self {
1290
- VacantEntry :: Simple ( entry) => entry. key( ) ,
1282
+ VacantEntry :: Simple ( entry) => entry. key,
1291
1283
#( #vacant_key, ) *
1292
1284
}
1293
1285
}
1294
1286
1295
1287
#[ inline]
1296
- fn insert( self , value: V ) -> & ' this mut V {
1288
+ fn insert( self , value: V ) -> & #lt mut V {
1297
1289
match self {
1298
1290
VacantEntry :: Simple ( entry) => entry. insert( value) ,
1299
1291
#( #vacant_insert, ) *
@@ -1302,11 +1294,11 @@ fn build_entry_impl(cx: &Ctxt<'_>, field_specs: &[FieldSpec<'_>]) -> Result<Toke
1302
1294
}
1303
1295
1304
1296
#[ automatically_derived]
1305
- impl <' this , V > #occupied_entry_trait<' this , #ident, V > for OccupiedEntry <' this , V > {
1297
+ impl <#lt , V > #occupied_entry_trait<#lt , #ident, V > for OccupiedEntry <#lt , V > {
1306
1298
#[ inline]
1307
1299
fn key( & self ) -> #ident {
1308
1300
match self {
1309
- OccupiedEntry :: Simple ( entry) => entry. key( ) ,
1301
+ OccupiedEntry :: Simple ( entry) => entry. key,
1310
1302
#( #occupied_key, ) *
1311
1303
}
1312
1304
}
@@ -1328,7 +1320,7 @@ fn build_entry_impl(cx: &Ctxt<'_>, field_specs: &[FieldSpec<'_>]) -> Result<Toke
1328
1320
}
1329
1321
1330
1322
#[ inline]
1331
- fn into_mut( self ) -> & ' this mut V {
1323
+ fn into_mut( self ) -> & #lt mut V {
1332
1324
match self {
1333
1325
OccupiedEntry :: Simple ( entry) => entry. into_mut( ) ,
1334
1326
#( #occupied_into_mut, ) *
@@ -1353,7 +1345,7 @@ fn build_entry_impl(cx: &Ctxt<'_>, field_specs: &[FieldSpec<'_>]) -> Result<Toke
1353
1345
}
1354
1346
1355
1347
#[ inline]
1356
- fn option_to_entry<V >( opt: & mut #option<V >, key: #ident) -> #entry_enum<OccupiedEntry < ' _, V >, VacantEntry < ' _ , V > > {
1348
+ fn option_to_entry<V >( opt: & mut #option<V >, key: #ident) -> #entry_enum<' _, Storage < V >, #ident , V > {
1357
1349
match #option_bucket_option:: new( opt) {
1358
1350
#option_bucket_option:: Some ( inner) => #entry_enum:: Occupied ( OccupiedEntry :: Simple ( SimpleOccupiedEntry { key, inner } ) ) ,
1359
1351
#option_bucket_option:: None ( inner) => #entry_enum:: Vacant ( VacantEntry :: Simple ( SimpleVacantEntry { key, inner } ) ) ,
@@ -1362,11 +1354,11 @@ fn build_entry_impl(cx: &Ctxt<'_>, field_specs: &[FieldSpec<'_>]) -> Result<Toke
1362
1354
1363
1355
#[ automatically_derived]
1364
1356
impl <V > #storage_entry_trait<#ident, V > for Storage <V > {
1365
- type Occupied <' this > = OccupiedEntry <' this , V > where V : ' this ;
1366
- type Vacant <' this > = VacantEntry <' this , V > where V : ' this ;
1357
+ type Occupied <#lt > = OccupiedEntry <#lt , V > where V : #lt ;
1358
+ type Vacant <#lt > = VacantEntry <#lt , V > where V : #lt ;
1367
1359
1368
1360
#[ inline]
1369
- fn entry( & mut self , key: #ident) -> #entry_enum<Self :: Occupied < ' _> , Self :: Vacant < ' _> > {
1361
+ fn entry( & mut self , key: #ident) -> #entry_enum<' _ , Self , #ident , V > {
1370
1362
match key {
1371
1363
#( #init, ) *
1372
1364
}
0 commit comments