Skip to content

Commit 3911a63

Browse files
committed
Hide ToString implementations that specialize the default ones
The status quo is highly confusing, since the overlap is not apparent, and specialization is not a feature of Rust. This addresses rust-lang#87545; I'm not certain if it closes it, since that issue might also be trackign a *general* solution for hiding specializing impls automatically.
1 parent f475098 commit 3911a63

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

library/alloc/src/string.rs

+9
Original file line numberDiff line numberDiff line change
@@ -2527,6 +2527,7 @@ impl<T: fmt::Display + ?Sized> ToString for T {
25272527
}
25282528
}
25292529

2530+
#[doc(hidden)]
25302531
#[cfg(not(no_global_oom_handling))]
25312532
#[unstable(feature = "ascii_char", issue = "110998")]
25322533
impl ToString for core::ascii::Char {
@@ -2536,6 +2537,7 @@ impl ToString for core::ascii::Char {
25362537
}
25372538
}
25382539

2540+
#[doc(hidden)]
25392541
#[cfg(not(no_global_oom_handling))]
25402542
#[stable(feature = "char_to_string_specialization", since = "1.46.0")]
25412543
impl ToString for char {
@@ -2545,6 +2547,7 @@ impl ToString for char {
25452547
}
25462548
}
25472549

2550+
#[doc(hidden)]
25482551
#[cfg(not(no_global_oom_handling))]
25492552
#[stable(feature = "bool_to_string_specialization", since = "1.68.0")]
25502553
impl ToString for bool {
@@ -2554,6 +2557,7 @@ impl ToString for bool {
25542557
}
25552558
}
25562559

2560+
#[doc(hidden)]
25572561
#[cfg(not(no_global_oom_handling))]
25582562
#[stable(feature = "u8_to_string_specialization", since = "1.54.0")]
25592563
impl ToString for u8 {
@@ -2574,6 +2578,7 @@ impl ToString for u8 {
25742578
}
25752579
}
25762580

2581+
#[doc(hidden)]
25772582
#[cfg(not(no_global_oom_handling))]
25782583
#[stable(feature = "i8_to_string_specialization", since = "1.54.0")]
25792584
impl ToString for i8 {
@@ -2597,6 +2602,7 @@ impl ToString for i8 {
25972602
}
25982603
}
25992604

2605+
#[doc(hidden)]
26002606
#[cfg(not(no_global_oom_handling))]
26012607
#[stable(feature = "str_to_string_specialization", since = "1.9.0")]
26022608
impl ToString for str {
@@ -2606,6 +2612,7 @@ impl ToString for str {
26062612
}
26072613
}
26082614

2615+
#[doc(hidden)]
26092616
#[cfg(not(no_global_oom_handling))]
26102617
#[stable(feature = "cow_str_to_string_specialization", since = "1.17.0")]
26112618
impl ToString for Cow<'_, str> {
@@ -2615,6 +2622,7 @@ impl ToString for Cow<'_, str> {
26152622
}
26162623
}
26172624

2625+
#[doc(hidden)]
26182626
#[cfg(not(no_global_oom_handling))]
26192627
#[stable(feature = "string_to_string_specialization", since = "1.17.0")]
26202628
impl ToString for String {
@@ -2624,6 +2632,7 @@ impl ToString for String {
26242632
}
26252633
}
26262634

2635+
#[doc(hidden)]
26272636
#[cfg(not(no_global_oom_handling))]
26282637
#[stable(feature = "fmt_arguments_to_string_specialization", since = "1.71.0")]
26292638
impl ToString for fmt::Arguments<'_> {

library/proc_macro/src/lib.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ impl FromStr for TokenStream {
177177

178178
// N.B., the bridge only provides `to_string`, implement `fmt::Display`
179179
// based on it (the reverse of the usual relationship between the two).
180+
#[doc(hidden)]
180181
#[stable(feature = "proc_macro_lib", since = "1.15.0")]
181182
impl ToString for TokenStream {
182183
fn to_string(&self) -> String {
@@ -738,6 +739,7 @@ impl From<Literal> for TokenTree {
738739

739740
// N.B., the bridge only provides `to_string`, implement `fmt::Display`
740741
// based on it (the reverse of the usual relationship between the two).
742+
#[doc(hidden)]
741743
#[stable(feature = "proc_macro_lib", since = "1.15.0")]
742744
impl ToString for TokenTree {
743745
fn to_string(&self) -> String {
@@ -872,6 +874,7 @@ impl Group {
872874

873875
// N.B., the bridge only provides `to_string`, implement `fmt::Display`
874876
// based on it (the reverse of the usual relationship between the two).
877+
#[doc(hidden)]
875878
#[stable(feature = "proc_macro_lib", since = "1.15.0")]
876879
impl ToString for Group {
877880
fn to_string(&self) -> String {
@@ -981,6 +984,7 @@ impl Punct {
981984
}
982985
}
983986

987+
#[doc(hidden)]
984988
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
985989
impl ToString for Punct {
986990
fn to_string(&self) -> String {
@@ -1083,8 +1087,7 @@ impl Ident {
10831087
}
10841088
}
10851089

1086-
/// Converts the identifier to a string that should be losslessly convertible
1087-
/// back into the same identifier.
1090+
#[doc(hidden)]
10881091
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
10891092
impl ToString for Ident {
10901093
fn to_string(&self) -> String {
@@ -1423,6 +1426,7 @@ impl FromStr for Literal {
14231426
}
14241427
}
14251428

1429+
#[doc(hidden)]
14261430
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
14271431
impl ToString for Literal {
14281432
fn to_string(&self) -> String {

0 commit comments

Comments
 (0)