Skip to content

Commit

Permalink
feat: allow use statements to be marked unstable
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 committed Jun 27, 2024
1 parent 9dad452 commit 4cf6f4c
Show file tree
Hide file tree
Showing 3 changed files with 16 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"),
}
}
1 change: 1 addition & 0 deletions src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ impl_has_visibility!(
syn::ItemTrait,
syn::ItemConst,
syn::ItemStatic,
syn::ItemUse,
);

impl ItemLike for syn::ItemStruct {
Expand Down

0 comments on commit 4cf6f4c

Please sign in to comment.