aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-09-12 11:53:29 +0100
committerGitHub <[email protected]>2019-09-12 11:53:29 +0100
commita1261631a89f7169a3f84dec33aff61758c601e3 (patch)
tree773c687fe89b8cec009de17142b3a59e80468b21 /crates/ra_syntax/src
parent561e7aea5bdaf6c51e0a87da9ff1d73e2df52be1 (diff)
parent8c078a01641518a6b093922d4b1d27d1a98bad08 (diff)
Merge #1818
1818: Infer box expression r=matklad a=uHOOCCOOHu Infer `box e` to be `std::boxed::Box<T>` where `e: T` Co-authored-by: uHOOCCOOHu <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r--crates/ra_syntax/src/ast/generated.rs40
-rw-r--r--crates/ra_syntax/src/grammar.ron2
2 files changed, 39 insertions, 3 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index d274b6fbc..a8a231ef3 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -307,6 +307,33 @@ impl BlockExpr {
307 } 307 }
308} 308}
309#[derive(Debug, Clone, PartialEq, Eq, Hash)] 309#[derive(Debug, Clone, PartialEq, Eq, Hash)]
310pub struct BoxExpr {
311 pub(crate) syntax: SyntaxNode,
312}
313impl AstNode for BoxExpr {
314 fn can_cast(kind: SyntaxKind) -> bool {
315 match kind {
316 BOX_EXPR => true,
317 _ => false,
318 }
319 }
320 fn cast(syntax: SyntaxNode) -> Option<Self> {
321 if Self::can_cast(syntax.kind()) {
322 Some(Self { syntax })
323 } else {
324 None
325 }
326 }
327 fn syntax(&self) -> &SyntaxNode {
328 &self.syntax
329 }
330}
331impl BoxExpr {
332 pub fn expr(&self) -> Option<Expr> {
333 AstChildren::new(&self.syntax).next()
334 }
335}
336#[derive(Debug, Clone, PartialEq, Eq, Hash)]
310pub struct BoxPat { 337pub struct BoxPat {
311 pub(crate) syntax: SyntaxNode, 338 pub(crate) syntax: SyntaxNode,
312} 339}
@@ -649,6 +676,7 @@ pub enum Expr {
649 BinExpr(BinExpr), 676 BinExpr(BinExpr),
650 Literal(Literal), 677 Literal(Literal),
651 MacroCall(MacroCall), 678 MacroCall(MacroCall),
679 BoxExpr(BoxExpr),
652} 680}
653impl From<TupleExpr> for Expr { 681impl From<TupleExpr> for Expr {
654 fn from(node: TupleExpr) -> Expr { 682 fn from(node: TupleExpr) -> Expr {
@@ -800,6 +828,11 @@ impl From<MacroCall> for Expr {
800 Expr::MacroCall(node) 828 Expr::MacroCall(node)
801 } 829 }
802} 830}
831impl From<BoxExpr> for Expr {
832 fn from(node: BoxExpr) -> Expr {
833 Expr::BoxExpr(node)
834 }
835}
803impl AstNode for Expr { 836impl AstNode for Expr {
804 fn can_cast(kind: SyntaxKind) -> bool { 837 fn can_cast(kind: SyntaxKind) -> bool {
805 match kind { 838 match kind {
@@ -807,9 +840,8 @@ impl AstNode for Expr {
807 | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL 840 | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL
808 | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | RECORD_LIT | CALL_EXPR | INDEX_EXPR 841 | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | RECORD_LIT | CALL_EXPR | INDEX_EXPR
809 | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | TRY_BLOCK_EXPR 842 | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | TRY_BLOCK_EXPR
810 | CAST_EXPR | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL => { 843 | CAST_EXPR | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL
811 true 844 | BOX_EXPR => true,
812 }
813 _ => false, 845 _ => false,
814 } 846 }
815 } 847 }
@@ -845,6 +877,7 @@ impl AstNode for Expr {
845 BIN_EXPR => Expr::BinExpr(BinExpr { syntax }), 877 BIN_EXPR => Expr::BinExpr(BinExpr { syntax }),
846 LITERAL => Expr::Literal(Literal { syntax }), 878 LITERAL => Expr::Literal(Literal { syntax }),
847 MACRO_CALL => Expr::MacroCall(MacroCall { syntax }), 879 MACRO_CALL => Expr::MacroCall(MacroCall { syntax }),
880 BOX_EXPR => Expr::BoxExpr(BoxExpr { syntax }),
848 _ => return None, 881 _ => return None,
849 }; 882 };
850 Some(res) 883 Some(res)
@@ -881,6 +914,7 @@ impl AstNode for Expr {
881 Expr::BinExpr(it) => &it.syntax, 914 Expr::BinExpr(it) => &it.syntax,
882 Expr::Literal(it) => &it.syntax, 915 Expr::Literal(it) => &it.syntax,
883 Expr::MacroCall(it) => &it.syntax, 916 Expr::MacroCall(it) => &it.syntax,
917 Expr::BoxExpr(it) => &it.syntax,
884 } 918 }
885 } 919 }
886} 920}
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron
index 993e58e64..8f064711d 100644
--- a/crates/ra_syntax/src/grammar.ron
+++ b/crates/ra_syntax/src/grammar.ron
@@ -483,6 +483,7 @@ Grammar(
483 "CastExpr": (options: ["Expr", "TypeRef"]), 483 "CastExpr": (options: ["Expr", "TypeRef"]),
484 "RefExpr": (options: ["Expr"]), 484 "RefExpr": (options: ["Expr"]),
485 "PrefixExpr": (options: ["Expr"]), 485 "PrefixExpr": (options: ["Expr"]),
486 "BoxExpr": (options: ["Expr"]),
486 "RangeExpr": (), 487 "RangeExpr": (),
487 "BinExpr": (), 488 "BinExpr": (),
488 489
@@ -520,6 +521,7 @@ Grammar(
520 "BinExpr", 521 "BinExpr",
521 "Literal", 522 "Literal",
522 "MacroCall", 523 "MacroCall",
524 "BoxExpr",
523 ], 525 ],
524 ), 526 ),
525 527