Skip to content

Commit 0de1693

Browse files
Parse impl const Trait for Ty syntax
1 parent 37259f8 commit 0de1693

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/librustc_parse/parser/item.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,10 +543,11 @@ impl<'a> Parser<'a> {
543543
/// impl<'a, T> TYPE { /* impl items */ }
544544
/// impl<'a, T> TRAIT for TYPE { /* impl items */ }
545545
/// impl<'a, T> !TRAIT for TYPE { /* impl items */ }
546+
/// impl<'a, T> const TRAIT for TYPE { /* impl items */ }
546547
///
547548
/// We actually parse slightly more relaxed grammar for better error reporting and recovery.
548-
/// `impl` GENERICS `!`? TYPE `for`? (TYPE | `..`) (`where` PREDICATES)? `{` BODY `}`
549-
/// `impl` GENERICS `!`? TYPE (`where` PREDICATES)? `{` BODY `}`
549+
/// `impl` GENERICS `const`? `!`? TYPE `for`? (TYPE | `..`) (`where` PREDICATES)? `{` BODY `}`
550+
/// `impl` GENERICS `const`? `!`? TYPE (`where` PREDICATES)? `{` BODY `}`
550551
fn parse_item_impl(
551552
&mut self,
552553
unsafety: Unsafety,
@@ -559,6 +560,13 @@ impl<'a> Parser<'a> {
559560
Generics::default()
560561
};
561562

563+
let constness = if self.eat_keyword(kw::Const) {
564+
self.sess.gated_spans.gate(sym::const_trait_impl, self.prev_span);
565+
Some(Constness::Const)
566+
} else {
567+
None
568+
};
569+
562570
// Disambiguate `impl !Trait for Type { ... }` and `impl ! { ... }` for the never type.
563571
let polarity = if self.check(&token::Not) && self.look_ahead(1, |t| t.can_begin_type()) {
564572
self.bump(); // `!`
@@ -619,7 +627,7 @@ impl<'a> Parser<'a> {
619627
err_path(ty_first.span)
620628
}
621629
};
622-
let trait_ref = TraitRef { path, ref_id: ty_first.id };
630+
let trait_ref = TraitRef { path, constness, ref_id: ty_first.id };
623631

624632
ItemKind::Impl(
625633
unsafety,

0 commit comments

Comments
 (0)