Skip to content

Commit

Permalink
Auto merge of rust-lang#114020 - steffahn:hide-specialized-ToString-i…
Browse files Browse the repository at this point in the history
…mpls, r=thomcc

Hide `ToString` implementations that specialize the default one

The status quo is highly confusing, since the overlap is not apparent, and specialization is not a feature of Rust. This change addresses rust-lang#87545; I'm not certain if it closes/fixes it entirely, since that issue might also be tracking the question of a *general* solution for hiding the documentation for specializing impls automatically.

Before
![Screenshot_20230724_234210](https://github.com/rust-lang/rust/assets/3986214/54bbe659-1790-4e95-a5d8-5426e710ceb8)

After
![Screenshot_20230724_234255](https://github.com/rust-lang/rust/assets/3986214/ee645d6e-c1c0-40c0-a0d3-a5c5f3dae65e)
  • Loading branch information
bors committed Jul 25, 2023
2 parents 5b1dc9d + 3911a63 commit c026d6a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 9 additions & 0 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2527,6 +2527,7 @@ impl<T: fmt::Display + ?Sized> ToString for T {
}
}

#[doc(hidden)]
#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "ascii_char", issue = "110998")]
impl ToString for core::ascii::Char {
Expand All @@ -2536,6 +2537,7 @@ impl ToString for core::ascii::Char {
}
}

#[doc(hidden)]
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "char_to_string_specialization", since = "1.46.0")]
impl ToString for char {
Expand All @@ -2545,6 +2547,7 @@ impl ToString for char {
}
}

#[doc(hidden)]
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "bool_to_string_specialization", since = "1.68.0")]
impl ToString for bool {
Expand All @@ -2554,6 +2557,7 @@ impl ToString for bool {
}
}

#[doc(hidden)]
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "u8_to_string_specialization", since = "1.54.0")]
impl ToString for u8 {
Expand All @@ -2574,6 +2578,7 @@ impl ToString for u8 {
}
}

#[doc(hidden)]
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "i8_to_string_specialization", since = "1.54.0")]
impl ToString for i8 {
Expand All @@ -2597,6 +2602,7 @@ impl ToString for i8 {
}
}

#[doc(hidden)]
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "str_to_string_specialization", since = "1.9.0")]
impl ToString for str {
Expand All @@ -2606,6 +2612,7 @@ impl ToString for str {
}
}

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

#[doc(hidden)]
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "string_to_string_specialization", since = "1.17.0")]
impl ToString for String {
Expand All @@ -2624,6 +2632,7 @@ impl ToString for String {
}
}

#[doc(hidden)]
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "fmt_arguments_to_string_specialization", since = "1.71.0")]
impl ToString for fmt::Arguments<'_> {
Expand Down
8 changes: 6 additions & 2 deletions library/proc_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ impl FromStr for TokenStream {

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

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

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

#[doc(hidden)]
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
impl ToString for Punct {
fn to_string(&self) -> String {
Expand Down Expand Up @@ -1083,8 +1087,7 @@ impl Ident {
}
}

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

#[doc(hidden)]
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
impl ToString for Literal {
fn to_string(&self) -> String {
Expand Down

0 comments on commit c026d6a

Please sign in to comment.