Skip to content

Commit 1509254

Browse files
committed
prevent TrivialClone implementations from appearing in rustdoc output
1 parent c5e262c commit 1509254

File tree

22 files changed

+48
-1
lines changed

22 files changed

+48
-1
lines changed

compiler/rustc_builtin_macros/src/deriving/bounds.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub(crate) fn expand_deriving_copy(
2424
associated_types: Vec::new(),
2525
is_const,
2626
safety: Safety::Default,
27+
document: true,
2728
};
2829

2930
trait_def.expand(cx, mitem, item, push);
@@ -48,6 +49,7 @@ pub(crate) fn expand_deriving_const_param_ty(
4849
associated_types: Vec::new(),
4950
is_const,
5051
safety: Safety::Default,
52+
document: true,
5153
};
5254

5355
trait_def.expand(cx, mitem, item, push);
@@ -63,6 +65,7 @@ pub(crate) fn expand_deriving_const_param_ty(
6365
associated_types: Vec::new(),
6466
is_const,
6567
safety: Safety::Default,
68+
document: true,
6669
};
6770

6871
trait_def.expand(cx, mitem, item, push);
@@ -87,6 +90,7 @@ pub(crate) fn expand_deriving_unsized_const_param_ty(
8790
associated_types: Vec::new(),
8891
is_const,
8992
safety: Safety::Default,
93+
document: true,
9094
};
9195

9296
trait_def.expand(cx, mitem, item, push);

compiler/rustc_builtin_macros/src/deriving/clone.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ pub(crate) fn expand_deriving_clone(
8282
associated_types: Vec::new(),
8383
is_const,
8484
safety: Safety::Unsafe(DUMMY_SP),
85+
// `TrivialClone` is not part of an API guarantee, so it shouldn't
86+
// appear in rustdoc output.
87+
document: false,
8588
};
8689

8790
trivial_def.expand_ext(cx, mitem, item, push, true);
@@ -107,6 +110,7 @@ pub(crate) fn expand_deriving_clone(
107110
associated_types: Vec::new(),
108111
is_const,
109112
safety: Safety::Default,
113+
document: true,
110114
};
111115

112116
trait_def.expand_ext(cx, mitem, item, push, is_simple)

compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub(crate) fn expand_deriving_eq(
4444
associated_types: Vec::new(),
4545
is_const,
4646
safety: Safety::Default,
47+
document: true,
4748
};
4849
trait_def.expand_ext(cx, mitem, item, push, true)
4950
}

compiler/rustc_builtin_macros/src/deriving/cmp/ord.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub(crate) fn expand_deriving_ord(
3535
associated_types: Vec::new(),
3636
is_const,
3737
safety: Safety::Default,
38+
document: true,
3839
};
3940

4041
trait_def.expand(cx, mitem, item, push)

compiler/rustc_builtin_macros/src/deriving/cmp/partial_eq.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ pub(crate) fn expand_deriving_partial_eq(
8585
associated_types: Vec::new(),
8686
is_const: false,
8787
safety: Safety::Default,
88+
document: true,
8889
};
8990
structural_trait_def.expand(cx, mitem, item, push);
9091

@@ -112,6 +113,7 @@ pub(crate) fn expand_deriving_partial_eq(
112113
associated_types: Vec::new(),
113114
is_const,
114115
safety: Safety::Default,
116+
document: true,
115117
};
116118
trait_def.expand(cx, mitem, item, push)
117119
}

compiler/rustc_builtin_macros/src/deriving/cmp/partial_ord.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ pub(crate) fn expand_deriving_partial_ord(
6565
associated_types: Vec::new(),
6666
is_const,
6767
safety: Safety::Default,
68+
document: true,
6869
};
6970
trait_def.expand(cx, mitem, item, push)
7071
}

compiler/rustc_builtin_macros/src/deriving/debug.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub(crate) fn expand_deriving_debug(
4242
associated_types: Vec::new(),
4343
is_const,
4444
safety: Safety::Default,
45+
document: true,
4546
};
4647
trait_def.expand(cx, mitem, item, push)
4748
}

compiler/rustc_builtin_macros/src/deriving/default.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub(crate) fn expand_deriving_default(
5151
associated_types: Vec::new(),
5252
is_const,
5353
safety: Safety::Default,
54+
document: true,
5455
};
5556
trait_def.expand(cx, mitem, item, push)
5657
}

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ pub(crate) struct TraitDef<'a> {
224224

225225
/// The safety of the `impl`.
226226
pub safety: Safety,
227+
228+
/// Whether the added `impl` should appear in rustdoc output.
229+
pub document: bool,
227230
}
228231

