Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ fn generate_item_with_correct_attrs(
attrs.extend(get_all_import_attributes(cx, import_id, def_id, is_inline));
is_inline = is_inline || import_is_inline;
}
add_without_unwanted_attributes(&mut attrs, target_attrs, is_inline, None);
let keep_target_cfg = is_inline || matches!(kind, ItemKind::TypeAliasItem(..));
add_without_unwanted_attributes(&mut attrs, target_attrs, keep_target_cfg, None);
attrs
} else {
// We only keep the item's attributes.
Expand Down
34 changes: 34 additions & 0 deletions tests/rustdoc-html/reexport/type-alias-reexport.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Regression test for <https://github.com/rust-lang/rust/issues/154921>.
// This test ensures that auto-generated and explicit `doc(cfg)` attributes are correctly
// preserved for locally re-exported type aliases.

//@ compile-flags: --cfg feature="foo"

#![crate_name = "foo"]
#![feature(doc_cfg)]

mod inner {
#[cfg(feature = "foo")]
pub type One = u32;

#[doc(cfg(feature = "foo"))]
pub type Two = u32;
}

//@ has 'foo/index.html'
// There should be two items in the type aliases table.
//@ count - '//*[@class="item-table"]/dt' 2
// Both of them should have the portability badge in the module index.
//@ count - '//*[@class="item-table"]/dt/*[@class="stab portability"]' 2

//@ has 'foo/type.One.html'
// Check that the individual type page has the portability badge.
//@ count - '//*[@id="main-content"]/*[@class="item-info"]/*[@class="stab portability"]' 1
//@ has - '//*[@id="main-content"]/*[@class="item-info"]/*[@class="stab portability"]' 'foo'

//@ has 'foo/type.Two.html'
// Check the explicit doc(cfg) type page as well.
//@ count - '//*[@id="main-content"]/*[@class="item-info"]/*[@class="stab portability"]' 1
//@ has - '//*[@id="main-content"]/*[@class="item-info"]/*[@class="stab portability"]' 'foo'

pub use self::inner::{One, Two};
Loading