diff --git a/examples/src/lib.rs b/examples/src/lib.rs index 3198651..df5475d 100644 --- a/examples/src/lib.rs +++ b/examples/src/lib.rs @@ -8,6 +8,16 @@ use ouroboros::self_referencing; #[cfg(test)] mod ok_tests; +pub struct Ext<'this, T, const REV: bool>(&'this Box); + +#[self_referencing(pub_extras)] +pub struct WithConstParam { + data: core::cell::RefCell, + #[borrows(data)] + #[not_covariant] + dref: Option>>, +} + #[self_referencing] /// A simple struct which contains an `i32` and a `&'this i32`. pub struct DataAndRef { diff --git a/ouroboros_macro/src/utils.rs b/ouroboros_macro/src/utils.rs index ec527df..c62ad29 100644 --- a/ouroboros_macro/src/utils.rs +++ b/ouroboros_macro/src/utils.rs @@ -28,7 +28,17 @@ pub fn make_generic_consumers(generics: &Generics) -> impl Iterator unimplemented!(), + // rustc don't require constants to consume, so we just skip it. + GenericParam::Const(ct) => { + let ident = ct.ident; + ( + quote! { () }, + format_ident!( + "_comsume_template_const_parameter_{}", + ident.to_string().to_snake_case() + ), + ) + }, }) } @@ -45,7 +55,10 @@ pub fn make_generic_arguments(generics: Vec<&GenericParam>) -> Vec let lifetime = <.lifetime; arguments.push(quote! { #lifetime }); } - GenericParam::Const(_) => unimplemented!("Const generics are not supported yet."), + GenericParam::Const(ct) => { + let ident = &ct.ident; + arguments.push(quote! { #ident }); + }, } } arguments