8
8
//! In this case we try to build an abstract representation of this constant using
9
9
//! `thir_abstract_const` which can then be checked for structural equality with other
10
10
//! generic constants mentioned in the `caller_bounds` of the current environment.
11
- use rustc_data_structures:: sync:: Lrc ;
12
11
use rustc_errors:: ErrorReported ;
13
12
use rustc_hir:: def:: DefKind ;
14
13
use rustc_index:: vec:: IndexVec ;
@@ -227,8 +226,7 @@ impl<'tcx> AbstractConst<'tcx> {
227
226
struct AbstractConstBuilder < ' a , ' tcx > {
228
227
tcx : TyCtxt < ' tcx > ,
229
228
body_id : thir:: ExprId ,
230
- /// `Lrc` is used to avoid borrowck difficulties in `recurse_build`
231
- body : Lrc < & ' a thir:: Thir < ' tcx > > ,
229
+ body : & ' a thir:: Thir < ' tcx > ,
232
230
/// The current WIP node tree.
233
231
nodes : IndexVec < NodeId , Node < ' tcx > > ,
234
232
}
@@ -253,8 +251,7 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
253
251
tcx : TyCtxt < ' tcx > ,
254
252
( body, body_id) : ( & ' a thir:: Thir < ' tcx > , thir:: ExprId ) ,
255
253
) -> Result < Option < AbstractConstBuilder < ' a , ' tcx > > , ErrorReported > {
256
- let builder =
257
- AbstractConstBuilder { tcx, body_id, body : Lrc :: new ( body) , nodes : IndexVec :: new ( ) } ;
254
+ let builder = AbstractConstBuilder { tcx, body_id, body, nodes : IndexVec :: new ( ) } ;
258
255
259
256
struct IsThirPolymorphic < ' a , ' tcx > {
260
257
is_poly : bool ,
@@ -328,7 +325,7 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
328
325
329
326
fn recurse_build ( & mut self , node : thir:: ExprId ) -> Result < NodeId , ErrorReported > {
330
327
use thir:: ExprKind ;
331
- let node = & self . body . clone ( ) . exprs [ node] ;
328
+ let node = & self . body . exprs [ node] ;
332
329
debug ! ( "recurse_build: node={:?}" , node) ;
333
330
Ok ( match & node. kind {
334
331
// I dont know if handling of these 3 is correct
@@ -338,10 +335,9 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
338
335
339
336
// subtle: associated consts are literals this arm handles
340
337
// `<T as Trait>::ASSOC` as well as `12`
341
- & ExprKind :: Literal { literal, .. }
342
- | & ExprKind :: StaticRef { literal, .. } => self . nodes . push ( Node :: Leaf ( literal) ) ,
338
+ & ExprKind :: Literal { literal, .. } => self . nodes . push ( Node :: Leaf ( literal) ) ,
343
339
344
- // FIXME(generic_const_exprs) handle `from_hir_call` field
340
+ // FIXME(generic_const_exprs): Handle `from_hir_call` field
345
341
ExprKind :: Call { fun, args, .. } => {
346
342
let fun = self . recurse_build ( * fun) ?;
347
343
@@ -361,24 +357,24 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
361
357
let arg = self . recurse_build ( arg) ?;
362
358
self . nodes . push ( Node :: UnaryOp ( op, arg) )
363
359
} ,
364
- // this is necessary so that the following compiles:
360
+ // This is necessary so that the following compiles:
365
361
//
366
362
// ```
367
363
// fn foo<const N: usize>(a: [(); N + 1]) {
368
364
// bar::<{ N + 1 }>();
369
365
// }
370
366
// ```
371
367
ExprKind :: Block { body : thir:: Block { stmts : box [ ] , expr : Some ( e) , .. } } => self . recurse_build ( * e) ?,
372
- // ExprKind::Use happens when a `hir::ExprKind::Cast` is a
368
+ // ` ExprKind::Use` happens when a `hir::ExprKind::Cast` is a
373
369
// "coercion cast" i.e. using a coercion or is a no-op.
374
- // this is important so that `N as usize as usize` doesnt unify with `N as usize`
370
+ // This is important so that `N as usize as usize` doesnt unify with `N as usize`. (untested)
375
371
& ExprKind :: Use { source}
376
372
| & ExprKind :: Cast { source } => {
377
373
let arg = self . recurse_build ( source) ?;
378
374
self . nodes . push ( Node :: Cast ( arg, node. ty ) )
379
375
} ,
380
376
381
- // FIXME(generic_const_exprs) we want to support these
377
+ // FIXME(generic_const_exprs): We may want to support these.
382
378
ExprKind :: AddressOf { .. }
383
379
| ExprKind :: Borrow { .. }
384
380
| ExprKind :: Deref { .. }
@@ -390,21 +386,24 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
390
386
| ExprKind :: Index { .. }
391
387
| ExprKind :: Field { .. }
392
388
| ExprKind :: ConstBlock { .. }
393
- | ExprKind :: Adt ( _) => return self . error (
389
+ | ExprKind :: Adt ( _) => self . error (
394
390
Some ( node. span ) ,
395
391
"unsupported operation in generic constant, this may be supported in the future" ,
396
- ) . map ( |never| never ) ,
392
+ ) ? ,
397
393
398
394
ExprKind :: Match { .. }
399
- | ExprKind :: VarRef { .. } //
400
- | ExprKind :: UpvarRef { .. } // we dont permit let stmts so...
395
+ // we dont permit let stmts so `VarRef` and `UpvarRef` cant happen
396
+ | ExprKind :: VarRef { .. }
397
+ | ExprKind :: UpvarRef { .. }
401
398
| ExprKind :: Closure { .. }
402
399
| ExprKind :: Let { .. } // let expressions imply control flow
403
400
| ExprKind :: Loop { .. }
404
401
| ExprKind :: Assign { .. }
402
+ | ExprKind :: StaticRef { .. }
405
403
| ExprKind :: LogicalOp { .. }
406
- | ExprKind :: Unary { .. } //
407
- | ExprKind :: Binary { .. } // we handle valid unary/binary ops above
404
+ // we handle valid unary/binary ops above
405
+ | ExprKind :: Unary { .. }
406
+ | ExprKind :: Binary { .. }
408
407
| ExprKind :: Break { .. }
409
408
| ExprKind :: Continue { .. }
410
409
| ExprKind :: If { .. }
@@ -415,7 +414,7 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
415
414
| ExprKind :: Box { .. } // allocations not allowed in constants
416
415
| ExprKind :: AssignOp { .. }
417
416
| ExprKind :: InlineAsm { .. }
418
- | ExprKind :: Yield { .. } => return self . error ( Some ( node. span ) , "unsupported operation in generic constant" ) . map ( |never| never ) ,
417
+ | ExprKind :: Yield { .. } => self . error ( Some ( node. span ) , "unsupported operation in generic constant" ) ? ,
419
418
} )
420
419
}
421
420
}
0 commit comments