Skip to content

Commit 49ccde0

Browse files
Re-add missing generics in first_non_private
1 parent 5859b44 commit 49ccde0

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,8 @@ fn first_non_private(
15051505
hir_id: hir::HirId,
15061506
path: &hir::Path<'_>,
15071507
) -> Option<Path> {
1508+
use std::mem::transmute;
1509+
15081510
let (parent_def_id, mut ident) = match &path.segments[..] {
15091511
[] => return None,
15101512
// Relative paths are available in the same scope as the owner.
@@ -1574,9 +1576,27 @@ fn first_non_private(
15741576
//
15751577
// 1. We found a public reexport.
15761578
// 2. We didn't find a public reexport so it's the "end type" path.
1577-
if let Some((path, res)) = last_path_res {
1578-
let path = hir::Path { segments: path.segments, res: *res, span: path.span };
1579-
return Some(clean_path(&path, cx));
1579+
if let Some((new_path, _)) = last_path_res {
1580+
// In here we need to play with the path data one last time to provide it the
1581+
// missing `args` and `res` of the final `Path` we get, which, since it comes
1582+
// from a re-export, doesn't have the generics that were originally there, so
1583+
// we add them by hand.
1584+
let mut segments = new_path.segments.to_vec();
1585+
if let Some(last) = segments.last_mut() {
1586+
// `transmute` is needed because we are using a wrong lifetime. Since
1587+
// `segments` will be dropped at the end of this block, it's fine.
1588+
last.args = unsafe {
1589+
transmute(
1590+
path.segments.last().as_ref().unwrap().args.clone(),
1591+
)
1592+
};
1593+
last.res = path.res;
1594+
}
1595+
// `transmute` is needed because we are using a wrong lifetime. Since
1596+
// `segments` will be dropped at the end of this block, it's fine.
1597+
let segments = unsafe { transmute(segments.as_slice()) };
1598+
let new_path = hir::Path { segments, res: path.res, span: new_path.span };
1599+
return Some(clean_path(&new_path, cx));
15801600
}
15811601
// If `last_path_res` is `None`, it can mean two things:
15821602
//

0 commit comments

Comments
 (0)