@@ -1402,7 +1402,7 @@ pub fn recurse_or_patterns<'tcx, F: FnMut(&'tcx Pat<'tcx>)>(pat: &'tcx Pat<'tcx>
1402
1402
/// Checks for the `#[automatically_derived]` attribute all `#[derive]`d
1403
1403
/// implementations have.
1404
1404
pub fn is_automatically_derived ( attrs : & [ ast:: Attribute ] ) -> bool {
1405
- attrs . iter ( ) . any ( |attr| attr . has_name ( sym:: automatically_derived) )
1405
+ has_attr ( attrs , sym:: automatically_derived)
1406
1406
}
1407
1407
1408
1408
/// Remove blocks around an expression.
@@ -1524,20 +1524,29 @@ pub fn clip(tcx: TyCtxt<'_>, u: u128, ity: rustc_ty::UintTy) -> u128 {
1524
1524
( u << amt) >> amt
1525
1525
}
1526
1526
1527
- pub fn any_parent_is_automatically_derived ( tcx : TyCtxt < ' _ > , node : HirId ) -> bool {
1527
+ pub fn has_attr ( attrs : & [ ast:: Attribute ] , symbol : Symbol ) -> bool {
1528
+ attrs. iter ( ) . any ( |attr| attr. has_name ( symbol) )
1529
+ }
1530
+
1531
+ pub fn any_parent_has_attr ( tcx : TyCtxt < ' _ > , node : HirId , symbol : Symbol ) -> bool {
1528
1532
let map = & tcx. hir ( ) ;
1529
1533
let mut prev_enclosing_node = None ;
1530
1534
let mut enclosing_node = node;
1531
1535
while Some ( enclosing_node) != prev_enclosing_node {
1532
- if is_automatically_derived ( map. attrs ( enclosing_node) ) {
1536
+ if has_attr ( map. attrs ( enclosing_node) , symbol ) {
1533
1537
return true ;
1534
1538
}
1535
1539
prev_enclosing_node = Some ( enclosing_node) ;
1536
1540
enclosing_node = map. get_parent_item ( enclosing_node) ;
1537
1541
}
1542
+
1538
1543
false
1539
1544
}
1540
1545
1546
+ pub fn any_parent_is_automatically_derived ( tcx : TyCtxt < ' _ > , node : HirId ) -> bool {
1547
+ any_parent_has_attr ( tcx, node, sym:: automatically_derived)
1548
+ }
1549
+
1541
1550
/// Matches a function call with the given path and returns the arguments.
1542
1551
///
1543
1552
/// Usage:
0 commit comments