about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authoroliver-giersch <oliver.giersch@googlemail.com>2018-10-15 14:38:34 +0200
committerGitHub <noreply@github.com>2018-10-15 14:38:34 +0200
commit30bfdc872020c6addcb2ea488b2a6dbdd5ef355a (patch)
tree9c2ccdcdd23848de81e3cbf54be11ea029ba1614 /src/libsyntax
parent3527d1d5298fafe6d9e480f95e47f970f1b3adc1 (diff)
parent5891a64165ea4819ca331f5a35f5318a91e1be3f (diff)
downloadrust-30bfdc872020c6addcb2ea488b2a6dbdd5ef355a.tar.gz
rust-30bfdc872020c6addcb2ea488b2a6dbdd5ef355a.zip
Merge pull request #5 from oliver-giersch/master
sync with upstream
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/feature_gate.rs10
-rw-r--r--src/libsyntax/parse/parser.rs8
2 files changed, 17 insertions, 1 deletions
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index b86b92fb29e..84122688c83 100644
--- a/src/libsyntax/feature_gate.rs
+++ b/src/libsyntax/feature_gate.rs
@@ -499,6 +499,9 @@ declare_features! (
 
     // #[cfg_attr(predicate, multiple, attributes, here)]
     (active, cfg_attr_multi, "1.31.0", Some(54881), None),
+
+    // Allows `const _: TYPE = VALUE`
+    (active, underscore_const_names, "1.31.0", Some(54912), None),
 );
 
 declare_features! (
@@ -1583,6 +1586,13 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
                 }
             }
 
+            ast::ItemKind::Const(_,_) => {
+                if i.ident.name == "_" {
+                    gate_feature_post!(&self, underscore_const_names, i.span,
+                                        "naming constants with `_` is unstable");
+                }
+            }
+
             ast::ItemKind::ForeignMod(ref foreign_module) => {
                 self.check_abi(foreign_module.abi, i.span);
             }
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index b5896f37c00..c7089a295fc 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -6346,7 +6346,13 @@ impl<'a> Parser<'a> {
     }
 
     fn parse_item_const(&mut self, m: Option<Mutability>) -> PResult<'a, ItemInfo> {
-        let id = self.parse_ident()?;
+        let id = match self.token {
+                token::Ident(ident, false) if ident.name == keywords::Underscore.name() => {
+                    self.bump(); // `_`
+                    ident.gensym()
+                    },
+                _ => self.parse_ident()?,
+            };
         self.expect(&token::Colon)?;
         let ty = self.parse_ty()?;
         self.expect(&token::Eq)?;