libc-rs/src/dox.rs

210 lines
5.0 KiB
Rust
Raw Normal View History

2015-09-17 08:54:56 +02:00
pub use self::imp::*;
Rename the dox configuration option to cross_platform_docs The libc crate is used as a dependency of the Rust compiler. Its build system passes `--cfg dox` to all crates when generating their documentation. libc's documentation is generated when the build system is asked to generate the compiler documentation because `cargo doc` automatically documents all dependencies. When the dox configuration option is enabled, libc disables its dependency on the core crate and provides the necessary definitions itself. The dox configuration option is meant for generating documentation for a multitude of targets even if the core crate for that target is not installed. However, when documenting the compiler, it's not necessary to do that; we can just use core or std as usual. This change is motivated by the changes made to the compiler in rust-lang/rust#48171. With these changes, it's necessary to provide implementations of the Clone and Copy traits for some primitive types in the library that defines these traits (previously, these implementations were provided by the compiler). Normally, these traits (and thus the implementations) are provided by core, so any crate that uses `#![no_core]` must now provide its own copy of the implementations. Because libc doesn't provide its own copy of the implementations yet, and because the compiler's build system passes `--cfg dox` to libc, generating the documentation for the compiler fails when generating documentation for libc. By renaming the configuration option, libc will use core or std and will thus have the necessary definitions for the documentation to be generated successfully.
2018-03-18 19:09:07 +01:00
#[cfg(not(cross_platform_docs))]
2015-09-17 08:54:56 +02:00
mod imp {
pub use core::option::Option;
pub use core::clone::Clone;
pub use core::marker::Copy;
pub use core::mem;
2015-09-17 08:54:56 +02:00
}
Rename the dox configuration option to cross_platform_docs The libc crate is used as a dependency of the Rust compiler. Its build system passes `--cfg dox` to all crates when generating their documentation. libc's documentation is generated when the build system is asked to generate the compiler documentation because `cargo doc` automatically documents all dependencies. When the dox configuration option is enabled, libc disables its dependency on the core crate and provides the necessary definitions itself. The dox configuration option is meant for generating documentation for a multitude of targets even if the core crate for that target is not installed. However, when documenting the compiler, it's not necessary to do that; we can just use core or std as usual. This change is motivated by the changes made to the compiler in rust-lang/rust#48171. With these changes, it's necessary to provide implementations of the Clone and Copy traits for some primitive types in the library that defines these traits (previously, these implementations were provided by the compiler). Normally, these traits (and thus the implementations) are provided by core, so any crate that uses `#![no_core]` must now provide its own copy of the implementations. Because libc doesn't provide its own copy of the implementations yet, and because the compiler's build system passes `--cfg dox` to libc, generating the documentation for the compiler fails when generating documentation for libc. By renaming the configuration option, libc will use core or std and will thus have the necessary definitions for the documentation to be generated successfully.
2018-03-18 19:09:07 +01:00
#[cfg(cross_platform_docs)]
2015-09-17 08:54:56 +02:00
mod imp {
pub enum Option<T> {
Some(T),
None,
}
2015-09-18 02:53:03 +02:00
impl<T: Copy> Copy for Option<T> {}
2015-09-18 02:28:45 +02:00
impl<T: Clone> Clone for Option<T> {
fn clone(&self) -> Option<T> { loop {} }
}
2015-09-17 08:54:56 +02:00
impl<T> Copy for *mut T {}
impl<T> Clone for *mut T {
fn clone(&self) -> *mut T { loop {} }
}
impl<T> Copy for *const T {}
impl<T> Clone for *const T {
fn clone(&self) -> *const T { loop {} }
}
2015-09-17 08:54:56 +02:00
pub trait Clone {
fn clone(&self) -> Self;
}
#[lang = "copy"]
pub trait Copy {}
2017-05-26 01:06:01 +02:00
#[lang = "freeze"]
pub trait Freeze {}
#[lang = "sync"]
pub trait Sync {}
impl<T> Sync for T {}
2015-09-17 08:54:56 +02:00
#[lang = "sized"]
pub trait Sized {}
macro_rules! each_int {
($mac:ident) => (
$mac!(u8);
$mac!(u16);
$mac!(u32);
$mac!(u64);
$mac!(usize);
2017-01-02 23:29:27 +01:00
each_signed_int!($mac);
)
}
macro_rules! each_signed_int {
($mac:ident) => (
2015-09-17 08:54:56 +02:00
$mac!(i8);
$mac!(i16);
$mac!(i32);
$mac!(i64);
$mac!(isize);
)
}
#[lang = "div"]
pub trait Div<RHS=Self> {
type Output;
fn div(self, rhs: RHS) -> Self::Output;
}
2015-09-17 08:54:56 +02:00
#[lang = "shl"]
pub trait Shl<RHS=Self> {
2015-09-17 08:54:56 +02:00
type Output;
fn shl(self, rhs: RHS) -> Self::Output;
}
#[lang = "mul"]
pub trait Mul<RHS=Self> {
type Output;
fn mul(self, rhs: RHS) -> Self::Output;
}
#[lang = "sub"]
pub trait Sub<RHS=Self> {
type Output;
fn sub(self, rhs: RHS) -> Self::Output;
}
2018-06-01 07:49:03 +02:00
#[lang = "bitand"]
pub trait BitAnd<RHS=Self> {
type Output;
fn bitand(self, rhs: RHS) -> Self::Output;
}
#[lang = "bitand_assign"]
pub trait BitAndAssign<RHS = Self> {
fn bitand_assign(&mut self, rhs: RHS);
}
2015-09-17 08:54:56 +02:00
#[lang = "bitor"]
2018-06-01 07:49:03 +02:00
pub trait BitOr<RHS=Self> {
2015-09-17 08:54:56 +02:00
type Output;
fn bitor(self, rhs: RHS) -> Self::Output;
}
2018-06-01 07:49:03 +02:00
#[lang = "bitor_assign"]
pub trait BitOrAssign<RHS = Self> {
fn bitor_assign(&mut self, rhs: RHS);
}
#[lang = "bitxor"]
pub trait BitXor<RHS=Self> {
type Output;
fn bitxor(self, rhs: RHS) -> Self::Output;
}
#[lang = "bitxor_assign"]
pub trait BitXorAssign<RHS = Self> {
fn bitxor_assign(&mut self, rhs: RHS);
}
2017-01-02 23:29:27 +01:00
#[lang = "neg"]
pub trait Neg {
type Output;
fn neg(self) -> Self::Output;
}
#[lang = "not"]
pub trait Not {
type Output;
fn not(self) -> Self::Output;
}
#[lang = "add"]
pub trait Add<RHS = Self> {
type Output;
fn add(self, r: RHS) -> Self::Output;
}
macro_rules! impl_traits {
2017-01-02 23:29:27 +01:00
($($i:ident)*) => ($(
impl Div<$i> for $i {
type Output = $i;
fn div(self, rhs: $i) -> $i { self / rhs }
}
impl Shl<$i> for $i {
type Output = $i;
fn shl(self, rhs: $i) -> $i { self << rhs }
}
impl Mul for $i {
type Output = $i;
fn mul(self, rhs: $i) -> $i { self * rhs }
}
impl Sub for $i {
type Output = $i;
fn sub(self, rhs: $i) -> $i { self - rhs }
}
2018-06-01 07:49:03 +02:00
impl BitAnd for $i {
type Output = $i;
fn bitand(self, rhs: $i) -> $i { self & rhs }
}
impl BitAndAssign for $i {
fn bitand_assign(&mut self, rhs: $i) { *self &= rhs; }
}
impl BitOr for $i {
type Output = $i;
fn bitor(self, rhs: $i) -> $i { self | rhs }
}
2018-06-01 07:49:03 +02:00
impl BitOrAssign for $i {
fn bitor_assign(&mut self, rhs: $i) { *self |= rhs; }
}
impl BitXor for $i {
type Output = $i;
fn bitxor(self, rhs: $i) -> $i { self ^ rhs }
}
impl BitXorAssign for $i {
fn bitxor_assign(&mut self, rhs: $i) { *self ^= rhs; }
}
impl Neg for $i {
type Output = $i;
fn neg(self) -> $i { -self }
}
2017-01-02 23:29:27 +01:00
impl Not for $i {
type Output = $i;
fn not(self) -> $i { !self }
}
impl Add<$i> for $i {
type Output = $i;
fn add(self, other: $i) -> $i { self + other }
}
impl Copy for $i {}
impl Clone for $i {
fn clone(&self) -> $i { loop {} }
}
2017-01-02 23:29:27 +01:00
)*)
}
each_int!(impl_traits);
2017-01-02 23:29:27 +01:00
pub mod mem {
pub fn size_of_val<T>(_: &T) -> usize { 4 }
2018-06-01 10:58:47 +02:00
pub const fn size_of<T>() -> usize { 4 }
}
2015-09-17 08:54:56 +02:00
}