Skip to content

Commit bd98fe0

Browse files
committed
Auto merge of #48040 - kennytm:rollup, r=kennytm
Rollup of 7 pull requests - Successful merges: #46962, #47986, #48012, #48013, #48026, #48031, #48036 - Failed merges:
2 parents ca7d839 + 7f0e87a commit bd98fe0

25 files changed

+235
-18
lines changed

config.toml.example

+4-4
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@
295295

296296
# Flag indicating whether git info will be retrieved from .git automatically.
297297
# Having the git information can cause a lot of rebuilds during development.
298-
# Note: If this attribute is not explicity set (e.g. if left commented out) it
298+
# Note: If this attribute is not explicitly set (e.g. if left commented out) it
299299
# will default to true if channel = "dev", but will default to false otherwise.
300300
#ignore-git = true
301301

@@ -317,8 +317,8 @@
317317
# bootstrap)
318318
#codegen-backends = ["llvm"]
319319

320-
# Flag indicating whether `libstd` calls an imported function to hande basic IO
321-
# when targetting WebAssembly. Enable this to debug tests for the `wasm32-unknown-unknown`
320+
# Flag indicating whether `libstd` calls an imported function to handle basic IO
321+
# when targeting WebAssembly. Enable this to debug tests for the `wasm32-unknown-unknown`
322322
# target, as without this option the test output will not be captured.
323323
#wasm-syscall = false
324324

@@ -349,7 +349,7 @@
349349
#linker = "cc"
350350

351351
# Path to the `llvm-config` binary of the installation of a custom LLVM to link
352-
# against. Note that if this is specifed we don't compile LLVM at all for this
352+
# against. Note that if this is specified we don't compile LLVM at all for this
353353
# target.
354354
#llvm-config = "../path/to/llvm/root/bin/llvm-config"
355355

src/Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bootstrap/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ serde_derive = "1.0.8"
4141
serde_json = "1.0.2"
4242
toml = "0.4"
4343
lazy_static = "0.2"
44+
time = "0.1"

src/bootstrap/dist.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use builder::{Builder, RunConfig, ShouldRun, Step};
3333
use compile;
3434
use tool::{self, Tool};
3535
use cache::{INTERNER, Interned};
36+
use time;
3637

