@@ -2355,6 +2355,38 @@ fn filter_tokens_from_list(
23552355 tokens
23562356}
23572357
2358+ fn filter_doc_attr_ident ( ident : Symbol , is_inline : bool ) -> bool {
2359+ if is_inline {
2360+ ident == sym:: hidden || ident == sym:: inline || ident == sym:: no_inline
2361+ } else {
2362+ ident == sym:: cfg
2363+ }
2364+ }
2365+
2366+ fn filter_doc_attr ( normal : & mut ast:: NormalAttr , is_inline : bool ) {
2367+ match normal. item . args {
2368+ ast:: AttrArgs :: Delimited ( ref mut args) => {
2369+ let tokens = filter_tokens_from_list ( args. tokens . clone ( ) , |token| {
2370+ !matches ! (
2371+ token,
2372+ TokenTree :: Token (
2373+ Token {
2374+ kind: TokenKind :: Ident (
2375+ ident,
2376+ _,
2377+ ) ,
2378+ ..
2379+ } ,
2380+ _,
2381+ ) if filter_doc_attr_ident( * ident, is_inline) ,
2382+ )
2383+ } ) ;
2384+ args. tokens = TokenStream :: new ( tokens) ;
2385+ }
2386+ ast:: AttrArgs :: Empty | ast:: AttrArgs :: Eq ( ..) => { }
2387+ }
2388+ }
2389+
23582390/// When inlining items, we merge their attributes (and all the reexports attributes too) with the
23592391/// final reexport. For example:
23602392///
@@ -2381,13 +2413,6 @@ fn add_without_unwanted_attributes<'hir>(
23812413 is_inline : bool ,
23822414 import_parent : Option < DefId > ,
23832415) {
2384- // If it's not `#[doc(inline)]`, we don't want all attributes, otherwise we keep everything.
2385- if !is_inline {
2386- for attr in new_attrs {
2387- attrs. push ( ( Cow :: Borrowed ( attr) , import_parent) ) ;
2388- }
2389- return ;
2390- }
23912416 for attr in new_attrs {
23922417 if matches ! ( attr. kind, ast:: AttrKind :: DocComment ( ..) ) {
23932418 attrs. push ( ( Cow :: Borrowed ( attr) , import_parent) ) ;
@@ -2396,34 +2421,14 @@ fn add_without_unwanted_attributes<'hir>(
23962421 let mut attr = attr. clone ( ) ;
23972422 match attr. kind {
23982423 ast:: AttrKind :: Normal ( ref mut normal) => {
2399- if let [ ident] = & * normal. item . path . segments &&
2400- let ident = ident. ident . name &&
2401- ident == sym:: doc
2402- {
2403- match normal. item . args {
2404- ast:: AttrArgs :: Delimited ( ref mut args) => {
2405- let tokens =
2406- filter_tokens_from_list ( args. tokens . clone ( ) , |token| {
2407- !matches ! (
2408- token,
2409- TokenTree :: Token (
2410- Token {
2411- kind: TokenKind :: Ident (
2412- sym:: hidden | sym:: inline | sym:: no_inline,
2413- _,
2414- ) ,
2415- ..
2416- } ,
2417- _,
2418- ) ,
2419- )
2420- } ) ;
2421- args. tokens = TokenStream :: new ( tokens) ;
2422- attrs. push ( ( Cow :: Owned ( attr) , import_parent) ) ;
2423- }
2424- ast:: AttrArgs :: Empty | ast:: AttrArgs :: Eq ( ..) => {
2425- attrs. push ( ( Cow :: Owned ( attr) , import_parent) ) ;
2426- }
2424+ if let [ ident] = & * normal. item . path . segments {
2425+ let ident = ident. ident . name ;
2426+ if ident == sym:: doc {
2427+ filter_doc_attr ( normal, is_inline) ;
2428+ attrs. push ( ( Cow :: Owned ( attr) , import_parent) ) ;
2429+ } else if ident != sym:: cfg {
2430+ // If it's not a `cfg()` attribute, we keep it.
2431+ attrs. push ( ( Cow :: Owned ( attr) , import_parent) ) ;
24272432 }
24282433 }
24292434 }
0 commit comments