Add has_default to GenericParamDefKind::Const
This currently creates a field which is always false on GenericParamDefKind for future use when consts are permitted to have defaults Update const_generics:default locations Previously just ignored them, now actually do something about them. Fix using type check instead of value Add parsing This adds all the necessary changes to lower const-generics defaults from parsing. Change P<Expr> to AnonConst This matches the arguments passed to instantiations of const generics, and makes it specific to just anonymous constants. Attempt to fix lowering bugs
This commit is contained in:
@@ -18,7 +18,9 @@ pub enum GenericParamDefKind {
|
||||
object_lifetime_default: ObjectLifetimeDefault,
|
||||
synthetic: Option<hir::SyntheticTyParamKind>,
|
||||
},
|
||||
Const,
|
||||
Const {
|
||||
has_default: bool,
|
||||
},
|
||||
}
|
||||
|
||||
impl GenericParamDefKind {
|
||||
@@ -26,14 +28,14 @@ impl GenericParamDefKind {
|
||||
match self {
|
||||
GenericParamDefKind::Lifetime => "lifetime",
|
||||
GenericParamDefKind::Type { .. } => "type",
|
||||
GenericParamDefKind::Const => "constant",
|
||||
GenericParamDefKind::Const { .. } => "constant",
|
||||
}
|
||||
}
|
||||
pub fn to_ord(&self, tcx: TyCtxt<'_>) -> ast::ParamKindOrd {
|
||||
match self {
|
||||
GenericParamDefKind::Lifetime => ast::ParamKindOrd::Lifetime,
|
||||
GenericParamDefKind::Type { .. } => ast::ParamKindOrd::Type,
|
||||
GenericParamDefKind::Const => {
|
||||
GenericParamDefKind::Const { .. } => {
|
||||
ast::ParamKindOrd::Const { unordered: tcx.features().const_generics }
|
||||
}
|
||||
}
|
||||
@@ -105,7 +107,7 @@ impl<'tcx> Generics {
|
||||
match param.kind {
|
||||
GenericParamDefKind::Lifetime => own_counts.lifetimes += 1,
|
||||
GenericParamDefKind::Type { .. } => own_counts.types += 1,
|
||||
GenericParamDefKind::Const => own_counts.consts += 1,
|
||||
GenericParamDefKind::Const { .. } => own_counts.consts += 1,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,12 +120,10 @@ impl<'tcx> Generics {
|
||||
for param in &self.params {
|
||||
match param.kind {
|
||||
GenericParamDefKind::Lifetime => (),
|
||||
GenericParamDefKind::Type { has_default, .. } => {
|
||||
GenericParamDefKind::Type { has_default, .. } |
|
||||
GenericParamDefKind::Const { has_default } => {
|
||||
own_defaults.types += has_default as usize;
|
||||
}
|
||||
GenericParamDefKind::Const => {
|
||||
// FIXME(const_generics:defaults)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ impl<'tcx> Generics {
|
||||
pub fn own_requires_monomorphization(&self) -> bool {
|
||||
for param in &self.params {
|
||||
match param.kind {
|
||||
GenericParamDefKind::Type { .. } | GenericParamDefKind::Const => return true,
|
||||
GenericParamDefKind::Type { .. } | GenericParamDefKind::Const { .. } => return true,
|
||||
GenericParamDefKind::Lifetime => {}
|
||||
}
|
||||
}
|
||||
@@ -189,7 +189,7 @@ impl<'tcx> Generics {
|
||||
pub fn const_param(&'tcx self, param: &ParamConst, tcx: TyCtxt<'tcx>) -> &GenericParamDef {
|
||||
let param = self.param_at(param.index as usize, tcx);
|
||||
match param.kind {
|
||||
GenericParamDefKind::Const => param,
|
||||
GenericParamDefKind::Const { .. } => param,
|
||||
_ => bug!("expected const parameter, but found another generic parameter"),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user