1
Fork 0

Rollup merge of #111841 - matthewjasper:validate-match-guards, r=compiler-errors

Run AST validation on match guards correctly

AST validation was being skipped on match guards other than `if let` guards.
This commit is contained in:
Matthias Krüger 2023-05-24 21:36:57 +02:00 committed by GitHub
commit 092352f6fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 240 additions and 38 deletions

View file

@ -118,7 +118,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let category = Category::of(&expr.kind).unwrap();
debug!(?category, ?expr.kind);
match category {
Category::Constant if let NeedsTemporary::No = needs_temporary || !expr.ty.needs_drop(this.tcx, this.param_env) => {
Category::Constant
if matches!(needs_temporary, NeedsTemporary::No)
|| !expr.ty.needs_drop(this.tcx, this.param_env) =>
{
let constant = this.as_constant(expr);
block.and(Operand::Constant(Box::new(constant)))
}
@ -126,7 +129,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let operand = unpack!(block = this.as_temp(block, scope, expr, Mutability::Mut));
// Overwrite temp local info if we have something more interesting to record.
if !matches!(local_info, LocalInfo::Boring) {
let decl_info = this.local_decls[operand].local_info.as_mut().assert_crate_local();
let decl_info =
this.local_decls[operand].local_info.as_mut().assert_crate_local();
if let LocalInfo::Boring | LocalInfo::BlockTailTemp(_) = **decl_info {
**decl_info = local_info;
}