diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 277ec91f15ed..598d6da390a3 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -477,6 +477,7 @@ fn build_module( }], }, did: None, + attrs: None, }, true, )), diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 2b25c6a26bcc..75c541a50ed5 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -2081,6 +2081,7 @@ crate enum ImportKind { crate struct ImportSource { crate path: Path, crate did: Option, + crate attrs: Option, } #[derive(Clone, Debug)] diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index c2a971d63751..898a5b0df5db 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -468,10 +468,10 @@ crate fn register_res(cx: &mut DocContext<'_>, res: Res) -> DefId { } crate fn resolve_use_source(cx: &mut DocContext<'_>, path: Path) -> ImportSource { - ImportSource { - did: if path.res.opt_def_id().is_none() { None } else { Some(register_res(cx, path.res)) }, - path, - } + let did = if path.res.opt_def_id().is_none() { None } else { Some(register_res(cx, path.res)) }; + let attrs = did.map(|did| cx.tcx.get_attrs(did).clean(cx)); + + ImportSource { did, path, attrs } } crate fn enter_impl_trait(cx: &mut DocContext<'_>, f: F) -> R diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index c37a21d1adef..045ff5b4b897 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -282,9 +282,14 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl } clean::ImportItem(ref import) => { - let (stab, stab_tags) = if let Some(def_id) = import.source.did { - // Just need an item with the correct def_id - let import_item = clean::Item { def_id, ..myitem.clone() }; + let (stab, stab_tags) = if let (Some(def_id), Some(attrs)) = + (import.source.did, import.source.attrs.clone()) + { + let attrs = Box::new(attrs); + + // Just need an item with the correct def_id and attrs + let import_item = clean::Item { def_id, attrs, ..myitem.clone() }; + let stab = import_item.stability_class(cx.tcx()); let stab_tags = Some(extra_info_tags(&import_item, item, cx.tcx())); (stab, stab_tags) diff --git a/src/test/rustdoc/issue-83832.rs b/src/test/rustdoc/issue-83832.rs index 93dff7c6ce64..a00401fbe09f 100644 --- a/src/test/rustdoc/issue-83832.rs +++ b/src/test/rustdoc/issue-83832.rs @@ -1,21 +1,36 @@ #![crate_name = "foo"] +#![feature(doc_cfg)] -pub mod io { +pub mod tag { #[deprecated(since = "0.1.8", note = "Use bar() instead")] - pub trait Reader {} - pub trait Writer {} + pub trait Deprecated {} + + #[doc(cfg(feature = "sync"))] + pub trait Portability {} + + pub trait Unstable {} } // @has foo/mod1/index.html pub mod mod1 { - // @has - '//code' 'pub use io::Reader;' + // @has - '//code' 'pub use tag::Deprecated;' // @has - '//span' 'Deprecated' - pub use io::Reader; + // @!has - '//span' 'sync' + pub use tag::Deprecated; } // @has foo/mod2/index.html pub mod mod2 { - // @has - '//code' 'pub use io::Writer;' + // @has - '//code' 'pub use tag::Portability;' // @!has - '//span' 'Deprecated' - pub use io::Writer; + // @has - '//span' 'sync' + pub use tag::Portability; +} + +// @has foo/mod3/index.html +pub mod mod3 { + // @has - '//code' 'pub use tag::Unstable;' + // @!has - '//span' 'Deprecated' + // @!has - '//span' 'sync' + pub use tag::Unstable; }