diff options
| author | Samuel Moelius <samuel.moelius@trailofbits.com> | 2024-04-20 01:17:28 +0000 |
|---|---|---|
| committer | Samuel Moelius <samuel.moelius@trailofbits.com> | 2024-04-20 01:20:03 +0000 |
| commit | de258cc6becde010381502ae0e80b4aca4064e3c (patch) | |
| tree | be1ea50dd8c5e6334c2b6000643826de1719c2d2 | |
| parent | 898baf81cdaf1682c6cbf6e575fb546741bc73a0 (diff) | |
| download | rust-de258cc6becde010381502ae0e80b4aca4064e3c.tar.gz rust-de258cc6becde010381502ae0e80b4aca4064e3c.zip | |
Fix `is_test_module_or_function`
| -rw-r--r-- | clippy_utils/src/lib.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index a13885b022f..5ea9b375f5b 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -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)| { |