3738
pub fn pkgname(build: &Build, component: &str) -> String {
3839
if component == "cargo" {
@@ -445,8 +446,7 @@ impl Step for Rustc {
445446
t!(fs::create_dir_all(image.join("share/man/man1")));
446447
let man_src = build.src.join("src/doc/man");
447448
let man_dst = image.join("share/man/man1");
448-
let date_output = output(Command::new("date").arg("+%B %Y"));
449-
let month_year = date_output.trim();
449+
let month_year = t!(time::strftime("%B %Y", &time::now()));
450450
// don't use our `bootstrap::util::{copy, cp_r}`, because those try
451451
// to hardlink, and we don't want to edit the source templates
452452
for entry_result in t!(fs::read_dir(man_src)) {
@@ -456,7 +456,7 @@ impl Step for Rustc {
456456
t!(fs::copy(&page_src, &page_dst));
457457
// template in month/year and version number
458458
replace_in_file(&page_dst,
459-
&[("<INSERT DATE HERE>", month_year),
459+
&[("<INSERT DATE HERE>", &month_year),
460460
("<INSERT VERSION HERE>", channel::CFG_RELEASE_NUM)]);
461461
}
462462

src/bootstrap/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ extern crate cc;
130130
extern crate getopts;
131131
extern crate num_cpus;
132132
extern crate toml;
133+
extern crate time;
133134

134135
#[cfg(unix)]
135136
extern crate libc;

src/libcore/iter/range.rs

+45-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use convert::TryFrom;
1212
use mem;
13-
use ops::{self, Add, Sub};
13+
use ops::{self, Add, Sub, Try};
1414
use usize;
1515

1616
use super::{FusedIterator, TrustedLen};
@@ -397,6 +397,28 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
397397
fn max(mut self) -> Option<A> {
398398
self.next_back()
399399
}
400+
401+
#[inline]
402+
fn try_fold<B, F, R>(&mut self, init: B, mut f: F) -> R where
403+
Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try<Ok=B>
404+
{
405+
let mut accum = init;
406+
if self.start <= self.end {
407+
loop {
408+
let (x, done) =
409+
if self.start < self.end {
410+
let n = self.start.add_one();
411+
(mem::replace(&mut self.start, n), false)
412+
} else {
413+
self.end.replace_zero();
414+
(self.start.replace_one(), true)
415+
};
416+
accum = f(accum, x)?;
417+
if done { break }
418+
}
419+
}
420+
Try::from_ok(accum)
421+
}
400422
}
401423

402424
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
@@ -418,6 +440,28 @@ impl<A: Step> DoubleEndedIterator for ops::RangeInclusive<A> {
418440
_ => None,
419441
}
420442
}
443+
444+
#[inline]
445+
fn try_rfold<B, F, R>(&mut self, init: B, mut f: F) -> R where
446+
Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try<Ok=B>
447+
{
448+
let mut accum = init;
449+
if self.start <= self.end {
450+
loop {
451+
let (x, done) =
452+
if self.start < self.end {
453+
let n = self.end.sub_one();
454+
(mem::replace(&mut self.end, n), false)
455+
} else {
456+
self.start.replace_one();
457+
(self.end.replace_zero(), true)
458+
};
459+
accum = f(accum, x)?;
460+
if done { break }
461+
}
462+
}
463+
Try::from_ok(accum)
464+
}
421465
}
422466

423467
#[unstable(feature = "fused", issue = "35602")]

src/libcore/tests/iter.rs

+20
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,26 @@ fn test_range_inclusive_min() {
14591459
assert_eq!(r.min(), None);
14601460
}
14611461

1462+
#[test]
1463+
fn test_range_inclusive_folds() {
1464+
assert_eq!((1..=10).sum::<i32>(), 55);
1465+
assert_eq!((1..=10).rev().sum::<i32>(), 55);
1466+
1467+
let mut it = 40..=50;
1468+
assert_eq!(it.try_fold(0, i8::checked_add), None);
1469+
assert_eq!(it, 44..=50);
1470+
assert_eq!(it.try_rfold(0, i8::checked_add), None);
1471+
assert_eq!(it, 44..=47);
1472+
1473+
let mut it = 10..=20;
1474+
assert_eq!(it.try_fold(0, |a,b| Some(a+b)), Some(165));
1475+
assert_eq!(it, 1..=0);
1476+
1477+
let mut it = 10..=20;
1478+
assert_eq!(it.try_rfold(0, |a,b| Some(a+b)), Some(165));
1479+
assert_eq!(it, 1..=0);
1480+
}
1481+
14621482
#[test]
14631483
fn test_repeat() {
14641484
let mut it = repeat(42);

src/libproc_macro/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ impl TokenTree {
685685
})
686686
}
687687

688-
DotEq => unreachable!(),
688+
DotEq => joint!('.', Eq),
689689
OpenDelim(..) | CloseDelim(..) => unreachable!(),
690690
Whitespace | Comment | Shebang(..) | Eof => unreachable!(),
691691
};

src/librustc/diagnostics.rs

+22
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,28 @@ trait Foo {
256256
}
257257
```
258258
259+
### The trait cannot contain associated constants
260+
261+
Just like static functions, associated constants aren't stored on the method
262+
table. If the trait or any subtrait contain an associated constant, they cannot
263+
be made into an object.
264+
265+
```compile_fail,E0038
266+
trait Foo {
267+
const X: i32;
268+
}
269+
270+
impl Foo {}
271+
```
272+
273+
A simple workaround is to use a helper method instead:
274+
275+
```
276+
trait Foo {
277+
fn x(&self) -> i32;
278+
}
279+
```
280+
259281
### The trait cannot use `Self` as a type parameter in the supertrait listing
260282
261283
This is similar to the second sub-error, but subtler. It happens in situations

src/libstd/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@
260260
#![feature(core_intrinsics)]
261261
#![feature(dropck_eyepatch)]
262262
#![feature(exact_size_is_empty)]
263+
#![feature(external_doc)]
263264
#![feature(fs_read_write)]
264265
#![feature(fixed_size_array)]
265266
#![feature(float_from_str_radix)]

src/libstd/os/raw/char.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Equivalent to C's `char` type.
2+
3+
[C's `char` type] is completely unlike [Rust's `char` type]; while Rust's type represents a unicode scalar value, C's `char` type is just an ordinary integer. This type will always be either [`i8`] or [`u8`], as the type is defined as being one byte long.
4+
5+
C chars are most commonly used to make C strings. Unlike Rust, where the length of a string is included alongside the string, C strings mark the end of a string with the character `'\0'`. See [`CStr`] for more information.
6+
7+
[C's `char` type]: https://en.wikipedia.org/wiki/C_data_types#Basic_types
8+
[Rust's `char` type]: ../../primitive.char.html
9+
[`CStr`]: ../../ffi/struct.CStr.html
10+
[`i8`]: ../../primitive.i8.html
11+
[`u8`]: ../../primitive.u8.html

src/libstd/os/raw/double.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Equivalent to C's `double` type.
2+
3+
This type will almost always be [`f64`], which is guaranteed to be an [IEEE-754 double-precision float] in Rust. That said, the standard technically only guarantees that it be a floating-point number with at least the precision of a [`float`], and it may be `f32` or something entirely different from the IEEE-754 standard.
4+
5+
[IEEE-754 double-precision float]: https://en.wikipedia.org/wiki/IEEE_754
6+
[`float`]: type.c_float.html
7+
[`f64`]: ../../primitive.f64.html

src/libstd/os/raw/float.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Equivalent to C's `float` type.
2+
3+
This type will almost always be [`f32`], which is guaranteed to be an [IEEE-754 single-precision float] in Rust. That said, the standard technically only guarantees that it be a floating-point number, and it may have less precision than `f32` or not follow the IEEE-754 standard at all.
4+
5+
[IEEE-754 single-precision float]: https://en.wikipedia.org/wiki/IEEE_754
6+
[`f32`]: ../../primitive.f32.html

src/libstd/os/raw/int.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Equivalent to C's `signed int` (`int`) type.
2+
3+
This type will almost always be [`i32`], but may differ on some esoteric systems. The C standard technically only requires that this type be a signed integer that is at least the size of a [`short`]; some systems define it as an [`i16`], for example.
4+
5+
[`short`]: type.c_short.html
6+
[`i32`]: ../../primitive.i32.html
7+
[`i16`]: ../../primitive.i16.html

src/libstd/os/raw/long.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Equivalent to C's `signed long` (`long`) type.
2+
3+
This type will always be [`i32`] or [`i64`]. Most notably, many Linux-based systems assume an `i64`, but Windows assumes `i32`. The C standard technically only requires that this type be a signed integer that is at least 32 bits and at least the size of an [`int`], although in practice, no system would have a `long` that is neither an `i32` nor `i64`.
4+
5+
[`int`]: type.c_int.html
6+
[`i32`]: ../../primitive.i32.html
7+
[`i64`]: ../../primitive.i64.html

src/libstd/os/raw/longlong.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Equivalent to C's `signed long long` (`long long`) type.
2+
3+
This type will almost always be [`i64`], but may differ on some systems. The C standard technically only requires that this type be a signed integer that is at least 64 bits and at least the size of a [`long`], although in practice, no system would have a `long long` that is not an `i64`, as most systems do not have a standardised [`i128`] type.
4+
5+
[`long`]: type.c_int.html
6+
[`i64`]: ../../primitive.i64.html
7+
[`i128`]: ../../primitive.i128.html

src/libstd/os/raw.rs src/libstd/os/raw/mod.rs

+33-5
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,19 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! Raw OS-specific types for the current platform/architecture
11+
//! Platform-specific types, as defined by C.
12+
//!
13+
//! Code that interacts via FFI will almost certainly be using the
14+
//! base types provided by C, which aren't nearly as nicely defined
15+
//! as Rust's primitive types. This module provides types which will
16+
//! match those defined by C, so that code that interacts with C will
17+
//! refer to the correct types.
1218
1319
#![stable(feature = "raw_os", since = "1.1.0")]
1420

1521
use fmt;
1622

23+
#[doc(include = "os/raw/char.md")]
1724
#[cfg(any(all(target_os = "linux", any(target_arch = "aarch64",
1825
target_arch = "arm",
1926
target_arch = "powerpc",
@@ -25,6 +32,7 @@ use fmt;
2532
all(target_os = "openbsd", target_arch = "aarch64"),
2633
all(target_os = "fuchsia", target_arch = "aarch64")))]
2734
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = u8;
35+
#[doc(include = "os/raw/char.md")]
2836
#[cfg(not(any(all(target_os = "linux", any(target_arch = "aarch64",
2937
target_arch = "arm",
3038
target_arch = "powerpc",
@@ -36,30 +44,50 @@ use fmt;
3644
all(target_os = "openbsd", target_arch = "aarch64"),
3745
all(target_os = "fuchsia", target_arch = "aarch64"))))]
3846
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = i8;
47+
#[doc(include = "os/raw/schar.md")]
3948
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_schar = i8;
49+
#[doc(include = "os/raw/uchar.md")]
4050
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_uchar = u8;
51+
#[doc(include = "os/raw/short.md")]
4152
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_short = i16;
53+
#[doc(include = "os/raw/ushort.md")]
4254
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ushort = u16;
55+
#[doc(include = "os/raw/int.md")]
4356
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_int = i32;
57+
#[doc(include = "os/raw/uint.md")]
4458
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_uint = u32;
59+
#[doc(include = "os/raw/long.md")]
4560
#[cfg(any(target_pointer_width = "32", windows))]
4661
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_long = i32;
62+
#[doc(include = "os/raw/ulong.md")]
4763
#[cfg(any(target_pointer_width = "32", windows))]
4864
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulong = u32;
65+
#[doc(include = "os/raw/long.md")]
4966
#[cfg(all(target_pointer_width = "64", not(windows)))]
5067
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_long = i64;
68+
#[doc(include = "os/raw/ulong.md")]
5169
#[cfg(all(target_pointer_width = "64", not(windows)))]
5270
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulong = u64;
71+
#[doc(include = "os/raw/longlong.md")]
5372
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_longlong = i64;
73+
#[doc(include = "os/raw/ulonglong.md")]
5474
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulonglong = u64;
75+
#[doc(include = "os/raw/float.md")]
5576
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_float = f32;
77+
#[doc(include = "os/raw/double.md")]
5678
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_double = f64;
5779

58-
/// Type used to construct void pointers for use with C.
80+
/// Equivalent to C's `void` type when used as a [pointer].
5981
///
60-
/// This type is only useful as a pointer target. Do not use it as a
61-
/// return type for FFI functions which have the `void` return type in
62-
/// C. Use the unit type `()` or omit the return type instead.
82+
/// In essence, `*const c_void` is equivalent to C's `const void*`
83+
/// and `*mut c_void` is equivalent to C's `void*`. That said, this is
84+
/// *not* the same as C's `void` return type, which is Rust's `()` type.
85+
///
86+
/// Ideally, this type would be equivalent to [`!`], but currently it may
87+
/// be more ideal to use `c_void` for FFI purposes.
88+
///
89+
/// [`!`]: ../../primitive.never.html
90+
/// [pointer]: ../../primitive.pointer.html
6391
// NB: For LLVM to recognize the void pointer type and by extension
6492
// functions like malloc(), we need to have it represented as i8* in
6593
// LLVM bitcode. The enum used here ensures this and prevents misuse

src/libstd/os/raw/schar.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Equivalent to C's `signed char` type.
2+
3+
This type will always be [`i8`], but is included for completeness. It is defined as being a signed integer the same size as a C [`char`].
4+
5+
[`char`]: type.c_char.html
6+
[`i8`]: ../../primitive.i8.html

src/libstd/os/raw/short.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Equivalent to C's `signed short` (`short`) type.
2+
3+
This type will almost always be [`i16`], but may differ on some esoteric systems. The C standard technically only requires that this type be a signed integer with at least 16 bits; some systems may define it as `i32`, for example.
4+
5+
[`char`]: type.c_char.html
6+
[`i16`]: ../../primitive.i16.html

src/libstd/os/raw/uchar.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Equivalent to C's `unsigned char` type.
2+
3+
This type will always be [`u8`], but is included for completeness. It is defined as being an unsigned integer the same size as a C [`char`].
4+
5+
[`char`]: type.c_char.html
6+
[`u8`]: ../../primitive.u8.html

src/libstd/os/raw/uint.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Equivalent to C's `unsigned int` type.
2+
3+
This type will almost always be [`u32`], but may differ on some esoteric systems. The C standard technically only requires that this type be an unsigned integer with the same size as an [`int`]; some systems define it as a [`u16`], for example.
4+
5+
[`int`]: type.c_int.html
6+
[`u32`]: ../../primitive.u32.html
7+
[`u16`]: ../../primitive.u16.html

src/libstd/os/raw/ulong.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Equivalent to C's `unsigned long` type.
2+
3+
This type will always be [`u32`] or [`u64`]. Most notably, many Linux-based systems assume an `u64`, but Windows assumes `u32`. The C standard technically only requires that this type be an unsigned integer with the size of a [`long`], although in practice, no system would have a `ulong` that is neither a `u32` nor `u64`.
4+
5+
[`long`]: type.c_long.html
6+
[`u32`]: ../../primitive.u32.html
7+
[`u64`]: ../../primitive.u64.html

src/libstd/os/raw/ulonglong.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Equivalent to C's `unsigned long long` type.
2+
3+
This type will almost always be [`u64`], but may differ on some systems. The C standard technically only requires that this type be an unsigned integer with the size of a [`long long`], although in practice, no system would have a `long long` that is not a `u64`, as most systems do not have a standardised [`u128`] type.
4+
5+
[`long long`]: type.c_longlong.html
6+
[`u64`]: ../../primitive.u64.html
7+
[`u128`]: ../../primitive.u128.html

0 commit comments

Comments
 (0)