@@ -739,60 +739,19 @@ pub fn translate(
739739
740740 // Identify typedefs that name unnamed types and collapse the two declarations
741741 // into a single name and declaration, eliminating the typedef altogether.
742- let mut prenamed_decls: IndexMap < CDeclId , CDeclId > = IndexMap :: new ( ) ;
743- for ( & decl_id, decl) in t. ast_context . iter_decls ( ) {
744- if let CDeclKind :: Typedef { ref name, typ, .. } = decl. kind {
745- if let Some ( subdecl_id) = t
746- . ast_context
747- . resolve_type ( typ. ctype )
748- . kind
749- . as_underlying_decl ( )
750- {
751- use CDeclKind :: * ;
752- let is_unnamed = match t. ast_context [ subdecl_id] . kind {
753- Struct { name : None , .. }
754- | Union { name : None , .. }
755- | Enum { name : None , .. } => true ,
756-
757- // Detect case where typedef and struct share the same name.
758- // In this case the purpose of the typedef was simply to eliminate
759- // the need for the 'struct' tag when referring to the type name.
760- Struct {
761- name : Some ( ref target_name) ,
762- ..
763- }
764- | Union {
765- name : Some ( ref target_name) ,
766- ..
767- }
768- | Enum {
769- name : Some ( ref target_name) ,
770- ..
771- } => name == target_name,
772-
773- _ => false ,
774- } ;
775-
776- if is_unnamed
777- && !prenamed_decls
778- . values ( )
779- . any ( |decl_id| * decl_id == subdecl_id)
780- {
781- prenamed_decls. insert ( decl_id, subdecl_id) ;
742+ t. ast_context . set_prenamed_decls ( ) ;
782743
783- t . type_converter
784- . borrow_mut ( )
785- . declare_decl_name ( decl_id , name ) ;
786- t . type_converter
787- . borrow_mut ( )
788- . alias_decl_name ( subdecl_id , decl_id ) ;
789- }
790- }
744+ for ( & decl_id , & subdecl_id ) in & t . ast_context . prenamed_decls {
745+ if let CDeclKind :: Typedef { ref name , .. } = t . ast_context [ decl_id ] . kind {
746+ t . type_converter
747+ . borrow_mut ( )
748+ . declare_decl_name ( decl_id , name ) ;
749+ t . type_converter
750+ . borrow_mut ( )
751+ . alias_decl_name ( subdecl_id , decl_id ) ;
791752 }
792753 }
793754
794- t. ast_context . prenamed_decls = prenamed_decls;
795-
796755 // Helper function that returns true if there is either a matching typedef or its
797756 // corresponding struct/union/enum
798757 fn contains ( prenamed_decls : & IndexMap < CDeclId , CDeclId > , decl_id : & CDeclId ) -> bool {
0 commit comments