diff options
| author | bors <bors@rust-lang.org> | 2015-12-19 02:45:15 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-12-19 02:45:15 +0000 |
| commit | 440ef8b1548edf9d03a5b880d77a8b476cfb7fa2 (patch) | |
| tree | 035b909d2c9572fe5d3e491a57e8b36b7649e914 /src/libsyntax/util/parser.rs | |
| parent | 8ad12c3e251df6b8ed42b4d32709f4f55470a0be (diff) | |
| parent | 95fdaf237575e44ecf16f9fb13ab60058909f281 (diff) | |
| download | rust-440ef8b1548edf9d03a5b880d77a8b476cfb7fa2.tar.gz rust-440ef8b1548edf9d03a5b880d77a8b476cfb7fa2.zip | |
Auto merge of #30184 - petrochenkov:ascr, r=nikomatsakis
This PR is a rebase of the original PR by @eddyb https://github.com/rust-lang/rust/pull/21836 with some unrebasable parts manually reapplied, feature gate added + type equality restriction added as described below. This implementation is partial because the type equality restriction is applied to all type ascription expressions and not only those in lvalue contexts. Thus, all difficulties with detection of these contexts and translation of coercions having effect in runtime are avoided. So, you can't write things with coercions like `let slice = &[1, 2, 3]: &[u8];`. It obviously makes type ascription less useful than it should be, but it's still much more useful than not having type ascription at all. In particular, things like `let v = something.iter().collect(): Vec<_>;` and `let u = t.into(): U;` work as expected and I'm pretty happy with these improvements alone. Part of https://github.com/rust-lang/rust/issues/23416
Diffstat (limited to 'src/libsyntax/util/parser.rs')
| -rw-r--r-- | src/libsyntax/util/parser.rs | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/libsyntax/util/parser.rs b/src/libsyntax/util/parser.rs index bf3a8def390..87ef96d87ff 100644 --- a/src/libsyntax/util/parser.rs +++ b/src/libsyntax/util/parser.rs @@ -60,7 +60,9 @@ pub enum AssocOp { /// `as` As, /// `..` range - DotDot + DotDot, + /// `:` + Colon, } #[derive(Debug, PartialEq, Eq)] @@ -100,6 +102,7 @@ impl AssocOp { Token::AndAnd => Some(LAnd), Token::OrOr => Some(LOr), Token::DotDot => Some(DotDot), + Token::Colon => Some(Colon), _ if t.is_keyword(keywords::As) => Some(As), _ => None } @@ -134,7 +137,7 @@ impl AssocOp { pub fn precedence(&self) -> usize { use self::AssocOp::*; match *self { - As => 14, + As | Colon => 14, Multiply | Divide | Modulus => 13, Add | Subtract => 12, ShiftLeft | ShiftRight => 11, @@ -158,7 +161,7 @@ impl AssocOp { Inplace | Assign | AssignOp(_) => Fixity::Right, As | Multiply | Divide | Modulus | Add | Subtract | ShiftLeft | ShiftRight | BitAnd | BitXor | BitOr | Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual | - LAnd | LOr => Fixity::Left, + LAnd | LOr | Colon => Fixity::Left, DotDot => Fixity::None } } @@ -168,7 +171,7 @@ impl AssocOp { match *self { Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual => true, Inplace | Assign | AssignOp(_) | As | Multiply | Divide | Modulus | Add | Subtract | - ShiftLeft | ShiftRight | BitAnd | BitXor | BitOr | LAnd | LOr | DotDot => false + ShiftLeft | ShiftRight | BitAnd | BitXor | BitOr | LAnd | LOr | DotDot | Colon => false } } @@ -178,7 +181,7 @@ impl AssocOp { Assign | AssignOp(_) | Inplace => true, Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual | As | Multiply | Divide | Modulus | Add | Subtract | ShiftLeft | ShiftRight | BitAnd | BitXor | BitOr | LAnd | - LOr | DotDot => false + LOr | DotDot | Colon => false } } @@ -203,8 +206,7 @@ impl AssocOp { BitOr => Some(ast::BiBitOr), LAnd => Some(ast::BiAnd), LOr => Some(ast::BiOr), - Inplace | Assign | AssignOp(_) | As | DotDot => None + Inplace | Assign | AssignOp(_) | As | DotDot | Colon => None } } - } |
