@@ -224,24 +224,13 @@ impl<'tcx> AbstractConst<'tcx> {
224224 }
225225}
226226
227- #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
228- struct WorkNode < ' tcx > {
229- node : Node < ' tcx > ,
230- span : Span ,
231- used : bool ,
232- }
233-
234227struct AbstractConstBuilder < ' a , ' tcx > {
235228 tcx : TyCtxt < ' tcx > ,
236229 body_id : thir:: ExprId ,
230+ /// `Lrc` is used to avoid borrowck difficulties in `recurse_build`
237231 body : Lrc < & ' a thir:: Thir < ' tcx > > ,
238232 /// 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 > > ,
245234}
246235
247236impl < ' a , ' tcx > AbstractConstBuilder < ' a , ' tcx > {
@@ -301,30 +290,6 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
301290 Ok ( Some ( builder) )
302291 }
303292
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-
328293 /// We do not allow all binary operations in abstract consts, so filter disallowed ones.
329294 fn check_binop ( op : mir:: BinOp ) -> bool {
330295 use mir:: BinOp :: * ;
@@ -348,23 +313,17 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
348313 /// encountering an unspported operation.
349314 fn build ( mut self ) -> Result < & ' tcx [ Node < ' tcx > ] , ErrorReported > {
350315 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 ) ?;
353317
354318 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 {
356320 // `AbstractConst`s should not contain any promoteds as they require references which
357321 // are not allowed.
358322 assert_eq ! ( ct. promoted, None ) ;
359323 }
360324 }
361325
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 ( ) ) )
368327 }
369328
370329 fn recurse_build ( & mut self , node : thir:: ExprId ) -> Result < NodeId , ErrorReported > {
@@ -380,7 +339,7 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
380339 // subtle: associated consts are literals this arm handles
381340 // `<T as Trait>::ASSOC` as well as `12`
382341 & 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) ) ,
384343
385344 // FIXME(generic_const_exprs) handle `from_hir_call` field
386345 ExprKind :: Call { fun, args, .. } => {
@@ -391,16 +350,16 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
391350 new_args. push ( self . recurse_build ( id) ?) ;
392351 }
393352 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) )
395354 } ,
396355 & ExprKind :: Binary { op, lhs, rhs } if Self :: check_binop ( op) => {
397356 let lhs = self . recurse_build ( lhs) ?;
398357 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) )
400359 }
401360 & ExprKind :: Unary { op, arg } if Self :: check_unop ( op) => {
402361 let arg = self . recurse_build ( arg) ?;
403- self . add_node ( Node :: UnaryOp ( op, arg) , node . span )
362+ self . nodes . push ( Node :: UnaryOp ( op, arg) )
404363 } ,
405364 // this is necessary so that the following compiles:
406365 //
@@ -416,7 +375,7 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
416375 & ExprKind :: Use { source}
417376 | & ExprKind :: Cast { source } => {
418377 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 ) )
420379 } ,
421380
422381 // FIXME(generic_const_exprs) we want to support these
0 commit comments