Merge #5381
5381: ItemTree: Lower tuple types despite invalid type r=flodiebold a=jonas-schievink Fixes https://github.com/rust-analyzer/rust-analyzer/issues/5380 Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
This commit is contained in:
commit
3f2ab436f4
@ -219,21 +219,20 @@ fn lower_record_field(&mut self, field: &ast::RecordFieldDef) -> Option<Field> {
|
||||
fn lower_tuple_fields(&mut self, fields: &ast::TupleFieldDefList) -> IdRange<Field> {
|
||||
let start = self.next_field_idx();
|
||||
for (i, field) in fields.fields().enumerate() {
|
||||
if let Some(data) = self.lower_tuple_field(i, &field) {
|
||||
let idx = self.data().fields.alloc(data);
|
||||
self.add_attrs(idx.into(), Attrs::new(&field, &self.hygiene));
|
||||
}
|
||||
let data = self.lower_tuple_field(i, &field);
|
||||
let idx = self.data().fields.alloc(data);
|
||||
self.add_attrs(idx.into(), Attrs::new(&field, &self.hygiene));
|
||||
}
|
||||
let end = self.next_field_idx();
|
||||
IdRange::new(start..end)
|
||||
}
|
||||
|
||||
fn lower_tuple_field(&mut self, idx: usize, field: &ast::TupleFieldDef) -> Option<Field> {
|
||||
fn lower_tuple_field(&mut self, idx: usize, field: &ast::TupleFieldDef) -> Field {
|
||||
let name = Name::new_tuple_field(idx);
|
||||
let visibility = self.lower_visibility(field);
|
||||
let type_ref = self.lower_type_ref(&field.type_ref()?);
|
||||
let type_ref = self.lower_type_ref_opt(field.type_ref());
|
||||
let res = Field { name, type_ref, visibility };
|
||||
Some(res)
|
||||
res
|
||||
}
|
||||
|
||||
fn lower_union(&mut self, union: &ast::UnionDef) -> Option<FileItemTreeId<Union>> {
|
||||
|
@ -489,4 +489,27 @@ fn f() {
|
||||
"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enum_variant_type_macro() {
|
||||
check_diagnostics(
|
||||
r#"
|
||||
macro_rules! Type {
|
||||
() => { u32 };
|
||||
}
|
||||
enum Foo {
|
||||
Bar(Type![])
|
||||
}
|
||||
impl Foo {
|
||||
fn new() {
|
||||
Foo::Bar(0);
|
||||
Foo::Bar(0, 1);
|
||||
//^^^^^^^^^^^^^^ Expected 1 argument, found 2
|
||||
Foo::Bar();
|
||||
//^^^^^^^^^^ Expected 1 argument, found 0
|
||||
}
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user