first pass at default values for const generics
- Adds optional default values to const generic parameters in the AST and HIR - Parses these optional default values - Adds a `const_generics_defaults` feature gate
This commit is contained in:
parent
f8ab56bf32
commit
61f33bfd29
20 changed files with 99 additions and 32 deletions
|
@ -733,7 +733,7 @@ fn validate_generic_param_order(
|
|||
let (ord_kind, ident) = match ¶m.kind {
|
||||
GenericParamKind::Lifetime => (ParamKindOrd::Lifetime, ident),
|
||||
GenericParamKind::Type { default: _ } => (ParamKindOrd::Type, ident),
|
||||
GenericParamKind::Const { ref ty, kw_span: _ } => {
|
||||
GenericParamKind::Const { ref ty, kw_span: _, default: _ } => {
|
||||
let ty = pprust::ty_to_string(ty);
|
||||
let unordered = sess.features_untracked().const_generics;
|
||||
(ParamKindOrd::Const { unordered }, Some(format!("const {}: {}", param.ident, ty)))
|
||||
|
@ -775,7 +775,7 @@ fn validate_generic_param_order(
|
|||
GenericParamKind::Type { default: None } => (),
|
||||
GenericParamKind::Lifetime => (),
|
||||
// FIXME(const_generics:defaults)
|
||||
GenericParamKind::Const { ty: _, kw_span: _ } => (),
|
||||
GenericParamKind::Const { ty: _, kw_span: _, default: _ } => (),
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
|
@ -1166,6 +1166,20 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||
}
|
||||
}
|
||||
}
|
||||
if !self.session.features_untracked().const_generics_defaults {
|
||||
if let GenericParamKind::Const { default: Some(ref default), .. } = param.kind {
|
||||
let mut err = self.err_handler().struct_span_err(
|
||||
default.value.span,
|
||||
"default values for const generic parameters are unstable",
|
||||
);
|
||||
err.help(
|
||||
"add `#![feature(const_generics_defaults)]` \
|
||||
to the crate attributes to enable",
|
||||
);
|
||||
err.emit();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
validate_generic_param_order(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue