@@ -68,6 +68,19 @@ impl Comments {
68
68
}
69
69
}
70
70
71
+ #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
72
+ pub ( crate ) enum Usage {
73
+ Unused ,
74
+ Discarded ,
75
+ Used ,
76
+ }
77
+
78
+ impl Usage {
79
+ pub ( crate ) fn is_unused ( self ) -> bool {
80
+ matches ! ( self , Usage :: Unused )
81
+ }
82
+ }
83
+
71
84
#[ derive( Clone , Debug , PartialEq , Eq ) ]
72
85
pub ( crate ) struct IntLiteral {
73
86
pub ( crate ) value : i64 ,
@@ -144,16 +157,15 @@ pub(crate) struct ConstantRef {
144
157
pub ( crate ) source : Option < Identifier > ,
145
158
pub ( crate ) name : String ,
146
159
pub ( crate ) resolved_type : types:: TypeRef ,
147
- pub ( crate ) unused : bool ,
160
+ pub ( crate ) usage : Usage ,
148
161
pub ( crate ) location : Location ,
149
162
}
150
163
151
164
#[ derive( Clone , Debug , PartialEq , Eq ) ]
152
165
pub ( crate ) struct IdentifierRef {
153
166
pub ( crate ) name : String ,
154
167
pub ( crate ) kind : types:: IdentifierKind ,
155
- /// A flag indicating the result of this node is unused.
156
- pub ( crate ) unused : bool ,
168
+ pub ( crate ) usage : Usage ,
157
169
pub ( crate ) location : Location ,
158
170
}
159
171
@@ -173,8 +185,7 @@ pub(crate) struct Call {
173
185
pub ( crate ) parens : bool ,
174
186
/// A flag indicating if the call resides directly in a `mut` expression.
175
187
pub ( crate ) in_mut : bool ,
176
- /// A flag indicating the result of this node is unused.
177
- pub ( crate ) unused : bool ,
188
+ pub ( crate ) usage : Usage ,
178
189
pub ( crate ) location : Location ,
179
190
}
180
191
@@ -229,7 +240,7 @@ pub(crate) struct AssignSetter {
229
240
pub ( crate ) name : Identifier ,
230
241
pub ( crate ) value : Expression ,
231
242
pub ( crate ) location : Location ,
232
- pub ( crate ) unused : bool ,
243
+ pub ( crate ) usage : Usage ,
233
244
pub ( crate ) expected_type : types:: TypeRef ,
234
245
}
235
246
@@ -622,6 +633,16 @@ impl Expression {
622
633
pub ( crate ) fn is_recover ( & self ) -> bool {
623
634
matches ! ( self , Expression :: Recover ( _) )
624
635
}
636
+
637
+ pub ( crate ) fn set_usage ( & mut self , usage : Usage ) {
638
+ match self {
639
+ Expression :: Call ( c) => c. usage = usage,
640
+ Expression :: IdentifierRef ( c) => c. usage = usage,
641
+ Expression :: ConstantRef ( c) => c. usage = usage,
642
+ Expression :: AssignSetter ( c) => c. usage = usage,
643
+ _ => { }
644
+ }
645
+ }
625
646
}
626
647
627
648
#[ derive( Clone , Debug , PartialEq , Eq ) ]
@@ -2123,7 +2144,7 @@ impl<'a> LowerToHir<'a> {
2123
2144
} ,
2124
2145
parens : false ,
2125
2146
in_mut : false ,
2126
- unused : false ,
2147
+ usage : Usage :: Used ,
2127
2148
arguments : Vec :: new ( ) ,
2128
2149
location : loc,
2129
2150
} ) ) ;
@@ -2156,7 +2177,7 @@ impl<'a> LowerToHir<'a> {
2156
2177
let var_ref = Expression :: IdentifierRef ( Box :: new ( IdentifierRef {
2157
2178
name : ARRAY_LIT_VAR . to_string ( ) ,
2158
2179
kind : types:: IdentifierKind :: Unknown ,
2159
- unused : false ,
2180
+ usage : Usage :: Used ,
2160
2181
location : node. location ,
2161
2182
} ) ) ;
2162
2183
@@ -2178,7 +2199,7 @@ impl<'a> LowerToHir<'a> {
2178
2199
} ,
2179
2200
parens : true ,
2180
2201
in_mut : false ,
2181
- unused : false ,
2202
+ usage : Usage :: Used ,
2182
2203
arguments : vec ! [ Argument :: Positional ( Box :: new(
2183
2204
PositionalArgument {
2184
2205
value: arg,
@@ -2208,7 +2229,7 @@ impl<'a> LowerToHir<'a> {
2208
2229
source : None ,
2209
2230
name : ARRAY_INTERNAL_NAME . to_string ( ) ,
2210
2231
resolved_type : types:: TypeRef :: Unknown ,
2211
- unused : false ,
2232
+ usage : Usage :: Used ,
2212
2233
location : node. location ,
2213
2234
} ,
2214
2235
) ) ) ,
@@ -2218,7 +2239,7 @@ impl<'a> LowerToHir<'a> {
2218
2239
} ,
2219
2240
parens : true ,
2220
2241
in_mut : false ,
2221
- unused : false ,
2242
+ usage : Usage :: Used ,
2222
2243
arguments : vec ! [ Argument :: Positional ( Box :: new(
2223
2244
PositionalArgument {
2224
2245
value: Expression :: Int ( Box :: new( IntLiteral {
@@ -2321,22 +2342,7 @@ impl<'a> LowerToHir<'a> {
2321
2342
}
2322
2343
2323
2344
fn expressions ( & mut self , node : ast:: Expressions ) -> Vec < Expression > {
2324
- let mut nodes = self . values ( node. values ) ;
2325
- let max = nodes. len ( ) . saturating_sub ( 1 ) ;
2326
-
2327
- for ( idx, node) in nodes. iter_mut ( ) . enumerate ( ) {
2328
- let rem = idx < max;
2329
-
2330
- match node {
2331
- Expression :: Call ( c) => c. unused = rem,
2332
- Expression :: IdentifierRef ( c) => c. unused = rem,
2333
- Expression :: ConstantRef ( c) => c. unused = rem,
2334
- Expression :: AssignSetter ( c) => c. unused = rem,
2335
- _ => { }
2336
- }
2337
- }
2338
-
2339
- nodes
2345
+ self . values ( node. values )
2340
2346
}
2341
2347
2342
2348
fn values ( & mut self , nodes : Vec < ast:: Expression > ) -> Vec < Expression > {
@@ -2495,7 +2501,7 @@ impl<'a> LowerToHir<'a> {
2495
2501
} ,
2496
2502
parens : true ,
2497
2503
in_mut : false ,
2498
- unused : false ,
2504
+ usage : Usage :: Used ,
2499
2505
arguments : vec ! [ Argument :: Positional ( Box :: new(
2500
2506
PositionalArgument {
2501
2507
value: self . expression( node. right) ,
@@ -2521,7 +2527,7 @@ impl<'a> LowerToHir<'a> {
2521
2527
source : self . optional_identifier ( node. source ) ,
2522
2528
name : node. name ,
2523
2529
resolved_type : types:: TypeRef :: Unknown ,
2524
- unused : false ,
2530
+ usage : Usage :: Used ,
2525
2531
location : node. location ,
2526
2532
} )
2527
2533
}
@@ -2530,7 +2536,7 @@ impl<'a> LowerToHir<'a> {
2530
2536
Box :: new ( IdentifierRef {
2531
2537
kind : types:: IdentifierKind :: Unknown ,
2532
2538
name : node. name ,
2533
- unused : false ,
2539
+ usage : Usage :: Used ,
2534
2540
location : node. location ,
2535
2541
} )
2536
2542
}
@@ -2564,7 +2570,7 @@ impl<'a> LowerToHir<'a> {
2564
2570
name : self . identifier ( node. name ) ,
2565
2571
parens : node. arguments . is_some ( ) ,
2566
2572
in_mut : false ,
2567
- unused : false ,
2573
+ usage : Usage :: Used ,
2568
2574
arguments : self . optional_call_arguments ( node. arguments ) ,
2569
2575
location : node. location ,
2570
2576
} ) )
@@ -2725,7 +2731,7 @@ impl<'a> LowerToHir<'a> {
2725
2731
let receiver = Expression :: IdentifierRef ( Box :: new ( IdentifierRef {
2726
2732
kind : types:: IdentifierKind :: Unknown ,
2727
2733
name : variable. name . clone ( ) ,
2728
- unused : false ,
2734
+ usage : Usage :: Used ,
2729
2735
location : variable. location ,
2730
2736
} ) ) ;
2731
2737
@@ -2741,7 +2747,7 @@ impl<'a> LowerToHir<'a> {
2741
2747
receiver : Some ( receiver) ,
2742
2748
parens : true ,
2743
2749
in_mut : false ,
2744
- unused : false ,
2750
+ usage : Usage :: Used ,
2745
2751
arguments : vec ! [ Argument :: Positional ( Box :: new(
2746
2752
PositionalArgument {
2747
2753
value: self . expression( node. value) ,
@@ -2780,7 +2786,7 @@ impl<'a> LowerToHir<'a> {
2780
2786
receiver : Some ( receiver) ,
2781
2787
parens : true ,
2782
2788
in_mut : false ,
2783
- unused : false ,
2789
+ usage : Usage :: Used ,
2784
2790
arguments : vec ! [ Argument :: Positional ( Box :: new(
2785
2791
PositionalArgument {
2786
2792
value: self . expression( node. value) ,
@@ -2801,7 +2807,7 @@ impl<'a> LowerToHir<'a> {
2801
2807
name : self . identifier ( node. name ) ,
2802
2808
value : self . expression ( node. value ) ,
2803
2809
location : node. location ,
2804
- unused : false ,
2810
+ usage : Usage :: Used ,
2805
2811
expected_type : types:: TypeRef :: Unknown ,
2806
2812
} )
2807
2813
}
@@ -2835,7 +2841,7 @@ impl<'a> LowerToHir<'a> {
2835
2841
name : name. clone ( ) ,
2836
2842
parens : false ,
2837
2843
in_mut : false ,
2838
- unused : false ,
2844
+ usage : Usage :: Used ,
2839
2845
arguments : Vec :: new ( ) ,
2840
2846
location : getter_loc,
2841
2847
} ) ) ;
@@ -2849,7 +2855,7 @@ impl<'a> LowerToHir<'a> {
2849
2855
receiver : Some ( getter_rec) ,
2850
2856
parens : true ,
2851
2857
in_mut : false ,
2852
- unused : false ,
2858
+ usage : Usage :: Used ,
2853
2859
arguments : vec ! [ Argument :: Positional ( Box :: new(
2854
2860
PositionalArgument {
2855
2861
value: self . expression( node. value) ,
@@ -2863,7 +2869,7 @@ impl<'a> LowerToHir<'a> {
2863
2869
location : node. location ,
2864
2870
} ) ) ,
2865
2871
location : node. location ,
2866
- unused : false ,
2872
+ usage : Usage :: Used ,
2867
2873
expected_type : types:: TypeRef :: Unknown ,
2868
2874
} )
2869
2875
}
@@ -5587,7 +5593,7 @@ mod tests {
5587
5593
} ,
5588
5594
parens: false ,
5589
5595
in_mut: false ,
5590
- unused : false ,
5596
+ usage : Usage :: Used ,
5591
5597
arguments: Vec :: new( ) ,
5592
5598
location: cols( 12 , 13 )
5593
5599
} ) ) ,
@@ -5628,7 +5634,7 @@ mod tests {
5628
5634
source: None ,
5629
5635
name: "$Array" . to_string( ) ,
5630
5636
resolved_type: types:: TypeRef :: Unknown ,
5631
- unused : false ,
5637
+ usage : Usage :: Used ,
5632
5638
location: cols( 8 , 11 ) ,
5633
5639
}
5634
5640
) ) ) ,
@@ -5638,7 +5644,7 @@ mod tests {
5638
5644
} ,
5639
5645
parens: true ,
5640
5646
in_mut: false ,
5641
- unused : false ,
5647
+ usage : Usage :: Used ,
5642
5648
arguments: vec![ Argument :: Positional ( Box :: new(
5643
5649
PositionalArgument {
5644
5650
value: Expression :: Int ( Box :: new(
@@ -5662,7 +5668,7 @@ mod tests {
5662
5668
IdentifierRef {
5663
5669
name: "$array" . to_string( ) ,
5664
5670
kind: types:: IdentifierKind :: Unknown ,
5665
- unused : false ,
5671
+ usage : Usage :: Used ,
5666
5672
location: cols( 8 , 11 ) ,
5667
5673
}
5668
5674
) ) ) ,
@@ -5672,7 +5678,7 @@ mod tests {
5672
5678
} ,
5673
5679
parens: true ,
5674
5680
in_mut: false ,
5675
- unused : false ,
5681
+ usage : Usage :: Used ,
5676
5682
arguments: vec![ Argument :: Positional ( Box :: new(
5677
5683
PositionalArgument {
5678
5684
value: Expression :: Int ( Box :: new( IntLiteral {
@@ -5688,7 +5694,7 @@ mod tests {
5688
5694
Expression :: IdentifierRef ( Box :: new( IdentifierRef {
5689
5695
name: "$array" . to_string( ) ,
5690
5696
kind: types:: IdentifierKind :: Unknown ,
5691
- unused : false ,
5697
+ usage : Usage :: Used ,
5692
5698
location: cols( 8 , 11 ) ,
5693
5699
} ) ) ,
5694
5700
] ,
@@ -5730,7 +5736,7 @@ mod tests {
5730
5736
source: None ,
5731
5737
name: "$Array" . to_string( ) ,
5732
5738
resolved_type: types:: TypeRef :: Unknown ,
5733
- unused : false ,
5739
+ usage : Usage :: Used ,
5734
5740
location: loc( 2 , 4 , 15 , 15 ) ,
5735
5741
}
5736
5742
) ) ) ,
@@ -5740,7 +5746,7 @@ mod tests {
5740
5746
} ,
5741
5747
parens: true ,
5742
5748
in_mut: false ,
5743
- unused : false ,
5749
+ usage : Usage :: Used ,
5744
5750
arguments: vec![ Argument :: Positional ( Box :: new(
5745
5751
PositionalArgument {
5746
5752
value: Expression :: Int ( Box :: new(
@@ -5761,7 +5767,7 @@ mod tests {
5761
5767
Expression :: IdentifierRef ( Box :: new( IdentifierRef {
5762
5768
name: "$array" . to_string( ) ,
5763
5769
kind: types:: IdentifierKind :: Unknown ,
5764
- unused : false ,
5770
+ usage : Usage :: Used ,
5765
5771
location: loc( 2 , 4 , 15 , 15 ) ,
5766
5772
} ) ) ,
5767
5773
] ,
@@ -5833,7 +5839,7 @@ mod tests {
5833
5839
} ) ) ) ,
5834
5840
parens: true ,
5835
5841
in_mut: false ,
5836
- unused : false ,
5842
+ usage : Usage :: Used ,
5837
5843
arguments: vec![ Argument :: Positional ( Box :: new(
5838
5844
PositionalArgument {
5839
5845
value: Expression :: Int ( Box :: new( IntLiteral {
@@ -5879,7 +5885,7 @@ mod tests {
5879
5885
source: None ,
5880
5886
name: "A" . to_string( ) ,
5881
5887
resolved_type: types:: TypeRef :: Unknown ,
5882
- unused : false ,
5888
+ usage : Usage :: Used ,
5883
5889
location: cols( 8 , 8 )
5884
5890
} ) )
5885
5891
) ;
@@ -5897,7 +5903,7 @@ mod tests {
5897
5903
IdentifierRef {
5898
5904
kind: types:: IdentifierKind :: Unknown ,
5899
5905
name: "a" . to_string( ) ,
5900
- unused : false ,
5906
+ usage : Usage :: Used ,
5901
5907
location: cols( 8 , 8 )
5902
5908
}
5903
5909
) ) ) ,
@@ -5907,7 +5913,7 @@ mod tests {
5907
5913
} ,
5908
5914
parens: false ,
5909
5915
in_mut: false ,
5910
- unused : false ,
5916
+ usage : Usage :: Used ,
5911
5917
arguments: Vec :: new( ) ,
5912
5918
location: cols( 8 , 10 )
5913
5919
} ) )
@@ -5923,7 +5929,7 @@ mod tests {
5923
5929
Expression :: IdentifierRef ( Box :: new( IdentifierRef {
5924
5930
kind: types:: IdentifierKind :: Unknown ,
5925
5931
name: "a" . to_string( ) ,
5926
- unused : false ,
5932
+ usage : Usage :: Used ,
5927
5933
location: cols( 8 , 8 )
5928
5934
} ) )
5929
5935
) ;
@@ -5944,7 +5950,7 @@ mod tests {
5944
5950
} ,
5945
5951
parens: true ,
5946
5952
in_mut: false ,
5947
- unused : false ,
5953
+ usage : Usage :: Used ,
5948
5954
arguments: vec![ Argument :: Positional ( Box :: new(
5949
5955
PositionalArgument {
5950
5956
value: Expression :: Int ( Box :: new( IntLiteral {
@@ -5975,7 +5981,7 @@ mod tests {
5975
5981
} ,
5976
5982
parens: true ,
5977
5983
in_mut: false ,
5978
- unused : false ,
5984
+ usage : Usage :: Used ,
5979
5985
arguments: vec![ Argument :: Named ( Box :: new( NamedArgument {
5980
5986
index: 0 ,
5981
5987
name: Identifier {
@@ -6007,7 +6013,7 @@ mod tests {
6007
6013
IdentifierRef {
6008
6014
kind: types:: IdentifierKind :: Unknown ,
6009
6015
name: "a" . to_string( ) ,
6010
- unused : false ,
6016
+ usage : Usage :: Used ,
6011
6017
location: cols( 8 , 8 )
6012
6018
}
6013
6019
) ) ) ,
@@ -6017,7 +6023,7 @@ mod tests {
6017
6023
} ,
6018
6024
parens: false ,
6019
6025
in_mut: false ,
6020
- unused : false ,
6026
+ usage : Usage :: Used ,
6021
6027
arguments: Vec :: new( ) ,
6022
6028
location: cols( 8 , 10 )
6023
6029
} ) )
@@ -6189,13 +6195,13 @@ mod tests {
6189
6195
IdentifierRef {
6190
6196
kind: types:: IdentifierKind :: Unknown ,
6191
6197
name: "a" . to_string( ) ,
6192
- unused : false ,
6198
+ usage : Usage :: Used ,
6193
6199
location: cols( 8 , 8 )
6194
6200
}
6195
6201
) ) ) ,
6196
6202
parens: true ,
6197
6203
in_mut: false ,
6198
- unused : false ,
6204
+ usage : Usage :: Used ,
6199
6205
arguments: vec![ Argument :: Positional ( Box :: new(
6200
6206
PositionalArgument {
6201
6207
value: Expression :: Int ( Box :: new( IntLiteral {
@@ -6229,7 +6235,7 @@ mod tests {
6229
6235
receiver: Expression :: IdentifierRef ( Box :: new( IdentifierRef {
6230
6236
kind: types:: IdentifierKind :: Unknown ,
6231
6237
name: "a" . to_string( ) ,
6232
- unused : false ,
6238
+ usage : Usage :: Used ,
6233
6239
location: cols( 8 , 8 )
6234
6240
} ) ) ,
6235
6241
name: Identifier {
@@ -6242,7 +6248,7 @@ mod tests {
6242
6248
location: cols( 14 , 14 )
6243
6249
} ) ) ,
6244
6250
location: cols( 8 , 14 ) ,
6245
- unused : false ,
6251
+ usage : Usage :: Used ,
6246
6252
expected_type: types:: TypeRef :: Unknown ,
6247
6253
} ) )
6248
6254
) ;
@@ -6259,7 +6265,7 @@ mod tests {
6259
6265
receiver: Expression :: IdentifierRef ( Box :: new( IdentifierRef {
6260
6266
kind: types:: IdentifierKind :: Unknown ,
6261
6267
name: "a" . to_string( ) ,
6262
- unused : false ,
6268
+ usage : Usage :: Used ,
6263
6269
location: cols( 8 , 8 )
6264
6270
} ) ) ,
6265
6271
name: Identifier {
@@ -6274,7 +6280,7 @@ mod tests {
6274
6280
IdentifierRef {
6275
6281
kind: types:: IdentifierKind :: Unknown ,
6276
6282
name: "a" . to_string( ) ,
6277
- unused : false ,
6283
+ usage : Usage :: Used ,
6278
6284
location: cols( 8 , 8 )
6279
6285
}
6280
6286
) ) ) ,
@@ -6284,13 +6290,13 @@ mod tests {
6284
6290
} ,
6285
6291
parens: false ,
6286
6292
in_mut: false ,
6287
- unused : false ,
6293
+ usage : Usage :: Used ,
6288
6294
arguments: Vec :: new( ) ,
6289
6295
location: cols( 8 , 10 )
6290
6296
} ) ) ) ,
6291
6297
parens: true ,
6292
6298
in_mut: false ,
6293
- unused : false ,
6299
+ usage : Usage :: Used ,
6294
6300
arguments: vec![ Argument :: Positional ( Box :: new(
6295
6301
PositionalArgument {
6296
6302
value: Expression :: Int ( Box :: new( IntLiteral {
@@ -6308,7 +6314,7 @@ mod tests {
6308
6314
location: cols( 8 , 15 )
6309
6315
} ) ) ,
6310
6316
location: cols( 8 , 15 ) ,
6311
- unused : false ,
6317
+ usage : Usage :: Used ,
6312
6318
expected_type: types:: TypeRef :: Unknown ,
6313
6319
} ) )
6314
6320
) ;
@@ -6333,7 +6339,7 @@ mod tests {
6333
6339
} ) ) ) ,
6334
6340
parens: true ,
6335
6341
in_mut: false ,
6336
- unused : false ,
6342
+ usage : Usage :: Used ,
6337
6343
arguments: vec![ Argument :: Positional ( Box :: new(
6338
6344
PositionalArgument {
6339
6345
value: Expression :: Int ( Box :: new( IntLiteral {
@@ -6724,7 +6730,7 @@ mod tests {
6724
6730
} ,
6725
6731
parens: true ,
6726
6732
in_mut: false ,
6727
- unused : false ,
6733
+ usage : Usage :: Used ,
6728
6734
arguments: Vec :: new( ) ,
6729
6735
location: cols( 12 , 14 )
6730
6736
} ) ) ,
0 commit comments