Skip to content

Commit 53a7cdd

Browse files
committed
Forbid inline const block referencing params from being used in patterns
1 parent 2bd17c1 commit 53a7cdd

File tree

1 file changed

+6
-1
lines changed
  • compiler/rustc_mir_build/src/thir/pattern

1 file changed

+6
-1
lines changed

compiler/rustc_mir_build/src/thir/pattern/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_middle::mir::UserTypeProjection;
2121
use rustc_middle::mir::{BorrowKind, Field, Mutability};
2222
use rustc_middle::thir::{Ascription, BindingMode, FieldPat, Pat, PatKind, PatRange, PatTyProj};
2323
use rustc_middle::ty::subst::{GenericArg, SubstsRef};
24-
use rustc_middle::ty::{self, AdtDef, DefIdTree, Region, Ty, TyCtxt, UserType};
24+
use rustc_middle::ty::{self, AdtDef, ConstKind, DefIdTree, Region, Ty, TyCtxt, UserType};
2525
use rustc_span::{Span, Symbol};
2626

2727
use std::cmp::Ordering;
@@ -545,6 +545,11 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
545545
hir::ExprKind::ConstBlock(ref anon_const) => {
546546
let anon_const_def_id = self.tcx.hir().local_def_id(anon_const.hir_id);
547547
let value = ty::Const::from_anon_const(self.tcx, anon_const_def_id);
548+
if matches!(value.val, ConstKind::Param(_)) {
549+
let span = self.tcx.hir().span(anon_const.hir_id);
550+
self.errors.push(PatternError::ConstParamInPattern(span));
551+
return PatKind::Wild;
552+
}
548553
return *self.const_to_pat(value, expr.hir_id, expr.span, false).kind;
549554
}
550555
hir::ExprKind::Lit(ref lit) => (lit, false),

0 commit comments

Comments
 (0)