Edit the inputs to const == val check instead of duplicating logic · rust-lang/rust@d62f885 (original) (raw)
`@@ -141,47 +141,49 @@ 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
`` +
// Since we generated a ref_str = <String as Deref>::deref(&place) -> eq_block
terminator,
``
``
177
`` +
// we need to add all further statements to eq_block
.
``
``
178
`` +
// Similarly, the normal test code should be generated for the &str
, instead of the String
.
``
``
179
`+
block = eq_block;
`
``
180
`+
place = ref_str;
`
``
181
`+
ty = ref_str_ty;
`
159
182
`}
`
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() {
`
``
183
`+
_ => {}
`
``
184
`+
}
`
``
185
+
``
186
`+
if !ty.is_scalar() {
`
185
187
`` // Use PartialEq::eq
instead of BinOp::Eq
``
186
188
`// (the binop can only handle primitives)
`
187
189
`self.non_scalar_compare(
`