about summary refs log tree commit diff
path: root/compiler/rustc_parse
diff options
context:
space:
mode:
authorRémy Rakic <remy.rakic+github@gmail.com>2020-12-31 18:32:06 +0100
committerRémy Rakic <remy.rakic+github@gmail.com>2021-01-01 11:01:01 +0100
commit942b7ce2c14b1c4fde5b9f27aa5bef39e0b990d5 (patch)
tree9532b132fe203e8115ef515448f1cc18f508b5c4 /compiler/rustc_parse
parent1fc3c4c16dde2a6cb4f565435d131b8c57bc1295 (diff)
downloadrust-942b7ce2c14b1c4fde5b9f27aa5bef39e0b990d5.tar.gz
rust-942b7ce2c14b1c4fde5b9f27aa5bef39e0b990d5.zip
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
Diffstat (limited to 'compiler/rustc_parse')
-rw-r--r--compiler/rustc_parse/src/parser/generics.rs17
1 files changed, 14 insertions, 3 deletions
diff --git a/compiler/rustc_parse/src/parser/generics.rs b/compiler/rustc_parse/src/parser/generics.rs
index ff84dba4177..42a13376863 100644
--- a/compiler/rustc_parse/src/parser/generics.rs
+++ b/compiler/rustc_parse/src/parser/generics.rs
@@ -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,