summary refs log tree commit diff
path: root/compiler/rustc_resolve/src
diff options
context:
space:
mode:
authorFrank King <frankking1729@gmail.com>2024-01-06 18:22:37 +0800
committerFrank King <frankking1729@gmail.com>2024-02-12 12:47:31 +0800
commit7660d6bf2c4e02b4f809b99f35c0f290e6171d45 (patch)
tree41a59e399973394f1845c56e0cfa0cdd5a647282 /compiler/rustc_resolve/src
parent7d012e8f19591f224b25cabf64d9da2bb2e08166 (diff)
downloadrust-7660d6bf2c4e02b4f809b99f35c0f290e6171d45.tar.gz
rust-7660d6bf2c4e02b4f809b99f35c0f290e6171d45.zip
Check representation of unnamed fields
Diffstat (limited to 'compiler/rustc_resolve/src')
-rw-r--r--compiler/rustc_resolve/src/def_collector.rs31
1 files changed, 18 insertions, 13 deletions
diff --git a/compiler/rustc_resolve/src/def_collector.rs b/compiler/rustc_resolve/src/def_collector.rs
index 08b1c88873e..45aea585f97 100644
--- a/compiler/rustc_resolve/src/def_collector.rs
+++ b/compiler/rustc_resolve/src/def_collector.rs
@@ -80,6 +80,22 @@ impl<'a, 'b, 'tcx> DefCollector<'a, 'b, 'tcx> {
             let name = field.ident.map_or_else(|| sym::integer(index(self)), |ident| ident.name);
             let def = self.create_def(field.id, name, DefKind::Field, field.span);
             self.with_parent(def, |this| visit::walk_field_def(this, field));
+            self.visit_anon_adt(&field.ty);
+        }
+    }
+
+    fn visit_anon_adt(&mut self, ty: &'a Ty) {
+        let def_kind = match &ty.kind {
+            TyKind::AnonStruct(..) => DefKind::Struct,
+            TyKind::AnonUnion(..) => DefKind::Union,
+            _ => return,
+        };
+        match &ty.kind {
+            TyKind::AnonStruct(node_id, _) | TyKind::AnonUnion(node_id, _) => {
+                let def_id = self.create_def(*node_id, kw::Empty, def_kind, ty.span);
+                self.with_parent(def_id, |this| visit::walk_ty(this, ty));
+            }
+            _ => {}
         }
     }
 
@@ -326,19 +342,8 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
     fn visit_ty(&mut self, ty: &'a Ty) {
         match &ty.kind {
             TyKind::MacCall(..) => self.visit_macro_invoc(ty.id),
-            TyKind::AnonStruct(node_id, fields) | TyKind::AnonUnion(node_id, fields) => {
-                let def_kind = match &ty.kind {
-                    TyKind::AnonStruct(..) => DefKind::Struct,
-                    TyKind::AnonUnion(..) => DefKind::Union,
-                    _ => unreachable!(),
-                };
-                let def_id = self.create_def(*node_id, kw::Empty, def_kind, ty.span);
-                self.with_parent(def_id, |this| {
-                    for f in fields {
-                        this.visit_field_def(f);
-                    }
-                });
-            }
+            // Anonymous structs or unions are visited later after defined.
+            TyKind::AnonStruct(..) | TyKind::AnonUnion(..) => {}
             _ => visit::walk_ty(self, ty),
         }
     }