Skip to content

Error reading Clippy's configuration file when allow-panic-in-tests is included in the file #13112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
shanebishop opened this issue Jul 16, 2024 · 3 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@shanebishop
Copy link

shanebishop commented Jul 16, 2024

Summary

I want to be able to prevent calls to panic! in all code in my project, except in tests, using allow-panic-in-tests. However, when I add allow-panic-in-tests=true in my clippy.toml, I get this error: "error reading Clippy's configuration file: unknown field allow-panic-in-tests".

Lint Name

clippy::panic

Reproducer

I start a new project with:

cargo new --lib clippy-panic-in-test
cd clippy-panic-in-test

I replaced the contents of src/lib.rs with this code:

#[cfg(test)]
mod tests {
    #[test]
    fn it_works() {
        panic!("kaboom");
    }
}

I've configured Clippy by creating clippy.toml with:

allow-panic-in-tests=true

I saw this happen:

$ cargo clippy --tests -- -Dclippy::panic
    Checking clippy-panic-in-test v0.1.0 (/home/shane/src/tmp/clippy-panic-in-test)
error: error reading Clippy's configuration file: unknown field `allow-panic-in-tests`, expected one of
           absolute-paths-allowed-crates             enum-variant-name-threshold
           absolute-paths-max-segments               enum-variant-size-threshold
           accept-comment-above-attributes           excessive-nesting-threshold
           accept-comment-above-statement            future-size-threshold
           allow-comparison-to-zero                  ignore-interior-mutability
           allow-dbg-in-tests                        large-error-threshold
           allow-expect-in-tests                     literal-representation-threshold
           allow-mixed-uninlined-format-args         matches-for-let-else
           allow-one-hash-in-raw-strings             max-fn-params-bools
           allow-print-in-tests                      max-include-file-size
           allow-private-module-inception            max-struct-bools
           allow-unwrap-in-tests                     max-suggested-slice-pattern-length
           allowed-dotfiles                          max-trait-bounds
           allowed-duplicate-crates                  min-ident-chars-threshold
           allowed-idents-below-min-chars            missing-docs-in-crate-items
           allowed-prefixes                          msrv
           allowed-scripts                           pass-by-value-size-limit
           allowed-wildcard-imports                  pub-underscore-fields-behavior
           arithmetic-side-effects-allowed           semicolon-inside-block-ignore-singleline
           arithmetic-side-effects-allowed-binary    semicolon-outside-block-ignore-multiline
           arithmetic-side-effects-allowed-unary     single-char-binding-names-threshold
           array-size-threshold                      stack-size-threshold
           avoid-breaking-exported-api               standard-macro-braces
           await-holding-invalid-types               struct-field-name-threshold
           blacklisted-names                         suppress-restriction-lint-in-const
           cargo-ignore-publish                      third-party
           check-private-items                       too-large-for-stack
           cognitive-complexity-threshold            too-many-arguments-threshold
           cyclomatic-complexity-threshold           too-many-lines-threshold
           disallowed-macros                         trivial-copy-size-limit
           disallowed-methods                        type-complexity-threshold
           disallowed-names                          unnecessary-box-size
           disallowed-types                          unreadable-literal-lint-fractions
           doc-valid-idents                          upper-case-acronyms-aggressive
           enable-raw-pointer-heuristic-for-send     vec-box-size-threshold
           enforce-iter-loop-reborrow                verbose-bit-mask-threshold
           enforced-import-renames                   warn-on-all-wildcard-imports
 --> /home/shane/src/tmp/clippy-panic-in-test/clippy.toml:1:1
  |
1 | allow-panic-in-tests=true
  | ^^^^^^^^^^^^^^^^^^^^ help: perhaps you meant: `allow-print-in-tests`

error: could not compile `clippy-panic-in-test` (lib test) due to 1 previous error

I expected Clippy to not raise any errors, as allow-panic-in-tests is documented as supported here.

Version

rustc 1.79.0 (129f3b996 2024-06-10)
binary: rustc
commit-hash: 129f3b9964af4d4a709d1383930ade12dfe7c081
commit-date: 2024-06-10
host: x86_64-unknown-linux-gnu
release: 1.79.0
LLVM version: 18.1.7

Clippy version

$ cargo clippy --version
clippy 0.1.79 (129f3b9 2024-06-10)

Additional Labels

No response

@shanebishop shanebishop added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Jul 16, 2024
@shanebishop
Copy link
Author

shanebishop commented Jul 16, 2024

I noticed that https://rust-lang.github.io/rust-clippy/master/index.html#/panic documents allow-panic-in-tests, but https://rust-lang.github.io/rust-clippy/rust-1.79.0/index.html#/panic does not. Does this mean the allow-panic-in-tests configuration variable won't be available until the next release of Clippy?

@y21
Copy link
Member

y21 commented Jul 16, 2024

Yes, the PR that added allow-panic-in-tests (#12803) was merged in May, but 1.79 already branched off in April, so it didn't make it into that release. It will be in 1.80.

@shanebishop
Copy link
Author

Thanks @y21, I will close this issue then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

2 participants