File tree 3 files changed +39
-1
lines changed
3 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -154,7 +154,7 @@ fn is_single_call_in_arm<'tcx>(
154
154
arg : & ' tcx Expr < ' _ > ,
155
155
drop_expr : & ' tcx Expr < ' _ > ,
156
156
) -> bool {
157
- if matches ! ( arg. kind , ExprKind :: Call ( .. ) | ExprKind :: MethodCall ( .. ) ) {
157
+ if arg. can_have_side_effects ( ) {
158
158
let parent_node = cx. tcx . hir ( ) . find_parent ( drop_expr. hir_id ) ;
159
159
if let Some ( Node :: Arm ( Arm { body, .. } ) ) = & parent_node {
160
160
return body. hir_id == drop_expr. hir_id ;
Original file line number Diff line number Diff line change @@ -77,3 +77,22 @@ fn issue9482(x: u8) {
77
77
_ => ( ) ,
78
78
}
79
79
}
80
+
81
+ fn issue112653 ( ) {
82
+ fn foo ( ) -> Result < u8 , ( ) > {
83
+ println ! ( "doing foo" ) ;
84
+ Ok ( 0 ) // result is not always useful, the side-effect matters
85
+ }
86
+ fn bar ( ) {
87
+ println ! ( "doing bar" ) ;
88
+ }
89
+
90
+ fn stuff ( ) -> Result < ( ) , ( ) > {
91
+ match 42 {
92
+ 0 => drop ( foo ( ) ?) , // drop is needed because we only care about side-effects
93
+ 1 => bar ( ) ,
94
+ _ => ( ) , // doing nothing (no side-effects needed here)
95
+ }
96
+ Ok ( ( ) )
97
+ }
98
+ }
Original file line number Diff line number Diff line change @@ -97,3 +97,22 @@ fn issue10122(x: u8) {
97
97
_ => ( ) ,
98
98
}
99
99
}
100
+
101
+ fn issue112653 ( ) {
102
+ fn foo ( ) -> Result < & ' static u8 , ( ) > {
103
+ println ! ( "doing foo" ) ;
104
+ Ok ( & 0 ) // result is not always useful, the side-effect matters
105
+ }
106
+ fn bar ( ) {
107
+ println ! ( "doing bar" ) ;
108
+ }
109
+
110
+ fn stuff ( ) -> Result < ( ) , ( ) > {
111
+ match 42 {
112
+ 0 => drop ( foo ( ) ?) , // drop is needed because we only care about side-effects
113
+ 1 => bar ( ) ,
114
+ _ => ( ) , // doing nothing (no side-effects needed here)
115
+ }
116
+ Ok ( ( ) )
117
+ }
118
+ }
You can’t perform that action at this time.
0 commit comments