diff options
| author | Boxy <rust@boxyuwu.dev> | 2024-08-19 01:14:09 +0100 | 
|---|---|---|
| committer | Boxy <rust@boxyuwu.dev> | 2024-08-19 01:14:22 +0100 | 
| commit | b8eedfa3d217e19f806fd4f46a89b074f5e8659f (patch) | |
| tree | d6b049a54b54f6086ec0314b887ba7fcaf4c59f7 /compiler/rustc_middle/src | |
| parent | f04f6ca36d2439375d20a98be013384afbab0782 (diff) | |
| download | rust-b8eedfa3d217e19f806fd4f46a89b074f5e8659f.tar.gz rust-b8eedfa3d217e19f806fd4f46a89b074f5e8659f.zip | |
Retroactively feature gate `ConstArgKind::Path`
Diffstat (limited to 'compiler/rustc_middle/src')
| -rw-r--r-- | compiler/rustc_middle/src/ty/consts.rs | 32 | 
1 files changed, 22 insertions, 10 deletions
| diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs index e373292741b..362ff8e988d 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -240,7 +240,7 @@ impl<'tcx> Const<'tcx> { let ty = tcx.type_of(def).no_bound_vars().expect("const parameter types cannot be generic"); - match Self::try_from_lit(tcx, ty, expr) { + match Self::try_from_lit_or_param(tcx, ty, expr) { Some(v) => v, None => ty::Const::new_unevaluated( tcx, @@ -281,7 +281,11 @@ impl<'tcx> Const<'tcx> { } #[instrument(skip(tcx), level = "debug")] - fn try_from_lit(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, expr: &'tcx hir::Expr<'tcx>) -> Option<Self> { + fn try_from_lit_or_param( + tcx: TyCtxt<'tcx>, + ty: Ty<'tcx>, + expr: &'tcx hir::Expr<'tcx>, + ) -> Option<Self> { // Unwrap a block, so that e.g. `{ P }` is recognised as a parameter. Const arguments // currently have to be wrapped in curly brackets, so it's necessary to special-case. let expr = match &expr.kind { @@ -291,6 +295,22 @@ impl<'tcx> Const<'tcx> { _ => expr, }; + if let hir::ExprKind::Path( + qpath @ hir::QPath::Resolved( + _, + &hir::Path { res: Res::Def(DefKind::ConstParam, _), .. }, + ), + ) = expr.kind + { + if tcx.features().const_arg_path { + span_bug!( + expr.span, + "try_from_lit: received const param which shouldn't be possible" + ); + } + return Some(Const::from_param(tcx, qpath, expr.hir_id)); + }; + let lit_input = match expr.kind { hir::ExprKind::Lit(lit) => Some(LitToConstInput { lit: &lit.node, ty, neg: false }), hir::ExprKind::Unary(hir::UnOp::Neg, expr) => match expr.kind { @@ -318,14 +338,6 @@ impl<'tcx> Const<'tcx> { } } - if let hir::ExprKind::Path(hir::QPath::Resolved( - _, - &hir::Path { res: Res::Def(DefKind::ConstParam, _), .. }, - )) = expr.kind - { - span_bug!(expr.span, "try_from_lit: received const param which shouldn't be possible") - } - None } | 
