Skip to content

Deny std methods that panic on their arguments - #343

Merged
jadamcrain merged 2 commits into
mainfrom
deny-panicking-methods-lint
Oct 24, 2026
Merged

jadamcrain merged 2 commits into
mainfrom
deny-panicking-methods-lint

Conversation

@jadamcrain

Copy link
Copy Markdown
Member

The crate already denies unwrap, expect, indexing, unchecked arithmetic and the panic macros, but not std methods that panic on their arguments, such as copy_from_slice (lengths differ), split_at (index past the end), chunks (size zero) or Vec::remove (index out of bounds). No built-in Clippy lint covers those.

  • rodbus/clippy.toml lists 116 such methods under disallowed-methods, each with a reason naming the form that can't panic (split_at_checked, get/get_mut, as_chunks, pop_front, ...), and clippy::disallowed_methods is denied. The file explains what is left out on purpose: allocation, the tokio runtime precondition, lock poisoning, and methods that already return Option/Result. Each entry was checked to fire on a call.
  • The 15 uses left in test code are rewritten into those forms with the same meaning; production code had none left.

Test-only apart from the configuration; the test list is unchanged.

The disallowed-methods list applies to test code too. Split with
split_at_checked, read pairs with as_chunks, copy with zip, fill the
CRC bytes and consume the buffer model by skipping, so the tests
keep their meaning without the listed methods.
The panic lints catch unwrap, indexing and arithmetic but not std
methods such as copy_from_slice, split_at or Duration::new, which panic
when an argument is out of range. List them in clippy.toml with the
form that can't panic, and deny the lint in the crate.
@jadamcrain
jadamcrain enabled auto-merge October 24, 2026 01:49
@jadamcrain
jadamcrain added this pull request to the merge queue Oct 24, 2026
Merged via the queue into main with commit 7b8ab6a Oct 24, 2026
25 checks passed
@jadamcrain
jadamcrain deleted the deny-panicking-methods-lint branch October 24, 2026 01:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant