File tree 4 files changed +40
-4
lines changed
4 files changed +40
-4
lines changed Original file line number Diff line number Diff line change @@ -70,10 +70,12 @@ impl QuestionMark {
70
70
replacement = Some ( format!( "Some({}?)" , receiver_str) ) ;
71
71
}
72
72
}
73
- } else if Self :: moves_by_default( cx, subject) {
74
- replacement = Some ( format!( "{}.as_ref()?;" , receiver_str) ) ;
73
+ } else if Self :: moves_by_default( cx, subject)
74
+ && !matches!( subject. kind, ExprKind :: Call ( ..) | ExprKind :: MethodCall ( ..) )
75
+ {
76
+ replacement = Some ( format!( "{}.as_ref()?;" , receiver_str) ) ;
75
77
} else {
76
- replacement = Some ( format!( "{}?;" , receiver_str) ) ;
78
+ replacement = Some ( format!( "{}?;" , receiver_str) ) ;
77
79
}
78
80
79
81
if let Some ( replacement_str) = replacement {
Original file line number Diff line number Diff line change @@ -93,6 +93,16 @@ impl MoveStruct {
93
93
}
94
94
}
95
95
96
+ fn func() -> Option<i32> {
97
+ fn f() -> Option<String> {
98
+ Some(String::new())
99
+ }
100
+
101
+ f()?;
102
+
103
+ Some(0)
104
+ }
105
+
96
106
fn main() {
97
107
some_func(Some(42));
98
108
some_func(None);
@@ -110,4 +120,6 @@ fn main() {
110
120
111
121
let so = SeemsOption::Some(45);
112
122
returns_something_similar_to_option(so);
123
+
124
+ func();
113
125
}
Original file line number Diff line number Diff line change @@ -121,6 +121,18 @@ impl MoveStruct {
121
121
}
122
122
}
123
123
124
+ fn func ( ) -> Option < i32 > {
125
+ fn f ( ) -> Option < String > {
126
+ Some ( String :: new ( ) )
127
+ }
128
+
129
+ if f ( ) . is_none ( ) {
130
+ return None ;
131
+ }
132
+
133
+ Some ( 0 )
134
+ }
135
+
124
136
fn main ( ) {
125
137
some_func ( Some ( 42 ) ) ;
126
138
some_func ( None ) ;
@@ -138,4 +150,6 @@ fn main() {
138
150
139
151
let so = SeemsOption :: Some ( 45 ) ;
140
152
returns_something_similar_to_option ( so) ;
153
+
154
+ func ( ) ;
141
155
}
Original file line number Diff line number Diff line change @@ -92,5 +92,13 @@ LL | | return None;
92
92
LL | | };
93
93
| |_________^ help: replace it with: `self.opt?`
94
94
95
- error: aborting due to 10 previous errors
95
+ error: this block may be rewritten with the `?` operator
96
+ --> $DIR/question_mark.rs:129:5
97
+ |
98
+ LL | / if f().is_none() {
99
+ LL | | return None;
100
+ LL | | }
101
+ | |_____^ help: replace it with: `f()?;`
102
+
103
+ error: aborting due to 11 previous errors
96
104
You can’t perform that action at this time.
0 commit comments