Skip to content

Varargs1 #9

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

Open
wants to merge 47 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
85f13f0
Add a convert::Infallible empty enum, make string::ParseError an alias
SimonSapin Feb 8, 2019
2f71203
Use convert::Infallible instead of never in the blanket TryFrom impl
SimonSapin Feb 8, 2019
c80a8f5
Stabilize TryFrom and TryInto
SimonSapin Feb 8, 2019
b2cf9a0
Add `impl From<!> for Infallible`
SimonSapin Feb 13, 2019
31bcec6
Add vectored read and write support
sfackler Feb 8, 2019
596f182
impl Deref/DerefMut for IoVec types
sfackler Feb 12, 2019
034de8d
Whitelist iovec types in linkchecker
sfackler Feb 14, 2019
5ca3b00
Add a tracking issue
sfackler Feb 14, 2019
cf26754
Review comments
SimonSapin Feb 17, 2019
904a91c
hir: impl Display for HirId
ljedrz Feb 18, 2019
00b74e5
hir: remove NodeId from Lifetime and Ty
ljedrz Feb 18, 2019
58ed683
passes: HirIdify Id
ljedrz Feb 18, 2019
1c18ac1
privacy: HirIdify ObsoleteVisiblePrivateTypesVisitor
ljedrz Feb 18, 2019
e4f8a6b
hir: remove NodeId from GenericParam
ljedrz Feb 18, 2019
cd5b5e7
hir: remove NodeId from WhereClause
ljedrz Feb 18, 2019
b6b2edb
hir: remove NodeId from WhereEqPredicate
ljedrz Feb 18, 2019
46e4f4a
middle: partially HirIdify stability
ljedrz Feb 18, 2019
c886d47
doc: partially HirIdify visit_ast
ljedrz Feb 18, 2019
63b4dd9
hir: remove NodeId from MacroDef
ljedrz Feb 18, 2019
2cf6e91
Update stdsimd
gnzlbg Feb 23, 2019
4c13791
Fix cloudabi
sfackler Feb 24, 2019
021a140
hir: remove NodeId from Block
ljedrz Feb 22, 2019
d7ced1d
hir: remove NodeId from Expr
ljedrz Feb 24, 2019
c5b87a2
Fix sgx
sfackler Feb 24, 2019
4785c74
Fix redox
sfackler Feb 25, 2019
77a30ec
update clippy
ljedrz Feb 24, 2019
19c302c
Update book submodule
kornelski Feb 24, 2019
8e1b5d8
Restrict value in key-value attributes to literals
petrochenkov Jan 3, 2019
eccc199
Stabilize `unrestricted_attribute_tokens`
petrochenkov Feb 25, 2019
00aae71
Auto merge of #58302 - SimonSapin:tryfrom, r=alexcrichton
bors Feb 25, 2019
0f6b148
Allow lang and lib features to share names
varkor Feb 25, 2019
55c173c
Auto merge of #57367 - petrochenkov:unrestab, r=Centril
bors Feb 25, 2019
fb162e6
Auto merge of #58357 - sfackler:vectored-io, r=alexcrichton
bors Feb 26, 2019
ea43c3c
Auto merge of #58561 - ljedrz:HirIdify_some_nodes, r=Zoxc
bors Feb 26, 2019
ccfa5d6
replace &'tcx Substs with SubstsRef
csmoe Feb 9, 2019
cf11729
rename Substs to InternalSubsts
csmoe Feb 26, 2019
02c4c28
Auto merge of #58675 - gnzlbg:usimd, r=alexcrichton
bors Feb 26, 2019
f0be457
Auto merge of #58321 - csmoe:substs, r=oli-obk
bors Feb 27, 2019
f5b5f92
Auto merge of #58709 - kornelski:book, r=QuietMisdreavus
bors Feb 27, 2019
4855370
Auto merge of #58741 - varkor:lang-lib-feature-shared-name, r=alexreg
bors Feb 27, 2019
cd56472
Fix tidy check for language and library features
dlrobertson Feb 26, 2019
58147d4
Support defining C compatible variadic functions
dlrobertson Nov 30, 2018
210c607
Add c_variadic language feature item
dlrobertson Feb 24, 2019
1a6e9e2
Add c_variadic to the unstable-book
dlrobertson Feb 24, 2019
a618ad6
Refactor FunctionCx::codgen_terminator
dlrobertson Feb 2, 2019
08bd4ff
Rename variadic to c_variadic
dlrobertson Feb 8, 2019
f7dd438
Fix doc comments in librustc/hir/lowering.rs
dlrobertson Feb 24, 2019
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
2 changes: 1 addition & 1 deletion src/doc/book
Submodule book updated 244 files
24 changes: 24 additions & 0 deletions src/doc/unstable-book/src/language-features/c-variadic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# `c_variadic`

