Skip to content

Commit 662c167

Browse files
Revert "Remove needs for transmute"
This reverts commit ea9a17b9995b7a076283777b7d462a360fece2d6.
1 parent bc7d958 commit 662c167

File tree

2 files changed

+20
-28
lines changed

2 files changed

+20
-28
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,11 +1500,13 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
15001500
/// or `doc(hidden)`). If it's not possible, it'll return the "end type".
15011501
///
15021502
/// If the path is not a re-export or is public, it'll return `None`.
1503-
fn first_non_private<'tcx>(
1504-
cx: &mut DocContext<'tcx>,
1503+
fn first_non_private(
1504+
cx: &mut DocContext<'_>,
15051505
hir_id: hir::HirId,
1506-
path: &hir::Path<'tcx>,
1506+
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.
@@ -1575,25 +1577,26 @@ fn first_non_private<'tcx>(
15751577
// 1. We found a public reexport.
15761578
// 2. We didn't find a public reexport so it's the "end type" path.
15771579
if let Some((new_path, _)) = last_path_res {
1578-
let new_hir_path = hir::Path {
1579-
segments: new_path.segments,
1580-
res: path.res,
1581-
span: new_path.span,
1582-
};
1583-
let mut new_clean_path = clean_path(&new_hir_path, cx);
15841580
// In here we need to play with the path data one last time to provide it the
15851581
// missing `args` and `res` of the final `Path` we get, which, since it comes
15861582
// from a re-export, doesn't have the generics that were originally there, so
15871583
// we add them by hand.
1588-
if let Some(path_last) = path.segments.last().as_ref()
1589-
&& let Some(new_path_last) = new_clean_path.segments[..].last_mut()
1590-
&& let Some(path_last_args) = path_last.args.as_ref()
1591-
&& path_last.args.is_some()
1592-
{
1593-
assert!(new_path_last.args.is_empty());
1594-
new_path_last.args = clean_generic_args(path_last_args, cx);
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;
15951594
}
1596-
return Some(new_clean_path);
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));
15971600
}
15981601
// If `last_path_res` is `None`, it can mean two things:
15991602
//

src/librustdoc/clean/types.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,17 +2203,6 @@ pub(crate) enum GenericArgs {
22032203
Parenthesized { inputs: Box<[Type]>, output: Option<Box<Type>> },
22042204
}
22052205

2206-
impl GenericArgs {
2207-
pub(crate) fn is_empty(&self) -> bool {
2208-
match self {
2209-
GenericArgs::AngleBracketed { args, bindings } => {
2210-
args.is_empty() && bindings.is_empty()
2211-
}
2212-
GenericArgs::Parenthesized { inputs, output } => inputs.is_empty() && output.is_none(),
2213-
}
2214-
}
2215-
}
2216-
22172206
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
22182207
pub(crate) struct PathSegment {
22192208
pub(crate) name: Symbol,

0 commit comments

Comments
 (0)