Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 1169832

Browse files
committed
rustdoc: extend #[doc(tuple_variadic)] to fn pointers
The attribute is also renamed `fake_variadic`.
1 parent 263edd4 commit 1169832

File tree

21 files changed

+61
-42
lines changed

21 files changed

+61
-42
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,8 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
402402
gate_feature_post!(self, rustdoc_internals, attr.span, msg);
403403
}
404404

405-
if nested_meta.has_name(sym::tuple_variadic) {
406-
let msg = "`#[doc(tuple_variadic)]` is meant for internal use only";
405+
if nested_meta.has_name(sym::fake_variadic) {
406+
let msg = "`#[doc(fake_variadic)]` is meant for internal use only";
407407
gate_feature_post!(self, rustdoc_internals, attr.span, msg);
408408
}
409409
}

compiler/rustc_error_messages/locales/en-US/passes.ftl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ passes-doc-keyword-not-mod = `#[doc(keyword = "...")]` should be used on modules
8181
8282
passes-doc-keyword-invalid-ident = `{$doc_keyword}` is not a valid identifier
8383
84-
passes-doc-tuple-variadic-not-first =
85-
`#[doc(tuple_variadic)]` must be used on the first of a set of tuple trait impls with varying arity
84+
passes-doc-fake-variadic-not-valid =
85+
`#[doc(fake_variadic)]` must be used on the first of a set of tuple or fn pointer trait impls with varying arity
8686
8787
passes-doc-keyword-only-impl = `#[doc(keyword = "...")]` should be used on impl blocks
8888

compiler/rustc_passes/src/check_attr.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -706,14 +706,20 @@ impl CheckAttrVisitor<'_> {
706706
true
707707
}
708708

