diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-04-07 14:22:18 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-04-07 14:22:18 +0100 |
commit | 1e2178eb8e02b0118c8cad7e631368cbee94ea72 (patch) | |
tree | 141bc3c57c8b1436e188abb6fd73468567a7d411 /crates/ra_syntax/src | |
parent | 36f5d997565b6390a4b524e7e1d0d805f0f26bdb (diff) | |
parent | b27fa33a9f459feb442682026670ca8e6001a424 (diff) |
Merge #1103
1103: Array inference r=flodiebold a=Lapz
Fixes the final item in #394. The only problem is that infering the repeat cause some types to be infered twices.
i.e
```rust
fn test() {
let y = unknown;
[y, &y];
}
```
results in the following diff:
```diff
[11; 48) '{ ...&y]; }': ()
[21; 22) 'y': &{unknown}
[25; 32) 'unknown': &{unknown}
-[38; 45) '[y, &y]': [&&{unknown}]
+[38; 45) '[y, &y]': [&&{unknown};usize]
[39; 40) 'y': &{unknown}
+[39; 40) 'y': &{unknown}
[42; 44) '&y': &&{unknown}
[43; 44) 'y': &{unknown}
```
Should the code produce two inference results for 'y' and if not could any tell me what needs to change.
Co-authored-by: Lenard Pratt <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r-- | crates/ra_syntax/src/ast.rs | 4 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/expr_extensions.rs | 22 |
2 files changed, 24 insertions, 2 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index a06a6375d..c2ab19d97 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -17,8 +17,8 @@ pub use self::{ | |||
17 | generated::*, | 17 | generated::*, |
18 | traits::*, | 18 | traits::*, |
19 | tokens::*, | 19 | tokens::*, |
20 | extensions::{PathSegmentKind, StructKind, FieldKind, SelfParamKind}, | 20 | extensions::{PathSegmentKind, StructKind,FieldKind, SelfParamKind}, |
21 | expr_extensions::{ElseBranch, PrefixOp, BinOp, LiteralKind}, | 21 | expr_extensions::{ElseBranch, PrefixOp, BinOp, LiteralKind,ArrayExprKind}, |
22 | }; | 22 | }; |
23 | 23 | ||
24 | /// The main trait to go from untyped `SyntaxNode` to a typed ast. The | 24 | /// The main trait to go from untyped `SyntaxNode` to a typed ast. The |
diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs index 1d8313810..9484c3b9b 100644 --- a/crates/ra_syntax/src/ast/expr_extensions.rs +++ b/crates/ra_syntax/src/ast/expr_extensions.rs | |||
@@ -193,6 +193,28 @@ impl ast::BinExpr { | |||
193 | } | 193 | } |
194 | } | 194 | } |
195 | 195 | ||
196 | pub enum ArrayExprKind<'a> { | ||
197 | Repeat { initializer: Option<&'a ast::Expr>, repeat: Option<&'a ast::Expr> }, | ||
198 | ElementList(AstChildren<'a, ast::Expr>), | ||
199 | } | ||
200 | |||
201 | impl ast::ArrayExpr { | ||
202 | pub fn kind(&self) -> ArrayExprKind { | ||
203 | if self.is_repeat() { | ||
204 | ArrayExprKind::Repeat { | ||
205 | initializer: children(self).nth(0), | ||
206 | repeat: children(self).nth(1), | ||
207 | } | ||
208 | } else { | ||
209 | ArrayExprKind::ElementList(children(self)) | ||
210 | } | ||
211 | } | ||
212 | |||
213 | fn is_repeat(&self) -> bool { | ||
214 | self.syntax().children_with_tokens().any(|it| it.kind() == SEMI) | ||
215 | } | ||
216 | } | ||
217 | |||
196 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] | 218 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] |
197 | pub enum LiteralKind { | 219 | pub enum LiteralKind { |
198 | String, | 220 | String, |