@@ -224,24 +224,13 @@ impl<'tcx> AbstractConst<'tcx> {
224
224
}
225
225
}
226
226
227
- #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
228
- struct WorkNode < ' tcx > {
229
- node : Node < ' tcx > ,
230
- span : Span ,
231
- used : bool ,
232
- }
233
-
234
227
struct AbstractConstBuilder < ' a , ' tcx > {
235
228
tcx : TyCtxt < ' tcx > ,
236
229
body_id : thir:: ExprId ,
230
+ /// `Lrc` is used to avoid borrowck difficulties in `recurse_build`
237
231
body : Lrc < & ' a thir:: Thir < ' tcx > > ,
238
232
/// The current WIP node tree.
239
- ///
240
- /// We require all nodes to be used in the final abstract const,
241
- /// so we store this here. Note that we also consider nodes as used
242
- /// if they are mentioned in an assert, so some used nodes are never
243
- /// actually reachable by walking the [`AbstractConst`].
244
- nodes : IndexVec < NodeId , WorkNode < ' tcx > > ,
233
+ nodes : IndexVec < NodeId , Node < ' tcx > > ,
245
234
}
246
235
247
236
impl < ' a , ' tcx > AbstractConstBuilder < ' a , ' tcx > {
@@ -301,30 +290,6 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
301
290
Ok ( Some ( builder) )
302
291
}
303
292
304
- fn add_node ( & mut self , node : Node < ' tcx > , span : Span ) -> NodeId {
305
- // Mark used nodes.
306
- match node {
307
- Node :: Leaf ( _) => ( ) ,
308
- Node :: Binop ( _, lhs, rhs) => {
309
- self . nodes [ lhs] . used = true ;
310
- self . nodes [ rhs] . used = true ;
311
- }
312
- Node :: UnaryOp ( _, input) => {
313
- self . nodes [ input] . used = true ;
314
- }
315
- Node :: FunctionCall ( func, nodes) => {
316
- self . nodes [ func] . used = true ;
317
- nodes. iter ( ) . for_each ( |& n| self . nodes [ n] . used = true ) ;
318
- }
319
- Node :: Cast ( operand, _) => {
320
- self . nodes [ operand] . used = true ;
321
- }
322
- }
323
-
324
- // Nodes start as unused.
325
- self . nodes . push ( WorkNode { node, span, used : false } )
326
- }
327
-
328
293
/// We do not allow all binary operations in abstract consts, so filter disallowed ones.
329
294
fn check_binop ( op : mir:: BinOp ) -> bool {
330
295
use mir:: BinOp :: * ;
@@ -348,23 +313,17 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
348
313
/// encountering an unspported operation.
349
314
fn build ( mut self ) -> Result < & ' tcx [ Node < ' tcx > ] , ErrorReported > {
350
315
debug ! ( "Abstractconstbuilder::build: body={:?}" , & * self . body) ;
351
- let last = self . recurse_build ( self . body_id ) ?;
352
- self . nodes [ last] . used = true ;
316
+ self . recurse_build ( self . body_id ) ?;
353
317
354
318
for n in self . nodes . iter ( ) {
355
- if let Node :: Leaf ( ty:: Const { val : ty:: ConstKind :: Unevaluated ( ct) , ty : _ } ) = n. node {
319
+ if let Node :: Leaf ( ty:: Const { val : ty:: ConstKind :: Unevaluated ( ct) , ty : _ } ) = n {
356
320
// `AbstractConst`s should not contain any promoteds as they require references which
357
321
// are not allowed.
358
322
assert_eq ! ( ct. promoted, None ) ;
359
323
}
360
324
}
361
325
362
- // FIXME I dont even think we can get unused nodes anymore with thir abstract const
363
- if let Some ( & unused) = self . nodes . iter ( ) . find ( |n| !n. used ) {
364
- self . error ( Some ( unused. span ) , "dead code" ) ?;
365
- }
366
-
367
- Ok ( self . tcx . arena . alloc_from_iter ( self . nodes . into_iter ( ) . map ( |n| n. node ) ) )
326
+ Ok ( self . tcx . arena . alloc_from_iter ( self . nodes . into_iter ( ) ) )
368
327
}
369
328
370
329
fn recurse_build ( & mut self , node : thir:: ExprId ) -> Result < NodeId , ErrorReported > {
@@ -380,7 +339,7 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
380
339
// subtle: associated consts are literals this arm handles
381
340
// `<T as Trait>::ASSOC` as well as `12`
382
341
& ExprKind :: Literal { literal, .. }
383
- | & ExprKind :: StaticRef { literal, .. } => self . add_node ( Node :: Leaf ( literal) , node . span ) ,
342
+ | & ExprKind :: StaticRef { literal, .. } => self . nodes . push ( Node :: Leaf ( literal) ) ,
384
343
385
344
// FIXME(generic_const_exprs) handle `from_hir_call` field
386
345
ExprKind :: Call { fun, args, .. } => {
@@ -391,16 +350,16 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
391
350
new_args. push ( self . recurse_build ( id) ?) ;
392
351
}
393
352
let new_args = self . tcx . arena . alloc_slice ( & new_args) ;
394
- self . add_node ( Node :: FunctionCall ( fun, new_args) , node . span )
353
+ self . nodes . push ( Node :: FunctionCall ( fun, new_args) )
395
354
} ,
396
355
& ExprKind :: Binary { op, lhs, rhs } if Self :: check_binop ( op) => {
397
356
let lhs = self . recurse_build ( lhs) ?;
398
357
let rhs = self . recurse_build ( rhs) ?;
399
- self . add_node ( Node :: Binop ( op, lhs, rhs) , node . span )
358
+ self . nodes . push ( Node :: Binop ( op, lhs, rhs) )
400
359
}
401
360
& ExprKind :: Unary { op, arg } if Self :: check_unop ( op) => {
402
361
let arg = self . recurse_build ( arg) ?;
403
- self . add_node ( Node :: UnaryOp ( op, arg) , node . span )
362
+ self . nodes . push ( Node :: UnaryOp ( op, arg) )
404
363
} ,
405
364
// this is necessary so that the following compiles:
406
365
//
@@ -416,7 +375,7 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
416
375
& ExprKind :: Use { source}
417
376
| & ExprKind :: Cast { source } => {
418
377
let arg = self . recurse_build ( source) ?;
419
- self . add_node ( Node :: Cast ( arg, node. ty ) , node . span )
378
+ self . nodes . push ( Node :: Cast ( arg, node. ty ) )
420
379
} ,
421
380
422
381
// FIXME(generic_const_exprs) we want to support these
0 commit comments