Revert "Remove needs for transmute"

This reverts commit ea9a17b9995b7a076283777b7d462a360fece2d6.
This commit is contained in:
Guillaume Gomez 2023-07-13 13:54:23 +02:00
parent bc7d958ab2
commit 662c167711
2 changed files with 20 additions and 28 deletions

View File

@ -1500,11 +1500,13 @@ fn param_eq_arg(param: &GenericParamDef, arg: &GenericArg) -> bool {
/// or `doc(hidden)`). If it's not possible, it'll return the "end type". /// or `doc(hidden)`). If it's not possible, it'll return the "end type".
/// ///
/// If the path is not a re-export or is public, it'll return `None`. /// If the path is not a re-export or is public, it'll return `None`.
fn first_non_private<'tcx>( fn first_non_private(
cx: &mut DocContext<'tcx>, cx: &mut DocContext<'_>,
hir_id: hir::HirId, hir_id: hir::HirId,
path: &hir::Path<'tcx>, path: &hir::Path<'_>,
) -> Option<Path> { ) -> Option<Path> {
use std::mem::transmute;
let (parent_def_id, mut ident) = match &path.segments[..] { let (parent_def_id, mut ident) = match &path.segments[..] {
[] => return None, [] => return None,
// Relative paths are available in the same scope as the owner. // Relative paths are available in the same scope as the owner.
@ -1575,25 +1577,26 @@ fn first_non_private<'tcx>(
// 1. We found a public reexport. // 1. We found a public reexport.
// 2. We didn't find a public reexport so it's the "end type" path. // 2. We didn't find a public reexport so it's the "end type" path.
if let Some((new_path, _)) = last_path_res { if let Some((new_path, _)) = last_path_res {
let new_hir_path = hir::Path {
segments: new_path.segments,
res: path.res,
span: new_path.span,
};
let mut new_clean_path = clean_path(&new_hir_path, cx);
// In here we need to play with the path data one last time to provide it the // In here we need to play with the path data one last time to provide it the
// missing `args` and `res` of the final `Path` we get, which, since it comes // missing `args` and `res` of the final `Path` we get, which, since it comes
// from a re-export, doesn't have the generics that were originally there, so // from a re-export, doesn't have the generics that were originally there, so
// we add them by hand. // we add them by hand.
if let Some(path_last) = path.segments.last().as_ref() let mut segments = new_path.segments.to_vec();
&& let Some(new_path_last) = new_clean_path.segments[..].last_mut() if let Some(last) = segments.last_mut() {
&& let Some(path_last_args) = path_last.args.as_ref() // `transmute` is needed because we are using a wrong lifetime. Since
&& path_last.args.is_some() // `segments` will be dropped at the end of this block, it's fine.
{ last.args = unsafe {
assert!(new_path_last.args.is_empty()); transmute(
new_path_last.args = clean_generic_args(path_last_args, cx); path.segments.last().as_ref().unwrap().args.clone(),
)
};
last.res = path.res;
} }
return Some(new_clean_path); // `transmute` is needed because we are using a wrong lifetime. Since
// `segments` will be dropped at the end of this block, it's fine.
let segments = unsafe { transmute(segments.as_slice()) };
let new_path = hir::Path { segments, res: path.res, span: new_path.span };
return Some(clean_path(&new_path, cx));
} }
// If `last_path_res` is `None`, it can mean two things: // If `last_path_res` is `None`, it can mean two things:
// //

View File

@ -2203,17 +2203,6 @@ pub(crate) enum GenericArgs {
Parenthesized { inputs: Box<[Type]>, output: Option<Box<Type>> }, Parenthesized { inputs: Box<[Type]>, output: Option<Box<Type>> },
} }
impl GenericArgs {
pub(crate) fn is_empty(&self) -> bool {
match self {
GenericArgs::AngleBracketed { args, bindings } => {
args.is_empty() && bindings.is_empty()
}
GenericArgs::Parenthesized { inputs, output } => inputs.is_empty() && output.is_none(),
}
}
}
#[derive(Clone, PartialEq, Eq, Debug, Hash)] #[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub(crate) struct PathSegment { pub(crate) struct PathSegment {
pub(crate) name: Symbol, pub(crate) name: Symbol,