From 41b09264097aeb33e5baca67fb5adf546090cc57 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 10 Feb 2021 23:24:55 -0500 Subject: [PATCH] Add doc aliases for most of the C standard library I took the very scientific approach of "ask some friends what parts of the standard library they use a lot". They suggested https://www.tutorialspoint.com/c_standard_library/ and also the short list `strcpy, strncpy, memcpy, memcpy, printf, scanf, fprintf, sprintf, asprintf, sscanf, strtok, strntok, malloc, calloc, free, strdup, strndup, err, errx `. Many of these already have aliases; those with `*n*` have no analogy in rust; `err` and `errx` have no analogy in Rust. I added most of the rest. This also includes aliases for standard types, like fixed-width integers. --- library/alloc/src/macros.rs | 1 + library/alloc/src/string.rs | 2 ++ library/core/src/char/methods.rs | 11 +++++++++++ library/core/src/mem/mod.rs | 1 + library/core/src/num/mod.rs | 4 ++++ library/core/src/option.rs | 2 ++ library/core/src/str/mod.rs | 4 ++++ library/std/src/env.rs | 1 + library/std/src/fs.rs | 2 ++ library/std/src/macros.rs | 1 + library/std/src/primitive_docs.rs | 25 +++++++++++++++---------- library/std/src/process.rs | 1 + library/std/src/time.rs | 1 + 13 files changed, 46 insertions(+), 10 deletions(-) diff --git a/library/alloc/src/macros.rs b/library/alloc/src/macros.rs index 6a64587a2237f..0d1993a56aeea 100644 --- a/library/alloc/src/macros.rs +++ b/library/alloc/src/macros.rs @@ -108,6 +108,7 @@ macro_rules! vec { #[macro_export] #[stable(feature = "rust1", since = "1.0.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "format_macro")] +#[doc(alias = "sprintf")] macro_rules! format { ($($arg:tt)*) => {{ let res = $crate::fmt::format($crate::__export::format_args!($($arg)*)); diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index f4ec4a36ffd2b..9cc42e295beec 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -820,6 +820,7 @@ impl String { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] + #[doc(alias = "strcat")] pub fn push_str(&mut self, string: &str) { self.vec.extend_from_slice(string.as_bytes()) } @@ -1750,6 +1751,7 @@ impl fmt::Display for FromUtf16Error { #[stable(feature = "rust1", since = "1.0.0")] impl Clone for String { + #[doc(alias = "strdup")] fn clone(&self) -> Self { String { vec: self.vec.clone() } } diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs index dcab2cd2d9db1..c05161b1975e5 100644 --- a/library/core/src/char/methods.rs +++ b/library/core/src/char/methods.rs @@ -280,6 +280,7 @@ impl char { /// '1'.is_digit(37); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[doc(alias = "isxdigit")] #[inline] pub fn is_digit(self, radix: u32) -> bool { self.to_digit(radix).is_some() @@ -844,6 +845,7 @@ impl char { /// assert!(!'q'.is_control()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[doc(alias = "iscntrl")] #[inline] pub fn is_control(self) -> bool { unicode::Cc(self) @@ -1093,6 +1095,7 @@ impl char { /// [`to_uppercase()`]: #method.to_uppercase #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] #[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.52.0")] + #[doc(alias = "toupper")] #[inline] pub const fn to_ascii_uppercase(&self) -> char { if self.is_ascii_lowercase() { @@ -1126,6 +1129,7 @@ impl char { /// [`to_lowercase()`]: #method.to_lowercase #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] #[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.52.0")] + #[doc(alias = "tolower")] #[inline] pub const fn to_ascii_lowercase(&self) -> char { if self.is_ascii_uppercase() { @@ -1237,6 +1241,7 @@ impl char { /// ``` #[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")] #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")] + #[doc(alias = "isalpha")] #[inline] pub const fn is_ascii_alphabetic(&self) -> bool { matches!(*self, 'A'..='Z' | 'a'..='z') @@ -1270,6 +1275,7 @@ impl char { /// ``` #[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")] #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")] + #[doc(alias = "isupper")] #[inline] pub const fn is_ascii_uppercase(&self) -> bool { matches!(*self, 'A'..='Z') @@ -1303,6 +1309,7 @@ impl char { /// ``` #[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")] #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")] + #[doc(alias = "islower")] #[inline] pub const fn is_ascii_lowercase(&self) -> bool { matches!(*self, 'a'..='z') @@ -1339,6 +1346,7 @@ impl char { /// ``` #[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")] #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")] + #[doc(alias = "isalnum")] #[inline] pub const fn is_ascii_alphanumeric(&self) -> bool { matches!(*self, '0'..='9' | 'A'..='Z' | 'a'..='z') @@ -1372,6 +1380,7 @@ impl char { /// ``` #[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")] #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")] + #[doc(alias = "isdigit")] #[inline] pub const fn is_ascii_digit(&self) -> bool { matches!(*self, '0'..='9') @@ -1445,6 +1454,7 @@ impl char { /// ``` #[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")] #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")] + #[doc(alias = "ispunct")] #[inline] pub const fn is_ascii_punctuation(&self) -> bool { matches!(*self, '!'..='/' | ':'..='@' | '['..='`' | '{'..='~') @@ -1528,6 +1538,7 @@ impl char { /// ``` #[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")] #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")] + #[doc(alias = "isspace")] #[inline] pub const fn is_ascii_whitespace(&self) -> bool { matches!(*self, '\t' | '\n' | '\x0C' | '\r' | ' ') diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs index 446d72f1d32e4..fe0698f52cccf 100644 --- a/library/core/src/mem/mod.rs +++ b/library/core/src/mem/mod.rs @@ -887,6 +887,7 @@ pub const fn replace(dest: &mut T, src: T) -> T { /// /// [`RefCell`]: crate::cell::RefCell #[doc(alias = "delete")] +#[doc(alias = "free")] #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn drop(_x: T) {} diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index f0bd976ba83d5..65a133c3c00d9 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -782,6 +782,10 @@ macro_rules! from_str_radix_int_impl { #[stable(feature = "rust1", since = "1.0.0")] impl FromStr for $t { type Err = ParseIntError; + #[doc(alias = "atoi")] + #[doc(alias = "atol")] + #[doc(alias = "strtod")] + #[doc(alias = "strtol")] fn from_str(src: &str) -> Result { from_str_radix(src, 10) } diff --git a/library/core/src/option.rs b/library/core/src/option.rs index da2c0cf476d16..b3bdde60c2a7f 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -162,6 +162,8 @@ pub enum Option { /// No value #[lang = "None"] #[stable(feature = "rust1", since = "1.0.0")] + #[doc(alias = "null")] + #[doc(alias = "nil")] None, /// Some value `T` #[lang = "Some"] diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index 95dd54976b2c0..6a1d7f1556691 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -1034,6 +1034,8 @@ impl str { /// assert_eq!(s.find(x), None); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[doc(alias = "strstr")] + #[doc(alias = "strchr")] #[inline] pub fn find<'a, P: Pattern<'a>>(&'a self, pat: P) -> Option { pat.into_searcher(self).next_match().map(|(i, _)| i) @@ -1080,6 +1082,7 @@ impl str { /// assert_eq!(s.rfind(x), None); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[doc(alias = "strrchr")] #[inline] pub fn rfind<'a, P>(&'a self, pat: P) -> Option where @@ -1202,6 +1205,7 @@ impl str { /// /// [`split_whitespace`]: str::split_whitespace #[stable(feature = "rust1", since = "1.0.0")] + #[doc(alias = "strtok")] #[inline] pub fn split<'a, P: Pattern<'a>>(&'a self, pat: P) -> Split<'a, P> { Split(SplitInternal { diff --git a/library/std/src/env.rs b/library/std/src/env.rs index 9763a2da34151..a9630581a36b8 100644 --- a/library/std/src/env.rs +++ b/library/std/src/env.rs @@ -201,6 +201,7 @@ impl fmt::Debug for VarsOs { /// } /// ``` #[stable(feature = "env", since = "1.0.0")] +#[doc(alias = "getenv")] pub fn var>(key: K) -> Result { _var(key.as_ref()) } diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index 860bc130b7d8b..f3868cd9a2bb1 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -304,6 +304,8 @@ pub fn read_to_string>(path: P) -> io::Result { /// } /// ``` #[stable(feature = "fs_read_write_bytes", since = "1.26.0")] +#[doc(alias = "fputs")] +#[doc(alias = "fprintf")] pub fn write, C: AsRef<[u8]>>(path: P, contents: C) -> io::Result<()> { fn inner(path: &Path, contents: &[u8]) -> io::Result<()> { File::create(path)?.write_all(contents) diff --git a/library/std/src/macros.rs b/library/std/src/macros.rs index b729349cf530f..cb854894cd728 100644 --- a/library/std/src/macros.rs +++ b/library/std/src/macros.rs @@ -91,6 +91,7 @@ macro_rules! print { #[macro_export] #[stable(feature = "rust1", since = "1.0.0")] #[allow_internal_unstable(print_internals, format_args_nl)] +#[doc(alias = "printf")] macro_rules! println { () => ($crate::print!("\n")); ($($arg:tt)*) => ({ diff --git a/library/std/src/primitive_docs.rs b/library/std/src/primitive_docs.rs index 64b22b64f4bf1..812ca463a6f41 100644 --- a/library/std/src/primitive_docs.rs +++ b/library/std/src/primitive_docs.rs @@ -342,6 +342,7 @@ mod prim_never {} /// assert_eq!(32, std::mem::size_of_val(&v[..])); /// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[doc(alias = "char32_t")] mod prim_char {} #[doc(primitive = "unit")] @@ -789,6 +790,7 @@ mod prim_str {} mod prim_tuple {} #[doc(primitive = "f32")] +#[doc(alias = "float")] /// A 32-bit floating point type (specifically, the "binary32" type defined in IEEE 754-2008). /// /// This type can represent a wide range of decimal numbers, like `3.5`, `27`, @@ -830,6 +832,7 @@ mod prim_tuple {} mod prim_f32 {} #[doc(primitive = "f64")] +#[doc(alias = "double")] /// A 64-bit floating point type (specifically, the "binary64" type defined in IEEE 754-2008). /// /// This type is very similar to [`f32`], but has increased @@ -845,25 +848,25 @@ mod prim_f32 {} mod prim_f64 {} #[doc(primitive = "i8")] -// +#[doc(alias = "int8_t")] /// The 8-bit signed integer type. #[stable(feature = "rust1", since = "1.0.0")] mod prim_i8 {} #[doc(primitive = "i16")] -// +#[doc(alias = "int16_t")] /// The 16-bit signed integer type. #[stable(feature = "rust1", since = "1.0.0")] mod prim_i16 {} #[doc(primitive = "i32")] -// +#[doc(alias = "int32_t")] /// The 32-bit signed integer type. #[stable(feature = "rust1", since = "1.0.0")] mod prim_i32 {} #[doc(primitive = "i64")] -// +#[doc(alias = "int64_t")] /// The 64-bit signed integer type. #[stable(feature = "rust1", since = "1.0.0")] mod prim_i64 {} @@ -875,25 +878,25 @@ mod prim_i64 {} mod prim_i128 {} #[doc(primitive = "u8")] -// +#[doc(alias = "uint8_t")] /// The 8-bit unsigned integer type. #[stable(feature = "rust1", since = "1.0.0")] mod prim_u8 {} #[doc(primitive = "u16")] -// +#[doc(alias = "uint16_t")] /// The 16-bit unsigned integer type. #[stable(feature = "rust1", since = "1.0.0")] mod prim_u16 {} #[doc(primitive = "u32")] -// +#[doc(alias = "uint32_t")] /// The 32-bit unsigned integer type. #[stable(feature = "rust1", since = "1.0.0")] mod prim_u32 {} #[doc(primitive = "u64")] -// +#[doc(alias = "uint64_t")] /// The 64-bit unsigned integer type. #[stable(feature = "rust1", since = "1.0.0")] mod prim_u64 {} @@ -905,17 +908,19 @@ mod prim_u64 {} mod prim_u128 {} #[doc(primitive = "isize")] -// /// The pointer-sized signed integer type. /// /// The size of this primitive is how many bytes it takes to reference any /// location in memory. For example, on a 32 bit target, this is 4 bytes /// and on a 64 bit target, this is 8 bytes. #[stable(feature = "rust1", since = "1.0.0")] +#[doc(alias = "ssize_t")] +#[doc(alias = "intptr_t")] // FIXME(#65473): maybe these should be different mod prim_isize {} #[doc(primitive = "usize")] -// +#[doc(alias = "size_t")] +#[doc(alias = "uintptr_t")] // FIXME(#65473): maybe these should be different /// The pointer-sized unsigned integer type. /// /// The size of this primitive is how many bytes it takes to reference any diff --git a/library/std/src/process.rs b/library/std/src/process.rs index 5690de681cab9..28dd545ef07ba 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -881,6 +881,7 @@ impl Command { /// assert!(output.status.success()); /// ``` #[stable(feature = "process", since = "1.0.0")] + #[doc(alias = "system")] pub fn output(&mut self) -> io::Result { self.inner .spawn(imp::Stdio::MakePipe, false) diff --git a/library/std/src/time.rs b/library/std/src/time.rs index 89addae078948..4a8ff6ea56b25 100644 --- a/library/std/src/time.rs +++ b/library/std/src/time.rs @@ -447,6 +447,7 @@ impl SystemTime { /// let sys_time = SystemTime::now(); /// ``` #[stable(feature = "time2", since = "1.8.0")] + #[doc(alias = "time")] pub fn now() -> SystemTime { SystemTime(time::SystemTime::now()) }