Skip to content

Commit bc7aa19

Browse files
authored
Unrolled build for #153136
Rollup merge of #153136 - GuillaumeGomez:reexport-doc-alias, r=lolbinarycat Correctly handle `#[doc(alias = "...")]` attribute on inlined reexports Fixes #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 1d113d2 + ab9e1da commit bc7aa19

File tree

7 files changed

+90
-1
lines changed

7 files changed

+90
-1
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2701,14 +2701,37 @@ fn add_without_unwanted_attributes<'hir>(
27012701
}
27022702
hir::Attribute::Parsed(AttributeKind::Doc(box d)) => {
27032703
// Remove attributes from `normal` that should not be inherited by `use` re-export.
2704-
let DocAttribute { hidden, inline, cfg, .. } = d;
2704+
let DocAttribute {
2705+
aliases,
2706+
hidden,
2707+
inline,
2708+
cfg,
2709+
auto_cfg: _,
2710+
auto_cfg_change: _,
2711+
fake_variadic: _,
2712+
keyword: _,
2713+
attribute: _,
2714+
masked: _,
2715+
notable_trait: _,
2716+
search_unbox: _,
2717+
html_favicon_url: _,
2718+
html_logo_url: _,
2719+
html_playground_url: _,
2720+
html_root_url: _,
2721+
html_no_source: _,
2722+
issue_tracker_base_url: _,
2723+
rust_logo: _,
2724+
test_attrs: _,
2725+
no_crate_inject: _,
2726+
} = d;
27052727
let mut attr = DocAttribute::default();
27062728
if is_inline {
27072729
attr.cfg = cfg.clone();
27082730
} else {
27092731
attr.inline = inline.clone();
27102732
attr.hidden = hidden.clone();
27112733
}
2734+
attr.aliases = aliases.clone();
27122735
attrs.push((
27132736
Cow::Owned(hir::Attribute::Parsed(AttributeKind::Doc(Box::new(attr)))),
27142737
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)