rustdoc: Extend fake_variadic to "wrapped" tuples
This allows impls such as `impl QueryData for OneOf<(T,)>` to be displayed as variadic: `impl QueryData for OneOf<(T₁, T₂, …, Tₙ)>`. See question on zulip: <https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/Make.20.60.23.5Bdoc.28fake_variadic.29.5D.60.20more.20useful>
This commit is contained in:
parent
8aca4bab08
commit
4e48768908
3 changed files with 55 additions and 6 deletions
|
@ -918,12 +918,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||
};
|
||||
match item_kind {
|
||||
Some(ItemKind::Impl(i)) => {
|
||||
let is_valid = matches!(&i.self_ty.kind, hir::TyKind::Tup([_]))
|
||||
|| if let hir::TyKind::BareFn(bare_fn_ty) = &i.self_ty.kind {
|
||||
bare_fn_ty.decl.inputs.len() == 1
|
||||
} else {
|
||||
false
|
||||
}
|
||||
let is_valid = doc_fake_variadic_is_allowed_self_ty(i.self_ty)
|
||||
|| if let Some(&[hir::GenericArg::Type(ty)]) = i
|
||||
.of_trait
|
||||
.as_ref()
|
||||
|
@ -2630,3 +2625,20 @@ fn check_duplicates(
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn doc_fake_variadic_is_allowed_self_ty(self_ty: &hir::Ty<'_>) -> bool {
|
||||
matches!(&self_ty.kind, hir::TyKind::Tup([_]))
|
||||
|| if let hir::TyKind::BareFn(bare_fn_ty) = &self_ty.kind {
|
||||
bare_fn_ty.decl.inputs.len() == 1
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|| (if let hir::TyKind::Path(hir::QPath::Resolved(_, path)) = &self_ty.kind
|
||||
&& let Some(&[hir::GenericArg::Type(ty)]) =
|
||||
path.segments.last().map(|last| last.args().args)
|
||||
{
|
||||
doc_fake_variadic_is_allowed_self_ty(ty)
|
||||
} else {
|
||||
false
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue