From 40bafe113ade5aebe70db559653a524df101e32a Mon Sep 17 00:00:00 2001 From: Josh McKinney Date: Thu, 27 Jun 2024 04:27:05 -0700 Subject: [PATCH] feat: allow use statements to be marked unstable (#3) This allows the pattern of re-exporting code defined in private modules, while still requiring the unstable feature to be enabled. --- example/src/lib.rs | 14 ++++++++++++++ src/lib.rs | 1 + src/unstable.rs | 2 ++ 3 files changed, 17 insertions(+) diff --git a/example/src/lib.rs b/example/src/lib.rs index 5c92851..8fdc3ba 100644 --- a/example/src/lib.rs +++ b/example/src/lib.rs @@ -18,3 +18,17 @@ pub fn risky_function() { pub struct RiskyStruct { pub x: u8, } + +mod private { + /// This function does something really risky! + /// + /// Don't use it yet! + #[stability::unstable(feature = "risky-private-function")] + pub fn risky_private_function() { + unimplemented!() + } +} + +#[allow(unused_imports)] +#[stability::unstable(feature = "risky-private-function")] +pub use private::risky_private_function; diff --git a/src/lib.rs b/src/lib.rs index cbfa076..5c58fe4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -122,6 +122,7 @@ pub fn unstable(args: TokenStream, input: TokenStream) -> TokenStream { Item::Trait(item_trait) => attributes.expand(item_trait), Item::Const(item_const) => attributes.expand(item_const), Item::Static(item_static) => attributes.expand(item_static), + Item::Use(item_use) => attributes.expand(item_use), _ => panic!("unsupported item type"), } } diff --git a/src/unstable.rs b/src/unstable.rs index 2a0701c..efd1248 100644 --- a/src/unstable.rs +++ b/src/unstable.rs @@ -91,6 +91,7 @@ impl UnstableAttribute { } pub(crate) trait ItemLike { + #[allow(unused)] fn attrs(&self) -> &[syn::Attribute]; fn push_attr(&mut self, attr: syn::Attribute); @@ -136,6 +137,7 @@ impl_has_visibility!( syn::ItemTrait, syn::ItemConst, syn::ItemStatic, + syn::ItemUse, ); impl ItemLike for syn::ItemStruct {