Skip to content

Commit 03a9889

Browse files
committed
Use tcx.arena.alloc_slice
1 parent 1f828f0 commit 03a9889

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

src/librustdoc/clean/mod.rs

+7-18
Original file line numberDiff line numberDiff line change
@@ -1499,30 +1499,18 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
14991499
fn first_non_private_clean_path<'tcx>(
15001500
cx: &mut DocContext<'tcx>,
15011501
path: &hir::Path<'tcx>,
1502-
mut new_path_segments: Vec<hir::PathSegment<'tcx>>,
1502+
new_path_segments: &'tcx mut [hir::PathSegment<'tcx>],
15031503
new_path_span: rustc_span::Span,
15041504
) -> Path {
1505-
use std::mem::transmute;
1506-
15071505
// In here we need to play with the path data one last time to provide it the
15081506
// missing `args` and `res` of the final `Path` we get, which, since it comes
15091507
// from a re-export, doesn't have the generics that were originally there, so
15101508
// we add them by hand.
15111509
if let Some(last) = new_path_segments.last_mut() {
1512-
// `transmute` is needed because we are using a wrong lifetime. Since
1513-
// `segments` will be dropped at the end of this block, it's fine.
1514-
last.args = unsafe { transmute(path.segments.last().as_ref().unwrap().args.clone()) };
1510+
last.args = path.segments.last().as_ref().unwrap().args.clone();
15151511
last.res = path.res;
15161512
}
1517-
// `transmute` is needed because we are using a wrong lifetime. Since
1518-
// `segments` will be dropped at the end of this block, it's fine.
1519-
let path = unsafe {
1520-
hir::Path {
1521-
segments: transmute(new_path_segments.as_slice()),
1522-
res: path.res,
1523-
span: new_path_span,
1524-
}
1525-
};
1513+
let path = hir::Path { segments: new_path_segments, res: path.res, span: new_path_span };
15261514
clean_path(&path, cx)
15271515
}
15281516

@@ -1541,8 +1529,9 @@ fn first_non_private<'tcx>(
15411529
.updated_qpath
15421530
.borrow()
15431531
.get(&use_id)
1544-
.map(|saved_path| (saved_path.segments.to_vec(), saved_path.span));
1532+
.map(|saved_path| (saved_path.segments, saved_path.span));
15451533
if let Some((segments, span)) = saved_path {
1534+
let segments = cx.tcx.arena.alloc_slice(segments);
15461535
return Some(first_non_private_clean_path(cx, path, segments, span));
15471536
}
15481537
let (parent_def_id, ident) = match &path.segments[..] {
@@ -1611,8 +1600,8 @@ fn first_non_private<'tcx>(
16111600
// 2. We didn't find a public reexport so it's the "end type" path.
16121601
if let Some((new_path, _)) = last_path_res {
16131602
cx.updated_qpath.borrow_mut().insert(use_id, new_path.clone());
1614-
let new_path_segments = new_path.segments.to_vec();
1615-
return Some(first_non_private_clean_path(cx, path, new_path_segments, new_path.span));
1603+
let segments = cx.tcx.arena.alloc_slice(new_path.segments);
1604+
return Some(first_non_private_clean_path(cx, path, segments, new_path.span));
16161605
}
16171606
// If `last_path_res` is `None`, it can mean two things:
16181607
//

0 commit comments

Comments
 (0)