diff options
author | Jonas Schievink <[email protected]> | 2020-07-14 18:57:41 +0100 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2020-07-14 18:57:41 +0100 |
commit | a4a8406c449a2c124659773408d0241d54eb243a (patch) | |
tree | 2af71e48e9d3fce856e6cd70d754d03345b1d66d /crates | |
parent | a50c64a4f13b47de7fa08eb3e6ff222a96389b28 (diff) |
ItemTree: Lower tuple types despite invalid type
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir_def/src/item_tree/lower.rs | 13 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/diagnostics/expr.rs | 23 |
2 files changed, 29 insertions, 7 deletions
diff --git a/crates/ra_hir_def/src/item_tree/lower.rs b/crates/ra_hir_def/src/item_tree/lower.rs index 0b1509e13..4182a9e3b 100644 --- a/crates/ra_hir_def/src/item_tree/lower.rs +++ b/crates/ra_hir_def/src/item_tree/lower.rs | |||
@@ -219,21 +219,20 @@ impl Ctx { | |||
219 | fn lower_tuple_fields(&mut self, fields: &ast::TupleFieldDefList) -> IdRange<Field> { | 219 | fn lower_tuple_fields(&mut self, fields: &ast::TupleFieldDefList) -> IdRange<Field> { |
220 | let start = self.next_field_idx(); | 220 | let start = self.next_field_idx(); |
221 | for (i, field) in fields.fields().enumerate() { | 221 | for (i, field) in fields.fields().enumerate() { |
222 | if let Some(data) = self.lower_tuple_field(i, &field) { | 222 | let data = self.lower_tuple_field(i, &field); |
223 | let idx = self.data().fields.alloc(data); | 223 | let idx = self.data().fields.alloc(data); |
224 | self.add_attrs(idx.into(), Attrs::new(&field, &self.hygiene)); | 224 | self.add_attrs(idx.into(), Attrs::new(&field, &self.hygiene)); |
225 | } | ||
226 | } | 225 | } |
227 | let end = self.next_field_idx(); | 226 | let end = self.next_field_idx(); |
228 | IdRange::new(start..end) | 227 | IdRange::new(start..end) |
229 | } | 228 | } |
230 | 229 | ||
231 | fn lower_tuple_field(&mut self, idx: usize, field: &ast::TupleFieldDef) -> Option<Field> { | 230 | fn lower_tuple_field(&mut self, idx: usize, field: &ast::TupleFieldDef) -> Field { |
232 | let name = Name::new_tuple_field(idx); | 231 | let name = Name::new_tuple_field(idx); |
233 | let visibility = self.lower_visibility(field); | 232 | let visibility = self.lower_visibility(field); |
234 | let type_ref = self.lower_type_ref(&field.type_ref()?); | 233 | let type_ref = self.lower_type_ref_opt(field.type_ref()); |
235 | let res = Field { name, type_ref, visibility }; | 234 | let res = Field { name, type_ref, visibility }; |
236 | Some(res) | 235 | res |
237 | } | 236 | } |
238 | 237 | ||
239 | fn lower_union(&mut self, union: &ast::UnionDef) -> Option<FileItemTreeId<Union>> { | 238 | fn lower_union(&mut self, union: &ast::UnionDef) -> Option<FileItemTreeId<Union>> { |
diff --git a/crates/ra_hir_ty/src/diagnostics/expr.rs b/crates/ra_hir_ty/src/diagnostics/expr.rs index 91caedc3d..21ff99a8c 100644 --- a/crates/ra_hir_ty/src/diagnostics/expr.rs +++ b/crates/ra_hir_ty/src/diagnostics/expr.rs | |||
@@ -489,4 +489,27 @@ fn f() { | |||
489 | "#, | 489 | "#, |
490 | ) | 490 | ) |
491 | } | 491 | } |
492 | |||
493 | #[test] | ||
494 | fn enum_variant_type_macro() { | ||
495 | check_diagnostics( | ||
496 | r#" | ||
497 | macro_rules! Type { | ||
498 | () => { u32 }; | ||
499 | } | ||
500 | enum Foo { | ||
501 | Bar(Type![]) | ||
502 | } | ||
503 | impl Foo { | ||
504 | fn new() { | ||
505 | Foo::Bar(0); | ||
506 | Foo::Bar(0, 1); | ||
507 | //^^^^^^^^^^^^^^ Expected 1 argument, found 2 | ||
508 | Foo::Bar(); | ||
509 | //^^^^^^^^^^ Expected 1 argument, found 0 | ||
510 | } | ||
511 | } | ||
512 | "#, | ||
513 | ); | ||
514 | } | ||
492 | } | 515 | } |