Skip to content

Commit

Permalink
Fix is_in_test_function
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Apr 20, 2024
1 parent 898baf8 commit e2c7782
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions clippy_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2505,8 +2505,9 @@ fn with_test_item_names(tcx: TyCtxt<'_>, module: LocalModDefId, f: impl Fn(&[Sym
/// Note: Add `//@compile-flags: --test` to UI tests with a `#[test]` function
pub fn is_in_test_function(tcx: TyCtxt<'_>, id: HirId) -> bool {
with_test_item_names(tcx, tcx.parent_module(id), |names| {
tcx.hir()
.parent_iter(id)
let node = tcx.hir_node(id);
once((id, node))
.chain(tcx.hir().parent_iter(id))
// Since you can nest functions we need to collect all until we leave
// function scope
.any(|(_id, node)| {
Expand Down

0 comments on commit e2c7782

Please sign in to comment.