From 262b35ea2c4dd9a16c28bf40cb5c124f664ce96c Mon Sep 17 00:00:00 2001 From: infrandomness Date: Fri, 8 Apr 2022 20:07:19 +0200 Subject: [PATCH 1/9] Introduce option_take_on_temporary lints This lint checks if Option::take() is used on a temporary value (a value that is not of type &mut Option and that is not a Place expression) to suggest omitting take() --- CHANGELOG.md | 1 + clippy_lints/src/lib.register_all.rs | 1 + clippy_lints/src/lib.register_complexity.rs | 1 + clippy_lints/src/lib.register_lints.rs | 1 + clippy_lints/src/lib.register_suspicious.rs | 1 + clippy_lints/src/methods/mod.rs | 21 +++++++++++++++++ .../src/methods/needless_option_take.rs | 23 +++++++++++++++++++ tests/ui/needless_option_take.fixed | 15 ++++++++++++ tests/ui/needless_option_take.rs | 5 ++++ tests/ui/needless_option_take.stderr | 10 ++++++++ 10 files changed, 79 insertions(+) create mode 100644 clippy_lints/src/methods/needless_option_take.rs create mode 100644 tests/ui/needless_option_take.fixed create mode 100644 tests/ui/needless_option_take.rs create mode 100644 tests/ui/needless_option_take.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index 858547c84c18..d4096ca89df8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3473,6 +3473,7 @@ Released 2018-09-13 [`needless_lifetimes`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes [`needless_match`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_match [`needless_option_as_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_option_as_deref +[`needless_option_take`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_option_take [`needless_pass_by_value`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_value [`needless_question_mark`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_question_mark [`needless_range_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_range_loop diff --git a/clippy_lints/src/lib.register_all.rs b/clippy_lints/src/lib.register_all.rs index 52c440de9dd4..84e3176c0030 100644 --- a/clippy_lints/src/lib.register_all.rs +++ b/clippy_lints/src/lib.register_all.rs @@ -183,6 +183,7 @@ LintId::of(methods::MAP_FLATTEN), LintId::of(methods::MAP_IDENTITY), LintId::of(methods::NEEDLESS_OPTION_AS_DEREF), + LintId::of(methods::NEEDLESS_OPTION_TAKE), LintId::of(methods::NEEDLESS_SPLITN), LintId::of(methods::NEW_RET_NO_SELF), LintId::of(methods::OK_EXPECT), diff --git a/clippy_lints/src/lib.register_complexity.rs b/clippy_lints/src/lib.register_complexity.rs index 10369a855ae6..2f6ebd445ebd 100644 --- a/clippy_lints/src/lib.register_complexity.rs +++ b/clippy_lints/src/lib.register_complexity.rs @@ -45,6 +45,7 @@ LintId::of(methods::MAP_FLATTEN), LintId::of(methods::MAP_IDENTITY), LintId::of(methods::NEEDLESS_OPTION_AS_DEREF), + LintId::of(methods::NEEDLESS_OPTION_TAKE), LintId::of(methods::NEEDLESS_SPLITN), LintId::of(methods::OPTION_AS_REF_DEREF), LintId::of(methods::OPTION_FILTER_MAP), diff --git a/clippy_lints/src/lib.register_lints.rs b/clippy_lints/src/lib.register_lints.rs index cfaa6871b50b..aa9435f3b59a 100644 --- a/clippy_lints/src/lib.register_lints.rs +++ b/clippy_lints/src/lib.register_lints.rs @@ -322,6 +322,7 @@ methods::MAP_IDENTITY, methods::MAP_UNWRAP_OR, methods::NEEDLESS_OPTION_AS_DEREF, + methods::NEEDLESS_OPTION_TAKE, methods::NEEDLESS_SPLITN, methods::NEW_RET_NO_SELF, methods::OK_EXPECT, diff --git a/clippy_lints/src/lib.register_suspicious.rs b/clippy_lints/src/lib.register_suspicious.rs index 82f45b5fd58b..6588ca4a4a71 100644 --- a/clippy_lints/src/lib.register_suspicious.rs +++ b/clippy_lints/src/lib.register_suspicious.rs @@ -22,6 +22,7 @@ LintId::of(loops::EMPTY_LOOP), LintId::of(loops::FOR_LOOPS_OVER_FALLIBLES), LintId::of(loops::MUT_RANGE_BOUND), + LintId::of(methods::OPTION_TAKE_ON_TEMPORARY), LintId::of(methods::SUSPICIOUS_MAP), LintId::of(mut_key::MUTABLE_KEY_TYPE), LintId::of(octal_escapes::OCTAL_ESCAPES), diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 82f4769a6997..3d4c193691af 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -43,6 +43,7 @@ mod map_identity; mod map_unwrap_or; mod needless_option_as_deref; +mod needless_option_take; mod ok_expect; mod option_as_ref_deref; mod option_map_or_none; @@ -2162,6 +2163,24 @@ "use of `char::is_digit(..)` with literal radix of 10 or 16" } +declare_clippy_lint! { + /// + /// ### Why is this bad? + /// + /// ### Example + /// ```rust + /// // example code where clippy issues a warning + /// ``` + /// Use instead: + /// ```rust + /// // example code which does not raise clippy warning + /// ``` + #[clippy::version = "1.61.0"] + pub NEEDLESS_OPTION_TAKE, + suspicious, + "using `.as_ref().take()` on a temporary value" +} + pub struct Methods { avoid_breaking_exported_api: bool, msrv: Option, @@ -2251,6 +2270,7 @@ pub fn new(avoid_breaking_exported_api: bool, msrv: Option) -> Sel ERR_EXPECT, NEEDLESS_OPTION_AS_DEREF, IS_DIGIT_ASCII_RADIX, + NEEDLESS_OPTION_TAKE, ]); /// Extracts a method call name, args, and `Span` of the method name. @@ -2623,6 +2643,7 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio } } }, + ("take", []) => needless_option_take::check(cx, expr, recv), ("to_os_string" | "to_owned" | "to_path_buf" | "to_vec", []) => { implicit_clone::check(cx, name, expr, recv); }, diff --git a/clippy_lints/src/methods/needless_option_take.rs b/clippy_lints/src/methods/needless_option_take.rs new file mode 100644 index 000000000000..b3696273e1d0 --- /dev/null +++ b/clippy_lints/src/methods/needless_option_take.rs @@ -0,0 +1,23 @@ +use clippy_utils::diagnostics::span_lint; +use clippy_utils::ty::is_type_diagnostic_item; +use rustc_hir::Expr; +use rustc_lint::LateContext; +use rustc_span::sym::Result as sym_result; + +use super::NEEDLESS_OPTION_TAKE; + +pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, recv: &'tcx Expr<'_>) { + if_chain! { + if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym_result); + let result_type = cx.typeck_results().expr_ty(recv); + + then { + span_lint( + cx, + NEEDLESS_OPTION_TAKE, + expr.span, + "Format test" + ); + } + }; +} diff --git a/tests/ui/needless_option_take.fixed b/tests/ui/needless_option_take.fixed new file mode 100644 index 000000000000..29691e81666f --- /dev/null +++ b/tests/ui/needless_option_take.fixed @@ -0,0 +1,15 @@ +// run-rustfix + +fn main() { + println!("Testing non erroneous option_take_on_temporary"); + let mut option = Some(1); + let _ = Box::new(move || option.take().unwrap()); + + println!("Testing non erroneous option_take_on_temporary"); + let x = Some(3); + x.as_ref(); + + println!("Testing erroneous option_take_on_temporary"); + let x = Some(3); + x.as_ref(); +} diff --git a/tests/ui/needless_option_take.rs b/tests/ui/needless_option_take.rs new file mode 100644 index 000000000000..2b32b9467f50 --- /dev/null +++ b/tests/ui/needless_option_take.rs @@ -0,0 +1,5 @@ +fn main() { + println!("Testing option_take_on_temporary"); + let x = Some(3); + let y = x.as_ref().take(); +} diff --git a/tests/ui/needless_option_take.stderr b/tests/ui/needless_option_take.stderr new file mode 100644 index 000000000000..cb3bf015b369 --- /dev/null +++ b/tests/ui/needless_option_take.stderr @@ -0,0 +1,10 @@ +error: called `Option::take()` on a temporary value + --> $DIR/needless_option_take.rs:14:5 + | +LL | x.as_ref().take(); + | ^^^^^^^^^^^^^^^^^ help: try: `x.as_ref()` + | + = note: `-D clippy::needless-option-take` implied by `-D warnings` + +error: aborting due to previous error + From ee9281d7a241c448f6bcbbb6cb8bdf8b17251a92 Mon Sep 17 00:00:00 2001 From: infrandomness Date: Fri, 8 Apr 2022 21:27:01 +0200 Subject: [PATCH 2/9] Implement checks to the expression The implemented checks are for checking if the expression is either of type `Option` and isn't a syntactical place --- .../src/methods/needless_option_take.rs | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/methods/needless_option_take.rs b/clippy_lints/src/methods/needless_option_take.rs index b3696273e1d0..27ef90093289 100644 --- a/clippy_lints/src/methods/needless_option_take.rs +++ b/clippy_lints/src/methods/needless_option_take.rs @@ -2,15 +2,17 @@ use clippy_utils::ty::is_type_diagnostic_item; use rustc_hir::Expr; use rustc_lint::LateContext; -use rustc_span::sym::Result as sym_result; +use rustc_span::sym; use super::NEEDLESS_OPTION_TAKE; -pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, recv: &'tcx Expr<'_>) { - if_chain! { - if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym_result); - let result_type = cx.typeck_results().expr_ty(recv); - +pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, _recv: &'tcx Expr<'_>) { + // Checks if expression type is equal to sym::Option and if the expr is not a syntactic place + if is_expr_option(cx, expr) && !expr.is_syntactic_place_expr() { + span_lint(cx, OPTION_TAKE_ON_TEMPORARY, expr.span, "Format test"); + } + /* if_chain! { + is_expr_option(cx, expr); then { span_lint( cx, @@ -19,5 +21,10 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, recv: &' "Format test" ); } - }; + };*/ +} + +fn is_expr_option(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { + let expr_type = cx.typeck_results().expr_ty(expr); + is_type_diagnostic_item(cx, expr_type, sym::Option) } From f8f144117da48b52f2c65292402dedcb1c59d9c1 Mon Sep 17 00:00:00 2001 From: infrandomness Date: Fri, 8 Apr 2022 21:54:44 +0200 Subject: [PATCH 3/9] Swap span_lint for span_lint_and_sugg This implements a machine applicable suggestion to any matched usage of `.as_ref().take()`` --- .../src/methods/needless_option_take.rs | 31 ++++++++++--------- tests/ui/needless_option_take.rs | 2 ++ tests/ui/option_take_on_temporary.fixed | 7 +++++ 3 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 tests/ui/option_take_on_temporary.fixed diff --git a/clippy_lints/src/methods/needless_option_take.rs b/clippy_lints/src/methods/needless_option_take.rs index 27ef90093289..57a43ff606a5 100644 --- a/clippy_lints/src/methods/needless_option_take.rs +++ b/clippy_lints/src/methods/needless_option_take.rs @@ -1,27 +1,30 @@ -use clippy_utils::diagnostics::span_lint; +use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::is_type_diagnostic_item; +use rustc_errors::Applicability; use rustc_hir::Expr; use rustc_lint::LateContext; use rustc_span::sym; use super::NEEDLESS_OPTION_TAKE; -pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, _recv: &'tcx Expr<'_>) { +pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, recv: &'tcx Expr<'_>) { // Checks if expression type is equal to sym::Option and if the expr is not a syntactic place if is_expr_option(cx, expr) && !expr.is_syntactic_place_expr() { - span_lint(cx, OPTION_TAKE_ON_TEMPORARY, expr.span, "Format test"); + let mut applicability = Applicability::MachineApplicable; + span_lint_and_sugg( + cx, + NEEDLESS_OPTION_TAKE, + expr.span, + "Called `Option::take()` on a temporary value", + "try", + format!( + "{}", + snippet_with_applicability(cx, recv.span, "..", &mut applicability) + ), + applicability, + ); } - /* if_chain! { - is_expr_option(cx, expr); - then { - span_lint( - cx, - NEEDLESS_OPTION_TAKE, - expr.span, - "Format test" - ); - } - };*/ } fn is_expr_option(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { diff --git a/tests/ui/needless_option_take.rs b/tests/ui/needless_option_take.rs index 2b32b9467f50..eb57ffeab453 100644 --- a/tests/ui/needless_option_take.rs +++ b/tests/ui/needless_option_take.rs @@ -1,3 +1,5 @@ +// run-rustfix + fn main() { println!("Testing option_take_on_temporary"); let x = Some(3); diff --git a/tests/ui/option_take_on_temporary.fixed b/tests/ui/option_take_on_temporary.fixed new file mode 100644 index 000000000000..9b4ca5a4ad16 --- /dev/null +++ b/tests/ui/option_take_on_temporary.fixed @@ -0,0 +1,7 @@ +// run-rustfix + +fn main() { + println!("Testing option_take_on_temporary"); + let x = Some(3); + let y = x.as_ref(); +} From cf83e18106160382cd86cc8b35add250373491b6 Mon Sep 17 00:00:00 2001 From: infrandomness Date: Fri, 8 Apr 2022 21:59:59 +0200 Subject: [PATCH 4/9] Swap the category of the lint This changes the lint from the suspicious category to the complexity category --- clippy_lints/src/lib.register_suspicious.rs | 1 - clippy_lints/src/methods/mod.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/clippy_lints/src/lib.register_suspicious.rs b/clippy_lints/src/lib.register_suspicious.rs index 6588ca4a4a71..82f45b5fd58b 100644 --- a/clippy_lints/src/lib.register_suspicious.rs +++ b/clippy_lints/src/lib.register_suspicious.rs @@ -22,7 +22,6 @@ LintId::of(loops::EMPTY_LOOP), LintId::of(loops::FOR_LOOPS_OVER_FALLIBLES), LintId::of(loops::MUT_RANGE_BOUND), - LintId::of(methods::OPTION_TAKE_ON_TEMPORARY), LintId::of(methods::SUSPICIOUS_MAP), LintId::of(mut_key::MUTABLE_KEY_TYPE), LintId::of(octal_escapes::OCTAL_ESCAPES), diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 3d4c193691af..36844b3609b9 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -2177,7 +2177,7 @@ /// ``` #[clippy::version = "1.61.0"] pub NEEDLESS_OPTION_TAKE, - suspicious, + complexity, "using `.as_ref().take()` on a temporary value" } From 8b2b343b23c50e136e14c303f2579ae2a2fda5f2 Mon Sep 17 00:00:00 2001 From: infrandomness Date: Sat, 9 Apr 2022 18:35:18 +0200 Subject: [PATCH 5/9] Delete unused variable `y` in test This fixes the errors occuring while running the ui tests --- tests/ui/needless_option_take.rs | 2 +- tests/ui/option_take_on_temporary.fixed | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ui/needless_option_take.rs b/tests/ui/needless_option_take.rs index eb57ffeab453..27cc9a2e61e7 100644 --- a/tests/ui/needless_option_take.rs +++ b/tests/ui/needless_option_take.rs @@ -3,5 +3,5 @@ fn main() { println!("Testing option_take_on_temporary"); let x = Some(3); - let y = x.as_ref().take(); + x.as_ref().take(); } diff --git a/tests/ui/option_take_on_temporary.fixed b/tests/ui/option_take_on_temporary.fixed index 9b4ca5a4ad16..7e2930766824 100644 --- a/tests/ui/option_take_on_temporary.fixed +++ b/tests/ui/option_take_on_temporary.fixed @@ -3,5 +3,5 @@ fn main() { println!("Testing option_take_on_temporary"); let x = Some(3); - let y = x.as_ref(); + x.as_ref(); } From b52bc9b96bb3b22b4ab4a793e3706e7a9b718952 Mon Sep 17 00:00:00 2001 From: infrandomness Date: Sun, 10 Apr 2022 10:59:43 +0200 Subject: [PATCH 6/9] Swap type checked expression Instead of type checking the entire expression (causing a false positive), only type check for a subset of the expression (the receiver of the matched function: `take()`) --- clippy_lints/src/methods/needless_option_take.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/methods/needless_option_take.rs b/clippy_lints/src/methods/needless_option_take.rs index 57a43ff606a5..297d83e9e37d 100644 --- a/clippy_lints/src/methods/needless_option_take.rs +++ b/clippy_lints/src/methods/needless_option_take.rs @@ -10,7 +10,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, recv: &'tcx Expr<'_>) { // Checks if expression type is equal to sym::Option and if the expr is not a syntactic place - if is_expr_option(cx, expr) && !expr.is_syntactic_place_expr() { + if is_expr_option(cx, recv) && !recv.is_syntactic_place_expr() { let mut applicability = Applicability::MachineApplicable; span_lint_and_sugg( cx, From 76268c0d5590ca06129722fed4afb306a847caab Mon Sep 17 00:00:00 2001 From: infrandomness Date: Sun, 10 Apr 2022 23:42:33 +0200 Subject: [PATCH 7/9] Introduce new lint check This checks if the expression has one of `core`, `option`, `Option` or `as_ref` in its path, this avoids false positives --- clippy_lints/src/methods/needless_option_take.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/methods/needless_option_take.rs b/clippy_lints/src/methods/needless_option_take.rs index 297d83e9e37d..5596515637e5 100644 --- a/clippy_lints/src/methods/needless_option_take.rs +++ b/clippy_lints/src/methods/needless_option_take.rs @@ -1,4 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::match_def_path; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::is_type_diagnostic_item; use rustc_errors::Applicability; @@ -10,7 +11,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, recv: &'tcx Expr<'_>) { // Checks if expression type is equal to sym::Option and if the expr is not a syntactic place - if is_expr_option(cx, recv) && !recv.is_syntactic_place_expr() { + if !recv.is_syntactic_place_expr() && is_expr_option(cx, recv) && has_expr_as_ref_path(cx, recv) { let mut applicability = Applicability::MachineApplicable; span_lint_and_sugg( cx, @@ -31,3 +32,10 @@ fn is_expr_option(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { let expr_type = cx.typeck_results().expr_ty(expr); is_type_diagnostic_item(cx, expr_type, sym::Option) } + +fn has_expr_as_ref_path(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { + if let Some(ref_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) { + return match_def_path(cx, ref_id, &["core", "option", "Option", "as_ref"]); + } + false +} From 822993675ff45d5b4b2f0a310c65d4abd1aef20a Mon Sep 17 00:00:00 2001 From: infrandomness Date: Mon, 11 Apr 2022 17:15:53 +0200 Subject: [PATCH 8/9] Modify lint description --- clippy_lints/src/methods/needless_option_take.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/methods/needless_option_take.rs b/clippy_lints/src/methods/needless_option_take.rs index 5596515637e5..829c118d2916 100644 --- a/clippy_lints/src/methods/needless_option_take.rs +++ b/clippy_lints/src/methods/needless_option_take.rs @@ -17,7 +17,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, recv: &' cx, NEEDLESS_OPTION_TAKE, expr.span, - "Called `Option::take()` on a temporary value", + "called `Option::take()` on a temporary value", "try", format!( "{}", From 2903b56f177b2b23db62d6bf2d500837d704fb4e Mon Sep 17 00:00:00 2001 From: infrandomness Date: Tue, 12 Apr 2022 19:34:55 +0200 Subject: [PATCH 9/9] 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 --- clippy_lints/src/methods/mod.rs | 6 ++++-- tests/ui/needless_option_take.rs | 10 +++++++++- tests/ui/option_take_on_temporary.fixed | 10 +++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 36844b3609b9..48fa30ba9295 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -2169,11 +2169,13 @@ /// /// ### Example /// ```rust - /// // example code where clippy issues a warning + /// let x = Some(3); + /// x.as_ref().take(); /// ``` /// Use instead: /// ```rust - /// // example code which does not raise clippy warning + /// let x = Some(3); + /// x.as_ref(); /// ``` #[clippy::version = "1.61.0"] pub NEEDLESS_OPTION_TAKE, diff --git a/tests/ui/needless_option_take.rs b/tests/ui/needless_option_take.rs index 27cc9a2e61e7..9f4109eb4635 100644 --- a/tests/ui/needless_option_take.rs +++ b/tests/ui/needless_option_take.rs @@ -1,7 +1,15 @@ // run-rustfix fn main() { - println!("Testing option_take_on_temporary"); + println!("Testing non erroneous option_take_on_temporary"); + let mut option = Some(1); + let _ = Box::new(move || option.take().unwrap()); + + println!("Testing non erroneous option_take_on_temporary"); + let x = Some(3); + x.as_ref(); + + println!("Testing erroneous option_take_on_temporary"); let x = Some(3); x.as_ref().take(); } diff --git a/tests/ui/option_take_on_temporary.fixed b/tests/ui/option_take_on_temporary.fixed index 7e2930766824..29691e81666f 100644 --- a/tests/ui/option_take_on_temporary.fixed +++ b/tests/ui/option_take_on_temporary.fixed @@ -1,7 +1,15 @@ // run-rustfix fn main() { - println!("Testing option_take_on_temporary"); + println!("Testing non erroneous option_take_on_temporary"); + let mut option = Some(1); + let _ = Box::new(move || option.take().unwrap()); + + println!("Testing non erroneous option_take_on_temporary"); + let x = Some(3); + x.as_ref(); + + println!("Testing erroneous option_take_on_temporary"); let x = Some(3); x.as_ref(); }