@@ -1363,6 +1363,40 @@ pub fn is_expr_used(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool {
1363
1363
)
1364
1364
}
1365
1365
1366
+ pub fn get_expr_use_or_unification_node ( tcx : TyCtxt < ' tcx > , expr : & Expr < ' _ > ) -> Option < Node < ' tcx > > {
1367
+ let map = tcx. hir ( ) ;
1368
+ let mut child_id = expr. hir_id ;
1369
+ let mut iter = map. parent_iter ( child_id) ;
1370
+ loop {
1371
+ match iter. next ( ) {
1372
+ None => break None ,
1373
+ Some ( ( id, Node :: Block ( _) ) ) => child_id = id,
1374
+ Some ( ( id, Node :: Arm ( arm) ) ) if arm. body . hir_id == child_id => child_id = id,
1375
+ Some ( ( _, Node :: Expr ( expr) ) ) => match expr. kind {
1376
+ ExprKind :: Match ( _, [ arm] , _) if arm. hir_id == child_id => child_id = expr. hir_id ,
1377
+ ExprKind :: Block ( ..) | ExprKind :: DropTemps ( _) => child_id = expr. hir_id ,
1378
+ ExprKind :: If ( _, then_expr, None ) if then_expr. hir_id == child_id => break None ,
1379
+ _ => break Some ( Node :: Expr ( expr) ) ,
1380
+ } ,
1381
+ Some ( ( _, node) ) => break Some ( node) ,
1382
+ }
1383
+ }
1384
+ }
1385
+
1386
+ pub fn is_expr_used_or_unified ( tcx : TyCtxt < ' _ > , expr : & Expr < ' _ > ) -> bool {
1387
+ !matches ! (
1388
+ get_expr_use_or_unification_node( tcx, expr) ,
1389
+ None | Some ( Node :: Stmt ( Stmt {
1390
+ kind: StmtKind :: Expr ( _) | StmtKind :: Semi ( _) ,
1391
+ ..
1392
+ } ) )
1393
+ )
1394
+ }
1395
+
1396
+ pub fn is_expr_final_block_expr ( tcx : TyCtxt < ' _ > , expr : & Expr < ' _ > ) -> bool {
1397
+ matches ! ( get_parent_node( tcx, expr. hir_id) , Some ( Node :: Block ( ..) ) )
1398
+ }
1399
+
1366
1400
pub fn is_no_std_crate ( cx : & LateContext < ' _ > ) -> bool {
1367
1401
cx. tcx . hir ( ) . attrs ( hir:: CRATE_HIR_ID ) . iter ( ) . any ( |attr| {
1368
1402
if let ast:: AttrKind :: Normal ( ref attr, _) = attr. kind {
0 commit comments