Ensuring correct lint message is output for Option and Result type
This commit is contained in:
parent
2b36017bad
commit
fe8c9d5965
@ -998,6 +998,7 @@ fn check_general_case(
|
||||
cx: &LateContext,
|
||||
name: &str,
|
||||
method_span: Span,
|
||||
self_expr: &hir::Expr,
|
||||
arg: &hir::Expr,
|
||||
span: Span,
|
||||
) {
|
||||
@ -1005,6 +1006,12 @@ fn check_general_case(
|
||||
return;
|
||||
}
|
||||
|
||||
let self_ty = cx.tables.expr_ty(self_expr);
|
||||
let closure = match match_type(cx, self_ty, &paths::OPTION) {
|
||||
true => "||",
|
||||
false => "|_|",
|
||||
};
|
||||
|
||||
// don't lint for constant values
|
||||
let owner_def = cx.tcx.hir.get_parent_did(arg.id);
|
||||
let promotable = cx.tcx.rvalue_promotable_map(owner_def).contains(&arg.hir_id.local_id);
|
||||
@ -1021,14 +1028,14 @@ fn check_general_case(
|
||||
span_replace_word,
|
||||
&format!("use of `{}` followed by a function call", name),
|
||||
"try this",
|
||||
format!("unwrap_or_else(|_| panic!({}))", sugg),
|
||||
format!("unwrap_or_else({} panic!({}))", closure, sugg),
|
||||
);
|
||||
}
|
||||
|
||||
if args.len() == 2 {
|
||||
match args[1].node {
|
||||
hir::ExprLit(_) => {},
|
||||
_ => check_general_case(cx, name, method_span, &args[1], expr.span),
|
||||
_ => check_general_case(cx, name, method_span, &args[0], &args[1], expr.span),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -427,7 +427,7 @@ error: use of `expect` followed by a function call
|
||||
--> $DIR/methods.rs:355:26
|
||||
|
|
||||
355 | with_none_and_format.expect(&format!("Error {}: fake error", error_code));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| panic!(&format!("Error {}: fake error", error_code)))`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!(&format!("Error {}: fake error", error_code)))`
|
||||
|
|
||||
= note: `-D expect-fun-call` implied by `-D warnings`
|
||||
|
||||
@ -435,7 +435,7 @@ error: use of `expect` followed by a function call
|
||||
--> $DIR/methods.rs:358:26
|
||||
|
|
||||
358 | with_none_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| panic!(format!("Error {}: fake error", error_code).as_str()))`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!(format!("Error {}: fake error", error_code).as_str()))`
|
||||
|
||||
error: use of `expect` followed by a function call
|
||||
--> $DIR/methods.rs:368:25
|
||||
|
Loading…
Reference in New Issue
Block a user