Handle all traits in type resolution, including no-export ones
authorMatt Corallo <git@bluematt.me>
Thu, 20 Jul 2023 22:51:01 +0000 (22:51 +0000)
committerMatt Corallo <git@bluematt.me>
Fri, 28 Jul 2023 23:06:00 +0000 (23:06 +0000)
In the previous commit, we set up handling of no-export traits with
only a single implementor. In order to utilize that, we need such
traits to participate in type resolution, which we add support for
here.

c-bindings-gen/src/main.rs
c-bindings-gen/src/types.rs

index 0a1d22a119aa9ea9a66aeb0984ae67877b9feda3..ad2690ce8a0ff99ac6695b18ac0607451f143ead 100644 (file)
@@ -73,7 +73,7 @@ fn maybe_convert_trait_impl<W: std::io::Write>(w: &mut W, trait_path: &syn::Path
                        let mut for_obj_vec = Vec::new();
                        types.write_c_type(&mut for_obj_vec, for_ty, Some(generics), false);
                        full_obj_path = String::from_utf8(for_obj_vec).unwrap();
-                       assert!(full_obj_path.starts_with(TypeResolver::generated_container_path()));
+                       if !full_obj_path.starts_with(TypeResolver::generated_container_path()) { return; }
                        for_obj = full_obj_path[TypeResolver::generated_container_path().len() + 2..].into();
                }
 
@@ -945,9 +945,11 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
                                if i.defaultness.is_some() || i.unsafety.is_some() { unimplemented!(); }
                                if let Some(trait_path) = i.trait_.as_ref() {
                                        if trait_path.0.is_some() { unimplemented!(); }
-                                       if types.understood_c_path(&trait_path.1) {
-                                               let full_trait_path = types.resolve_path(&trait_path.1, None);
-                                               let trait_obj = *types.crate_types.traits.get(&full_trait_path).unwrap();
+                                       let full_trait_path_opt = types.maybe_resolve_path(&trait_path.1, None);
+                                       let trait_obj_opt = full_trait_path_opt.as_ref().and_then(|path| types.crate_types.traits.get(path));
+                                       if types.understood_c_path(&trait_path.1) && trait_obj_opt.is_some() {
+                                               let full_trait_path = full_trait_path_opt.unwrap();
+                                               let trait_obj = *trait_obj_opt.unwrap();
 
                                                let supertrait_name;
                                                let supertrait_resolver;
index bc42bda05c614ccaf3b20e7673d3f877e0fd3f35..e18c46518e03137a6de2c22936e32804a0cf703d 100644 (file)
@@ -594,13 +594,8 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr
                                        }
                                },
                                syn::Item::Trait(t) => {
-                                       match export_status(&t.attrs) {
-                                               ExportStatus::Export|ExportStatus::NotImplementable => {
-                                                       if let syn::Visibility::Public(_) = t.vis {
-                                                               declared.insert(t.ident.clone(), DeclType::Trait(t));
-                                                       }
-                                               },
-                                               _ => continue,
+                                       if let syn::Visibility::Public(_) = t.vis {
+                                               declared.insert(t.ident.clone(), DeclType::Trait(t));
                                        }
                                },
                                syn::Item::Mod(m) => {