Some refactoring
This commit is contained in:
parent
e4e5db4e42
commit
8ef81388e2
27 changed files with 74 additions and 89 deletions
|
@ -507,7 +507,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
GenericParamDefKind::Const { has_default } => {
|
||||
let ty = tcx.at(self.span).type_of(param.def_id);
|
||||
if !infer_args && has_default {
|
||||
let c = ty::Const::from_anon_const(tcx, param.def_id.expect_local());
|
||||
let c = substs.unwrap()[param.index as usize].expect_const();
|
||||
ty::subst::GenericArg::from(c)
|
||||
} else if infer_args {
|
||||
self.astconv.ct_infer(ty, Some(param), self.span).into()
|
||||
|
@ -515,6 +515,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
// We've already errored above about the mismatch.
|
||||
tcx.const_error(ty).into()
|
||||
}
|
||||
// FIXME(const_generic_defaults)
|
||||
/*
|
||||
if !infer_args && has_default {
|
||||
/*
|
||||
|
|
|
@ -1447,7 +1447,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
if infer_args || !has_default {
|
||||
return self.fcx.var_for_def(self.span, param);
|
||||
}
|
||||
// FIXME(const_generics:defaults)
|
||||
// FIXME(const_generic_defaults)
|
||||
// No const parameters were provided, we have to infer them.
|
||||
todo!()
|
||||
}
|
||||
|
|
|
@ -713,10 +713,11 @@ fn check_where_clauses<'tcx, 'fcx>(
|
|||
let generics = tcx.generics_of(def_id);
|
||||
|
||||
let is_our_default = |def: &ty::GenericParamDef| match def.kind {
|
||||
GenericParamDefKind::Type { has_default, .. } => {
|
||||
GenericParamDefKind::Type { has_default, .. }
|
||||
| GenericParamDefKind::Const { has_default } => {
|
||||
has_default && def.index >= generics.parent_count as u32
|
||||
}
|
||||
_ => unreachable!(),
|
||||
GenericParamDefKind::Lifetime => unreachable!(),
|
||||
};
|
||||
|
||||
// Check that concrete defaults are well-formed. See test `type-check-defaults.rs`.
|
||||
|
@ -758,7 +759,7 @@ fn check_where_clauses<'tcx, 'fcx>(
|
|||
fcx.tcx.mk_param_from_def(param)
|
||||
}
|
||||
|
||||
GenericParamDefKind::Const { .. } | GenericParamDefKind::Type { .. } => {
|
||||
GenericParamDefKind::Type { .. } | GenericParamDefKind::Const { .. } => {
|
||||
// If the param has a default, ...
|
||||
if is_our_default(param) {
|
||||
let default_ty = fcx.tcx.type_of(param.def_id);
|
||||
|
|
|
@ -254,10 +254,14 @@ impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
|
|||
self.tcx.ensure().type_of(def_id);
|
||||
}
|
||||
hir::GenericParamKind::Type { .. } => {}
|
||||
hir::GenericParamKind::Const { .. } => {
|
||||
hir::GenericParamKind::Const { default, .. } => {
|
||||
let def_id = self.tcx.hir().local_def_id(param.hir_id);
|
||||
self.tcx.ensure().type_of(def_id);
|
||||
// FIXME(const_generics_defaults)
|
||||
if let Some(default) = default {
|
||||
let def_id = self.tcx.hir().local_def_id(default.hir_id);
|
||||
self.tcx.ensure().type_of(def_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,8 +83,7 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
|
|||
return generics
|
||||
.params
|
||||
.iter()
|
||||
.filter(|param| matches!(param.kind, ty::GenericParamDefKind::Const { ..
|
||||
}))
|
||||
.filter(|param| matches!(param.kind, ty::GenericParamDefKind::Const { .. }))
|
||||
.nth(arg_index)
|
||||
.map(|param| param.def_id);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue