Skip to content

Commit

Permalink
feat: allow use statements to be marked unstable (#3)
Browse files Browse the repository at this point in the history
This allows the pattern of re-exporting code defined in private modules,
while still requiring the unstable feature to be enabled.
  • Loading branch information
joshka authored Jun 27, 2024
1 parent 9dad452 commit 40bafe1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
14 changes: 14 additions & 0 deletions example/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
}
2 changes: 2 additions & 0 deletions src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -136,6 +137,7 @@ impl_has_visibility!(
syn::ItemTrait,
syn::ItemConst,
syn::ItemStatic,
syn::ItemUse,
);

impl ItemLike for syn::ItemStruct {
Expand Down

0 comments on commit 40bafe1

Please sign in to comment.