Skip to content

Commit 1c3fe9d

Browse files
Parse impl const Trait for Ty syntax
1 parent fd4a6a1 commit 1c3fe9d

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
@@ -542,10 +542,11 @@ impl<'a> Parser<'a> {
542542
/// impl<'a, T> TYPE { /* impl items */ }
543543
/// impl<'a, T> TRAIT for TYPE { /* impl items */ }
544544
/// impl<'a, T> !TRAIT for TYPE { /* impl items */ }
545+
/// impl<'a, T> const TRAIT for TYPE { /* impl items */ }
545546
///
546547
/// We actually parse slightly more relaxed grammar for better error reporting and recovery.
547-
/// `impl` GENERICS `!`? TYPE `for`? (TYPE | `..`) (`where` PREDICATES)? `{` BODY `}`
548-
/// `impl` GENERICS `!`? TYPE (`where` PREDICATES)? `{` BODY `}`
548+
/// `impl` GENERICS `const`? `!`? TYPE `for`? (TYPE | `..`) (`where` PREDICATES)? `{` BODY `}`
549+
/// `impl` GENERICS `const`? `!`? TYPE (`where` PREDICATES)? `{` BODY `}`
549550
fn parse_item_impl(
550551
&mut self,
551552
unsafety: Unsafety,
@@ -558,6 +559,13 @@ impl<'a> Parser<'a> {
558559
Generics::default()
559560
};
560561

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

623631
ItemKind::Impl(
624632
unsafety,

0 commit comments

Comments
 (0)