Skip to content

Commit 0c07af1

Browse files
Rollup merge of rust-lang#153136 - GuillaumeGomez:reexport-doc-alias, r=lolbinarycat
Correctly handle `#[doc(alias = "...")]` attribute on inlined reexports Fixes rust-lang#152939. During the doc attributing migration to the new API, this information got lost. At least now we have a test for it. :) r? @lolbinarycat
2 parents 46e366f + ab9e1da commit 0c07af1

7 files changed

Lines changed: 90 additions & 1 deletion

File tree

src/librustdoc/clean/mod.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2709,14 +2709,37 @@ fn add_without_unwanted_attributes<'hir>(
27092709
}
27102710
hir::Attribute::Parsed(AttributeKind::Doc(box d)) => {
27112711
// Remove attributes from `normal` that should not be inherited by `use` re-export.
2712-
let DocAttribute { hidden, inline, cfg, .. } = d;
2712+
let DocAttribute {
2713+
aliases,
2714+
hidden,
2715+
inline,
2716+
cfg,
2717+
auto_cfg: _,
2718+
auto_cfg_change: _,
2719+
fake_variadic: _,
2720+
keyword: _,
2721+
attribute: _,
2722+
masked: _,
2723+
notable_trait: _,
2724+
search_unbox: _,
2725+
html_favicon_url: _,
2726+
html_logo_url: _,
2727+
html_playground_url: _,
2728+
html_root_url: _,
2729+
html_no_source: _,
2730+
issue_tracker_base_url: _,
2731+
rust_logo: _,
2732+
test_attrs: _,
2733+
no_crate_inject: _,
2734+
} = d;
27132735
let mut attr = DocAttribute::default();
27142736
if is_inline {
27152737
attr.cfg = cfg.clone();
27162738
} else {
27172739
attr.inline = inline.clone();
27182740
attr.hidden = hidden.clone();
27192741
}
2742+
attr.aliases = aliases.clone();
27202743
attrs.push((
27212744
Cow::Owned(hir::Attribute::Parsed(AttributeKind::Doc(Box::new(attr)))),
27222745
import_parent,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#[doc(alias = "answer")]
2+
pub fn number() {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![feature(rustdoc_internals)]
2+
3+
#[doc(search_unbox)]
4+
pub struct Inside<T>(T);
5+
6+
#[doc(search_unbox)]
7+
pub struct Out<A, B = ()> {
8+
a: A,
9+
b: B,
10+
}
11+
12+
#[doc(search_unbox)]
13+
pub struct Out1<A, const N: usize> {
14+
a: [A; N],
15+
}
16+
17+
#[doc(search_unbox)]
18+
pub struct Out2<A, const N: usize> {
19+
a: [A; N],
20+
}

tests/rustdoc-js/reexport-alias.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// exact-check
2+
3+
// This test ensures that inlined reexport items keep the `#[doc(alias = "...")]`
4+
// information.
5+
// This is a regression test for <https://github.com/rust-lang/rust/issues/152939>.
6+
7+
const EXPECTED = {
8+
'query': 'answer',
9+
'others': [
10+
{ 'path': 'foo', 'name': 'number', 'is_alias': true },
11+
],
12+
};

tests/rustdoc-js/reexport-alias.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//@ aux-crate:priv:reexport_alias=reexport-alias.rs
2+
//@ compile-flags: -Zunstable-options --extern equivalent
3+
4+
#![crate_name = "foo"]
5+
6+
extern crate reexport_alias;
7+
8+
pub use reexport_alias::number;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// exact-check
2+
3+
// This test ensures that `search_unbox` works even on inlined reexports.
4+
5+
const EXPECTED = [
6+
{
7+
'query': 'Inside<T> -> Out1<T>',
8+
'others': [
9+
{ 'path': 'foo', 'name': 'alpha' },
10+
],
11+
},
12+
]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ aux-crate:priv:reexport_search_unbox=reexport-search_unbox.rs
2+
//@ compile-flags: -Zunstable-options --extern equivalent
3+
4+
#![crate_name = "foo"]
5+
6+
extern crate reexport_search_unbox;
7+
8+
pub use reexport_search_unbox::{Inside, Out, Out1, Out2};
9+
10+
pub fn alpha<const N: usize, T>(_: Inside<T>) -> Out<Out1<T, N>, Out2<T, N>> {
11+
loop {}
12+
}

0 commit comments

Comments
 (0)