make const_generics_defaults
use the unstable syntax mechanism
This is important to not accidentally stabilize the parsing of the syntax while it still is experimental and not formally accepted
This commit is contained in:
parent
1fc3c4c16d
commit
942b7ce2c1
9 changed files with 45 additions and 35 deletions
|
@ -5,7 +5,7 @@ use rustc_ast::{
|
|||
self as ast, Attribute, GenericBounds, GenericParam, GenericParamKind, WhereClause,
|
||||
};
|
||||
use rustc_errors::PResult;
|
||||
use rustc_span::symbol::kw;
|
||||
use rustc_span::symbol::{kw, sym};
|
||||
|
||||
impl<'a> Parser<'a> {
|
||||
/// Parses bounds of a lifetime parameter `BOUND + BOUND + BOUND`, possibly with trailing `+`.
|
||||
|
@ -56,8 +56,19 @@ impl<'a> Parser<'a> {
|
|||
self.expect(&token::Colon)?;
|
||||
let ty = self.parse_ty()?;
|
||||
|
||||
// Parse optional const generics default value.
|
||||
let default = if self.eat(&token::Eq) { Some(self.parse_const_arg()?) } else { None };
|
||||
// Parse optional const generics default value, taking care of feature gating the spans
|
||||
// with the unstable syntax mechanism.
|
||||
let default = if self.eat(&token::Eq) {
|
||||
// The gated span goes from the `=` to the end of the const argument that follows (and
|
||||
// which could be a block expression).
|
||||
let start = self.prev_token.span;
|
||||
let const_arg = self.parse_const_arg()?;
|
||||
let span = start.to(const_arg.value.span);
|
||||
self.sess.gated_spans.gate(sym::const_generics_defaults, span);
|
||||
Some(const_arg)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Ok(GenericParam {
|
||||
ident,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue