@@ -151,6 +151,8 @@ pub(crate) struct ConstantRef {
151
151
pub ( crate ) struct IdentifierRef {
152
152
pub ( crate ) name : String ,
153
153
pub ( crate ) kind : types:: IdentifierKind ,
154
+ /// A flag indicating the result of this node is unused.
155
+ pub ( crate ) unused : bool ,
154
156
pub ( crate ) location : Location ,
155
157
}
156
158
@@ -170,6 +172,8 @@ pub(crate) struct Call {
170
172
pub ( crate ) parens : bool ,
171
173
/// A flag indicating if the call resides directly in a `mut` expression.
172
174
pub ( crate ) in_mut : bool ,
175
+ /// A flag indicating the result of this node is unused.
176
+ pub ( crate ) unused : bool ,
173
177
pub ( crate ) location : Location ,
174
178
}
175
179
@@ -2117,6 +2121,7 @@ impl<'a> LowerToHir<'a> {
2117
2121
} ,
2118
2122
parens : false ,
2119
2123
in_mut : false ,
2124
+ unused : false ,
2120
2125
arguments : Vec :: new ( ) ,
2121
2126
location : loc,
2122
2127
} ) ) ;
@@ -2149,6 +2154,7 @@ impl<'a> LowerToHir<'a> {
2149
2154
let var_ref = Expression :: IdentifierRef ( Box :: new ( IdentifierRef {
2150
2155
name : ARRAY_LIT_VAR . to_string ( ) ,
2151
2156
kind : types:: IdentifierKind :: Unknown ,
2157
+ unused : false ,
2152
2158
location : node. location ,
2153
2159
} ) ) ;
2154
2160
@@ -2170,6 +2176,7 @@ impl<'a> LowerToHir<'a> {
2170
2176
} ,
2171
2177
parens : true ,
2172
2178
in_mut : false ,
2179
+ unused : false ,
2173
2180
arguments : vec ! [ Argument :: Positional ( Box :: new(
2174
2181
PositionalArgument {
2175
2182
value: arg,
@@ -2208,6 +2215,7 @@ impl<'a> LowerToHir<'a> {
2208
2215
} ,
2209
2216
parens : true ,
2210
2217
in_mut : false ,
2218
+ unused : false ,
2211
2219
arguments : vec ! [ Argument :: Positional ( Box :: new(
2212
2220
PositionalArgument {
2213
2221
value: Expression :: Int ( Box :: new( IntLiteral {
@@ -2310,7 +2318,20 @@ impl<'a> LowerToHir<'a> {
2310
2318
}
2311
2319
2312
2320
fn expressions ( & mut self , node : ast:: Expressions ) -> Vec < Expression > {
2313
- self . values ( node. values )
2321
+ let mut nodes = self . values ( node. values ) ;
2322
+ let max = nodes. len ( ) . saturating_sub ( 1 ) ;
2323
+
2324
+ for ( idx, node) in nodes. iter_mut ( ) . enumerate ( ) {
2325
+ let rem = idx < max;
2326
+
2327
+ match node {
2328
+ Expression :: Call ( c) => c. unused = rem,
2329
+ Expression :: IdentifierRef ( c) => c. unused = rem,
2330
+ _ => { }
2331
+ }
2332
+ }
2333
+
2334
+ nodes
2314
2335
}
2315
2336
2316
2337
fn values ( & mut self , nodes : Vec < ast:: Expression > ) -> Vec < Expression > {
@@ -2469,6 +2490,7 @@ impl<'a> LowerToHir<'a> {
2469
2490
} ,
2470
2491
parens : true ,
2471
2492
in_mut : false ,
2493
+ unused : false ,
2472
2494
arguments : vec ! [ Argument :: Positional ( Box :: new(
2473
2495
PositionalArgument {
2474
2496
value: self . expression( node. right) ,
@@ -2502,6 +2524,7 @@ impl<'a> LowerToHir<'a> {
2502
2524
Box :: new ( IdentifierRef {
2503
2525
kind : types:: IdentifierKind :: Unknown ,
2504
2526
name : node. name ,
2527
+ unused : false ,
2505
2528
location : node. location ,
2506
2529
} )
2507
2530
}
@@ -2535,6 +2558,7 @@ impl<'a> LowerToHir<'a> {
2535
2558
name : self . identifier ( node. name ) ,
2536
2559
parens : node. arguments . is_some ( ) ,
2537
2560
in_mut : false ,
2561
+ unused : false ,
2538
2562
arguments : self . optional_call_arguments ( node. arguments ) ,
2539
2563
location : node. location ,
2540
2564
} ) )
@@ -2695,6 +2719,7 @@ impl<'a> LowerToHir<'a> {
2695
2719
let receiver = Expression :: IdentifierRef ( Box :: new ( IdentifierRef {
2696
2720
kind : types:: IdentifierKind :: Unknown ,
2697
2721
name : variable. name . clone ( ) ,
2722
+ unused : false ,
2698
2723
location : variable. location ,
2699
2724
} ) ) ;
2700
2725
@@ -2710,6 +2735,7 @@ impl<'a> LowerToHir<'a> {
2710
2735
receiver : Some ( receiver) ,
2711
2736
parens : true ,
2712
2737
in_mut : false ,
2738
+ unused : false ,
2713
2739
arguments : vec ! [ Argument :: Positional ( Box :: new(
2714
2740
PositionalArgument {
2715
2741
value: self . expression( node. value) ,
@@ -2748,6 +2774,7 @@ impl<'a> LowerToHir<'a> {
2748
2774
receiver : Some ( receiver) ,
2749
2775
parens : true ,
2750
2776
in_mut : false ,
2777
+ unused : false ,
2751
2778
arguments : vec ! [ Argument :: Positional ( Box :: new(
2752
2779
PositionalArgument {
2753
2780
value: self . expression( node. value) ,
@@ -2801,6 +2828,7 @@ impl<'a> LowerToHir<'a> {
2801
2828
name : name. clone ( ) ,
2802
2829
parens : false ,
2803
2830
in_mut : false ,
2831
+ unused : false ,
2804
2832
arguments : Vec :: new ( ) ,
2805
2833
location : getter_loc,
2806
2834
} ) ) ;
@@ -2814,6 +2842,7 @@ impl<'a> LowerToHir<'a> {
2814
2842
receiver : Some ( getter_rec) ,
2815
2843
parens : true ,
2816
2844
in_mut : false ,
2845
+ unused : false ,
2817
2846
arguments : vec ! [ Argument :: Positional ( Box :: new(
2818
2847
PositionalArgument {
2819
2848
value: self . expression( node. value) ,
@@ -5550,6 +5579,7 @@ mod tests {
5550
5579
} ,
5551
5580
parens: false ,
5552
5581
in_mut: false ,
5582
+ unused: false ,
5553
5583
arguments: Vec :: new( ) ,
5554
5584
location: cols( 12 , 13 )
5555
5585
} ) ) ,
@@ -5599,6 +5629,7 @@ mod tests {
5599
5629
} ,
5600
5630
parens: true ,
5601
5631
in_mut: false ,
5632
+ unused: false ,
5602
5633
arguments: vec![ Argument :: Positional ( Box :: new(
5603
5634
PositionalArgument {
5604
5635
value: Expression :: Int ( Box :: new(
@@ -5622,6 +5653,7 @@ mod tests {
5622
5653
IdentifierRef {
5623
5654
name: "$array" . to_string( ) ,
5624
5655
kind: types:: IdentifierKind :: Unknown ,
5656
+ unused: false ,
5625
5657
location: cols( 8 , 11 ) ,
5626
5658
}
5627
5659
) ) ) ,
@@ -5631,6 +5663,7 @@ mod tests {
5631
5663
} ,
5632
5664
parens: true ,
5633
5665
in_mut: false ,
5666
+ unused: false ,
5634
5667
arguments: vec![ Argument :: Positional ( Box :: new(
5635
5668
PositionalArgument {
5636
5669
value: Expression :: Int ( Box :: new( IntLiteral {
@@ -5646,6 +5679,7 @@ mod tests {
5646
5679
Expression :: IdentifierRef ( Box :: new( IdentifierRef {
5647
5680
name: "$array" . to_string( ) ,
5648
5681
kind: types:: IdentifierKind :: Unknown ,
5682
+ unused: false ,
5649
5683
location: cols( 8 , 11 ) ,
5650
5684
} ) ) ,
5651
5685
] ,
@@ -5696,6 +5730,7 @@ mod tests {
5696
5730
} ,
5697
5731
parens: true ,
5698
5732
in_mut: false ,
5733
+ unused: false ,
5699
5734
arguments: vec![ Argument :: Positional ( Box :: new(
5700
5735
PositionalArgument {
5701
5736
value: Expression :: Int ( Box :: new(
@@ -5716,6 +5751,7 @@ mod tests {
5716
5751
Expression :: IdentifierRef ( Box :: new( IdentifierRef {
5717
5752
name: "$array" . to_string( ) ,
5718
5753
kind: types:: IdentifierKind :: Unknown ,
5754
+ unused: false ,
5719
5755
location: loc( 2 , 4 , 15 , 15 ) ,
5720
5756
} ) ) ,
5721
5757
] ,
@@ -5787,6 +5823,7 @@ mod tests {
5787
5823
} ) ) ) ,
5788
5824
parens: true ,
5789
5825
in_mut: false ,
5826
+ unused: false ,
5790
5827
arguments: vec![ Argument :: Positional ( Box :: new(
5791
5828
PositionalArgument {
5792
5829
value: Expression :: Int ( Box :: new( IntLiteral {
@@ -5849,6 +5886,7 @@ mod tests {
5849
5886
IdentifierRef {
5850
5887
kind: types:: IdentifierKind :: Unknown ,
5851
5888
name: "a" . to_string( ) ,
5889
+ unused: false ,
5852
5890
location: cols( 8 , 8 )
5853
5891
}
5854
5892
) ) ) ,
@@ -5858,6 +5896,7 @@ mod tests {
5858
5896
} ,
5859
5897
parens: false ,
5860
5898
in_mut: false ,
5899
+ unused: false ,
5861
5900
arguments: Vec :: new( ) ,
5862
5901
location: cols( 8 , 10 )
5863
5902
} ) )
@@ -5873,6 +5912,7 @@ mod tests {
5873
5912
Expression :: IdentifierRef ( Box :: new( IdentifierRef {
5874
5913
kind: types:: IdentifierKind :: Unknown ,
5875
5914
name: "a" . to_string( ) ,
5915
+ unused: false ,
5876
5916
location: cols( 8 , 8 )
5877
5917
} ) )
5878
5918
) ;
@@ -5893,6 +5933,7 @@ mod tests {
5893
5933
} ,
5894
5934
parens: true ,
5895
5935
in_mut: false ,
5936
+ unused: false ,
5896
5937
arguments: vec![ Argument :: Positional ( Box :: new(
5897
5938
PositionalArgument {
5898
5939
value: Expression :: Int ( Box :: new( IntLiteral {
@@ -5923,6 +5964,7 @@ mod tests {
5923
5964
} ,
5924
5965
parens: true ,
5925
5966
in_mut: false ,
5967
+ unused: false ,
5926
5968
arguments: vec![ Argument :: Named ( Box :: new( NamedArgument {
5927
5969
index: 0 ,
5928
5970
name: Identifier {
@@ -5954,6 +5996,7 @@ mod tests {
5954
5996
IdentifierRef {
5955
5997
kind: types:: IdentifierKind :: Unknown ,
5956
5998
name: "a" . to_string( ) ,
5999
+ unused: false ,
5957
6000
location: cols( 8 , 8 )
5958
6001
}
5959
6002
) ) ) ,
@@ -5963,6 +6006,7 @@ mod tests {
5963
6006
} ,
5964
6007
parens: false ,
5965
6008
in_mut: false ,
6009
+ unused: false ,
5966
6010
arguments: Vec :: new( ) ,
5967
6011
location: cols( 8 , 10 )
5968
6012
} ) )
@@ -6134,11 +6178,13 @@ mod tests {
6134
6178
IdentifierRef {
6135
6179
kind: types:: IdentifierKind :: Unknown ,
6136
6180
name: "a" . to_string( ) ,
6181
+ unused: false ,
6137
6182
location: cols( 8 , 8 )
6138
6183
}
6139
6184
) ) ) ,
6140
6185
parens: true ,
6141
6186
in_mut: false ,
6187
+ unused: false ,
6142
6188
arguments: vec![ Argument :: Positional ( Box :: new(
6143
6189
PositionalArgument {
6144
6190
value: Expression :: Int ( Box :: new( IntLiteral {
@@ -6172,6 +6218,7 @@ mod tests {
6172
6218
receiver: Expression :: IdentifierRef ( Box :: new( IdentifierRef {
6173
6219
kind: types:: IdentifierKind :: Unknown ,
6174
6220
name: "a" . to_string( ) ,
6221
+ unused: false ,
6175
6222
location: cols( 8 , 8 )
6176
6223
} ) ) ,
6177
6224
name: Identifier {
@@ -6200,6 +6247,7 @@ mod tests {
6200
6247
receiver: Expression :: IdentifierRef ( Box :: new( IdentifierRef {
6201
6248
kind: types:: IdentifierKind :: Unknown ,
6202
6249
name: "a" . to_string( ) ,
6250
+ unused: false ,
6203
6251
location: cols( 8 , 8 )
6204
6252
} ) ) ,
6205
6253
name: Identifier {
@@ -6214,6 +6262,7 @@ mod tests {
6214
6262
IdentifierRef {
6215
6263
kind: types:: IdentifierKind :: Unknown ,
6216
6264
name: "a" . to_string( ) ,
6265
+ unused: false ,
6217
6266
location: cols( 8 , 8 )
6218
6267
}
6219
6268
) ) ) ,
@@ -6223,11 +6272,13 @@ mod tests {
6223
6272
} ,
6224
6273
parens: false ,
6225
6274
in_mut: false ,
6275
+ unused: false ,
6226
6276
arguments: Vec :: new( ) ,
6227
6277
location: cols( 8 , 10 )
6228
6278
} ) ) ) ,
6229
6279
parens: true ,
6230
6280
in_mut: false ,
6281
+ unused: false ,
6231
6282
arguments: vec![ Argument :: Positional ( Box :: new(
6232
6283
PositionalArgument {
6233
6284
value: Expression :: Int ( Box :: new( IntLiteral {
@@ -6269,6 +6320,7 @@ mod tests {
6269
6320
} ) ) ) ,
6270
6321
parens: true ,
6271
6322
in_mut: false ,
6323
+ unused: false ,
6272
6324
arguments: vec![ Argument :: Positional ( Box :: new(
6273
6325
PositionalArgument {
6274
6326
value: Expression :: Int ( Box :: new( IntLiteral {
@@ -6659,6 +6711,7 @@ mod tests {
6659
6711
} ,
6660
6712
parens: true ,
6661
6713
in_mut: false ,
6714
+ unused: false ,
6662
6715
arguments: Vec :: new( ) ,
6663
6716
location: cols( 12 , 14 )
6664
6717
} ) ) ,
0 commit comments