From a78271b8611d7ab7709976dfb94ae36b668ac42b Mon Sep 17 00:00:00 2001 From: Pierre-Andre Gagnon Date: Thu, 18 Feb 2021 17:32:55 -0500 Subject: [PATCH] Changed fn body suggestion msg --- clippy_lints/src/unnecessary_wraps.rs | 14 ++++++-------- tests/ui/unnecessary_wraps.rs | 18 ++++++++++++++++++ tests/ui/unnecessary_wraps.stderr | 14 +++++++------- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/clippy_lints/src/unnecessary_wraps.rs b/clippy_lints/src/unnecessary_wraps.rs index b097d531bc4..607585125a4 100644 --- a/clippy_lints/src/unnecessary_wraps.rs +++ b/clippy_lints/src/unnecessary_wraps.rs @@ -131,11 +131,12 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps { }); if can_sugg && !suggs.is_empty() { - let (lint_msg, return_type_suggestion_msg, return_type_suggestion) = if inner_type.is_unit() { + let (lint_msg, return_type_sugg_msg, return_type_sugg, body_sugg_msg) = if inner_type.is_unit() { ( "this function's return value is unnecessary".to_string(), "remove the return type...".to_string(), snippet(cx, fn_decl.output.span(), "..").to_string(), + "...and then remove returned values", ) } else { ( @@ -145,21 +146,18 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps { ), format!("remove `{}` from the return type...", return_type_label), inner_type.to_string(), + "...and then change returning expressions", ) }; span_lint_and_then(cx, UNNECESSARY_WRAPS, span, lint_msg.as_str(), |diag| { diag.span_suggestion( fn_decl.output.span(), - return_type_suggestion_msg.as_str(), - return_type_suggestion, - Applicability::MaybeIncorrect, - ); - diag.multipart_suggestion( - "...and then change the returning expressions", - suggs, + return_type_sugg_msg.as_str(), + return_type_sugg, Applicability::MaybeIncorrect, ); + diag.multipart_suggestion(body_sugg_msg, suggs, Applicability::MaybeIncorrect); }); } } diff --git a/tests/ui/unnecessary_wraps.rs b/tests/ui/unnecessary_wraps.rs index 5aaa99bbe5a..a510263e67d 100644 --- a/tests/ui/unnecessary_wraps.rs +++ b/tests/ui/unnecessary_wraps.rs @@ -141,6 +141,24 @@ fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> { } } +// should not be linted +fn issue_6640_3() -> Option<()> { + if true { + Some(()) + } else { + None + } +} + +// should not be linted +fn issue_6640_4() -> Result<(), ()> { + if true { + Ok(()) + } else { + Err(()) + } +} + fn main() { // method calls are not linted func1(true, true); diff --git a/tests/ui/unnecessary_wraps.stderr b/tests/ui/unnecessary_wraps.stderr index 40effb89499..9a861c61a46 100644 --- a/tests/ui/unnecessary_wraps.stderr +++ b/tests/ui/unnecessary_wraps.stderr @@ -15,7 +15,7 @@ help: remove `Option` from the return type... | LL | fn func1(a: bool, b: bool) -> i32 { | ^^^ -help: ...and then change the returning expressions +help: ...and then change returning expressions | LL | return 42; LL | } @@ -41,7 +41,7 @@ help: remove `Option` from the return type... | LL | fn func2(a: bool, b: bool) -> i32 { | ^^^ -help: ...and then change the returning expressions +help: ...and then change returning expressions | LL | return 10; LL | } @@ -63,7 +63,7 @@ help: remove `Option` from the return type... | LL | fn func5() -> i32 { | ^^^ -help: ...and then change the returning expressions +help: ...and then change returning expressions | LL | 1 | @@ -80,7 +80,7 @@ help: remove `Result` from the return type... | LL | fn func7() -> i32 { | ^^^ -help: ...and then change the returning expressions +help: ...and then change returning expressions | LL | 1 | @@ -97,7 +97,7 @@ help: remove `Option` from the return type... | LL | fn func12() -> i32 { | ^^^ -help: ...and then change the returning expressions +help: ...and then change returning expressions | LL | 1 | @@ -118,7 +118,7 @@ help: remove the return type... | LL | fn issue_6640_1(a: bool, b: bool) -> Option<()> { | ^^^^^^^^^^ -help: ...and then change the returning expressions +help: ...and then remove returned values | LL | return ; LL | } @@ -144,7 +144,7 @@ help: remove the return type... | LL | fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> { | ^^^^^^^^^^^^^^^ -help: ...and then change the returning expressions +help: ...and then remove returned values | LL | return ; LL | }