Support traits and structs with lifetime bounds (which are ignored)
authorMatt Corallo <git@bluematt.me>
Fri, 29 Oct 2021 18:59:25 +0000 (18:59 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 30 Nov 2021 15:39:48 +0000 (15:39 +0000)
c-bindings-gen/src/main.rs
c-bindings-gen/src/types.rs

index 4d5b07021c7cd110aafe6917fa77a2f5dd70880a..280f94e9de408af0e367d67234cec85f672a939b 100644 (file)
@@ -491,13 +491,18 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
                                        &syn::TraitItem::Type(ref t) => {
                                                if t.default.is_some() || t.generics.lt_token.is_some() { unimplemented!(); }
                                                let mut bounds_iter = t.bounds.iter();
-                                               match bounds_iter.next().unwrap() {
-                                                       syn::TypeParamBound::Trait(tr) => {
-                                                               writeln!(w, "\ttype {} = crate::{};", t.ident, $type_resolver.resolve_path(&tr.path, Some(&gen_types))).unwrap();
-                                                       },
-                                                       _ => unimplemented!(),
+                                               loop {
+                                                       match bounds_iter.next().unwrap() {
+                                                               syn::TypeParamBound::Trait(tr) => {
+                                                                       writeln!(w, "\ttype {} = crate::{};", t.ident, $type_resolver.resolve_path(&tr.path, Some(&gen_types))).unwrap();
+                                                                       for bound in bounds_iter {
+                                                                               if let syn::TypeParamBound::Trait(_) = bound { unimplemented!(); }
+                                                                       }
+                                                                       break;
+                                                               },
+                                                               syn::TypeParamBound::Lifetime(_) => {},
+                                                       }
                                                }
-                                               if bounds_iter.next().is_some() { unimplemented!(); }
                                        },
                                        _ => unimplemented!(),
                                }
index 498bdf5c079bef414ed5a81ad32296feac5f57fe..357fe4c815004a3ae775827a46ef3a34b013cc5b 100644 (file)
@@ -294,23 +294,28 @@ impl<'a, 'p: 'a> GenericTypes<'a, 'p> {
                                &syn::TraitItem::Type(ref t) => {
                                        if t.default.is_some() || t.generics.lt_token.is_some() { unimplemented!(); }
                                        let mut bounds_iter = t.bounds.iter();
-                                       match bounds_iter.next().unwrap() {
-                                               syn::TypeParamBound::Trait(tr) => {
-                                                       assert_simple_bound(&tr);
-                                                       if let Some(path) = types.maybe_resolve_path(&tr.path, None) {
-                                                               if types.skip_path(&path) { continue; }
-                                                               // In general we handle Deref<Target=X> as if it were just X (and
-                                                               // implement Deref<Target=Self> for relevant types). We don't
-                                                               // bother to implement it for associated types, however, so we just
-                                                               // ignore such bounds.
-                                                               if path != "std::ops::Deref" && path != "core::ops::Deref" {
-                                                                       self.typed_generics.insert(&t.ident, path);
+                                       loop {
+                                               match bounds_iter.next().unwrap() {
+                                                       syn::TypeParamBound::Trait(tr) => {
+                                                               assert_simple_bound(&tr);
+                                                               if let Some(path) = types.maybe_resolve_path(&tr.path, None) {
+                                                                       if types.skip_path(&path) { continue; }
+                                                                       // In general we handle Deref<Target=X> as if it were just X (and
+                                                                       // implement Deref<Target=Self> for relevant types). We don't
+                                                                       // bother to implement it for associated types, however, so we just
+                                                                       // ignore such bounds.
+                                                                       if path != "std::ops::Deref" && path != "core::ops::Deref" {
+                                                                               self.typed_generics.insert(&t.ident, path);
+                                                                       }
+                                                               } else { unimplemented!(); }
+                                                               for bound in bounds_iter {
+                                                                       if let syn::TypeParamBound::Trait(_) = bound { unimplemented!(); }
                                                                }
-                                                       } else { unimplemented!(); }
-                                               },
-                                               _ => unimplemented!(),
+                                                               break;
+                                                       },
+                                                       syn::TypeParamBound::Lifetime(_) => {},
+                                               }
                                        }
-                                       if bounds_iter.next().is_some() { unimplemented!(); }
                                },
                                _ => {},
                        }