Repository navigation
Deny std methods that panic on their arguments - #343
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The crate already denies
unwrap,expect, indexing, unchecked arithmetic and the panic macros, but not std methods that panic on their arguments, such ascopy_from_slice(lengths differ),split_at(index past the end),chunks(size zero) orVec::remove(index out of bounds). No built-in Clippy lint covers those.rodbus/clippy.tomllists 116 such methods underdisallowed-methods, each with a reason naming the form that can't panic (split_at_checked,get/get_mut,as_chunks,pop_front, ...), andclippy::disallowed_methodsis denied. The file explains what is left out on purpose: allocation, the tokio runtime precondition, lock poisoning, and methods that already returnOption/Result. Each entry was checked to fire on a call.Test-only apart from the configuration; the test list is unchanged.