about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-10-26 21:23:32 +0000
committerbors <bors@rust-lang.org>2015-10-26 21:23:32 +0000
commit04475b92f9309356a90fe970816774d14ef5b4ed (patch)
treea58af9f0164fc9dffae9a69e925bc840ed13d4b6 /src/libsyntax/parse
parent2c42c9881542a0f3a8b573a56cd1c12643d4be52 (diff)
parentf9b8c49cdb75fb571c7b3ea4af90b0e96929276c (diff)
downloadrust-04475b92f9309356a90fe970816774d14ef5b4ed.tar.gz
rust-04475b92f9309356a90fe970816774d14ef5b4ed.zip
Auto merge of #29274 - thepowersgang:issues-29107-const-unsafe-fn-order, r=nikomatsakis
This PR switches the implemented ordering from `unsafe const fn` (as was in the original RFC) to `const unsafe fn` (which is what the lang team decided on)
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/parser.rs24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 7d15389d561..e153f1665e3 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -4380,7 +4380,8 @@ impl<'a> Parser<'a> {
     /// true if we are looking at `const ID`, false for things like `const fn` etc
     pub fn is_const_item(&mut self) -> bool {
         self.token.is_keyword(keywords::Const) &&
-            !self.look_ahead(1, |t| t.is_keyword(keywords::Fn))
+            !self.look_ahead(1, |t| t.is_keyword(keywords::Fn)) &&
+            !self.look_ahead(1, |t| t.is_keyword(keywords::Unsafe))
     }
 
     /// parses all the "front matter" for a `fn` declaration, up to
@@ -4388,11 +4389,12 @@ impl<'a> Parser<'a> {
     ///
     /// - `const fn`
     /// - `unsafe fn`
+    /// - `const unsafe fn`
     /// - `extern fn`
     /// - etc
     pub fn parse_fn_front_matter(&mut self) -> PResult<(ast::Constness, ast::Unsafety, abi::Abi)> {
-        let unsafety = try!(self.parse_unsafety());
         let is_const_fn = try!(self.eat_keyword(keywords::Const));
+        let unsafety = try!(self.parse_unsafety());
         let (constness, unsafety, abi) = if is_const_fn {
             (Constness::Const, unsafety, abi::Rust)
         } else {
@@ -5300,11 +5302,18 @@ impl<'a> Parser<'a> {
             return Ok(Some(item));
         }
         if try!(self.eat_keyword(keywords::Const) ){
-            if self.check_keyword(keywords::Fn) {
+            if self.check_keyword(keywords::Fn)
+                || (self.check_keyword(keywords::Unsafe)
+                    && self.look_ahead(1, |t| t.is_keyword(keywords::Fn))) {
                 // CONST FUNCTION ITEM
+                let unsafety = if try!(self.eat_keyword(keywords::Unsafe) ){
+                    Unsafety::Unsafe
+                } else {
+                    Unsafety::Normal
+                };
                 try!(self.bump());
                 let (ident, item_, extra_attrs) =
-                    try!(self.parse_item_fn(Unsafety::Normal, Constness::Const, abi::Rust));
+                    try!(self.parse_item_fn(unsafety, Constness::Const, abi::Rust));
                 let last_span = self.last_span;
                 let item = self.mk_item(lo,
                                         last_span.hi,
@@ -5387,14 +5396,9 @@ impl<'a> Parser<'a> {
             } else {
                 abi::Rust
             };
-            let constness = if abi == abi::Rust && try!(self.eat_keyword(keywords::Const) ){
-                Constness::Const
-            } else {
-                Constness::NotConst
-            };
             try!(self.expect_keyword(keywords::Fn));
             let (ident, item_, extra_attrs) =
-                try!(self.parse_item_fn(Unsafety::Unsafe, constness, abi));
+                try!(self.parse_item_fn(Unsafety::Unsafe, Constness::NotConst, abi));
             let last_span = self.last_span;
             let item = self.mk_item(lo,
                                     last_span.hi,