@@ -25,7 +25,7 @@ pub fn unstable_macro(args: TokenStream, input: TokenStream) -> TokenStream {
2525 Item :: Trait ( item_trait) => unstable_attribute. expand ( item_trait) ,
2626 Item :: Const ( item_const) => unstable_attribute. expand ( item_const) ,
2727 Item :: Static ( item_static) => unstable_attribute. expand ( item_static) ,
28- Item :: Use ( item_use) => unstable_attribute. expand ( item_use) ,
28+ Item :: Use ( item_use) => unstable_attribute. expand_use ( item_use) ,
2929 Item :: Impl ( item_impl) => unstable_attribute. expand_impl ( item_impl) ,
3030 _ => panic ! ( "unsupported item type" ) ,
3131 } ,
@@ -87,6 +87,25 @@ impl UnstableAttribute {
8787 }
8888 }
8989
90+ pub fn expand_use ( & self , item : impl ItemLike + ToTokens + Clone ) -> TokenStream {
91+ // We don't want to transform `pub use` items. Adding documentation has adverse effects.
92+ // The reexported type can signal its own stability, the reexport itself can really only
93+ // use the label that rustdoc renders.
94+ let feature_flag = self . feature_flag ( ) ;
95+
96+ #[ cfg( not( instability_disable_unstable_docs) ) ]
97+ let cfg_gate_unstable = quote ! { #[ cfg( any( doc, feature = #feature_flag) ) ] } ;
98+
99+ #[ cfg( instability_disable_unstable_docs) ]
100+ let cfg_gate_unstable = quote ! { #[ cfg( feature = #feature_flag) ] } ;
101+
102+ quote ! {
103+ #cfg_gate_unstable
104+ #[ cfg_attr( docsrs, doc( cfg( feature = #feature_flag) ) ) ]
105+ #item
106+ }
107+ }
108+
90109 pub fn expand_impl ( & self , mut item : impl Stability + ToTokens ) -> TokenStream {
91110 let feature_flag = self . feature_flag ( ) ;
92111 self . add_doc ( & mut item) ;
@@ -400,16 +419,14 @@ mod tests {
400419 let item: syn:: ItemUse = parse_quote ! {
401420 pub use crate :: foo:: bar;
402421 } ;
403- let tokens = UnstableAttribute :: default ( ) . expand ( item) ;
422+ let tokens = UnstableAttribute :: default ( ) . expand_use ( item) ;
404423 let expected = quote ! {
405424 #[ cfg( any( doc, feature = "unstable" ) ) ]
406425 #[ cfg_attr( docsrs, doc( cfg( feature = "unstable" ) ) ) ]
407- #[ doc = #DEFAULT_DOC ]
408426 pub use crate :: foo:: bar;
409427
410428 #[ cfg( not( any( doc, feature = "unstable" ) ) ) ]
411429 #[ allow( unused_imports) ]
412- #[ doc = #DEFAULT_DOC ]
413430 pub ( crate ) use crate :: foo:: bar;
414431 } ;
415432 assert_eq ! ( tokens. to_string( ) , expected. to_string( ) ) ;
@@ -462,20 +479,18 @@ mod tests {
462479 }
463480
464481 #[ test]
465- fn expand_public_use ( ) {
482+ fn expand_public_use_no_docs ( ) {
466483 let item: syn:: ItemUse = parse_quote ! {
467484 pub use crate :: foo:: bar;
468485 } ;
469- let tokens = UnstableAttribute :: default ( ) . expand ( item) ;
486+ let tokens = UnstableAttribute :: default ( ) . expand_use ( item) ;
470487 let expected = quote ! {
471488 #[ cfg( feature = "unstable" ) ]
472489 #[ cfg_attr( docsrs, doc( cfg( feature = "unstable" ) ) ) ]
473- #[ doc = #DEFAULT_DOC ]
474490 pub use crate :: foo:: bar;
475491
476492 #[ cfg( not( feature = "unstable" ) ) ]
477493 #[ allow( unused_imports) ]
478- #[ doc = #DEFAULT_DOC ]
479494 pub ( crate ) use crate :: foo:: bar;
480495 } ;
481496 assert_eq ! ( tokens. to_string( ) , expected. to_string( ) ) ;
0 commit comments