Skip to content

Commit 5aaf753

Browse files
committed
Handle all traits in type resolution, including no-export ones
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.
1 parent b7defa4 commit 5aaf753

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

c-bindings-gen/src/main.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn maybe_convert_trait_impl<W: std::io::Write>(w: &mut W, trait_path: &syn::Path
7373
let mut for_obj_vec = Vec::new();
7474
types.write_c_type(&mut for_obj_vec, for_ty, Some(generics), false);
7575
full_obj_path = String::from_utf8(for_obj_vec).unwrap();
76-
assert!(full_obj_path.starts_with(TypeResolver::generated_container_path()));
76+
if !full_obj_path.starts_with(TypeResolver::generated_container_path()) { return; }
7777
for_obj = full_obj_path[TypeResolver::generated_container_path().len() + 2..].into();
7878
}
7979

@@ -945,9 +945,11 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
945945
if i.defaultness.is_some() || i.unsafety.is_some() { unimplemented!(); }
946946
if let Some(trait_path) = i.trait_.as_ref() {
947947
if trait_path.0.is_some() { unimplemented!(); }
948-
if types.understood_c_path(&trait_path.1) {
949-
let full_trait_path = types.resolve_path(&trait_path.1, None);
950-
let trait_obj = *types.crate_types.traits.get(&full_trait_path).unwrap();
948+
let full_trait_path_opt = types.maybe_resolve_path(&trait_path.1, None);
949+
let trait_obj_opt = full_trait_path_opt.as_ref().and_then(|path| types.crate_types.traits.get(path));
950+
if types.understood_c_path(&trait_path.1) && trait_obj_opt.is_some() {
951+
let full_trait_path = full_trait_path_opt.unwrap();
952+
let trait_obj = *trait_obj_opt.unwrap();
951953

952954
let supertrait_name;
953955
let supertrait_resolver;

c-bindings-gen/src/types.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -594,13 +594,8 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr
594594
}
595595
},
596596
syn::Item::Trait(t) => {
597-
match export_status(&t.attrs) {
598-
ExportStatus::Export|ExportStatus::NotImplementable => {
599-
if let syn::Visibility::Public(_) = t.vis {
600-
declared.insert(t.ident.clone(), DeclType::Trait(t));
601-
}
602-
},
603-
_ => continue,
597+
if let syn::Visibility::Public(_) = t.vis {
598+
declared.insert(t.ident.clone(), DeclType::Trait(t));
604599
}
605600
},
606601
syn::Item::Mod(m) => {

0 commit comments

Comments
 (0)