@@ -141,47 +141,46 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
141
141
self . cfg . terminate ( block, self . source_info ( match_start_span) , terminator) ;
142
142
}
143
143
144
- TestKind :: Eq { value, ty } => {
144
+ TestKind :: Eq { value, mut ty } => {
145
145
let tcx = self . tcx ;
146
146
let success_block = target_block ( TestBranch :: Success ) ;
147
147
let fail_block = target_block ( TestBranch :: Failure ) ;
148
148
149
149
let expect_ty = value. ty ( ) ;
150
150
let expect = self . literal_operand ( test. span , value) ;
151
- if let ty:: Adt ( def, _) = ty. kind ( )
152
- && tcx. is_lang_item ( def. did ( ) , LangItem :: String )
153
- {
154
- if !tcx. features ( ) . string_deref_patterns ( ) {
155
- span_bug ! (
151
+
152
+ let mut place = place;
153
+ let mut block = block;
154
+ match ty. kind ( ) {
155
+ ty:: Adt ( def, _) if tcx. is_lang_item ( def. did ( ) , LangItem :: String ) => {
156
+ if !tcx. features ( ) . string_deref_patterns ( ) {
157
+ span_bug ! (
158
+ test. span,
159
+ "matching on `String` went through without enabling string_deref_patterns"
160
+ ) ;
161
+ }
162
+ let re_erased = tcx. lifetimes . re_erased ;
163
+ let ref_str_ty = Ty :: new_imm_ref ( tcx, re_erased, tcx. types . str_ ) ;
164
+ let ref_str = self . temp ( ref_str_ty, test. span ) ;
165
+ let eq_block = self . cfg . start_new_block ( ) ;
166
+ // `let ref_str: &str = <String as Deref>::deref(&place);`
167
+ self . call_deref (
168
+ block,
169
+ eq_block,
170
+ place,
171
+ Mutability :: Not ,
172
+ ty,
173
+ ref_str,
156
174
test. span ,
157
- "matching on `String` went through without enabling string_deref_patterns"
158
175
) ;
176
+ block = eq_block;
177
+ place = ref_str;
178
+ ty = ref_str_ty;
159
179
}
160
- let re_erased = tcx. lifetimes . re_erased ;
161
- let ref_str_ty = Ty :: new_imm_ref ( tcx, re_erased, tcx. types . str_ ) ;
162
- let ref_str = self . temp ( ref_str_ty, test. span ) ;
163
- let eq_block = self . cfg . start_new_block ( ) ;
164
- // `let ref_str: &str = <String as Deref>::deref(&place);`
165
- self . call_deref (
166
- block,
167
- eq_block,
168
- place,
169
- Mutability :: Not ,
170
- ty,
171
- ref_str,
172
- test. span ,
173
- ) ;
174
- self . non_scalar_compare (
175
- eq_block,
176
- success_block,
177
- fail_block,
178
- source_info,
179
- expect,
180
- expect_ty,
181
- Operand :: Copy ( ref_str) ,
182
- ref_str_ty,
183
- ) ;
184
- } else if !ty. is_scalar ( ) {
180
+ _ => { }
181
+ }
182
+
183
+ if !ty. is_scalar ( ) {
185
184
// Use `PartialEq::eq` instead of `BinOp::Eq`
186
185
// (the binop can only handle primitives)
187
186
self . non_scalar_compare (
0 commit comments