Skip to content

Commit 41b0926

Browse files
committed
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.
1 parent 7750402 commit 41b0926

File tree

13 files changed

+46
-10
lines changed

13 files changed

+46
-10
lines changed

library/alloc/src/macros.rs

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ macro_rules! vec {
108108
#[macro_export]
109109
#[stable(feature = "rust1", since = "1.0.0")]
110110
#[cfg_attr(not(test), rustc_diagnostic_item = "format_macro")]
111+
#[doc(alias = "sprintf")]
111112
macro_rules! format {
112113
($($arg:tt)*) => {{
113114
let res = $crate::fmt::format($crate::__export::format_args!($($arg)*));

library/alloc/src/string.rs

+2
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,7 @@ impl String {
820820
/// ```
821821
#[inline]
822822
#[stable(feature = "rust1", since = "1.0.0")]
823+
#[doc(alias = "strcat")]
823824
pub fn push_str(&mut self, string: &str) {
824825
self.vec.extend_from_slice(string.as_bytes())
825826
}
@@ -1750,6 +1751,7 @@ impl fmt::Display for FromUtf16Error {
17501751

17511752
#[stable(feature = "rust1", since = "1.0.0")]
17521753
impl Clone for String {
1754+
#[doc(alias = "strdup")]
17531755
fn clone(&self) -> Self {
17541756
String { vec: self.vec.clone() }
17551757
}

library/core/src/char/methods.rs

+11
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ impl char {
280280
/// '1'.is_digit(37);
281281
/// ```
282282
#[stable(feature = "rust1", since = "1.0.0")]
283+
#[doc(alias = "isxdigit")]
283284
#[inline]
284285
pub fn is_digit(self, radix: u32) -> bool {
285286
self.to_digit(radix).is_some()
@@ -844,6 +845,7 @@ impl char {
844845
/// assert!(!'q'.is_control());
845846
/// ```
846847
#[stable(feature = "rust1", since = "1.0.0")]
848+
#[doc(alias = "iscntrl")]
847849
#[inline]
848850
pub fn is_control(self) -> bool {
849851
unicode::Cc(self)
@@ -1093,6 +1095,7 @@ impl char {
10931095
/// [`to_uppercase()`]: #method.to_uppercase
10941096
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
10951097
#[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.52.0")]
1098+
#[doc(alias = "toupper")]
10961099
#[inline]
10971100
pub const fn to_ascii_uppercase(&self) -> char {
10981101
if self.is_ascii_lowercase() {
@@ -1126,6 +1129,7 @@ impl char {
11261129
/// [`to_lowercase()`]: #method.to_lowercase
11271130
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
11281131
#[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.52.0")]
1132+
#[doc(alias = "tolower")]
11291133
#[inline]
11301134
pub const fn to_ascii_lowercase(&self) -> char {
11311135
if self.is_ascii_uppercase() {
@@ -1237,6 +1241,7 @@ impl char {
12371241
/// ```
12381242
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
12391243
#[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")]
1244+
#[doc(alias = "isalpha")]
12401245
#[inline]
12411246
pub const fn is_ascii_alphabetic(&self) -> bool {
12421247
matches!(*self, 'A'..='Z' | 'a'..='z')
@@ -1270,6 +1275,7 @@ impl char {
12701275
/// ```
12711276
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
12721277
#[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")]
1278+
#[doc(alias = "isupper")]
12731279
#[inline]
12741280
pub const fn is_ascii_uppercase(&self) -> bool {
12751281
matches!(*self, 'A'..='Z')
@@ -1303,6 +1309,7 @@ impl char {
13031309
/// ```
13041310
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
13051311
#[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")]
1312+
#[doc(alias = "islower")]
13061313
#[inline]
13071314
pub const fn is_ascii_lowercase(&self) -> bool {
13081315
matches!(*self, 'a'..='z')
@@ -1339,6 +1346,7 @@ impl char {
13391346
/// ```
13401347
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
13411348
#[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")]
1349+
#[doc(alias = "isalnum")]
13421350
#[inline]
13431351
pub const fn is_ascii_alphanumeric(&self) -> bool {
13441352
matches!(*self, '0'..='9' | 'A'..='Z' | 'a'..='z')
@@ -1372,6 +1380,7 @@ impl char {
13721380
/// ```
13731381
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
13741382
#[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")]
1383+
#[doc(alias = "isdigit")]
13751384
#[inline]
13761385
pub const fn is_ascii_digit(&self) -> bool {
13771386
matches!(*self, '0'..='9')
@@ -1445,6 +1454,7 @@ impl char {
14451454
/// ```
14461455
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
14471456
#[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")]
1457+
#[doc(alias = "ispunct")]
14481458
#[inline]
14491459
pub const fn is_ascii_punctuation(&self) -> bool {
14501460
matches!(*self, '!'..='/' | ':'..='@' | '['..='`' | '{'..='~')
@@ -1528,6 +1538,7 @@ impl char {
15281538
/// ```
15291539
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
15301540
#[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")]
1541+
#[doc(alias = "isspace")]
15311542
#[inline]
15321543
pub const fn is_ascii_whitespace(&self) -> bool {
15331544
matches!(*self, '\t' | '\n' | '\x0C' | '\r' | ' ')

library/core/src/mem/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,7 @@ pub const fn replace<T>(dest: &mut T, src: T) -> T {
887887
///
888888
/// [`RefCell`]: crate::cell::RefCell
889889
#[doc(alias = "delete")]
890+
#[doc(alias = "free")]
890891
#[inline]
891892
#[stable(feature = "rust1", since = "1.0.0")]
892893
pub fn drop<T>(_x: T) {}

library/core/src/num/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,10 @@ macro_rules! from_str_radix_int_impl {
782782
#[stable(feature = "rust1", since = "1.0.0")]
783783
impl FromStr for $t {
784784
type Err = ParseIntError;
785+
#[doc(alias = "atoi")]
786+
#[doc(alias = "atol")]
787+
#[doc(alias = "strtod")]
788+
#[doc(alias = "strtol")]
785789
fn from_str(src: &str) -> Result<Self, ParseIntError> {
786790
from_str_radix(src, 10)
787791
}

library/core/src/option.rs

+2
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ pub enum Option<T> {
162162
/// No value
163163
#[lang = "None"]
164164
#[stable(feature = "rust1", since = "1.0.0")]
165+
#[doc(alias = "null")]
166+
#[doc(alias = "nil")]
165167
None,
166168
/// Some value `T`
167169
#[lang = "Some"]

library/core/src/str/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,8 @@ impl str {
10341034
/// assert_eq!(s.find(x), None);
10351035
/// ```
10361036
#[stable(feature = "rust1", since = "1.0.0")]
1037+
#[doc(alias = "strstr")]
1038+
#[doc(alias = "strchr")]
10371039
#[inline]
10381040
pub fn find<'a, P: Pattern<'a>>(&'a self, pat: P) -> Option<usize> {
10391041
pat.into_searcher(self).next_match().map(|(i, _)| i)
@@ -1080,6 +1082,7 @@ impl str {
10801082
/// assert_eq!(s.rfind(x), None);
10811083
/// ```
10821084
#[stable(feature = "rust1", since = "1.0.0")]
1085+
#[doc(alias = "strrchr")]
10831086
#[inline]
10841087
pub fn rfind<'a, P>(&'a self, pat: P) -> Option<usize>
10851088
where
@@ -1202,6 +1205,7 @@ impl str {
12021205
///
12031206
/// [`split_whitespace`]: str::split_whitespace
12041207
#[stable(feature = "rust1", since = "1.0.0")]
1208+
#[doc(alias = "strtok")]
12051209
#[inline]
12061210
pub fn split<'a, P: Pattern<'a>>(&'a self, pat: P) -> Split<'a, P> {
12071211
Split(SplitInternal {

library/std/src/env.rs

+1
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ impl fmt::Debug for VarsOs {
201201
/// }
202202
/// ```
203203
#[stable(feature = "env", since = "1.0.0")]
204+
#[doc(alias = "getenv")]
204205
pub fn var<K: AsRef<OsStr>>(key: K) -> Result<String, VarError> {
205206
_var(key.as_ref())
206207
}

library/std/src/fs.rs

+2
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ pub fn read_to_string<P: AsRef<Path>>(path: P) -> io::Result<String> {
304304
/// }
305305
/// ```
306306
#[stable(feature = "fs_read_write_bytes", since = "1.26.0")]
307+
#[doc(alias = "fputs")]
308+
#[doc(alias = "fprintf")]
307309
pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> io::Result<()> {
308310
fn inner(path: &Path, contents: &[u8]) -> io::Result<()> {
309311
File::create(path)?.write_all(contents)

library/std/src/macros.rs

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ macro_rules! print {
9191
#[macro_export]
9292
#[stable(feature = "rust1", since = "1.0.0")]
9393
#[allow_internal_unstable(print_internals, format_args_nl)]
94+
#[doc(alias = "printf")]
9495
macro_rules! println {
9596
() => ($crate::print!("\n"));
9697
($($arg:tt)*) => ({

library/std/src/primitive_docs.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ mod prim_never {}
342342
/// assert_eq!(32, std::mem::size_of_val(&v[..]));
343343
/// ```
344344
#[stable(feature = "rust1", since = "1.0.0")]
345+
#[doc(alias = "char32_t")]
345346
mod prim_char {}
346347

347348
#[doc(primitive = "unit")]
@@ -789,6 +790,7 @@ mod prim_str {}
789790
mod prim_tuple {}
790791

791792
#[doc(primitive = "f32")]
793+
#[doc(alias = "float")]
792794
/// A 32-bit floating point type (specifically, the "binary32" type defined in IEEE 754-2008).
793795
///
794796
/// This type can represent a wide range of decimal numbers, like `3.5`, `27`,
@@ -830,6 +832,7 @@ mod prim_tuple {}
830832
mod prim_f32 {}
831833

832834
#[doc(primitive = "f64")]
835+
#[doc(alias = "double")]
833836
/// A 64-bit floating point type (specifically, the "binary64" type defined in IEEE 754-2008).
834837
///
835838
/// This type is very similar to [`f32`], but has increased
@@ -845,25 +848,25 @@ mod prim_f32 {}
845848
mod prim_f64 {}
846849

847850
#[doc(primitive = "i8")]
848-
//
851+
#[doc(alias = "int8_t")]
849852
/// The 8-bit signed integer type.
850853
#[stable(feature = "rust1", since = "1.0.0")]
851854
mod prim_i8 {}
852855

853856
#[doc(primitive = "i16")]
854-
//
857+
#[doc(alias = "int16_t")]
855858
/// The 16-bit signed integer type.
856859
#[stable(feature = "rust1", since = "1.0.0")]
857860
mod prim_i16 {}
858861

859862
#[doc(primitive = "i32")]
860-
//
863+
#[doc(alias = "int32_t")]
861864
/// The 32-bit signed integer type.
862865
#[stable(feature = "rust1", since = "1.0.0")]
863866
mod prim_i32 {}
864867

865868
#[doc(primitive = "i64")]
866-
//
869+
#[doc(alias = "int64_t")]
867870
/// The 64-bit signed integer type.
868871
#[stable(feature = "rust1", since = "1.0.0")]
869872
mod prim_i64 {}
@@ -875,25 +878,25 @@ mod prim_i64 {}
875878
mod prim_i128 {}
876879

877880
#[doc(primitive = "u8")]
878-
//
881+
#[doc(alias = "uint8_t")]
879882
/// The 8-bit unsigned integer type.
880883
#[stable(feature = "rust1", since = "1.0.0")]
881884
mod prim_u8 {}
882885

883886
#[doc(primitive = "u16")]
884-
//
887+
#[doc(alias = "uint16_t")]
885888
/// The 16-bit unsigned integer type.
886889
#[stable(feature = "rust1", since = "1.0.0")]
887890
mod prim_u16 {}
888891

889892
#[doc(primitive = "u32")]
890-
//
893+
#[doc(alias = "uint32_t")]
891894
/// The 32-bit unsigned integer type.
892895
#[stable(feature = "rust1", since = "1.0.0")]
893896
mod prim_u32 {}
894897

895898
#[doc(primitive = "u64")]
896-
//
899+
#[doc(alias = "uint64_t")]
897900
/// The 64-bit unsigned integer type.
898901
#[stable(feature = "rust1", since = "1.0.0")]
899902
mod prim_u64 {}
@@ -905,17 +908,19 @@ mod prim_u64 {}
905908
mod prim_u128 {}
906909

907910
#[doc(primitive = "isize")]
908-
//
909911
/// The pointer-sized signed integer type.
910912
///
911913
/// The size of this primitive is how many bytes it takes to reference any
912914
/// location in memory. For example, on a 32 bit target, this is 4 bytes
913915
/// and on a 64 bit target, this is 8 bytes.
914916
#[stable(feature = "rust1", since = "1.0.0")]
917+
#[doc(alias = "ssize_t")]
918+
#[doc(alias = "intptr_t")] // FIXME(#65473): maybe these should be different
915919
mod prim_isize {}
916920

917921
#[doc(primitive = "usize")]
918-
//
922+
#[doc(alias = "size_t")]
923+
#[doc(alias = "uintptr_t")] // FIXME(#65473): maybe these should be different
919924
/// The pointer-sized unsigned integer type.
920925
///
921926
/// The size of this primitive is how many bytes it takes to reference any

library/std/src/process.rs

+1
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,7 @@ impl Command {
881881
/// assert!(output.status.success());
882882
/// ```
883883
#[stable(feature = "process", since = "1.0.0")]
884+
#[doc(alias = "system")]
884885
pub fn output(&mut self) -> io::Result<Output> {
885886
self.inner
886887
.spawn(imp::Stdio::MakePipe, false)

library/std/src/time.rs

+1
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ impl SystemTime {
447447
/// let sys_time = SystemTime::now();
448448
/// ```
449449
#[stable(feature = "time2", since = "1.8.0")]
450+
#[doc(alias = "time")]
450451
pub fn now() -> SystemTime {
451452
SystemTime(time::SystemTime::now())
452453
}

0 commit comments

Comments
 (0)