229232
pub(crate) struct MethodDef<'a> {
@@ -787,7 +790,11 @@ impl<'a> TraitDef<'a> {
787790
let path = cx.path_all(self.span, false, vec![type_ident], self_params);
788791
let self_type = cx.ty_path(path);
789792

790-
let attrs = thin_vec![cx.attr_word(sym::automatically_derived, self.span),];
793+
let mut attrs = thin_vec![cx.attr_word(sym::automatically_derived, self.span),];
794+
if !self.document {
795+
attrs.push(cx.attr_nested_word(sym::doc, sym::hidden, self.span));
796+
}
797+
791798
let opt_trait_ref = Some(trait_ref);
792799

793800
cx.item(

compiler/rustc_builtin_macros/src/deriving/hash.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub(crate) fn expand_deriving_hash(
4242
associated_types: Vec::new(),
4343
is_const,
4444
safety: Safety::Default,
45+
document: true,
4546
};
4647

4748
hash_trait_def.expand(cx, mitem, item, push);

library/core/src/array/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ impl<T: Clone, const N: usize> Clone for [T; N] {
427427
}
428428
}
429429

430+
#[doc(hidden)]
430431
#[unstable(feature = "trivial_clone", issue = "none")]
431432
unsafe impl<T: TrivialClone, const N: usize> TrivialClone for [T; N] {}
432433

library/core/src/clone.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ mod impls {
539539
}
540540
}
541541

542+
#[doc(hidden)]
542543
#[unstable(feature = "trivial_clone", issue = "none")]
543544
unsafe impl TrivialClone for $t {}
544545
)*
@@ -560,9 +561,11 @@ mod impls {
560561
}
561562
}
562563

564+
#[doc(hidden)]
563565
#[unstable(feature = "trivial_clone", issue = "none")]
564566
unsafe impl TrivialClone for ! {}
565567

568+
#[doc(hidden)]
566569
#[unstable(feature = "trivial_clone", issue = "none")]
567570
unsafe impl TrivialClone for () {}
568571

@@ -574,6 +577,7 @@ mod impls {
574577
}
575578
}
576579

580+
#[doc(hidden)]
577581
#[unstable(feature = "trivial_clone", issue = "none")]
578582
unsafe impl<T: ?Sized> TrivialClone for *const T {}
579583

@@ -585,6 +589,7 @@ mod impls {
585589
}
586590
}
587591

592+
#[doc(hidden)]
588593
#[unstable(feature = "trivial_clone", issue = "none")]
589594
unsafe impl<T: ?Sized> TrivialClone for *mut T {}
590595

@@ -598,6 +603,7 @@ mod impls {
598603
}
599604
}
600605

606+
#[doc(hidden)]
601607
#[unstable(feature = "trivial_clone", issue = "none")]
602608
unsafe impl<T: ?Sized> TrivialClone for &T {}
603609

library/core/src/marker.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,7 @@ impl<T: ?Sized> Clone for PhantomData<T> {
813813
}
814814
}
815815

816+
#[doc(hidden)]
816817
#[unstable(feature = "trivial_clone", issue = "none")]
817818
unsafe impl<T: ?Sized> TrivialClone for PhantomData<T> {}
818819

library/core/src/marker/variance.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ macro_rules! phantom_type {
6161

6262
impl<T> Copy for $name<T> where T: ?Sized {}
6363

64+
#[doc(hidden)]
6465
unsafe impl<T> TrivialClone for $name<T> where T: ?Sized {}
6566

6667
impl<T> PartialEq for $name<T>

library/core/src/mem/maybe_uninit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ impl<T: Copy> Clone for MaybeUninit<T> {
274274
}
275275

276276
// SAFETY: the clone implementation is a copy, see above.
277+
#[doc(hidden)]
277278
#[unstable(feature = "trivial_clone", issue = "none")]
278279
unsafe impl<T> TrivialClone for MaybeUninit<T> where MaybeUninit<T>: Clone {}
279280

library/core/src/mem/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,7 @@ impl<T> clone::Clone for Discriminant<T> {
10391039
}
10401040
}
10411041

1042+
#[doc(hidden)]
10421043
#[unstable(feature = "trivial_clone", issue = "none")]
10431044
unsafe impl<T> TrivialClone for Discriminant<T> {}
10441045

library/core/src/num/nonzero.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ impl<T> UseCloned for NonZero<T> where T: ZeroablePrimitive {}
189189
#[stable(feature = "nonzero", since = "1.28.0")]
190190
impl<T> Copy for NonZero<T> where T: ZeroablePrimitive {}
191191

192+
#[doc(hidden)]
192193
#[unstable(feature = "trivial_clone", issue = "none")]
193194
unsafe impl<T> TrivialClone for NonZero<T> where T: ZeroablePrimitive {}
194195

