1
1
use std:: ops:: AddAssign ;
2
2
3
- fn print_str ( s : & str ) { // s
3
+ fn print_str ( s : & str ) // s
4
+ {
4
5
println ! ( "{}" , s) ; // $ read_access=s
5
6
}
6
7
7
- fn print_i64 ( i : i64 ) { // i
8
+ fn print_i64 ( i : i64 ) // i
9
+ {
8
10
println ! ( "{}" , i) ; // $ read_access=i
9
11
}
10
12
@@ -91,10 +93,12 @@ fn let_pattern3() {
91
93
}
92
94
93
95
fn let_pattern4 ( ) {
94
- let Some ( x5) : Option < & str > = Some ( "x5" ) // x5
95
- else {
96
- todo ! ( )
97
- } ;
96
+ let Some ( x5) : Option < & str > // x5
97
+ = Some ( "x5" )
98
+
99
+ else {
100
+ todo ! ( )
101
+ } ;
98
102
print_str ( x5) ; // $ read_access=x5
99
103
}
100
104
@@ -127,23 +131,27 @@ fn match_pattern1() {
127
131
fn match_pattern2 ( ) {
128
132
let numbers = ( 2 , 4 , 8 , 16 , 32 ) ; // numbers
129
133
130
- match numbers { // $ read_access=numbers
134
+ match numbers // $ read_access=numbers
135
+ {
131
136
(
132
- first, _, // first
133
- third, _, // third
134
- fifth // fifth
137
+ first, // first
138
+ _,
139
+ third, // third
140
+ _,
141
+ fifth, // fifth
135
142
) => {
136
143
print_i64 ( first) ; // $ read_access=first
137
144
print_i64 ( third) ; // $ read_access=third
138
145
print_i64 ( fifth) ; // $ read_access=fifth
139
146
}
140
147
}
141
148
142
- match numbers { // $ read_access=numbers
149
+ match numbers // $ read_access=numbers
150
+ {
143
151
(
144
152
first, // first
145
153
..,
146
- last // last
154
+ last, // last
147
155
) => {
148
156
print_i64 ( first) ; // $ read_access=first
149
157
print_i64 ( last) ; // $ read_access=last
@@ -168,15 +176,19 @@ enum Message {
168
176
fn match_pattern4 ( ) {
169
177
let msg = Message :: Hello { id : 0 } ; // msg
170
178
171
- match msg { // $ read_access=msg
179
+ match msg // $ read_access=msg
180
+ {
172
181
Message :: Hello {
173
182
id : id_variable @ 3 ..=7 , // id_variable
174
183
} => print_i64 ( id_variable) , // $ read_access=id_variable
175
184
Message :: Hello { id : 10 ..=12 } => {
176
185
println ! ( "Found an id in another range" )
177
186
}
178
- Message :: Hello { id } => // id
179
- print_i64 ( id) , // $ read_access=id
187
+ Message :: Hello { id } // id
188
+ =>
189
+ {
190
+ print_i64 ( id) // $ read_access=id
191
+ }
180
192
}
181
193
}
182
194
@@ -262,36 +274,36 @@ fn param_pattern1(
262
274
(
263
275
b3, // b3
264
276
c1, // c1
265
- ) : ( & str , & str ) ) -> ( ) {
277
+ ) : ( & str , & str ) ,
278
+ ) -> ( ) {
266
279
print_str ( a8) ; // $ read_access=a8
267
280
print_str ( b3) ; // $ read_access=b3
268
281
print_str ( c1) ; // $ read_access=c1
269
282
}
270
283
271
- fn param_pattern2 (
272
- ( Either :: Left ( a9) | Either :: Right ( a9) ) : Either // a9
284
+ fn param_pattern2 ( ( Either :: Left ( a9) | Either :: Right ( a9) ) : Either , // a9
273
285
) -> ( ) {
274
286
print_i64 ( a9) ; // $ read_access=a9
275
287
}
276
288
277
289
fn destruct_assignment ( ) {
278
290
let (
279
291
mut a10, // a10
280
- mut b4, // b4
281
- mut c2 // c2
292
+ mut b4, // b4
293
+ mut c2, // c2
282
294
) = ( 1 , 2 , 3 ) ;
283
295
print_i64 ( a10) ; // $ read_access=a10
284
296
print_i64 ( b4) ; // $ read_access=b4
285
297
print_i64 ( c2) ; // $ read_access=c2
286
298
287
299
(
288
- c2, // $ write_access=c2
289
- b4, // $ write_access=b4
290
- a10 // $ write_access=a10
300
+ c2, // $ write_access=c2
301
+ b4, // $ write_access=b4
302
+ a10, // $ write_access=a10
291
303
) = (
292
304
a10, // $ read_access=a10
293
- b4, // $ read_access=b4
294
- c2 // $ read_access=c2
305
+ b4, // $ read_access=b4
306
+ c2, // $ read_access=c2
295
307
) ;
296
308
print_i64 ( a10) ; // $ read_access=a10
297
309
print_i64 ( b4) ; // $ read_access=b4
@@ -300,7 +312,7 @@ fn destruct_assignment() {
300
312
match ( 4 , 5 ) {
301
313
(
302
314
a10, // a10_2
303
- b4 // b4
315
+ b4, // b4
304
316
) => {
305
317
print_i64 ( a10) ; // $ read_access=a10_2
306
318
print_i64 ( b4) ; // $ read_access=b4
@@ -320,8 +332,8 @@ fn closure_variable() {
320
332
print_i64 ( n1) ; // $ read_access=n1
321
333
322
334
immutable_variable ( ) ;
323
- let immutable_variable =
324
- |x : i64 | // x_2
335
+ let immutable_variable = // immutable_variable
336
+ |x : i64 | // x_2
325
337
x; // $ read_access=x_2
326
338
let n2 = // n2
327
339
immutable_variable ( 6 ) ; // $ read_access=immutable_variable
@@ -335,15 +347,17 @@ fn nested_function() {
335
347
x; // $ read_access=x_1
336
348
print_i64 ( f ( 1 ) ) ; // $ read_access=f1
337
349
338
- fn f ( x : i64 ) -> i64 { // x_2
350
+ fn f ( x : i64 ) -> i64 // x_2
351
+ {
339
352
x + 1 // $ read_access=x_2
340
353
}
341
354
342
355
print_i64 ( f ( 2 ) ) ; // $ read_access=f1
343
356
344
357
{
345
358
print_i64 ( f ( 3 ) ) ;
346
- fn f ( x : i64 ) -> i64 { // x_3
359
+ fn f ( x : i64 ) -> i64 // x_3
360
+ {
347
361
2 * x // $ read_access=x_3
348
362
}
349
363
@@ -383,14 +397,14 @@ fn mutate() {
383
397
print_i64 ( i) ; // $ read_access=i
384
398
}
385
399
386
- fn mutate_param ( x : & mut i64 ) -> & mut i64 {
400
+ fn mutate_param ( x : & mut i64 ) -> & mut i64 {
387
401
* x = // $ read_access=x
388
402
* x + // $ read_access=x
389
403
* x; // $ read_access=x
390
404
return x; // $ read_access=x
391
405
}
392
406
393
- fn mutate_param2 < ' a > ( x : & ' a mut i64 , y : & mut & ' a mut i64 ) {
407
+ fn mutate_param2 < ' a > ( x : & ' a mut i64 , y : & mut & ' a mut i64 ) {
394
408
* x = // $ read_access=x
395
409
* x + // $ read_access=x
396
410
* x; // $ read_access=x
@@ -411,7 +425,7 @@ fn mutate_arg() {
411
425
& mut & mut x; // $ access=x
412
426
mutate_param2 (
413
427
& mut z, // $ access=z
414
- w // $ read_access=w
428
+ w, // $ read_access=w
415
429
) ;
416
430
* * w = 11 ; // $ read_access=w
417
431
// prints 11, not 8
@@ -472,38 +486,43 @@ async fn async_block_capture() {
472
486
print_i64 ( i) ; // $ read_access=i
473
487
}
474
488
475
- fn phi ( b : bool ) {
489
+ fn phi ( b : bool ) {
476
490
let mut x = 1 ; // x
477
491
print_i64 ( x) ; // $ read_access=x
478
492
print_i64 ( x + 1 ) ; // $ read_access=x
479
- if b { // $ read_access=b
493
+ #[ rustfmt:: skip]
494
+ let _ = if b // $ read_access=b
495
+ {
480
496
x = 2 ; // $ write_access=x
481
497
print_i64 ( x) ; // $ read_access=x
482
498
print_i64 ( x + 1 ) ; // $ read_access=x
483
499
} else {
484
500
x = 3 ; // $ write_access=x
485
501
print_i64 ( x) ; // $ read_access=x
486
502
print_i64 ( x + 1 ) ; // $ read_access=x
487
- }
503
+ } ;
488
504
print_i64 ( x) ; // $ read_access=x
489
505
}
490
506
491
- fn phi_read ( b1 : bool , b2 : bool ) {
507
+ fn phi_read ( b1 : bool , b2 : bool ) {
492
508
let x = 1 ; // x
493
- if b1 { // $ read_access=b1
509
+ #[ rustfmt:: skip]
510
+ let _ = if b1 // $ read_access=b1
511
+ {
494
512
print_i64 ( x) ; // $ read_access=x
495
513
} else {
496
514
print_i64 ( x) ; // $ read_access=x
497
- }
515
+ } ;
498
516
499
- if b2 { // $ read_access=b2
517
+ #[ rustfmt:: skip]
518
+ let _ = if b2 // $ read_access=b2
519
+ {
500
520
print_i64 ( x) ; // $ read_access=x
501
521
} else {
502
522
print_i64 ( x) ; // $ read_access=x
503
- }
523
+ } ;
504
524
}
505
525
506
-
507
526
struct MyStruct {
508
527
val : i64 ,
509
528
}
@@ -555,38 +574,34 @@ fn ref_arg() {
555
574
}
556
575
557
576
trait Bar {
558
- fn bar ( & self ) ;
577
+ fn bar ( & self ) ;
559
578
}
560
579
561
580
impl MyStruct {
562
- fn bar ( & mut self ) {
563
- * self = MyStruct { val : 3 } ; // $ read_access=self
564
- }
581
+ fn bar ( & mut self ) {
582
+ * self = MyStruct { val : 3 } ; // $ read_access=self
583
+ }
565
584
}
566
585
567
586
fn ref_methodcall_receiver ( ) {
568
- let mut a = MyStruct { val : 1 } ; // a
569
- a. bar ( ) ; // $ read_access=a
570
- // prints 3, not 1
571
- print_i64 ( a. val ) ; // $ read_access=a
587
+ let mut a = MyStruct { val : 1 } ; // a
588
+ a. bar ( ) ; // $ read_access=a
589
+ // prints 3, not 1
590
+ print_i64 ( a. val ) ; // $ read_access=a
572
591
}
573
592
574
593
macro_rules! let_in_macro {
575
- ( $e: expr) => {
576
- {
577
- let var_in_macro = $e;
578
- var_in_macro
579
- }
580
- } ;
594
+ ( $e: expr) => { {
595
+ let var_in_macro = $e;
596
+ var_in_macro
597
+ } } ;
581
598
}
582
599
583
600
macro_rules! let_in_macro2 {
584
- ( $e: expr) => {
585
- {
586
- let var_in_macro = 0 ;
587
- $e
588
- }
589
- } ;
601
+ ( $e: expr) => { {
602
+ let var_in_macro = 0 ;
603
+ $e
604
+ } } ;
590
605
}
591
606
592
607
fn macro_invocation ( ) {
@@ -601,6 +616,24 @@ fn macro_invocation() {
601
616
print_i64 ( var_in_macro) ; // $ read_access=var_in_macro1
602
617
}
603
618
619
+ fn let_without_initializer ( ) {
620
+ let x; // x
621
+ x = 1 ; // $ write_access=x
622
+ print_i64 ( x) ; // $ read_access=x
623
+ }
624
+
625
+ fn capture_phi ( ) {
626
+ let mut x = 100 ; // x
627
+ let mut cap = |b : bool | {
628
+ #[ rustfmt:: skip]
629
+ let _ = if b { // $ read_access=b
630
+ x = 200 ; // $ write_access=x
631
+ } ;
632
+ } ;
633
+ cap ( true ) ; // $ read_access=cap
634
+ print_i64 ( x) ; // $ read_access=x
635
+ }
636
+
604
637
fn main ( ) {
605
638
immutable_variable ( ) ;
606
639
mutable_variable ( ) ;
@@ -637,4 +670,5 @@ fn main() {
637
670
ref_arg ( ) ;
638
671
ref_methodcall_receiver ( ) ;
639
672
macro_invocation ( ) ;
673
+ capture_phi ( ) ;
640
674
}
0 commit comments