709-
fn check_doc_tuple_variadic(&self, meta: &NestedMetaItem, hir_id: HirId) -> bool {
709+
fn check_doc_fake_variadic(&self, meta: &NestedMetaItem, hir_id: HirId) -> bool {
710710
match self.tcx.hir().find(hir_id).and_then(|node| match node {
711711
hir::Node::Item(item) => Some(&item.kind),
712712
_ => None,
713713
}) {
714714
Some(ItemKind::Impl(ref i)) => {
715-
if !matches!(&i.self_ty.kind, hir::TyKind::Tup([_])) {
716-
self.tcx.sess.emit_err(errors::DocTupleVariadicNotFirst { span: meta.span() });
715+
let is_valid = matches!(&i.self_ty.kind, hir::TyKind::Tup([_]))
716+
|| if let hir::TyKind::BareFn(bare_fn_ty) = &i.self_ty.kind {
717+
bare_fn_ty.decl.inputs.len() == 1
718+
} else {
719+
false
720+
};
721+
if !is_valid {
722+
self.tcx.sess.emit_err(errors::DocFakeVariadicNotValid { span: meta.span() });
717723
return false;
718724
}
719725
}
@@ -887,9 +893,9 @@ impl CheckAttrVisitor<'_> {
887893
is_valid = false
888894
}
889895

890-
sym::tuple_variadic
891-
if !self.check_attr_not_crate_level(meta, hir_id, "tuple_variadic")
892-
|| !self.check_doc_tuple_variadic(meta, hir_id) =>
896+
sym::fake_variadic
897+
if !self.check_attr_not_crate_level(meta, hir_id, "fake_variadic")
898+
|| !self.check_doc_fake_variadic(meta, hir_id) =>
893899
{
894900
is_valid = false
895901
}
@@ -939,7 +945,7 @@ impl CheckAttrVisitor<'_> {
939945
| sym::notable_trait
940946
| sym::passes
941947
| sym::plugins
942-
| sym::tuple_variadic => {}
948+
| sym::fake_variadic => {}
943949

944950
sym::test => {
945951
if !self.check_test_attr(meta, hir_id) {

compiler/rustc_passes/src/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ pub struct DocKeywordInvalidIdent {
212212
}
213213

214214
#[derive(SessionDiagnostic)]
215-
#[error(passes::doc_tuple_variadic_not_first)]
216-
pub struct DocTupleVariadicNotFirst {
215+
#[error(passes::doc_fake_variadic_not_valid)]
216+
pub struct DocFakeVariadicNotValid {
217217
#[primary_span]
218218
pub span: Span,
219219
}

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@ symbols! {
685685
fabsf32,
686686
fabsf64,
687687
fadd_fast,
688+
fake_variadic,
688689
fdiv_fast,
689690
feature,
690691
fence,
@@ -1460,7 +1461,6 @@ symbols! {
14601461
tuple,
14611462
tuple_from_req,
14621463
tuple_indexing,
1463-
tuple_variadic,
14641464
two_phase,
14651465
ty,
14661466
type_alias_enum_variants,

library/core/src/fmt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2562,7 +2562,7 @@ macro_rules! tuple {
25622562

25632563
macro_rules! maybe_tuple_doc {
25642564
($a:ident @ #[$meta:meta] $item:item) => {
2565-
#[doc(tuple_variadic)]
2565+
#[cfg_attr(not(bootstrap), doc(fake_variadic))]
25662566
#[doc = "This trait is implemented for tuples up to twelve items long."]
25672567
#[$meta]
25682568
$item

library/core/src/hash/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ mod impls {
900900

901901
macro_rules! maybe_tuple_doc {
902902
($a:ident @ #[$meta:meta] $item:item) => {
903-
#[doc(tuple_variadic)]
903+
#[cfg_attr(not(bootstrap), doc(fake_variadic))]
904904
#[doc = "This trait is implemented for tuples up to twelve items long."]
905905
#[$meta]
906906
$item

library/core/src/primitive_docs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ impl<T> (T,) {}
996996
// Fake impl that's only really used for docs.
997997
#[cfg(doc)]
998998
#[stable(feature = "rust1", since = "1.0.0")]
999-
#[doc(tuple_variadic)]
999+
#[cfg_attr(not(bootstrap), doc(fake_variadic))]
10001000
/// This trait is implemented on arbitrary-length tuples.
10011001
impl<T: Clone> Clone for (T,) {
10021002
fn clone(&self) -> Self {
@@ -1007,7 +1007,7 @@ impl<T: Clone> Clone for (T,) {
10071007
// Fake impl that's only really used for docs.
10081008
#[cfg(doc)]
10091009
#[stable(feature = "rust1", since = "1.0.0")]
1010-
#[doc(tuple_variadic)]
1010+
#[cfg_attr(not(bootstrap), doc(fake_variadic))]
10111011
/// This trait is implemented on arbitrary-length tuples.
10121012
impl<T: Copy> Copy for (T,) {
10131013
// empty

library/core/src/tuple.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ macro_rules! tuple_impls {
107107
// Otherwise, it hides the docs entirely.
108108
macro_rules! maybe_tuple_doc {
109109
($a:ident @ #[$meta:meta] $item:item) => {
110-
#[doc(tuple_variadic)]
110+
#[cfg_attr(not(bootstrap), doc(fake_variadic))]
111111
#[doc = "This trait is implemented for tuples up to twelve items long."]
112112
#[$meta]
113113
$item

library/std/src/primitive_docs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ impl<T> (T,) {}
996996
// Fake impl that's only really used for docs.
997997
#[cfg(doc)]
998998
#[stable(feature = "rust1", since = "1.0.0")]
999-
#[doc(tuple_variadic)]
999+
#[cfg_attr(not(bootstrap), doc(fake_variadic))]
10001000
/// This trait is implemented on arbitrary-length tuples.
10011001
impl<T: Clone> Clone for (T,) {
10021002
fn clone(&self) -> Self {
@@ -1007,7 +1007,7 @@ impl<T: Clone> Clone for (T,) {
10071007
// Fake impl that's only really used for docs.
10081008
#[cfg(doc)]
10091009
#[stable(feature = "rust1", since = "1.0.0")]
1010-
#[doc(tuple_variadic)]
1010+
#[cfg_attr(not(bootstrap), doc(fake_variadic))]
10111011
/// This trait is implemented on arbitrary-length tuples.
10121012
impl<T: Copy> Copy for (T,) {
10131013
// empty

0 commit comments

Comments
 (0)