mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 23:34:48 +00:00
question_mark: don't add as_ref()
for a call expression
This commit is contained in:
parent
eb9c15a6b3
commit
f58bb5b234
@ -70,10 +70,12 @@ impl QuestionMark {
|
|||||||
replacement = Some(format!("Some({}?)", receiver_str));
|
replacement = Some(format!("Some({}?)", receiver_str));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if Self::moves_by_default(cx, subject) {
|
} else if Self::moves_by_default(cx, subject)
|
||||||
replacement = Some(format!("{}.as_ref()?;", receiver_str));
|
&& !matches!(subject.kind, ExprKind::Call(..) | ExprKind::MethodCall(..))
|
||||||
|
{
|
||||||
|
replacement = Some(format!("{}.as_ref()?;", receiver_str));
|
||||||
} else {
|
} else {
|
||||||
replacement = Some(format!("{}?;", receiver_str));
|
replacement = Some(format!("{}?;", receiver_str));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(replacement_str) = replacement {
|
if let Some(replacement_str) = replacement {
|
||||||
|
@ -93,6 +93,16 @@ impl MoveStruct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn func() -> Option<i32> {
|
||||||
|
fn f() -> Option<String> {
|
||||||
|
Some(String::new())
|
||||||
|
}
|
||||||
|
|
||||||
|
f()?;
|
||||||
|
|
||||||
|
Some(0)
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
some_func(Some(42));
|
some_func(Some(42));
|
||||||
some_func(None);
|
some_func(None);
|
||||||
@ -110,4 +120,6 @@ fn main() {
|
|||||||
|
|
||||||
let so = SeemsOption::Some(45);
|
let so = SeemsOption::Some(45);
|
||||||
returns_something_similar_to_option(so);
|
returns_something_similar_to_option(so);
|
||||||
|
|
||||||
|
func();
|
||||||
}
|
}
|
||||||
|
@ -121,6 +121,18 @@ impl MoveStruct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn func() -> Option<i32> {
|
||||||
|
fn f() -> Option<String> {
|
||||||
|
Some(String::new())
|
||||||
|
}
|
||||||
|
|
||||||
|
if f().is_none() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
Some(0)
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
some_func(Some(42));
|
some_func(Some(42));
|
||||||
some_func(None);
|
some_func(None);
|
||||||
@ -138,4 +150,6 @@ fn main() {
|
|||||||
|
|
||||||
let so = SeemsOption::Some(45);
|
let so = SeemsOption::Some(45);
|
||||||
returns_something_similar_to_option(so);
|
returns_something_similar_to_option(so);
|
||||||
|
|
||||||
|
func();
|
||||||
}
|
}
|
||||||
|
@ -92,5 +92,13 @@ LL | | return None;
|
|||||||
LL | | };
|
LL | | };
|
||||||
| |_________^ help: replace it with: `self.opt?`
|
| |_________^ help: replace it with: `self.opt?`
|
||||||
|
|
||||||
error: aborting due to 10 previous errors
|
error: this block may be rewritten with the `?` operator
|
||||||
|
--> $DIR/question_mark.rs:129:5
|
||||||
|
|
|
||||||
|
LL | / if f().is_none() {
|
||||||
|
LL | | return None;
|
||||||
|
LL | | }
|
||||||
|
| |_____^ help: replace it with: `f()?;`
|
||||||
|
|
||||||
|
error: aborting due to 11 previous errors
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user