From a91ec594601cc1b3e11cf110a403c54ae826044b Mon Sep 17 00:00:00 2001 From: dswij <dswijj@gmail.com> Date: Fri, 22 Oct 2021 13:43:21 +0800 Subject: [PATCH] Update `question_mark` expected test output --- tests/ui/question_mark.fixed | 25 ++++++++++++++++++++++--- tests/ui/question_mark.stderr | 28 ++++++++++++++-------------- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/tests/ui/question_mark.fixed b/tests/ui/question_mark.fixed index ccb2e5a302e..060ea8c8c54 100644 --- a/tests/ui/question_mark.fixed +++ b/tests/ui/question_mark.fixed @@ -2,6 +2,9 @@ #![allow(unreachable_code)] #![allow(clippy::unnecessary_wraps)] +use std::env; +use std::path::PathBuf; + fn some_func(a: Option<u32>) -> Option<u32> { a?; @@ -104,18 +107,34 @@ fn func() -> Option<i32> { Some(0) } -fn result_func(x: Result<i32, &str>) -> Result<i32, &str> { +fn func_returning_result() -> Result<i32, String> { + Ok(1) +} + +fn result_func(x: Result<i32, String>) -> Result<i32, String> { let _ = x?; - x?; + x.as_ref()?; // No warning let y = if let Ok(x) = x { x } else { - return Err("some error"); + return Err("some error".to_string()); }; + // issue #7859 + // no warning + let _ = if let Ok(x) = func_returning_result() { + x + } else { + return Err("some error".to_string()); + }; + + if func_returning_result().is_err() { + return func_returning_result(); + } + Ok(y) } diff --git a/tests/ui/question_mark.stderr b/tests/ui/question_mark.stderr index 161588cb73c..8eee7f8cb18 100644 --- a/tests/ui/question_mark.stderr +++ b/tests/ui/question_mark.stderr @@ -1,5 +1,5 @@ error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:6:5 + --> $DIR/question_mark.rs:9:5 | LL | / if a.is_none() { LL | | return None; @@ -9,7 +9,7 @@ LL | | } = note: `-D clippy::question-mark` implied by `-D warnings` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:51:9 + --> $DIR/question_mark.rs:54:9 | LL | / if (self.opt).is_none() { LL | | return None; @@ -17,7 +17,7 @@ LL | | } | |_________^ help: replace it with: `(self.opt)?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:55:9 + --> $DIR/question_mark.rs:58:9 | LL | / if self.opt.is_none() { LL | | return None @@ -25,7 +25,7 @@ LL | | } | |_________^ help: replace it with: `self.opt?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:59:17 + --> $DIR/question_mark.rs:62:17 | LL | let _ = if self.opt.is_none() { | _________________^ @@ -36,7 +36,7 @@ LL | | }; | |_________^ help: replace it with: `Some(self.opt?)` error: this if-let-else may be rewritten with the `?` operator - --> $DIR/question_mark.rs:65:17 + --> $DIR/question_mark.rs:68:17 | LL | let _ = if let Some(x) = self.opt { | _________________^ @@ -47,7 +47,7 @@ LL | | }; | |_________^ help: replace it with: `self.opt?` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:82:9 + --> $DIR/question_mark.rs:85:9 | LL | / if self.opt.is_none() { LL | | return None; @@ -55,7 +55,7 @@ LL | | } | |_________^ help: replace it with: `self.opt.as_ref()?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:90:9 + --> $DIR/question_mark.rs:93:9 | LL | / if self.opt.is_none() { LL | | return None; @@ -63,7 +63,7 @@ LL | | } | |_________^ help: replace it with: `self.opt.as_ref()?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:98:9 + --> $DIR/question_mark.rs:101:9 | LL | / if self.opt.is_none() { LL | | return None; @@ -71,7 +71,7 @@ LL | | } | |_________^ help: replace it with: `self.opt.as_ref()?;` error: this if-let-else may be rewritten with the `?` operator - --> $DIR/question_mark.rs:105:26 + --> $DIR/question_mark.rs:108:26 | LL | let v: &Vec<_> = if let Some(ref v) = self.opt { | __________________________^ @@ -82,7 +82,7 @@ LL | | }; | |_________^ help: replace it with: `self.opt.as_ref()?` error: this if-let-else may be rewritten with the `?` operator - --> $DIR/question_mark.rs:115:17 + --> $DIR/question_mark.rs:118:17 | LL | let v = if let Some(v) = self.opt { | _________________^ @@ -93,7 +93,7 @@ LL | | }; | |_________^ help: replace it with: `self.opt?` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:130:5 + --> $DIR/question_mark.rs:133:5 | LL | / if f().is_none() { LL | | return None; @@ -101,18 +101,18 @@ LL | | } | |_____^ help: replace it with: `f()?;` error: this if-let-else may be rewritten with the `?` operator - --> $DIR/question_mark.rs:138:13 + --> $DIR/question_mark.rs:145:13 | LL | let _ = if let Ok(x) = x { x } else { return x }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `x?` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:140:5 + --> $DIR/question_mark.rs:147:5 | LL | / if x.is_err() { LL | | return x; LL | | } - | |_____^ help: replace it with: `x?;` + | |_____^ help: replace it with: `x.as_ref()?;` error: aborting due to 13 previous errors