Allow const patterns of matches to contain pattern types
This commit is contained in:
parent
b9856b6e40
commit
7ad16974b9
9 changed files with 233 additions and 9 deletions
|
@ -1568,11 +1568,15 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
CastKind::Transmute => {
|
||||
span_mirbug!(
|
||||
self,
|
||||
rvalue,
|
||||
"Unexpected CastKind::Transmute, which is not permitted in Analysis MIR",
|
||||
);
|
||||
let ty_from = op.ty(self.body, tcx);
|
||||
match ty_from.kind() {
|
||||
ty::Pat(base, _) if base == ty => {}
|
||||
_ => span_mirbug!(
|
||||
self,
|
||||
rvalue,
|
||||
"Unexpected CastKind::Transmute {ty_from:?} -> {ty:?}, which is not permitted in Analysis MIR",
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -140,8 +140,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
let success_block = target_block(TestBranch::Success);
|
||||
let fail_block = target_block(TestBranch::Failure);
|
||||
|
||||
let expect_ty = value.ty();
|
||||
let expect = self.literal_operand(test.span, value);
|
||||
let mut expect_ty = value.ty();
|
||||
let mut expect = self.literal_operand(test.span, value);
|
||||
|
||||
let mut place = place;
|
||||
let mut block = block;
|
||||
|
@ -174,6 +174,31 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
place = ref_str;
|
||||
ty = ref_str_ty;
|
||||
}
|
||||
&ty::Pat(base, _) => {
|
||||
assert_eq!(ty, value.ty());
|
||||
assert!(base.is_trivially_pure_clone_copy());
|
||||
|
||||
let transmuted_place = self.temp(base, test.span);
|
||||
self.cfg.push_assign(
|
||||
block,
|
||||
self.source_info(scrutinee_span),
|
||||
transmuted_place,
|
||||
Rvalue::Cast(CastKind::Transmute, Operand::Copy(place), base),
|
||||
);
|
||||
|
||||
let transmuted_expect = self.temp(base, test.span);
|
||||
self.cfg.push_assign(
|
||||
block,
|
||||
self.source_info(test.span),
|
||||
transmuted_expect,
|
||||
Rvalue::Cast(CastKind::Transmute, expect, base),
|
||||
);
|
||||
|
||||
place = transmuted_place;
|
||||
expect = Operand::Copy(transmuted_expect);
|
||||
ty = base;
|
||||
expect_ty = base;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue