Skip to content

Commit 35843d3

Browse files
committed
cfg(doc) shenanigans to get struct.String.html
1 parent 966f4a9 commit 35843d3

1 file changed

Lines changed: 42 additions & 26 deletions

File tree

library/alloc/src/string.rs

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -66,31 +66,6 @@ use crate::str::{self, CharIndices, Chars, Utf8Error, from_utf8_unchecked_mut};
6666
use crate::str::{FromStr, from_boxed_utf8_unchecked};
6767
use crate::vec::{self, Vec};
6868

69-
/// A hack because we cannot add a type parameter, even one with a default value, to existing types
70-
/// which previously had no parameters.
71-
///
72-
/// Introducing generic parameters means any use of the type is now a possible site of type
73-
/// inference. Where previously, `String` just meant, well `String`, now `String` can mean
74-
/// `String<_>` (ie please infer the value from the context), or `String<Global>` (ie please use the
75-
/// default value). It's not always clear which is meant, and this is an open issue [#98931].
76-
///
77-
/// [#98931]: https://github.com/rust-lang/rust/issues/98931
78-
#[unstable(feature = "allocator_api", issue = "32838")]
79-
pub mod generic {
80-
use super::{Allocator, Global, Vec};
81-
82-
/// A generic version of [`alloc::string::String`], which adds a type parameter for an Allocator
83-
///
84-
/// see the docs for [`alloc::string::String`] for more info
85-
///
86-
/// [`alloc::string::String`]: super::String
87-
#[unstable(feature = "allocator_api", issue = "32838")]
88-
#[lang = "String"]
89-
pub struct String<#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> {
90-
pub(super) vec: Vec<u8, A>,
91-
}
92-
}
93-
9469
/// A UTF-8–encoded, growable string.
9570
///
9671
/// `String` is the most common string type. It has ownership over the contents
@@ -371,10 +346,50 @@ pub mod generic {
371346
/// [Deref]: core::ops::Deref "ops::Deref"
372347
/// [`Deref`]: core::ops::Deref "ops::Deref"
373348
/// [`as_str()`]: String::as_str
349+
#[cfg(doc)]
350+
pub struct String<A: Allocator = Global> {
351+
vec: Vec<u8, A>,
352+
}
353+
354+
#[cfg(doc)]
355+
#[allow(missing_docs)]
356+
pub mod generic {
357+
pub use super::String;
358+
}
359+
360+
#[cfg(not(doc))]
361+
#[allow(missing_docs)]
374362
#[rustc_diagnostic_item = "string_in_global"]
375363
#[stable(feature = "rust1", since = "1.0.0")]
376364
pub type String = generic::String;
377365

366+
/// A hack because we cannot add a type parameter, even one with a default value, to existing types
367+
/// which previously had no parameters.
368+
///
369+
/// Introducing generic parameters means any use of the type is now a possible site of type
370+
/// inference. Where previously, `String` just meant, well `String`, now `String` can mean
371+
/// `String<_>` (ie please infer the value from the context), or `String<Global>` (ie please use the
372+
/// default value). It's not always clear which is meant, and this is an open issue [#98931].
373+
///
374+
/// [#98931]: https://github.com/rust-lang/rust/issues/98931
375+
#[cfg(not(doc))]
376+
#[unstable(feature = "allocator_api", issue = "32838")]
377+
pub mod generic {
378+
use super::{Allocator, Global, Vec};
379+
380+
/// A generic version of [`alloc::string::String`], which adds a type parameter for an Allocator
381+
///
382+
/// see the docs for [`alloc::string::String`] for more info
383+
///
384+
/// [`alloc::string::String`]: super::String
385+
#[unstable(feature = "allocator_api", issue = "32838")]
386+
#[lang = "String"]
387+
pub struct String<#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> {
388+
pub(super) vec: Vec<u8, A>,
389+
}
390+
}
391+
392+
378393
/// A possible error value when converting a `String` from a UTF-8 byte vector.
379394
///
380395
/// This type is the error type for the [`from_utf8`] method on [`String`]. It
@@ -2228,7 +2243,8 @@ impl<A: Allocator> generic::String<A> {
22282243
/// assert_eq!(s, "Test Results: ✅❌❌");
22292244
/// ```
22302245
///
2231-
/// [replacen]: ../../../std/primitive.str.html#method.replacen
2246+
#[cfg_attr(not(doc), doc = "[replacen]: ../../../std/primitive.str.html#method.replacen")]
2247+
#[cfg_attr(doc, doc = "[replacen]: ../../std/primitive.str.html#method.replacen")]
22322248
#[cfg(not(no_global_oom_handling))]
22332249
#[unstable(feature = "string_replace_in_place", issue = "147949")]
22342250
pub fn replace_first<P: Pattern>(&mut self, from: P, to: &str) {

0 commit comments

Comments
 (0)