File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed
tests/ui/compile-fail/init Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -1202,6 +1202,21 @@ macro_rules! __init_internal {
1202
1202
// have been initialized. Therefore we can now dismiss the guards by forgetting them.
1203
1203
$( :: core:: mem:: forget( $guards) ; ) *
1204
1204
} ;
1205
+ ( init_slot( $( $use_data: ident) ?) :
1206
+ @data( $data: ident) ,
1207
+ @slot( $slot: ident) ,
1208
+ @guards( $( $guards: ident, ) * ) ,
1209
+ // arbitrary code block
1210
+ @munch_fields( _: { $( $code: tt) * } , $( $rest: tt) * ) ,
1211
+ ) => {
1212
+ { $( $code) * }
1213
+ $crate:: __init_internal!( init_slot( $( $use_data) ?) :
1214
+ @data( $data) ,
1215
+ @slot( $slot) ,
1216
+ @guards( $( $guards, ) * ) ,
1217
+ @munch_fields( $( $rest) * ) ,
1218
+ ) ;
1219
+ } ;
1205
1220
( init_slot( $use_data: ident) : // `use_data` is present, so we use the `data` to init fields.
1206
1221
@data( $data: ident) ,
1207
1222
@slot( $slot: ident) ,
@@ -1351,6 +1366,20 @@ macro_rules! __init_internal {
1351
1366
) ;
1352
1367
}
1353
1368
} ;
1369
+ ( make_initializer:
1370
+ @slot( $slot: ident) ,
1371
+ @type_name( $t: path) ,
1372
+ @munch_fields( _: { $( $code: tt) * } , $( $rest: tt) * ) ,
1373
+ @acc( $( $acc: tt) * ) ,
1374
+ ) => {
1375
+ // code blocks are ignored for the initializer check
1376
+ $crate:: __init_internal!( make_initializer:
1377
+ @slot( $slot) ,
1378
+ @type_name( $t) ,
1379
+ @munch_fields( $( $rest) * ) ,
1380
+ @acc( $( $acc) * ) ,
1381
+ ) ;
1382
+ } ;
1354
1383
( make_initializer:
1355
1384
@slot( $slot: ident) ,
1356
1385
@type_name( $t: path) ,
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ help: you might have forgotten to add the struct literal inside the block
12
12
--> src/macros.rs
13
13
|
14
14
~ ::core::ptr::write($slot, $t { SomeStruct {
15
- |9 $($acc)*
15
+ |4 $($acc)*
16
16
~ } });
17
17
|
18
18
You can’t perform that action at this time.
0 commit comments