diff options
| author | bors <bors@rust-lang.org> | 2015-01-05 04:20:46 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-01-05 04:20:46 +0000 |
| commit | ed22606c8382822efc555f72f895c560289a5c70 (patch) | |
| tree | 9ed24b7cb51cc64e178d08f421c35d49f97cdb6f /src/libsyntax/parse | |
| parent | ad9e759382ad7daed26f86732f41f5f83cd673e2 (diff) | |
| parent | c062fac835e64c1ebf71da784714de562eac732c (diff) | |
| download | rust-ed22606c8382822efc555f72f895c560289a5c70.tar.gz rust-ed22606c8382822efc555f72f895c560289a5c70.zip | |
auto merge of #20285 : FlaPer87/rust/oibit-send-and-friends, r=nikomatsakis
This commit introduces the syntax for negative implementations of traits
as shown below:
`impl !Trait for Type {}`
cc #13231
Part of RFC rust-lang/rfcs#127
r? @nikomatsakis
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 37ac86a3324..cc67079e538 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -4801,6 +4801,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(); @@ -4823,6 +4830,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 }; @@ -4832,7 +4847,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)) } |
