diff options
| author | Dylan MacKenzie <ecstaticmorse@gmail.com> | 2020-01-02 15:49:45 -0800 |
|---|---|---|
| committer | Dylan MacKenzie <ecstaticmorse@gmail.com> | 2020-01-09 16:46:14 -0800 |
| commit | 1c3fe9de4e9b7c41cc0ba86696b4e58f9e0e36e4 (patch) | |
| tree | 146fc88b39bc95299db9146be5409b9d3a1ad8f3 | |
| parent | fd4a6a12136c5b5d6bce4081e95890df1fd1febd (diff) | |
| download | rust-1c3fe9de4e9b7c41cc0ba86696b4e58f9e0e36e4.tar.gz rust-1c3fe9de4e9b7c41cc0ba86696b4e58f9e0e36e4.zip | |
Parse `impl const Trait for Ty` syntax
| -rw-r--r-- | src/librustc_parse/parser/item.rs | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/librustc_parse/parser/item.rs b/src/librustc_parse/parser/item.rs index 918e826fc26..86ab8bf57a3 100644 --- a/src/librustc_parse/parser/item.rs +++ b/src/librustc_parse/parser/item.rs @@ -542,10 +542,11 @@ impl<'a> Parser<'a> { /// impl<'a, T> TYPE { /* impl items */ } /// impl<'a, T> TRAIT for TYPE { /* impl items */ } /// impl<'a, T> !TRAIT for TYPE { /* impl items */ } + /// impl<'a, T> const TRAIT for TYPE { /* impl items */ } /// /// We actually parse slightly more relaxed grammar for better error reporting and recovery. - /// `impl` GENERICS `!`? TYPE `for`? (TYPE | `..`) (`where` PREDICATES)? `{` BODY `}` - /// `impl` GENERICS `!`? TYPE (`where` PREDICATES)? `{` BODY `}` + /// `impl` GENERICS `const`? `!`? TYPE `for`? (TYPE | `..`) (`where` PREDICATES)? `{` BODY `}` + /// `impl` GENERICS `const`? `!`? TYPE (`where` PREDICATES)? `{` BODY `}` fn parse_item_impl( &mut self, unsafety: Unsafety, @@ -558,6 +559,13 @@ impl<'a> Parser<'a> { Generics::default() }; + let constness = if self.eat_keyword(kw::Const) { + self.sess.gated_spans.gate(sym::const_trait_impl, self.prev_span); + Some(Constness::Const) + } else { + None + }; + // Disambiguate `impl !Trait for Type { ... }` and `impl ! { ... }` for the never type. let polarity = if self.check(&token::Not) && self.look_ahead(1, |t| t.can_begin_type()) { self.bump(); // `!` @@ -618,7 +626,7 @@ impl<'a> Parser<'a> { err_path(ty_first.span) } }; - let trait_ref = TraitRef { path, ref_id: ty_first.id }; + let trait_ref = TraitRef { path, constness, ref_id: ty_first.id }; ItemKind::Impl( unsafety, |
