hir: Create hir::ConstArgKind
enum
This will allow lowering const params to a dedicated enum variant, rather than to an `AnonConst` that is later examined during `ty` lowering.
This commit is contained in:
parent
71f8aed510
commit
11b144aa98
13 changed files with 102 additions and 40 deletions
|
@ -1594,7 +1594,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
|
|||
i += 1;
|
||||
}
|
||||
GenericArg::Const(ct) => {
|
||||
self.visit_anon_const(&ct.value);
|
||||
self.visit_const_arg(ct);
|
||||
i += 1;
|
||||
}
|
||||
GenericArg::Infer(inf) => {
|
||||
|
|
|
@ -8,10 +8,10 @@ use rustc_ast::ast::ParamKindOrd;
|
|||
use rustc_errors::{
|
||||
codes::*, struct_span_code_err, Applicability, Diag, ErrorGuaranteed, MultiSpan,
|
||||
};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::GenericArg;
|
||||
use rustc_hir::{self as hir, ConstArgKind};
|
||||
use rustc_middle::ty::{
|
||||
self, GenericArgsRef, GenericParamDef, GenericParamDefKind, IsSuggestable, Ty,
|
||||
};
|
||||
|
@ -113,7 +113,8 @@ fn generic_arg_mismatch_err(
|
|||
}
|
||||
}
|
||||
(GenericArg::Const(cnst), GenericParamDefKind::Type { .. }) => {
|
||||
let body = tcx.hir().body(cnst.value.body);
|
||||
let ConstArgKind::Anon(anon) = cnst.kind;
|
||||
let body = tcx.hir().body(anon.body);
|
||||
if let rustc_hir::ExprKind::Path(rustc_hir::QPath::Resolved(_, path)) = body.value.kind
|
||||
{
|
||||
if let Res::Def(DefKind::Fn { .. }, id) = path.res {
|
||||
|
|
|
@ -470,11 +470,13 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||
(&GenericParamDefKind::Type { has_default, .. }, GenericArg::Infer(inf)) => {
|
||||
handle_ty_args(has_default, &inf.to_ty())
|
||||
}
|
||||
(GenericParamDefKind::Const { .. }, GenericArg::Const(ct)) => {
|
||||
let did = ct.value.def_id;
|
||||
tcx.feed_anon_const_type(did, tcx.type_of(param.def_id));
|
||||
ty::Const::from_anon_const(tcx, did).into()
|
||||
}
|
||||
(GenericParamDefKind::Const { .. }, GenericArg::Const(ct)) => match &ct.kind {
|
||||
hir::ConstArgKind::Anon(anon) => {
|
||||
let did = anon.def_id;
|
||||
tcx.feed_anon_const_type(did, tcx.type_of(param.def_id));
|
||||
ty::Const::from_anon_const(tcx, did).into()
|
||||
}
|
||||
},
|
||||
(&GenericParamDefKind::Const { .. }, hir::GenericArg::Infer(inf)) => {
|
||||
self.lowerer.ct_infer(Some(param), inf.span).into()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue