Skip to content

Commit 2903b56

Browse files
committed
Add tests and docs
This adds test to make sure correct behavior of lint - The first test's option variable is not a temporary variable - The second test does not make usage of `take()` - The third test makes usage of `take()` and uses a temporary variable
1 parent 8229936 commit 2903b56

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

clippy_lints/src/methods/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -2169,11 +2169,13 @@ declare_clippy_lint! {
21692169
///
21702170
/// ### Example
21712171
/// ```rust
2172-
/// // example code where clippy issues a warning
2172+
/// let x = Some(3);
2173+
/// x.as_ref().take();
21732174
/// ```
21742175
/// Use instead:
21752176
/// ```rust
2176-
/// // example code which does not raise clippy warning
2177+
/// let x = Some(3);
2178+
/// x.as_ref();
21772179
/// ```
21782180
#[clippy::version = "1.61.0"]
21792181
pub NEEDLESS_OPTION_TAKE,

tests/ui/needless_option_take.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
// run-rustfix
22

33
fn main() {
4-
println!("Testing option_take_on_temporary");
4+
println!("Testing non erroneous option_take_on_temporary");
5+
let mut option = Some(1);
6+
let _ = Box::new(move || option.take().unwrap());
7+
8+
println!("Testing non erroneous option_take_on_temporary");
9+
let x = Some(3);
10+
x.as_ref();
11+
12+
println!("Testing erroneous option_take_on_temporary");
513
let x = Some(3);
614
x.as_ref().take();
715
}
+9-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
// run-rustfix
22

33
fn main() {
4-
println!("Testing option_take_on_temporary");
4+
println!("Testing non erroneous option_take_on_temporary");
5+
let mut option = Some(1);
6+
let _ = Box::new(move || option.take().unwrap());
7+
8+
println!("Testing non erroneous option_take_on_temporary");
9+
let x = Some(3);
10+
x.as_ref();
11+
12+
println!("Testing erroneous option_take_on_temporary");
513
let x = Some(3);
614
x.as_ref();
715
}

0 commit comments

Comments
 (0)