-
Notifications
You must be signed in to change notification settings - Fork 13k
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
rustdoc: Also index impl Trait
s and raw pointers
#92339
Changes from 1 commit
8f5a308
283c71e
f27ed72
1186c15
e7222b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -185,24 +185,19 @@ crate fn get_function_type_for_search<'tcx>( | |
item: &clean::Item, | ||
tcx: TyCtxt<'tcx>, | ||
) -> Option<IndexItemFunctionType> { | ||
let (mut inputs, mut output) = match *item.kind { | ||
let (inputs, output) = match *item.kind { | ||
clean::FunctionItem(ref f) => get_fn_inputs_and_outputs(f, tcx), | ||
clean::MethodItem(ref m, _) => get_fn_inputs_and_outputs(m, tcx), | ||
clean::TyMethodItem(ref m) => get_fn_inputs_and_outputs(m, tcx), | ||
_ => return None, | ||
}; | ||
|
||
inputs.retain(|a| a.ty.name.is_some()); | ||
output.retain(|a| a.ty.name.is_some()); | ||
|
||
Some(IndexItemFunctionType { inputs, output }) | ||
} | ||
|
||
fn get_index_type(clean_type: &clean::Type, generics: Vec<TypeWithKind>) -> RenderType { | ||
RenderType { | ||
name: get_index_type_name(clean_type).map(|s| s.as_str().to_ascii_lowercase()), | ||
generics: if generics.is_empty() { None } else { Some(generics) }, | ||
} | ||
fn get_index_type(clean_type: &clean::Type, generics: Vec<TypeWithKind>) -> Option<RenderType> { | ||
get_index_type_name(clean_type) | ||
.map(|s| RenderType { name: s.as_str().to_ascii_lowercase(), generics }) | ||
} | ||
|
||
fn get_index_type_name(clean_type: &clean::Type) -> Option<Symbol> { | ||
|
@@ -306,19 +301,17 @@ fn add_generics_and_bounds_as_types<'tcx>( | |
return; | ||
} | ||
} | ||
let mut index_ty = get_index_type(&ty, generics); | ||
if index_ty.name.as_ref().map(|s| s.is_empty()).unwrap_or(true) { | ||
return; | ||
} | ||
let Some(mut index_ty) = get_index_type(&ty, generics) | ||
else { return }; | ||
if is_full_generic { | ||
// We remove the name of the full generic because we have no use for it. | ||
index_ty.name = Some(String::new()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like, in the multi-generic case you were worried about, the old code didn't actually set the value to On the one hand, this means we can get rid of the Option wrapper without breaking anything. On the other hand, this is really strange code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the record, I approve of this refactoring. If the generated JSON uses the empty string as its sentinel here (and it should, because it's smaller), then RenderType should just use the empty string here to match. My point here is that the old code, which uses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is another open PR which fixes this part but can't find it... T_T |
||
res.push(TypeWithKind::from((index_ty, ItemType::Generic))); | ||
index_ty.name = String::new(); | ||
res.push(TypeWithKind { ty: index_ty, kind: ItemType::Generic }); | ||
} else if let Some(kind) = ty.def_id_no_primitives().map(|did| tcx.def_kind(did).into()) { | ||
res.push(TypeWithKind::from((index_ty, kind))); | ||
res.push(TypeWithKind { ty: index_ty, kind }); | ||
} else if ty.is_primitive() { | ||
// This is a primitive, let's store it as such. | ||
res.push(TypeWithKind::from((index_ty, ItemType::Primitive))); | ||
res.push(TypeWithKind { ty: index_ty, kind: ItemType::Primitive }); | ||
} | ||
} | ||
|
||
|
@@ -416,7 +409,9 @@ fn get_fn_inputs_and_outputs<'tcx>( | |
} else { | ||
if let Some(kind) = arg.type_.def_id_no_primitives().map(|did| tcx.def_kind(did).into()) | ||
{ | ||
all_types.push(TypeWithKind::from((get_index_type(&arg.type_, vec![]), kind))); | ||
if let Some(ty) = get_index_type(&arg.type_, vec![]) { | ||
all_types.push(TypeWithKind { ty, kind }); | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -429,7 +424,9 @@ fn get_fn_inputs_and_outputs<'tcx>( | |
if let Some(kind) = | ||
return_type.def_id_no_primitives().map(|did| tcx.def_kind(did).into()) | ||
{ | ||
ret_types.push(TypeWithKind::from((get_index_type(return_type, vec![]), kind))); | ||
if let Some(ty) = get_index_type(return_type, vec![]) { | ||
ret_types.push(TypeWithKind { ty, kind }); | ||
} | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this and similar refactorings have any effect on behavior? I found it quite bizarre that the search-index representation of a type can exist without a name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible in case you have something like
T: Display + Whatever
. In this case, sinceT
isn't a type, we don't keep its name. Please revert this change.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change didn't cause any tests to fail though. Could you please write a test case that passes on
master
and fails with this refactoring? Otherwise it'll be hard to not break this code accidentally.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add one then. Something like (in
rustdoc-js
):Then look for
Something
. You shouldn't have any result.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#93339