Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add doc aliases for a lot of the C standard library #81988

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions library/alloc/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)*));
Expand Down
2 changes: 2 additions & 0 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down Expand Up @@ -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() }
}
Expand Down
11 changes: 11 additions & 0 deletions library/core/src/char/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ impl char {
/// '1'.is_digit(37);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[doc(alias = "isxdigit")]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is moderately iffy because you have to pass a radix of 16, but it's close enough.

#[inline]
pub fn is_digit(self, radix: u32) -> bool {
self.to_digit(radix).is_some()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")]
jyn514 marked this conversation as resolved.
Show resolved Hide resolved
#[inline]
pub const fn to_ascii_uppercase(&self) -> char {
if self.is_ascii_lowercase() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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, '!'..='/' | ':'..='@' | '['..='`' | '{'..='~')
Expand Down Expand Up @@ -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' | ' ')
Expand Down
1 change: 1 addition & 0 deletions library/core/src/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,7 @@ pub const fn replace<T>(dest: &mut T, src: T) -> T {
///
/// [`RefCell`]: crate::cell::RefCell
#[doc(alias = "delete")]
#[doc(alias = "free")]
Comment on lines 889 to +890
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm very surprised someone added delete but not free.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This alias does seem very reasonable to add.

#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn drop<T>(_x: T) {}
Expand Down
4 changes: 4 additions & 0 deletions library/core/src/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Comment on lines +785 to +788
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured these were all "close enough" since int and long don't have a fixed size.

fn from_str(src: &str) -> Result<Self, ParseIntError> {
from_str_radix(src, 10)
}
Expand Down
2 changes: 2 additions & 0 deletions library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ pub enum Option<T> {
/// No value
#[lang = "None"]
#[stable(feature = "rust1", since = "1.0.0")]
#[doc(alias = "null")]
#[doc(alias = "nil")]
Comment on lines +165 to +166
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C does not have nil, and null should be NULL if it is referring to the library side of C.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can separate this into a separate PR if you like, but I think the aliases are useful.

null should be NULL if it is referring to the library side of C.

doc(alias) is case insensitive.

Copy link
Contributor

@ojeda ojeda Feb 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still, writing the original name would be better, no? Otherwise we should change e.g. Map to map in the Java one, etc.

Copy link
Contributor

@ojeda ojeda Feb 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, I guess you want to keep null for other languages that use that one -- again, this depends on how we are looking at this: whether we are trying to keep a mapping or just search terms for any language that matches. If the latter, I agree: null is better.

None,
/// Some value `T`
#[lang = "Some"]
Expand Down
4 changes: 4 additions & 0 deletions library/core/src/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize> {
pat.into_searcher(self).next_match().map(|(i, _)| i)
Expand Down Expand Up @@ -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<usize>
where
Expand Down Expand Up @@ -1202,6 +1205,7 @@ impl str {
///
/// [`split_whitespace`]: str::split_whitespace
#[stable(feature = "rust1", since = "1.0.0")]
#[doc(alias = "strtok")]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is iffy, but C doesn't really have a split function and I didn't know where else to put strtok.

#[inline]
pub fn split<'a, P: Pattern<'a>>(&'a self, pat: P) -> Split<'a, P> {
Split(SplitInternal {
Expand Down
1 change: 1 addition & 0 deletions library/std/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ impl fmt::Debug for VarsOs {
/// }
/// ```
#[stable(feature = "env", since = "1.0.0")]
#[doc(alias = "getenv")]
pub fn var<K: AsRef<OsStr>>(key: K) -> Result<String, VarError> {
_var(key.as_ref())
}
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ pub fn read_to_string<P: AsRef<Path>>(path: P) -> io::Result<String> {
/// }
/// ```
#[stable(feature = "fs_read_write_bytes", since = "1.26.0")]
#[doc(alias = "fputs")]
#[doc(alias = "fprintf")]
pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> io::Result<()> {
fn inner(path: &Path, contents: &[u8]) -> io::Result<()> {
File::create(path)?.write_all(contents)
Expand Down
1 change: 1 addition & 0 deletions library/std/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)*) => ({
Expand Down
25 changes: 15 additions & 10 deletions library/std/src/primitive_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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`,
Expand Down Expand Up @@ -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
Expand All @@ -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 {}
Expand All @@ -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 {}
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions library/std/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,7 @@ impl Command {
/// assert!(output.status.success());
/// ```
#[stable(feature = "process", since = "1.0.0")]
#[doc(alias = "system")]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also go under spawn(). In C system blocks but returns no value.

pub fn output(&mut self) -> io::Result<Output> {
self.inner
.spawn(imp::Stdio::MakePipe, false)
Expand Down
1 change: 1 addition & 0 deletions library/std/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down