The tracking issue for this feature is: [#44930]

[#44930]: https://github.com/rust-lang/rust/issues/44930

------------------------

The `c_variadic` language feature enables C-variadic functions to be
defined in Rust. The may be called both from within Rust and via FFI.

## Examples

```rust
#![feature(c_variadic)]

pub unsafe extern "C" fn add(n: usize, mut args: ...) -> usize {
let mut sum = 0;
for _ in 0..n {
sum += args.arg::<usize>();
}
sum
}
```
26 changes: 26 additions & 0 deletions src/doc/unstable-book/src/library-features/c-variadic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# `c_variadic`

The tracking issue for this feature is: [#44930]

[#44930]: https://github.com/rust-lang/rust/issues/44930

------------------------

The `c_variadic` library feature exposes the `VaList` structure,
Rust's analogue of C's `va_list` type.

## Examples

```rust
#![feature(c_variadic)]

use std::ffi::VaList;

pub unsafe extern "C" fn vadd(n: usize, mut args: VaList) -> usize {
let mut sum = 0;
for _ in 0..n {
sum += args.arg::<usize>();
}
sum
}
```
37 changes: 3 additions & 34 deletions src/liballoc/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ impl String {
/// [`str::from_utf8`]: ../../std/str/fn.from_utf8.html
/// [`as_bytes`]: struct.String.html#method.as_bytes
/// [`FromUtf8Error`]: struct.FromUtf8Error.html
/// [`Err`]: ../../stdresult/enum.Result.html#variant.Err
/// [`Err`]: ../../std/result/enum.Result.html#variant.Err
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn from_utf8(vec: Vec<u8>) -> Result<String, FromUtf8Error> {
Expand Down Expand Up @@ -2073,48 +2073,17 @@ impl ops::DerefMut for String {
/// [`String`]: struct.String.html
/// [`from_str`]: ../../std/str/trait.FromStr.html#tymethod.from_str
#[stable(feature = "str_parse_error", since = "1.5.0")]
#[derive(Copy)]
pub enum ParseError {}
pub type ParseError = core::convert::Infallible;

#[stable(feature = "rust1", since = "1.0.0")]
impl FromStr for String {
type Err = ParseError;
type Err = core::convert::Infallible;
#[inline]
fn from_str(s: &str) -> Result<String, ParseError> {
Ok(String::from(s))
}
}

#[stable(feature = "str_parse_error", since = "1.5.0")]
impl Clone for ParseError {
fn clone(&self) -> ParseError {
match *self {}
}
}

#[stable(feature = "str_parse_error", since = "1.5.0")]
impl fmt::Debug for ParseError {
fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {}
}
}

#[stable(feature = "str_parse_error2", since = "1.8.0")]
impl fmt::Display for ParseError {
fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {}
}
}

#[stable(feature = "str_parse_error", since = "1.5.0")]
impl PartialEq for ParseError {
fn eq(&self, _: &ParseError) -> bool {
match *self {}
}
}

#[stable(feature = "str_parse_error", since = "1.5.0")]
impl Eq for ParseError {}

/// A trait for converting a value to a `String`.
///
Expand Down
8 changes: 4 additions & 4 deletions src/libcore/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ unsafe impl<T, A: Unsize<[T]>> FixedSizeArray<T> for A {
}

/// The error type returned when a conversion from a slice to an array fails.
#[unstable(feature = "try_from", issue = "33417")]
#[stable(feature = "try_from", since = "1.34.0")]
#[derive(Debug, Copy, Clone)]
pub struct TryFromSliceError(());

Expand Down Expand Up @@ -138,7 +138,7 @@ macro_rules! array_impls {
}
}

#[unstable(feature = "try_from", issue = "33417")]
#[stable(feature = "try_from", since = "1.34.0")]
impl<'a, T> TryFrom<&'a [T]> for [T; $N] where T: Copy {
type Error = TryFromSliceError;

Expand All @@ -147,7 +147,7 @@ macro_rules! array_impls {
}
}

#[unstable(feature = "try_from", issue = "33417")]
#[stable(feature = "try_from", since = "1.34.0")]
impl<'a, T> TryFrom<&'a [T]> for &'a [T; $N] {
type Error = TryFromSliceError;

Expand All @@ -161,7 +161,7 @@ macro_rules! array_impls {
}
}

#[unstable(feature = "try_from", issue = "33417")]
#[stable(feature = "try_from", since = "1.34.0")]
impl<'a, T> TryFrom<&'a mut [T]> for &'a mut [T; $N] {
type Error = TryFromSliceError;

Expand Down
6 changes: 3 additions & 3 deletions src/libcore/char/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl FromStr for char {
}


#[unstable(feature = "try_from", issue = "33417")]
#[stable(feature = "try_from", since = "1.34.0")]
impl TryFrom<u32> for char {
type Error = CharTryFromError;

Expand All @@ -233,11 +233,11 @@ impl TryFrom<u32> for char {
}

/// The error type returned when a conversion from u32 to char fails.
#[unstable(feature = "try_from", issue = "33417")]
#[stable(feature = "try_from", since = "1.34.0")]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct CharTryFromError(());

#[unstable(feature = "try_from", issue = "33417")]
#[stable(feature = "try_from", since = "1.34.0")]
impl fmt::Display for CharTryFromError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
"converted integer out of range for `char`".fmt(f)
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/char/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub use self::convert::{from_u32, from_digit};
pub use self::convert::from_u32_unchecked;
#[stable(feature = "char_from_str", since = "1.20.0")]
pub use self::convert::ParseCharError;
#[unstable(feature = "try_from", issue = "33417")]
#[stable(feature = "try_from", since = "1.34.0")]
pub use self::convert::CharTryFromError;
#[stable(feature = "decode_utf16", since = "1.9.0")]
pub use self::decode::{decode_utf16, DecodeUtf16, DecodeUtf16Error};
Expand Down
128 changes: 123 additions & 5 deletions src/libcore/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

#![stable(feature = "rust1", since = "1.0.0")]

use fmt;

/// An identity function.
///
/// Two things are important to note about this function:
Expand Down Expand Up @@ -367,22 +369,26 @@ pub trait From<T>: Sized {
///
/// [`TryFrom`]: trait.TryFrom.html
/// [`Into`]: trait.Into.html
#[unstable(feature = "try_from", issue = "33417")]
#[stable(feature = "try_from", since = "1.34.0")]
pub trait TryInto<T>: Sized {
/// The type returned in the event of a conversion error.
#[stable(feature = "try_from", since = "1.34.0")]
type Error;

/// Performs the conversion.
#[stable(feature = "try_from", since = "1.34.0")]
fn try_into(self) -> Result<T, Self::Error>;
}

/// Attempt to construct `Self` via a conversion.
#[unstable(feature = "try_from", issue = "33417")]
#[stable(feature = "try_from", since = "1.34.0")]
pub trait TryFrom<T>: Sized {
/// The type returned in the event of a conversion error.
#[stable(feature = "try_from", since = "1.34.0")]
type Error;

/// Performs the conversion.
#[stable(feature = "try_from", since = "1.34.0")]
fn try_from(value: T) -> Result<Self, Self::Error>;
}

Expand Down Expand Up @@ -450,7 +456,7 @@ impl<T> From<T> for T {


// TryFrom implies TryInto
#[unstable(feature = "try_from", issue = "33417")]
#[stable(feature = "try_from", since = "1.34.0")]
impl<T, U> TryInto<U> for T where U: TryFrom<T>
{
type Error = U::Error;
Expand All @@ -462,9 +468,9 @@ impl<T, U> TryInto<U> for T where U: TryFrom<T>

// Infallible conversions are semantically equivalent to fallible conversions
// with an uninhabited error type.
#[unstable(feature = "try_from", issue = "33417")]
#[stable(feature = "try_from", since = "1.34.0")]
impl<T, U> TryFrom<U> for T where U: Into<T> {
type Error = !;
type Error = Infallible;

fn try_from(value: U) -> Result<Self, Self::Error> {
Ok(U::into(value))
Expand Down Expand Up @@ -496,3 +502,115 @@ impl AsRef<str> for str {
self
}
}

////////////////////////////////////////////////////////////////////////////////
// THE NO-ERROR ERROR TYPE
////////////////////////////////////////////////////////////////////////////////

/// The error type for errors that can never happen.
///
/// Since this enum has no variant, a value of this type can never actually exist.
/// This can be useful for generic APIs that use [`Result`] and parameterize the error type,
/// to indicate that the result is always [`Ok`].
///
/// For example, the [`TryFrom`] trait (conversion that returns a [`Result`])
/// has a blanket implementation for all types where a reverse [`Into`] implementation exists.
///
/// ```ignore (illustrates std code, duplicating the impl in a doctest would be an error)
/// impl<T, U> TryFrom<U> for T where U: Into<T> {
/// type Error = Infallible;
///
/// fn try_from(value: U) -> Result<Self, Infallible> {
/// Ok(U::into(value)) // Never returns `Err`
/// }
/// }
/// ```
///
/// # Future compatibility
///
/// This enum has the same role as [the `!` “never” type][never],
/// which is unstable in this version of Rust.
/// When `!` is stabilized, we plan to make `Infallible` a type alias to it:
///
/// ```ignore (illustrates future std change)
/// pub type Infallible = !;
/// ```
///
/// … and eventually deprecate `Infallible`.
///
///
/// However there is one case where `!` syntax can be used
/// before `!` is stabilized as a full-fleged type: in the position of a function’s return type.
/// Specifically, it is possible implementations for two different function pointer types:
///
/// ```
/// trait MyTrait {}
/// impl MyTrait for fn() -> ! {}
/// impl MyTrait for fn() -> std::convert::Infallible {}
/// ```
///
/// With `Infallible` being an enum, this code is valid.
/// However when `Infallible` becomes an alias for the never type,
/// the two `impl`s will start to overlap
/// and therefore will be disallowed by the language’s trait coherence rules.
///
/// [`Ok`]: ../result/enum.Result.html#variant.Ok
/// [`Result`]: ../result/enum.Result.html
/// [`TryFrom`]: trait.TryFrom.html
/// [`Into`]: trait.Into.html
/// [never]: ../../std/primitive.never.html
#[stable(feature = "convert_infallible", since = "1.34.0")]
#[derive(Copy)]
pub enum Infallible {}

#[stable(feature = "convert_infallible", since = "1.34.0")]
impl Clone for Infallible {
fn clone(&self) -> Infallible {
match *self {}
}
}

#[stable(feature = "convert_infallible", since = "1.34.0")]
impl fmt::Debug for Infallible {
fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {}
}
}

#[stable(feature = "convert_infallible", since = "1.34.0")]
impl fmt::Display for Infallible {
fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {}
}
}

#[stable(feature = "convert_infallible", since = "1.34.0")]
impl PartialEq for Infallible {
fn eq(&self, _: &Infallible) -> bool {
match *self {}
}
}

#[stable(feature = "convert_infallible", since = "1.34.0")]
impl Eq for Infallible {}

#[stable(feature = "convert_infallible", since = "1.34.0")]
impl PartialOrd for Infallible {
fn partial_cmp(&self, _other: &Self) -> Option<crate::cmp::Ordering> {
match *self {}
}
}

#[stable(feature = "convert_infallible", since = "1.34.0")]
impl Ord for Infallible {
fn cmp(&self, _other: &Self) -> crate::cmp::Ordering {
match *self {}
}
}

#[stable(feature = "convert_infallible", since = "1.34.0")]
impl From<!> for Infallible {
fn from(x: !) -> Self {
x
}
}
1 change: 0 additions & 1 deletion src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@
#![feature(abi_unadjusted)]
#![feature(adx_target_feature)]
#![feature(maybe_uninit, maybe_uninit_slice, maybe_uninit_array)]
#![feature(unrestricted_attribute_tokens)]
#![feature(external_doc)]

#[prelude_import]
Expand Down
Loading