Skip to content

Commit 967ec5e

Browse files
authored
Merge pull request #653 from dtolnay/lifetimes
Enable lifetimes on opaque Rust types
2 parents 42883ac + 5b9bbdf commit 967ec5e

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

macro/src/expand.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,19 +677,20 @@ fn expand_rust_type_import(ety: &ExternType) -> TokenStream {
677677

678678
fn expand_rust_type_impl(ety: &ExternType) -> TokenStream {
679679
let ident = &ety.name.rust;
680+
let generics = &ety.generics;
680681
let span = ident.span();
681682
let unsafe_impl = quote_spanned!(ety.type_token.span=> unsafe impl);
682683

683684
let mut impls = quote_spanned! {span=>
684-
#unsafe_impl ::cxx::private::RustType for #ident {}
685+
#unsafe_impl #generics ::cxx::private::RustType for #ident #generics {}
685686
};
686687

687688
for derive in &ety.derives {
688689
if derive.what == Trait::ExternType {
689690
let type_id = type_id(&ety.name);
690691
let span = derive.span;
691692
impls.extend(quote_spanned! {span=>
692-
unsafe impl ::cxx::ExternType for #ident {
693+
unsafe impl #generics ::cxx::ExternType for #ident #generics {
693694
type Id = #type_id;
694695
type Kind = ::cxx::kind::Opaque;
695696
}

syntax/check.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,6 @@ fn check_api_type(cx: &mut Check, ety: &ExternType) {
335335
cx.error(derive, msg);
336336
}
337337

338-
if let Some(lifetime) = ety.generics.lifetimes.first() {
339-
if ety.lang == Lang::Rust {
340-
let msg = "extern Rust type with lifetimes is not supported yet";
341-
cx.error(lifetime, msg);
342-
}
343-
}
344-
345338
if !ety.bounds.is_empty() {
346339
let bounds = &ety.bounds;
347340
let span = quote!(#(#bounds)*);

tests/ffi/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ pub mod ffi {
210210
type Job = crate::module::ffi::Job;
211211
}
212212

213+
extern "Rust" {
214+
#[derive(ExternType)]
215+
type Reference<'a>;
216+
}
217+
213218
unsafe extern "C++" {
214219
type Borrow<'a>;
215220

@@ -377,6 +382,8 @@ impl R {
377382
}
378383
}
379384

385+
pub struct Reference<'a>(&'a String);
386+
380387
impl ffi::Shared {
381388
fn r_method_on_shared(&self) -> String {
382389
"2020".to_owned()

0 commit comments

Comments
 (0)