mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-27 14:24:08 +00:00
Parse impl const Trait for Ty
syntax
This commit is contained in:
parent
fd4a6a1213
commit
1c3fe9de4e
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user