library/core/src/option.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,6 +2054,7 @@ where
20542054
#[unstable(feature = "ergonomic_clones", issue = "132290")]
20552055
impl<T> crate::clone::UseCloned for Option<T> where T: crate::clone::UseCloned {}
20562056

2057+
#[doc(hidden)]
20572058
#[unstable(feature = "trivial_clone", issue = "none")]
20582059
unsafe impl<T: TrivialClone> TrivialClone for Option<T> {}
20592060

library/core/src/ptr/metadata.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ impl<Dyn: ?Sized> Clone for DynMetadata<Dyn> {
229229
}
230230
}
231231

232+
#[doc(hidden)]
232233
unsafe impl<Dyn: ?Sized> TrivialClone for DynMetadata<Dyn> {}
233234

234235
impl<Dyn: ?Sized> Eq for DynMetadata<Dyn> {}

library/core/src/ptr/non_null.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,6 +1583,7 @@ impl<T: ?Sized> Clone for NonNull<T> {
15831583
#[stable(feature = "nonnull", since = "1.25.0")]
15841584
impl<T: ?Sized> Copy for NonNull<T> {}
15851585

1586+
#[doc(hidden)]
15861587
#[unstable(feature = "trivial_clone", issue = "none")]
15871588
unsafe impl<T: ?Sized> TrivialClone for NonNull<T> {}
15881589

library/core/src/ptr/unique.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ impl<T: ?Sized> Clone for Unique<T> {
162162
#[unstable(feature = "ptr_internals", issue = "none")]
163163
impl<T: ?Sized> Copy for Unique<T> {}
164164

165+
#[doc(hidden)]
165166
#[unstable(feature = "trivial_clone", issue = "none")]
166167
unsafe impl<T: ?Sized> TrivialClone for Unique<T> {}
167168

tests/ui/deriving/deriving-all-codegen.stdout

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ extern crate std;
2525
// Empty struct.
2626
struct Empty;
2727
#[automatically_derived]
28+
#[doc(hidden)]
2829
unsafe impl ::core::clone::TrivialClone for Empty { }
2930
#[automatically_derived]
3031
impl ::core::clone::Clone for Empty {
@@ -87,6 +88,7 @@ struct Point {
8788
y: u32,
8889
}
8990
#[automatically_derived]
91+
#[doc(hidden)]
9092
unsafe impl ::core::clone::TrivialClone for Point { }
9193
#[automatically_derived]
9294
impl ::core::clone::Clone for Point {
@@ -174,6 +176,7 @@ struct PackedPoint {
174176
y: u32,
175177
}
176178
#[automatically_derived]
179+
#[doc(hidden)]
177180
unsafe impl ::core::clone::TrivialClone for PackedPoint { }
178181
#[automatically_derived]
179182
impl ::core::clone::Clone for PackedPoint {
@@ -268,6 +271,7 @@ struct Big {
268271
b8: u32,
269272
}
270273
#[automatically_derived]
274+
#[doc(hidden)]
271275
unsafe impl ::core::clone::TrivialClone for Big { }
272276
#[automatically_derived]
273277
impl ::core::clone::Clone for Big {
@@ -771,6 +775,7 @@ impl<T: ::core::cmp::Ord + ::core::marker::Copy + Trait, U: ::core::cmp::Ord +
771775
// An empty enum.
772776
enum Enum0 {}
773777
#[automatically_derived]
778+
#[doc(hidden)]
774779
unsafe impl ::core::clone::TrivialClone for Enum0 { }
775780
#[automatically_derived]
776781
impl ::core::clone::Clone for Enum0 {
@@ -968,6 +973,7 @@ enum Fieldless {
968973
C,
969974
}
970975
#[automatically_derived]
976+
#[doc(hidden)]
971977
unsafe impl ::core::clone::TrivialClone for Fieldless { }
972978
#[automatically_derived]
973979
impl ::core::clone::Clone for Fieldless {
@@ -1052,6 +1058,7 @@ enum Mixed {
10521058
},
10531059
}
10541060
#[automatically_derived]
1061+
#[doc(hidden)]
10551062
unsafe impl ::core::clone::TrivialClone for Mixed { }
10561063
#[automatically_derived]
10571064
impl ::core::clone::Clone for Mixed {
@@ -1451,6 +1458,7 @@ pub union Union {
14511458
pub i: i32,
14521459
}
14531460
#[automatically_derived]
1461+
#[doc(hidden)]
14541462
unsafe impl ::core::clone::TrivialClone for Union { }
14551463
#[automatically_derived]
14561464
impl ::core::clone::Clone for Union {

0 commit comments

Comments
 (0)