diff options
| author | Flavio Percoco <flaper87@gmail.com> | 2014-12-28 23:33:18 +0100 |
|---|---|---|
| committer | Flavio Percoco <flaper87@gmail.com> | 2015-01-04 23:16:13 +0100 |
| commit | 8b883ab2681e34ef94575f45c6c0e6c2bca23ab7 (patch) | |
| tree | 899739abf4baa17ccbc570add56eca1987d030f9 /src/libsyntax/parse | |
| parent | 470118f3e915cdc8f936aca0640b28a7a3d8dc6c (diff) | |
| download | rust-8b883ab2681e34ef94575f45c6c0e6c2bca23ab7.tar.gz rust-8b883ab2681e34ef94575f45c6c0e6c2bca23ab7.zip | |
Add syntax for negative implementations of traits
This commit introduces the syntax for negative implmenetations of traits
as shown below:
`impl !Trait for Type {}`
cc #13231
Part of RFC #3
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index c0444363d4e..b4223a989ba 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -4802,6 +4802,13 @@ impl<'a> Parser<'a> { // allow this to be parsed as a trait. let could_be_trait = self.token != token::OpenDelim(token::Paren); + let neg_span = self.span; + let polarity = if self.eat(&token::Not) { + ast::ImplPolarity::Negative + } else { + ast::ImplPolarity::Positive + }; + // Parse the trait. let mut ty = self.parse_ty_sum(); @@ -4824,6 +4831,14 @@ impl<'a> Parser<'a> { ty = self.parse_ty_sum(); opt_trait_ref } else { + match polarity { + ast::ImplPolarity::Negative => { + // This is a negated type implementation + // `impl !MyType {}`, which is not allowed. + self.span_err(neg_span, "inherent implementation can't be negated"); + }, + _ => {} + } None }; @@ -4833,7 +4848,7 @@ impl<'a> Parser<'a> { let ident = ast_util::impl_pretty_name(&opt_trait, &*ty); (ident, - ItemImpl(unsafety, generics, opt_trait, ty, impl_items), + ItemImpl(unsafety, polarity, generics, opt_trait, ty, impl_items), Some(attrs)) } |
