diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-04-11 18:37:02 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-04-11 18:37:02 +0100 |
commit | 1a1c09ed3e3a34c0a8750f98ece9ad85595395d2 (patch) | |
tree | 44136a4ce738d388bb9b0ce9f5569cf68465cbe2 /crates/ra_hir_ty/src | |
parent | 11d400b63b07d3cffbe8d1363b802a2d52f5d786 (diff) | |
parent | 0aece75cdd40daa4d48484103cfcd36ba13ba076 (diff) |
Merge #3951
3951: Simplify records grammar r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty/src')
-rw-r--r-- | crates/ra_hir_ty/src/expr.rs | 55 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests.rs | 4 |
2 files changed, 26 insertions, 33 deletions
diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs index 827b687de..69b527f74 100644 --- a/crates/ra_hir_ty/src/expr.rs +++ b/crates/ra_hir_ty/src/expr.rs | |||
@@ -89,21 +89,19 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
89 | let (_, source_map) = db.body_with_source_map(self.func.into()); | 89 | let (_, source_map) = db.body_with_source_map(self.func.into()); |
90 | 90 | ||
91 | if let Ok(source_ptr) = source_map.expr_syntax(id) { | 91 | if let Ok(source_ptr) = source_map.expr_syntax(id) { |
92 | if let Some(expr) = source_ptr.value.as_ref().left() { | 92 | let root = source_ptr.file_syntax(db.upcast()); |
93 | let root = source_ptr.file_syntax(db.upcast()); | 93 | if let ast::Expr::RecordLit(record_lit) = &source_ptr.value.to_node(&root) { |
94 | if let ast::Expr::RecordLit(record_lit) = expr.to_node(&root) { | 94 | if let Some(field_list) = record_lit.record_field_list() { |
95 | if let Some(field_list) = record_lit.record_field_list() { | 95 | let variant_data = variant_data(db.upcast(), variant_def); |
96 | let variant_data = variant_data(db.upcast(), variant_def); | 96 | let missed_fields = missed_fields |
97 | let missed_fields = missed_fields | 97 | .into_iter() |
98 | .into_iter() | 98 | .map(|idx| variant_data.fields()[idx].name.clone()) |
99 | .map(|idx| variant_data.fields()[idx].name.clone()) | 99 | .collect(); |
100 | .collect(); | 100 | self.sink.push(MissingFields { |
101 | self.sink.push(MissingFields { | 101 | file: source_ptr.file_id, |
102 | file: source_ptr.file_id, | 102 | field_list: AstPtr::new(&field_list), |
103 | field_list: AstPtr::new(&field_list), | 103 | missed_fields, |
104 | missed_fields, | 104 | }) |
105 | }) | ||
106 | } | ||
107 | } | 105 | } |
108 | } | 106 | } |
109 | } | 107 | } |
@@ -205,18 +203,16 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
205 | } | 203 | } |
206 | 204 | ||
207 | if let Ok(source_ptr) = source_map.expr_syntax(id) { | 205 | if let Ok(source_ptr) = source_map.expr_syntax(id) { |
208 | if let Some(expr) = source_ptr.value.as_ref().left() { | 206 | let root = source_ptr.file_syntax(db.upcast()); |
209 | let root = source_ptr.file_syntax(db.upcast()); | 207 | if let ast::Expr::MatchExpr(match_expr) = &source_ptr.value.to_node(&root) { |
210 | if let ast::Expr::MatchExpr(match_expr) = expr.to_node(&root) { | 208 | if let (Some(match_expr), Some(arms)) = |
211 | if let (Some(match_expr), Some(arms)) = | 209 | (match_expr.expr(), match_expr.match_arm_list()) |
212 | (match_expr.expr(), match_expr.match_arm_list()) | 210 | { |
213 | { | 211 | self.sink.push(MissingMatchArms { |
214 | self.sink.push(MissingMatchArms { | 212 | file: source_ptr.file_id, |
215 | file: source_ptr.file_id, | 213 | match_expr: AstPtr::new(&match_expr), |
216 | match_expr: AstPtr::new(&match_expr), | 214 | arms: AstPtr::new(&arms), |
217 | arms: AstPtr::new(&arms), | 215 | }) |
218 | }) | ||
219 | } | ||
220 | } | 216 | } |
221 | } | 217 | } |
222 | } | 218 | } |
@@ -247,9 +243,8 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
247 | let (_, source_map) = db.body_with_source_map(self.func.into()); | 243 | let (_, source_map) = db.body_with_source_map(self.func.into()); |
248 | 244 | ||
249 | if let Ok(source_ptr) = source_map.expr_syntax(id) { | 245 | if let Ok(source_ptr) = source_map.expr_syntax(id) { |
250 | if let Some(expr) = source_ptr.value.left() { | 246 | self.sink |
251 | self.sink.push(MissingOkInTailExpr { file: source_ptr.file_id, expr }); | 247 | .push(MissingOkInTailExpr { file: source_ptr.file_id, expr: source_ptr.value }); |
252 | } | ||
253 | } | 248 | } |
254 | } | 249 | } |
255 | } | 250 | } |
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs index 54e31602f..81fc0f63a 100644 --- a/crates/ra_hir_ty/src/tests.rs +++ b/crates/ra_hir_ty/src/tests.rs | |||
@@ -82,9 +82,7 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { | |||
82 | 82 | ||
83 | for (expr, ty) in inference_result.type_of_expr.iter() { | 83 | for (expr, ty) in inference_result.type_of_expr.iter() { |
84 | let syntax_ptr = match body_source_map.expr_syntax(expr) { | 84 | let syntax_ptr = match body_source_map.expr_syntax(expr) { |
85 | Ok(sp) => { | 85 | Ok(sp) => sp.map(|ast| ast.syntax_node_ptr()), |
86 | sp.map(|ast| ast.either(|it| it.syntax_node_ptr(), |it| it.syntax_node_ptr())) | ||
87 | } | ||
88 | Err(SyntheticSyntax) => continue, | 86 | Err(SyntheticSyntax) => continue, |
89 | }; | 87 | }; |
90 | types.push((syntax_ptr.clone(), ty)); | 88 | types.push((syntax_ptr.clone(), ty)); |