Skip to content

[rustdoc] If re-export is private, get the next item until a public one is found or expose the private item directly #113374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove needs for transmute
  • Loading branch information
GuillaumeGomez committed Jul 24, 2023
commit bc7d958ab2768d022a3ed6af96a222543b13e1a3
37 changes: 17 additions & 20 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1500,13 +1500,11 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
/// 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`.
fn first_non_private(
cx: &mut DocContext<'_>,
fn first_non_private<'tcx>(
cx: &mut DocContext<'tcx>,
hir_id: hir::HirId,
path: &hir::Path<'_>,
path: &hir::Path<'tcx>,
) -> Option<Path> {
use std::mem::transmute;

let (parent_def_id, mut ident) = match &path.segments[..] {
[] => return None,
// Relative paths are available in the same scope as the owner.
Expand Down Expand Up @@ -1577,26 +1575,25 @@ fn first_non_private(
// 1. We found a public reexport.
// 2. We didn't find a public reexport so it's the "end type" path.
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
// 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
// we add them by hand.
let mut segments = new_path.segments.to_vec();
if let Some(last) = segments.last_mut() {
// `transmute` is needed because we are using a wrong lifetime. Since
// `segments` will be dropped at the end of this block, it's fine.
last.args = unsafe {
transmute(
path.segments.last().as_ref().unwrap().args.clone(),
)
};
last.res = path.res;
if let Some(path_last) = path.segments.last().as_ref()
&& let Some(new_path_last) = new_clean_path.segments[..].last_mut()
&& let Some(path_last_args) = path_last.args.as_ref()
&& path_last.args.is_some()
{
assert!(new_path_last.args.is_empty());
new_path_last.args = clean_generic_args(path_last_args, cx);
}
// `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));
return Some(new_clean_path);
}
// If `last_path_res` is `None`, it can mean two things:
//
Expand Down
11 changes: 11 additions & 0 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2203,6 +2203,17 @@ pub(crate) enum GenericArgs {
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)]
pub(crate) struct PathSegment {
pub(crate) name: Symbol,
Expand Down