mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-11 07:34:18 +00:00
Auto merge of #8080 - dswij:8019, r=giraffate
Fix FP on `question_mark` if returned object is not local Closes #8019 changelog: [`question_mark`] Fix FP when returned object is not local
This commit is contained in:
commit
f615ea474b
3 changed files with 39 additions and 1 deletions
|
@ -159,7 +159,7 @@ impl QuestionMark {
|
|||
fn expression_returns_unmodified_err(cx: &LateContext<'_>, expr: &Expr<'_>, cond_expr: &Expr<'_>) -> bool {
|
||||
match peel_blocks_with_stmt(expr).kind {
|
||||
ExprKind::Ret(Some(ret_expr)) => Self::expression_returns_unmodified_err(cx, ret_expr, cond_expr),
|
||||
ExprKind::Path(_) => path_to_local(expr) == path_to_local(cond_expr),
|
||||
ExprKind::Path(_) => path_to_local(expr).is_some() && path_to_local(expr) == path_to_local(cond_expr),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,6 +136,24 @@ fn result_func(x: Result<i32, i32>) -> Result<i32, i32> {
|
|||
Ok(y)
|
||||
}
|
||||
|
||||
// see issue #8019
|
||||
pub enum NotOption {
|
||||
None,
|
||||
First,
|
||||
AfterFirst,
|
||||
}
|
||||
|
||||
fn obj(_: i32) -> Result<(), NotOption> {
|
||||
Err(NotOption::First)
|
||||
}
|
||||
|
||||
fn f() -> NotOption {
|
||||
if obj(2).is_err() {
|
||||
return NotOption::None;
|
||||
}
|
||||
NotOption::First
|
||||
}
|
||||
|
||||
fn main() {
|
||||
some_func(Some(42));
|
||||
some_func(None);
|
||||
|
@ -157,4 +175,5 @@ fn main() {
|
|||
func();
|
||||
|
||||
let _ = result_func(Ok(42));
|
||||
let _ = f();
|
||||
}
|
||||
|
|
|
@ -168,6 +168,24 @@ fn result_func(x: Result<i32, i32>) -> Result<i32, i32> {
|
|||
Ok(y)
|
||||
}
|
||||
|
||||
// see issue #8019
|
||||
pub enum NotOption {
|
||||
None,
|
||||
First,
|
||||
AfterFirst,
|
||||
}
|
||||
|
||||
fn obj(_: i32) -> Result<(), NotOption> {
|
||||
Err(NotOption::First)
|
||||
}
|
||||
|
||||
fn f() -> NotOption {
|
||||
if obj(2).is_err() {
|
||||
return NotOption::None;
|
||||
}
|
||||
NotOption::First
|
||||
}
|
||||
|
||||
fn main() {
|
||||
some_func(Some(42));
|
||||
some_func(None);
|
||||
|
@ -189,4 +207,5 @@ fn main() {
|
|||
func();
|
||||
|
||||
let _ = result_func(Ok(42));
|
||||
let _ = f();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue