Skip to content

Commit f7b2098

Browse files
committed
Fix a false positive in unnecessary_wraps
1 parent 7a73a25 commit f7b2098

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3878,7 +3878,7 @@ fn is_bool(ty: &hir::Ty<'_>) -> bool {
38783878
}
38793879

38803880
// Returns `true` if `expr` contains a return expression
3881-
fn contains_return(expr: &hir::Expr<'_>) -> bool {
3881+
pub(crate) fn contains_return(expr: &hir::Expr<'_>) -> bool {
38823882
struct RetCallFinder {
38833883
found: bool,
38843884
}

clippy_lints/src/unnecessary_wraps.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::methods::contains_return;
12
use crate::utils::{
23
in_macro, is_type_diagnostic_item, match_qpath, paths, return_ty, snippet, span_lint_and_then,
34
visitors::find_all_ret_expressions,
@@ -95,6 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps {
9596
if let ExprKind::Path(ref qpath) = func.kind;
9697
if match_qpath(qpath, path);
9798
if args.len() == 1;
99+
if !contains_return(&args[0]);
98100
then {
99101
suggs.push((ret_expr.span, snippet(cx, args[0].span.source_callsite(), "..").to_string()));
100102
true

tests/ui/unnecessary_wraps.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ impl B for A {
109109
}
110110
}
111111

112+
fn issue_6384(s: &str) -> Option<&str> {
113+
Some(match s {
114+
"a" => "A",
115+
_ => return None,
116+
})
117+
}
118+
112119
fn main() {
113120
// method calls are not linted
114121
func1(true, true);

0 commit comments

Comments
 (0)