Skip to content

rust: deny unwrap, expect, panic and friends in every non-test crate, with a guard #12395

Open

Description

@TrapsterDK

Today 221 crate roots carry #![cfg_attr(not(test), deny(clippy::expect_used, clippy::unwrap_used, clippy::unreachable, clippy::todo))]. Gaps:

  • About 19 lib.rs/main.rs roots on main lack the deny block.
  • clippy::panic, clippy::unimplemented and clippy::exit are not denied. About 263 panic! calls sit in files outside test dirs (some are in #[cfg(test)] modules).
  • No guard test checks that every crate root carries the block.

Do:

  1. Add clippy::panic, clippy::unimplemented and clippy::exit to the deny set in every crate root.
  2. Add the block to every non-test crate root missing it.
  3. Replace non-test unwrap/expect/panic! with error returns (Result, ?, typed errors). Process exit only in main.
  4. Add a //tools/ci guard that fails when a non-test crate root lacks the full deny set. No allowlist.
  5. Make sure the clippy aspect runs these crates in CI with warnings as errors.

Split by package if large; one PR per package group, Part of this issue.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xut2i1LBYg969L4ZJRMURT

Activity

  1. added
    P2
    on Nov 12, 2026
  2. TrapsterDK commented on Nov 12, 2026

    @TrapsterDK
    CollaboratorAuthor

    Decision: enforce once, repo-wide, instead of per-crate blocks.

    • .dx/bazelrc/correctness.bazelrc clippy flags: -Dclippy::unwrap_used -Dclippy::expect_used -Dclippy::panic -Dclippy::unreachable -Dclippy::todo -Dclippy::unimplemented -Dclippy::exit -Dclippy::indexing_slicing -Dclippy::unwrap_in_result -Dclippy::panic_in_result_fn -Dclippy::get_unwrap -Dclippy::string_slice -Dclippy::fallible_impl_from -Dclippy::wildcard_enum_match_arm -Dclippy::let_underscore_must_use -Dclippy::undocumented_unsafe_blocks -Dclippy::allow_attributes_without_reason -Dclippy::allow_attributes.
    • .bazelrc rustc flags: --deny=unsafe_code --deny=unsafe_op_in_unsafe_fn --deny=unused_must_use.
    • tools/workspace/clippy.toml: allow-unwrap-in-tests, allow-expect-in-tests, allow-panic-in-tests, allow-indexing-slicing-in-tests = true.
    • Exceptions only as #[expect(<lint>, reason = "...")] on the item. unsafe only where FFI or the OS needs it, each block with a // SAFETY: line.
    • Delete the per-crate cfg_attr(not(test), deny(...)) blocks.
    • Guard: a //tools/ci test fails on #[allow( of these lints and on an #[expect( without reason.

    Land in parts: config + guard first with existing violations as #[expect], then remove them package by package.

    🤖 Generated with Claude Code

    https://claude.ai/code/session_01Xut2i1LBYg969L4ZJRMURT

  3. TrapsterDK commented on Nov 12, 2026

    @TrapsterDK
    CollaboratorAuthor

    Decision: the strict tier (--@rules_dx//config:config_tier=strict) also turns these on for consumers. core/quality/tiers/clippy/strict.txt gains the panic, exhaustiveness and unsafe lints from the decision above, tests stay exempt, and the strict tier docs list them. rules_dx itself runs on strict.

    🤖 Generated with Claude Code

    https://claude.ai/code/session_01Xut2i1LBYg969L4ZJRMURT

  4. TrapsterDK commented on Nov 12, 2026

    @TrapsterDK
    CollaboratorAuthor

    Part 1 is #12403: strict tier carries every lint; rules_dx enforces the zero-violation ones; test/testonly crates exempt from the panic family; per-crate deny blocks dropped; guard //tools/ci:lint_attributes_test.

    Remaining, non-test violation counts (testonly excluded):

    • indexing_slicing ~2255, string_slice ~655, let_underscore_must_use ~439, wildcard_enum_match_arm ~196
    • panic ~176: cli/test_scratch, cli/gomod, cli/shim, cli/audit, cli/adopt, tools/ci/ci_workflow (deploy/private, tools/testing mostly testonly)
    • unsafe_code ~101 (cli/process 67, cli/cli 7, cli/worktree 5, cli/shim 4, more outside cli), undocumented_unsafe_blocks ~70
    • allow_attributes / allow_attributes_without_reason ~46: cli/plan, cli/cli, cli/process, cli/worktree, cli/audit, cli/generate, cli/depcheck, cli/update
    • exit ~4: tools/coverage/collect, tools/coverage/d, dotnet/private/coverage
    • Add each lint to .bazelrc once its count is zero; finally set families.rust to strict in dx.toml (also brings clippy::pedantic).

    🤖 Generated with Claude Code

    https://claude.ai/code/session_01Xut2hwH5AS7ytCaBAYwEtU

  5. TrapsterDK commented on Nov 12, 2026

    @TrapsterDK
    CollaboratorAuthor

    Part 2 is #12413: clippy::exit is zero and denied in .bazelrc (coverage collectors return Result; the Windows ctrl handler in cli/shim has #[expect(clippy::exit, reason = ...)]).

    Remaining:

    • allow_attributes / allow_attributes_without_reason ~46: cli/plan, cli/cli, cli/process, cli/worktree, cli/audit, cli/generate, cli/depcheck, cli/update
    • undocumented_unsafe_blocks ~70, unsafe_code ~101
    • wildcard_enum_match_arm, let_underscore_must_use, panic, string_slice, indexing_slicing
    • then families.rust = strict in dx.toml

    🤖 Generated with Claude Code

    https://claude.ai/code/session_01Xut2hwH5AS7ytCaBAYwEtU

  6. TrapsterDK commented on Nov 12, 2026

    @TrapsterDK
    CollaboratorAuthor

    PR #12434 handles the clippy/dead_code/unreachable allows in cli/plan, cli/cli, cli/process, cli/worktree, cli/audit, cli/generate, cli/depcheck and cli/update.

    Remaining allow_attributes work:

    • cfg_attr(not(unix|linux), allow(dead_code)) in cli/process (groups.rs, lifecycle.rs Group, lifecycle_unix.rs, slot_pool.rs), cli/worktree/host.rs and cli/cli/src/exec/stream_probe_tests.rs. These need Windows/macOS clippy to verify.
    • Outside cli: deploy/private (cloudflare.rs, npm.rs), core/quality/runner helm.rs, dotnet/private/coverage, api_spec tests, apple fake.rs, tools/docs extractors, tools/testing (nested, appcontainer), tools/ci/test_duplicates_test.rs, cli/shim/tests/support.
    • Then deny clippy::allow_attributes and allow_attributes_without_reason in .bazelrc.

    🤖 Generated with Claude Code

    https://claude.ai/code/session_01Xut2hwH5AS7ytCaBAYwEtU

  7. TrapsterDK commented on Nov 12, 2026

    @TrapsterDK
    CollaboratorAuthor

    PR #12445 turns the remaining plain allows (api_spec, apple, core/quality/runner helm, deploy, dotnet coverage, tools/ci, tools/docs, tools/testing/nested, cli/shim tests, cli/cli update tests) into reasoned expects.

    Remaining:

    • cfg_attr(not(unix|linux), allow(dead_code)) in cli/process, cli/worktree/host.rs, cli/cli/src/exec/stream_probe_tests.rs, tools/testing/nested/src/lib.rs (664, 817), tools/testing/hermetic/appcontainer/args.rs (need Windows/macOS clippy)
    • then deny clippy::allow_attributes and allow_attributes_without_reason in .bazelrc
    • undocumented_unsafe_blocks, unsafe_code, wildcard_enum_match_arm, let_underscore_must_use, panic, string_slice, indexing_slicing
    • then families.rust = strict in dx.toml

    🤖 Generated with Claude Code

    https://claude.ai/code/session_01Xut2hwH5AS7ytCaBAYwEtU

  8. TrapsterDK commented on Nov 13, 2026

    @TrapsterDK
    CollaboratorAuthor

    PR #12516 (draft) gates the remaining platform-only items with cfg (tests gated alike), turns the shared ones into reasoned cfg_attr(..., expect(dead_code)), and denies clippy::allow_attributes / allow_attributes_without_reason in .bazelrc. It needs a green Windows + macOS CI run before it leaves draft.

    Remaining:

    • undocumented_unsafe_blocks, unsafe_code
    • wildcard_enum_match_arm, let_underscore_must_use, panic, string_slice, indexing_slicing
    • then families.rust = strict in dx.toml

    🤖 Generated with Claude Code

    https://claude.ai/code/session_01Xut2hygW8NyPkC1Ea1mT4L

  9. 203 remaining items

  10. TrapsterDK commented on Nov 21, 2026

    @TrapsterDK
    CollaboratorAuthor

    cloud-claim 773b7f3b


    Generated by Claude Code

  11. added
    cloud-taken
    and removed
    cloud-pool
    on Nov 21, 2026
  12. TrapsterDK commented on Nov 21, 2026

    @TrapsterDK
    CollaboratorAuthor

    Next slice: #14590 clears missing_errors_doc in 12 small //cli crates (26 sites). Left in //cli outside //cli/cli: 611 sites, largest first adopt 74, audit 58, depcheck 56, module_bazel 51, update 46, output 38, archive 28, atomic_fs 28, process 27, exec_core 25 (count with --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect --output_groups=clippy_checks --@rules_rust//rust/settings:clippy_flag=-Dclippy::missing_errors_doc); then //cli/cli, too_many_lines, the sweep outside //cli, and families.rust tier strict in dx.toml.


    Generated by Claude Code

  13. added
    cloud-pool
    and removed
    cloud-taken
    on Nov 22, 2026
  14. TrapsterDK commented on Nov 22, 2026

    @TrapsterDK
    CollaboratorAuthor

    cloud-claim 6c09baa5


    Generated by Claude Code

  15. added
    cloud-taken
    and removed
    cloud-pool
    on Nov 22, 2026
  16. TrapsterDK commented on Nov 22, 2026

    @TrapsterDK
    CollaboratorAuthor

    Next slice: #14628 clears missing_errors_doc in //cli/depcheck (58) and //cli/module_bazel (51). Still left in //cli outside //cli/cli: adopt 74, audit 58, update 46, output 38, archive 28, atomic_fs 28, process 27, exec_core 25 and smaller crates. After that come //cli/cli, too_many_lines, the same sweep outside //cli, and families.rust tier strict in dx.toml.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2cloud-takenmodel:opus

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions