-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
Summary
I have a codebase where I want to prevent the use of unwrap outside of tests (unitest, integration).
For that I tried to use the lint clippy::unwrap_unsed with the configuration allow-unwrap-in-tests=true.
That work for unit tests and in integration tests when the function have #[test] above it,
but do not work for helper functions that are a part of the integration test.
Lint Name
clippy::unwrap_unsed
Reproducer
I start a new project with:
cargo new --lib clippy-unwrap-in-integration-test
cd clippy-unwrap-in-integration-testI create an integration test in tests/foo.rs
fn helper() -> u32 { Some(42).unwrap() }
#[test]
fn test() {
let _ = helper();
let _ = Some(21).unwrap();
}I've configured clippy by creating clippy.toml with:
allow-unwrap-in-tests=trueThen with the clippy command:
cargo clippy --tests -- --deny=clippy::unwrap_usedI saw this happen:
Checking clippy-unwrap-in-integration-test v0.1.0 (/tmp/clippy-unwrap-in-integration-test)
error: used `unwrap()` on an `Option` value
--> tests/foo.rs:1:22
|
1 | fn helper() -> u32 { Some(42).unwrap() }
| ^^^^^^^^^^^^^^^^^
|
= help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_used
= note: requested on the command line with `-D clippy::unwrap-used`
error: could not compile `clippy-unwrap-in-integration-test` (test "foo") due to previous error
warning: build failed, waiting for other jobs to finish...I expected that clippy don't raise an error for the used unwrap in the function helper present in the integration test.
Version
rustc 1.70.0 (90c541806 2023-05-31)
binary: rustc
commit-hash: 90c541806f23a127002de5b4038be731ba1458ca
commit-date: 2023-05-31
host: x86_64-unknown-linux-gnu
release: 1.70.0
LLVM version: 16.0.2
Additional Labels
No response
FirelightFlagboy, jwodder, edmorley, sirewix, oxalica and 3 more
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have