Auto merge of #33959 - Manishearth:rollup, r=Manishearth
Rollup of 8 pull requests - Successful merges: #33793, #33893, #33912, #33913, #33914, #33917, #33937, #33938 - Failed merges:
This commit is contained in:
commit
5da602bda3
@ -72,7 +72,7 @@
|
||||
use boxed::Box;
|
||||
|
||||
use core::sync::atomic;
|
||||
use core::sync::atomic::Ordering::{Relaxed, Release, Acquire, SeqCst};
|
||||
use core::sync::atomic::Ordering::{Acquire, Relaxed, Release, SeqCst};
|
||||
use core::borrow;
|
||||
use core::fmt;
|
||||
use core::cmp::Ordering;
|
||||
@ -85,7 +85,7 @@ use core::ops::CoerceUnsized;
|
||||
use core::ptr::{self, Shared};
|
||||
use core::marker::Unsize;
|
||||
use core::hash::{Hash, Hasher};
|
||||
use core::{usize, isize};
|
||||
use core::{isize, usize};
|
||||
use core::convert::From;
|
||||
use heap::deallocate;
|
||||
|
||||
@ -608,11 +608,13 @@ impl<T> Weak<T> {
|
||||
#[stable(feature = "downgraded_weak", since = "1.10.0")]
|
||||
pub fn new() -> Weak<T> {
|
||||
unsafe {
|
||||
Weak { ptr: Shared::new(Box::into_raw(box ArcInner {
|
||||
strong: atomic::AtomicUsize::new(0),
|
||||
weak: atomic::AtomicUsize::new(1),
|
||||
data: uninitialized(),
|
||||
}))}
|
||||
Weak {
|
||||
ptr: Shared::new(Box::into_raw(box ArcInner {
|
||||
strong: atomic::AtomicUsize::new(0),
|
||||
weak: atomic::AtomicUsize::new(1),
|
||||
data: uninitialized(),
|
||||
})),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -655,7 +657,9 @@ impl<T: ?Sized> Weak<T> {
|
||||
|
||||
// See comments in `Arc::clone` for why we do this (for `mem::forget`).
|
||||
if n > MAX_REFCOUNT {
|
||||
unsafe { abort(); }
|
||||
unsafe {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
// Relaxed is valid for the same reason it is on Arc's Clone impl
|
||||
@ -946,7 +950,7 @@ mod tests {
|
||||
use std::mem::drop;
|
||||
use std::ops::Drop;
|
||||
use std::option::Option;
|
||||
use std::option::Option::{Some, None};
|
||||
use std::option::Option::{None, Some};
|
||||
use std::sync::atomic;
|
||||
use std::sync::atomic::Ordering::{Acquire, SeqCst};
|
||||
use std::thread;
|
||||
|
@ -64,7 +64,7 @@ use core::hash::{self, Hash};
|
||||
use core::marker::{self, Unsize};
|
||||
use core::mem;
|
||||
use core::ops::{CoerceUnsized, Deref, DerefMut};
|
||||
use core::ops::{Placer, Boxed, Place, InPlace, BoxPlace};
|
||||
use core::ops::{BoxPlace, Boxed, InPlace, Place, Placer};
|
||||
use core::ptr::{self, Unique};
|
||||
use core::raw::TraitObject;
|
||||
use core::convert::From;
|
||||
@ -535,7 +535,8 @@ pub trait FnBox<A> {
|
||||
|
||||
#[unstable(feature = "fnbox",
|
||||
reason = "will be deprecated if and when Box<FnOnce> becomes usable", issue = "28796")]
|
||||
impl<A, F> FnBox<A> for F where F: FnOnce<A>
|
||||
impl<A, F> FnBox<A> for F
|
||||
where F: FnOnce<A>
|
||||
{
|
||||
type Output = F::Output;
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
use core::any::Any;
|
||||
use core::ops::Deref;
|
||||
use core::result::Result::{Ok, Err};
|
||||
use core::result::Result::{Err, Ok};
|
||||
use core::clone::Clone;
|
||||
|
||||
use std::boxed::Box;
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
use core::{isize, usize};
|
||||
#[cfg(not(test))]
|
||||
use core::intrinsics::{size_of, min_align_of};
|
||||
use core::intrinsics::{min_align_of, size_of};
|
||||
|
||||
#[allow(improper_ctypes)]
|
||||
extern "C" {
|
||||
|
@ -159,11 +159,11 @@ use core::borrow;
|
||||
use core::cell::Cell;
|
||||
use core::cmp::Ordering;
|
||||
use core::fmt;
|
||||
use core::hash::{Hasher, Hash};
|
||||
use core::intrinsics::{assume, abort};
|
||||
use core::hash::{Hash, Hasher};
|
||||
use core::intrinsics::{abort, assume};
|
||||
use core::marker;
|
||||
use core::marker::Unsize;
|
||||
use core::mem::{self, align_of_val, size_of_val, forget, uninitialized};
|
||||
use core::mem::{self, align_of_val, forget, size_of_val, uninitialized};
|
||||
use core::ops::Deref;
|
||||
use core::ops::CoerceUnsized;
|
||||
use core::ptr::{self, Shared};
|
||||
@ -935,7 +935,7 @@ mod tests {
|
||||
use std::boxed::Box;
|
||||
use std::cell::RefCell;
|
||||
use std::option::Option;
|
||||
use std::option::Option::{Some, None};
|
||||
use std::option::Option::{None, Some};
|
||||
use std::result::Result::{Err, Ok};
|
||||
use std::mem::drop;
|
||||
use std::clone::Clone;
|
||||
|
@ -1097,8 +1097,34 @@ impl str {
|
||||
/// assert_eq!(d, &["", "", "", "", "a", "", "b", "c"]);
|
||||
/// ```
|
||||
///
|
||||
/// This can lead to possibly surprising behavior when whitespace is used
|
||||
/// as the separator. This code is correct:
|
||||
/// Contiguous separators are separated by the empty string.
|
||||
///
|
||||
/// ```
|
||||
/// let x = "(///)".to_string();
|
||||
/// let d: Vec<_> = x.split('/').collect();;
|
||||
///
|
||||
/// assert_eq!(d, &["(", "", "", ")"]);
|
||||
/// ```
|
||||
///
|
||||
/// Separators at the start or end of a string are neighbored
|
||||
/// by empty strings.
|
||||
///
|
||||
/// ```
|
||||
/// let d: Vec<_> = "010".split("0").collect();
|
||||
/// assert_eq!(d, &["", "1", ""]);
|
||||
/// ```
|
||||
///
|
||||
/// When the empty string is used as a separator, it separates
|
||||
/// every character in the string, along with the beginning
|
||||
/// and end of the string.
|
||||
///
|
||||
/// ```
|
||||
/// let f: Vec<_> = "rust".split("").collect();
|
||||
/// assert_eq!(f, &["", "r", "u", "s", "t", ""]);
|
||||
/// ```
|
||||
///
|
||||
/// Contiguous separators can lead to possibly surprising behavior
|
||||
/// when whitespace is used as the separator. This code is correct:
|
||||
///
|
||||
/// ```
|
||||
/// let x = " a b c".to_string();
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
//! The ChaCha random number generator.
|
||||
|
||||
use {Rng, SeedableRng, Rand};
|
||||
use {Rand, Rng, SeedableRng};
|
||||
|
||||
const KEY_WORDS: usize = 8; // 8 words for the 256-bit key
|
||||
const STATE_WORDS: usize = 16;
|
||||
@ -216,7 +216,8 @@ mod tests {
|
||||
let s = ::test::rng().gen_iter::<u32>().take(8).collect::<Vec<u32>>();
|
||||
let mut ra: ChaChaRng = SeedableRng::from_seed(&*s);
|
||||
let mut rb: ChaChaRng = SeedableRng::from_seed(&*s);
|
||||
assert!(ra.gen_ascii_chars().take(100)
|
||||
assert!(ra.gen_ascii_chars()
|
||||
.take(100)
|
||||
.eq(rb.gen_ascii_chars().take(100)));
|
||||
}
|
||||
|
||||
@ -225,7 +226,8 @@ mod tests {
|
||||
let seed: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7];
|
||||
let mut ra: ChaChaRng = SeedableRng::from_seed(seed);
|
||||
let mut rb: ChaChaRng = SeedableRng::from_seed(seed);
|
||||
assert!(ra.gen_ascii_chars().take(100)
|
||||
assert!(ra.gen_ascii_chars()
|
||||
.take(100)
|
||||
.eq(rb.gen_ascii_chars().take(100)));
|
||||
}
|
||||
|
||||
|
@ -13,8 +13,8 @@
|
||||
#[cfg(not(test))] // only necessary for no_std
|
||||
use FloatMath;
|
||||
|
||||
use {Rng, Rand};
|
||||
use distributions::{ziggurat, ziggurat_tables, Sample, IndependentSample};
|
||||
use {Rand, Rng};
|
||||
use distributions::{IndependentSample, Sample, ziggurat, ziggurat_tables};
|
||||
|
||||
/// A wrapper around an `f64` to generate Exp(1) random numbers.
|
||||
///
|
||||
@ -88,7 +88,7 @@ impl IndependentSample<f64> for Exp {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use distributions::{Sample, IndependentSample};
|
||||
use distributions::{IndependentSample, Sample};
|
||||
use super::Exp;
|
||||
|
||||
#[test]
|
||||
|
@ -16,9 +16,9 @@ use self::ChiSquaredRepr::*;
|
||||
#[cfg(not(test))] // only necessary for no_std
|
||||
use FloatMath;
|
||||
|
||||
use {Rng, Open01};
|
||||
use {Open01, Rng};
|
||||
use super::normal::StandardNormal;
|
||||
use super::{IndependentSample, Sample, Exp};
|
||||
use super::{Exp, IndependentSample, Sample};
|
||||
|
||||
/// The Gamma distribution `Gamma(shape, scale)` distribution.
|
||||
///
|
||||
@ -291,8 +291,8 @@ impl IndependentSample<f64> for StudentT {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use distributions::{Sample, IndependentSample};
|
||||
use super::{ChiSquared, StudentT, FisherF};
|
||||
use distributions::{IndependentSample, Sample};
|
||||
use super::{ChiSquared, FisherF, StudentT};
|
||||
|
||||
#[test]
|
||||
fn test_chi_squared_one() {
|
||||
|
@ -22,11 +22,11 @@ use core::num::Float;
|
||||
|
||||
use core::marker::PhantomData;
|
||||
|
||||
use {Rng, Rand};
|
||||
use {Rand, Rng};
|
||||
|
||||
pub use self::range::Range;
|
||||
pub use self::gamma::{Gamma, ChiSquared, FisherF, StudentT};
|
||||
pub use self::normal::{Normal, LogNormal};
|
||||
pub use self::gamma::{ChiSquared, FisherF, Gamma, StudentT};
|
||||
pub use self::normal::{LogNormal, Normal};
|
||||
pub use self::exponential::Exp;
|
||||
|
||||
pub mod range;
|
||||
@ -266,8 +266,8 @@ fn ziggurat<R: Rng, P, Z>(rng: &mut R,
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use {Rng, Rand};
|
||||
use super::{RandSample, WeightedChoice, Weighted, Sample, IndependentSample};
|
||||
use {Rand, Rng};
|
||||
use super::{IndependentSample, RandSample, Sample, Weighted, WeightedChoice};
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
struct ConstRand(usize);
|
||||
|
@ -13,8 +13,8 @@
|
||||
#[cfg(not(test))] // only necessary for no_std
|
||||
use FloatMath;
|
||||
|
||||
use {Rng, Rand, Open01};
|
||||
use distributions::{ziggurat, ziggurat_tables, Sample, IndependentSample};
|
||||
use {Open01, Rand, Rng};
|
||||
use distributions::{IndependentSample, Sample, ziggurat, ziggurat_tables};
|
||||
|
||||
/// A wrapper around an `f64` to generate N(0, 1) random numbers
|
||||
/// (a.k.a. a standard normal, or Gaussian).
|
||||
@ -145,8 +145,8 @@ impl IndependentSample<f64> for LogNormal {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use distributions::{Sample, IndependentSample};
|
||||
use super::{Normal, LogNormal};
|
||||
use distributions::{IndependentSample, Sample};
|
||||
use super::{LogNormal, Normal};
|
||||
|
||||
#[test]
|
||||
fn test_normal() {
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
use core::marker::Sized;
|
||||
use Rng;
|
||||
use distributions::{Sample, IndependentSample};
|
||||
use distributions::{IndependentSample, Sample};
|
||||
|
||||
/// Sample values uniformly between two bounds.
|
||||
///
|
||||
@ -148,7 +148,7 @@ float_impl! { f64 }
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use distributions::{Sample, IndependentSample};
|
||||
use distributions::{IndependentSample, Sample};
|
||||
use super::Range;
|
||||
|
||||
#[should_panic]
|
||||
|
@ -16,7 +16,7 @@ use core::slice;
|
||||
use core::iter::repeat;
|
||||
use core::num::Wrapping as w;
|
||||
|
||||
use {Rng, SeedableRng, Rand};
|
||||
use {Rand, Rng, SeedableRng};
|
||||
|
||||
type w32 = w<u32>;
|
||||
type w64 = w<u64>;
|
||||
@ -591,14 +591,15 @@ mod tests {
|
||||
use std::prelude::v1::*;
|
||||
|
||||
use {Rng, SeedableRng};
|
||||
use super::{IsaacRng, Isaac64Rng};
|
||||
use super::{Isaac64Rng, IsaacRng};
|
||||
|
||||
#[test]
|
||||
fn test_rng_32_rand_seeded() {
|
||||
let s = ::test::rng().gen_iter::<u32>().take(256).collect::<Vec<u32>>();
|
||||
let mut ra: IsaacRng = SeedableRng::from_seed(&s[..]);
|
||||
let mut rb: IsaacRng = SeedableRng::from_seed(&s[..]);
|
||||
assert!(ra.gen_ascii_chars().take(100)
|
||||
assert!(ra.gen_ascii_chars()
|
||||
.take(100)
|
||||
.eq(rb.gen_ascii_chars().take(100)));
|
||||
}
|
||||
#[test]
|
||||
@ -606,7 +607,8 @@ mod tests {
|
||||
let s = ::test::rng().gen_iter::<u64>().take(256).collect::<Vec<u64>>();
|
||||
let mut ra: Isaac64Rng = SeedableRng::from_seed(&s[..]);
|
||||
let mut rb: Isaac64Rng = SeedableRng::from_seed(&s[..]);
|
||||
assert!(ra.gen_ascii_chars().take(100)
|
||||
assert!(ra.gen_ascii_chars()
|
||||
.take(100)
|
||||
.eq(rb.gen_ascii_chars().take(100)));
|
||||
}
|
||||
|
||||
@ -615,7 +617,8 @@ mod tests {
|
||||
let seed: &[_] = &[1, 23, 456, 7890, 12345];
|
||||
let mut ra: IsaacRng = SeedableRng::from_seed(seed);
|
||||
let mut rb: IsaacRng = SeedableRng::from_seed(seed);
|
||||
assert!(ra.gen_ascii_chars().take(100)
|
||||
assert!(ra.gen_ascii_chars()
|
||||
.take(100)
|
||||
.eq(rb.gen_ascii_chars().take(100)));
|
||||
}
|
||||
#[test]
|
||||
@ -623,7 +626,8 @@ mod tests {
|
||||
let seed: &[_] = &[1, 23, 456, 7890, 12345];
|
||||
let mut ra: Isaac64Rng = SeedableRng::from_seed(seed);
|
||||
let mut rb: Isaac64Rng = SeedableRng::from_seed(seed);
|
||||
assert!(ra.gen_ascii_chars().take(100)
|
||||
assert!(ra.gen_ascii_chars()
|
||||
.take(100)
|
||||
.eq(rb.gen_ascii_chars().take(100)));
|
||||
}
|
||||
|
||||
|
@ -47,10 +47,10 @@ use core::f64;
|
||||
use core::intrinsics;
|
||||
use core::marker::PhantomData;
|
||||
|
||||
pub use isaac::{IsaacRng, Isaac64Rng};
|
||||
pub use isaac::{Isaac64Rng, IsaacRng};
|
||||
pub use chacha::ChaChaRng;
|
||||
|
||||
use distributions::{Range, IndependentSample};
|
||||
use distributions::{IndependentSample, Range};
|
||||
use distributions::range::SampleRange;
|
||||
|
||||
#[cfg(test)]
|
||||
@ -67,7 +67,7 @@ mod rand_impls;
|
||||
// depend on libstd. This will go away when librand is integrated
|
||||
// into libstd.
|
||||
#[doc(hidden)]
|
||||
trait FloatMath : Sized {
|
||||
trait FloatMath: Sized {
|
||||
fn exp(self) -> Self;
|
||||
fn ln(self) -> Self;
|
||||
fn sqrt(self) -> Self;
|
||||
@ -102,14 +102,14 @@ impl FloatMath for f64 {
|
||||
|
||||
/// A type that can be randomly generated using an `Rng`.
|
||||
#[doc(hidden)]
|
||||
pub trait Rand : Sized {
|
||||
pub trait Rand: Sized {
|
||||
/// Generates a random instance of this type using the specified source of
|
||||
/// randomness.
|
||||
fn rand<R: Rng>(rng: &mut R) -> Self;
|
||||
}
|
||||
|
||||
/// A random number generator.
|
||||
pub trait Rng : Sized {
|
||||
pub trait Rng: Sized {
|
||||
/// Return the next random u32.
|
||||
///
|
||||
/// This rarely needs to be called directly, prefer `r.gen()` to
|
||||
|
@ -83,8 +83,8 @@ impl<S, R: SeedableRng<S>, Rsdr: Reseeder<R> + Default>
|
||||
self.bytes_generated = 0;
|
||||
}
|
||||
|
||||
/// Create a new `ReseedingRng` from the given reseeder and
|
||||
/// seed. This uses a default value for `generation_threshold`.
|
||||
/// Create a new `ReseedingRng` from the given reseeder and
|
||||
/// seed. This uses a default value for `generation_threshold`.
|
||||
fn from_seed((rsdr, seed): (Rsdr, S)) -> ReseedingRng<R, Rsdr> {
|
||||
ReseedingRng {
|
||||
rng: SeedableRng::from_seed(seed),
|
||||
@ -122,8 +122,8 @@ impl Default for ReseedWithDefault {
|
||||
mod tests {
|
||||
use std::prelude::v1::*;
|
||||
|
||||
use super::{ReseedingRng, ReseedWithDefault};
|
||||
use {SeedableRng, Rng};
|
||||
use super::{ReseedWithDefault, ReseedingRng};
|
||||
use {Rng, SeedableRng};
|
||||
|
||||
struct Counter {
|
||||
i: u32,
|
||||
@ -166,7 +166,8 @@ mod tests {
|
||||
fn test_rng_seeded() {
|
||||
let mut ra: MyRng = SeedableRng::from_seed((ReseedWithDefault, 2));
|
||||
let mut rb: MyRng = SeedableRng::from_seed((ReseedWithDefault, 2));
|
||||
assert!(ra.gen_ascii_chars().take(100)
|
||||
assert!(ra.gen_ascii_chars()
|
||||
.take(100)
|
||||
.eq(rb.gen_ascii_chars().take(100)));
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,8 @@ remainder of a zero divisor) in a static or constant expression. Erroneous
|
||||
code example:
|
||||
|
||||
```compile_fail
|
||||
#[deny(const_err)]
|
||||
|
||||
const X: i32 = 42 / 0;
|
||||
// error: attempted to divide by zero in a constant expression
|
||||
```
|
||||
@ -66,7 +68,7 @@ this restriction.
|
||||
|
||||
This happens when a trait has a method like the following:
|
||||
|
||||
```compile_fail
|
||||
```
|
||||
trait Trait {
|
||||
fn foo(&self) -> Self;
|
||||
}
|
||||
@ -364,6 +366,18 @@ type X = u32; // ok!
|
||||
"##,
|
||||
|
||||
E0133: r##"
|
||||
Unsafe code was used outside of an unsafe function or block.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
unsafe fn f() { return; } // This is the unsafe code
|
||||
|
||||
fn main() {
|
||||
f(); // error: call to unsafe function requires unsafe function or block
|
||||
}
|
||||
```
|
||||
|
||||
Using unsafe functionality is potentially dangerous and disallowed by safety
|
||||
checks. Examples:
|
||||
|
||||
@ -378,7 +392,7 @@ unsafe instructions with an `unsafe` block. For instance:
|
||||
unsafe fn f() { return; }
|
||||
|
||||
fn main() {
|
||||
unsafe { f(); }
|
||||
unsafe { f(); } // ok!
|
||||
}
|
||||
```
|
||||
|
||||
@ -392,15 +406,58 @@ function `main()`. If there are multiple such functions, please rename one.
|
||||
"##,
|
||||
|
||||
E0137: r##"
|
||||
More than one function was declared with the `#[main]` attribute.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
#![feature(main)]
|
||||
|
||||
#[main]
|
||||
fn foo() {}
|
||||
|
||||
#[main]
|
||||
fn f() {} // error: multiple functions with a #[main] attribute
|
||||
```
|
||||
|
||||
This error indicates that the compiler found multiple functions with the
|
||||
`#[main]` attribute. This is an error because there must be a unique entry
|
||||
point into a Rust program.
|
||||
point into a Rust program. Example:
|
||||
|
||||
```
|
||||
#![feature(main)]
|
||||
|
||||
#[main]
|
||||
fn f() {} // ok!
|
||||
```
|
||||
"##,
|
||||
|
||||
E0138: r##"
|
||||
More than one function was declared with the `#[start]` attribute.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
#![feature(start)]
|
||||
|
||||
#[start]
|
||||
fn foo(argc: isize, argv: *const *const u8) -> isize {}
|
||||
|
||||
#[start]
|
||||
fn f(argc: isize, argv: *const *const u8) -> isize {}
|
||||
// error: multiple 'start' functions
|
||||
```
|
||||
|
||||
This error indicates that the compiler found multiple functions with the
|
||||
`#[start]` attribute. This is an error because there must be a unique entry
|
||||
point into a Rust program.
|
||||
point into a Rust program. Example:
|
||||
|
||||
```
|
||||
#![feature(start)]
|
||||
|
||||
#[start]
|
||||
fn foo(argc: isize, argv: *const *const u8) -> isize { 0 } // ok!
|
||||
```
|
||||
"##,
|
||||
|
||||
// FIXME link this to the relevant turpl chapters for instilling fear of the
|
||||
@ -481,6 +538,17 @@ call to `mem::forget(v)` in case you want to avoid destructors being called.
|
||||
"##,
|
||||
|
||||
E0152: r##"
|
||||
A lang item was redefined.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
#![feature(lang_items)]
|
||||
|
||||
#[lang = "panic_fmt"]
|
||||
struct Foo; // error: duplicate lang item found: `panic_fmt`
|
||||
```
|
||||
|
||||
Lang items are already implemented in the standard library. Unless you are
|
||||
writing a free-standing application (e.g. a kernel), you do not need to provide
|
||||
them yourself.
|
||||
|
@ -153,7 +153,7 @@ structure that is currently uninitialized.
|
||||
|
||||
For example, this can happen when a drop has taken place:
|
||||
|
||||
```compile_fail
|
||||
```ignore
|
||||
struct Foo {
|
||||
a: u32,
|
||||
}
|
||||
|
@ -76,6 +76,8 @@ Not-a-Number (NaN) values cannot be compared for equality and hence can never
|
||||
match the input to a match expression. So, the following will not compile:
|
||||
|
||||
```compile_fail
|
||||
#![deny(illegal_floating_point_constant_pattern)]
|
||||
|
||||
const NAN: f32 = 0.0 / 0.0;
|
||||
|
||||
let number = 0.1f32;
|
||||
@ -160,7 +162,7 @@ let Some(y) = x;
|
||||
If you encounter this error you probably need to use a `match` or `if let` to
|
||||
deal with the possibility of failure. Example:
|
||||
|
||||
```compile_fail
|
||||
```
|
||||
let x = Some(1);
|
||||
|
||||
match x {
|
||||
|
@ -50,11 +50,36 @@ match 5u32 {
|
||||
"##,
|
||||
|
||||
E0161: r##"
|
||||
A value was moved. However, its size was not known at compile time, and only
|
||||
values of a known size can be moved.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
#![feature(box_syntax)]
|
||||
|
||||
fn main() {
|
||||
let array: &[isize] = &[1, 2, 3];
|
||||
let _x: Box<[isize]> = box *array;
|
||||
// error: cannot move a value of type [isize]: the size of [isize] cannot
|
||||
// be statically determined
|
||||
}
|
||||
```
|
||||
|
||||
In Rust, you can only move a value when its size is known at compile time.
|
||||
|
||||
To work around this restriction, consider "hiding" the value behind a reference:
|
||||
either `&x` or `&mut x`. Since a reference has a fixed size, this lets you move
|
||||
it around as usual.
|
||||
it around as usual. Example:
|
||||
|
||||
```
|
||||
#![feature(box_syntax)]
|
||||
|
||||
fn main() {
|
||||
let array: &[isize] = &[1, 2, 3];
|
||||
let _x: Box<&[isize]> = box array; // ok!
|
||||
}
|
||||
```
|
||||
"##,
|
||||
|
||||
E0265: r##"
|
||||
|
@ -17,6 +17,8 @@ A private trait was used on a public type parameter bound. Erroneous code
|
||||
examples:
|
||||
|
||||
```compile_fail
|
||||
#![deny(private_in_public)]
|
||||
|
||||
trait Foo {
|
||||
fn dummy(&self) { }
|
||||
}
|
||||
@ -45,6 +47,8 @@ E0446: r##"
|
||||
A private type was used in a public type signature. Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
#![deny(private_in_public)]
|
||||
|
||||
mod Foo {
|
||||
struct Bar(u32);
|
||||
|
||||
@ -73,7 +77,7 @@ mod Foo {
|
||||
E0447: r##"
|
||||
The `pub` keyword was used inside a function. Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```ignore
|
||||
fn foo() {
|
||||
pub struct Bar; // error: visibility has no effect inside functions
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ variable declarations and expression statements.
|
||||
|
||||
Here is an example that demonstrates the error:
|
||||
|
||||
```compile_fail
|
||||
```ignore
|
||||
fn f() {
|
||||
// Variable declaration before import
|
||||
let x = 0;
|
||||
|
@ -15,7 +15,7 @@ register_long_diagnostics! {
|
||||
E0510: r##"
|
||||
`return_address` was used in an invalid context. Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```ignore
|
||||
#![feature(intrinsics)]
|
||||
|
||||
extern "rust-intrinsic" {
|
||||
@ -54,7 +54,7 @@ E0511: r##"
|
||||
Invalid monomorphization of an intrinsic function was used. Erroneous code
|
||||
example:
|
||||
|
||||
```compile_fail
|
||||
```ignore
|
||||
#![feature(platform_intrinsics)]
|
||||
|
||||
extern "platform-intrinsic" {
|
||||
|
@ -931,7 +931,7 @@ first instance of `Foo` could be made to initialize another instance!
|
||||
|
||||
Here's an example of a struct that has this problem:
|
||||
|
||||
```compile_fail
|
||||
```ignore
|
||||
struct Foo { x: Box<Foo> } // error
|
||||
```
|
||||
|
||||
@ -952,7 +952,7 @@ are generic.
|
||||
|
||||
This will cause an error:
|
||||
|
||||
```compile_fail
|
||||
```ignore
|
||||
#![feature(repr_simd)]
|
||||
|
||||
#[repr(simd)]
|
||||
@ -1143,7 +1143,7 @@ for an explicit choice of the discriminant type. In either cases, the
|
||||
discriminant values must fall within a valid range for the expected type;
|
||||
otherwise this error is raised. For example:
|
||||
|
||||
```compile_fail
|
||||
```ignore
|
||||
#[repr(u8)]
|
||||
enum Thing {
|
||||
A = 1024,
|
||||
@ -1154,7 +1154,7 @@ enum Thing {
|
||||
Here, 1024 lies outside the valid range for `u8`, so the discriminant for `A` is
|
||||
invalid. Here is another, more subtle example which depends on target word size:
|
||||
|
||||
```compile_fail
|
||||
```ignore
|
||||
enum DependsOnPointerSize {
|
||||
A = 1 << 32
|
||||
}
|
||||
@ -1864,12 +1864,35 @@ fn main<T>() { // error: main function is not allowed to have type parameters
|
||||
"##,
|
||||
|
||||
E0132: r##"
|
||||
A function with the `start` attribute was declared with type parameters.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
#![feature(start)]
|
||||
|
||||
#[start]
|
||||
fn f<T>() {}
|
||||
```
|
||||
|
||||
It is not possible to declare type parameters on a function that has the `start`
|
||||
attribute. Such a function must have the following type signature:
|
||||
attribute. Such a function must have the following type signature (for more
|
||||
information: http://doc.rust-lang.org/stable/book/no-stdlib.html):
|
||||
|
||||
```ignore
|
||||
fn(isize, *const *const u8) -> isize;
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
#![feature(start)]
|
||||
|
||||
#[start]
|
||||
fn my_start(argc: isize, argv: *const *const u8) -> isize {
|
||||
0
|
||||
}
|
||||
```
|
||||
"##,
|
||||
|
||||
E0163: r##"
|
||||
@ -2076,7 +2099,7 @@ E0193: r##"
|
||||
`where` clauses must use generic type parameters: it does not make sense to use
|
||||
them otherwise. An example causing this error:
|
||||
|
||||
```compile_fail
|
||||
```ignore
|
||||
trait Foo {
|
||||
fn bar(&self);
|
||||
}
|
||||
@ -3140,7 +3163,7 @@ An attempt was made to access an associated constant through either a generic
|
||||
type parameter or `Self`. This is not supported yet. An example causing this
|
||||
error is shown below:
|
||||
|
||||
```compile_fail
|
||||
```ignore
|
||||
#![feature(associated_consts)]
|
||||
|
||||
trait Foo {
|
||||
@ -3327,6 +3350,7 @@ The maximum value of an enum was reached, so it cannot be automatically
|
||||
set in the next enum value. Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
#[deny(overflowing_literals)]
|
||||
enum Foo {
|
||||
X = 0x7fffffffffffffff,
|
||||
Y, // error: enum discriminant overflowed on value after
|
||||
|
@ -271,8 +271,12 @@ fn runtest(test: &str, cratename: &str, cfgs: Vec<String>, libs: SearchPaths,
|
||||
match res {
|
||||
Ok(r) => {
|
||||
match r {
|
||||
Err(count) if count > 0 && compile_fail == false => {
|
||||
sess.fatal("aborting due to previous error(s)")
|
||||
Err(count) => {
|
||||
if count > 0 && compile_fail == false {
|
||||
sess.fatal("aborting due to previous error(s)")
|
||||
} else if count == 0 && compile_fail == true {
|
||||
panic!("test compiled while it wasn't supposed to")
|
||||
}
|
||||
}
|
||||
Ok(()) if compile_fail => panic!("test compiled while it wasn't supposed to"),
|
||||
_ => {}
|
||||
|
@ -27,4 +27,3 @@ extern crate libc;
|
||||
mod libunwind;
|
||||
#[cfg(not(target_env = "msvc"))]
|
||||
pub use libunwind::*;
|
||||
|
||||
|
@ -38,7 +38,7 @@ pub enum _Unwind_State {
|
||||
_US_UNWIND_FRAME_RESUME = 2,
|
||||
_US_ACTION_MASK = 3,
|
||||
_US_FORCE_UNWIND = 8,
|
||||
_US_END_OF_STACK = 16
|
||||
_US_END_OF_STACK = 16,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@ -59,9 +59,8 @@ pub type _Unwind_Exception_Class = u64;
|
||||
|
||||
pub type _Unwind_Word = libc::uintptr_t;
|
||||
|
||||
pub type _Unwind_Trace_Fn =
|
||||
extern fn(ctx: *mut _Unwind_Context,
|
||||
arg: *mut libc::c_void) -> _Unwind_Reason_Code;
|
||||
pub type _Unwind_Trace_Fn = extern "C" fn(ctx: *mut _Unwind_Context, arg: *mut libc::c_void)
|
||||
-> _Unwind_Reason_Code;
|
||||
|
||||
#[cfg(target_arch = "x86")]
|
||||
pub const unwinder_private_data_size: usize = 5;
|
||||
@ -97,9 +96,8 @@ pub struct _Unwind_Exception {
|
||||
|
||||
pub enum _Unwind_Context {}
|
||||
|
||||
pub type _Unwind_Exception_Cleanup_Fn =
|
||||
extern "C" fn(unwind_code: _Unwind_Reason_Code,
|
||||
exception: *mut _Unwind_Exception);
|
||||
pub type _Unwind_Exception_Cleanup_Fn = extern "C" fn(unwind_code: _Unwind_Reason_Code,
|
||||
exception: *mut _Unwind_Exception);
|
||||
|
||||
#[cfg_attr(any(all(target_os = "linux", not(target_env = "musl")),
|
||||
target_os = "freebsd",
|
||||
@ -127,20 +125,18 @@ pub type _Unwind_Exception_Cleanup_Fn =
|
||||
#[cfg_attr(all(target_os = "windows", target_env = "gnu"),
|
||||
link(name = "gcc_eh"))]
|
||||
#[cfg(not(cargobuild))]
|
||||
extern {}
|
||||
extern "C" {}
|
||||
|
||||
extern {
|
||||
extern "C" {
|
||||
// iOS on armv7 uses SjLj exceptions and requires to link
|
||||
// against corresponding routine (..._SjLj_...)
|
||||
#[cfg(not(all(target_os = "ios", target_arch = "arm")))]
|
||||
#[unwind]
|
||||
pub fn _Unwind_RaiseException(exception: *mut _Unwind_Exception)
|
||||
-> _Unwind_Reason_Code;
|
||||
pub fn _Unwind_RaiseException(exception: *mut _Unwind_Exception) -> _Unwind_Reason_Code;
|
||||
|
||||
#[cfg(all(target_os = "ios", target_arch = "arm"))]
|
||||
#[unwind]
|
||||
fn _Unwind_SjLj_RaiseException(e: *mut _Unwind_Exception)
|
||||
-> _Unwind_Reason_Code;
|
||||
fn _Unwind_SjLj_RaiseException(e: *mut _Unwind_Exception) -> _Unwind_Reason_Code;
|
||||
|
||||
pub fn _Unwind_DeleteException(exception: *mut _Unwind_Exception);
|
||||
|
||||
@ -151,19 +147,18 @@ extern {
|
||||
#[cfg(not(all(target_os = "ios", target_arch = "arm")))]
|
||||
pub fn _Unwind_Backtrace(trace: _Unwind_Trace_Fn,
|
||||
trace_argument: *mut libc::c_void)
|
||||
-> _Unwind_Reason_Code;
|
||||
-> _Unwind_Reason_Code;
|
||||
|
||||
// available since GCC 4.2.0, should be fine for our purpose
|
||||
#[cfg(all(not(all(target_os = "android", target_arch = "arm")),
|
||||
not(all(target_os = "linux", target_arch = "arm"))))]
|
||||
pub fn _Unwind_GetIPInfo(ctx: *mut _Unwind_Context,
|
||||
ip_before_insn: *mut libc::c_int)
|
||||
-> libc::uintptr_t;
|
||||
-> libc::uintptr_t;
|
||||
|
||||
#[cfg(all(not(target_os = "android"),
|
||||
not(all(target_os = "linux", target_arch = "arm"))))]
|
||||
pub fn _Unwind_FindEnclosingFunction(pc: *mut libc::c_void)
|
||||
-> *mut libc::c_void;
|
||||
pub fn _Unwind_FindEnclosingFunction(pc: *mut libc::c_void) -> *mut libc::c_void;
|
||||
}
|
||||
|
||||
// ... and now we just providing access to SjLj counterspart
|
||||
@ -171,8 +166,7 @@ extern {
|
||||
// (see also comment above regarding _Unwind_RaiseException)
|
||||
#[cfg(all(target_os = "ios", target_arch = "arm"))]
|
||||
#[inline]
|
||||
pub unsafe fn _Unwind_RaiseException(exc: *mut _Unwind_Exception)
|
||||
-> _Unwind_Reason_Code {
|
||||
pub unsafe fn _Unwind_RaiseException(exc: *mut _Unwind_Exception) -> _Unwind_Reason_Code {
|
||||
_Unwind_SjLj_RaiseException(exc)
|
||||
}
|
||||
|
||||
@ -207,18 +201,20 @@ pub unsafe fn _Unwind_GetIP(ctx: *mut _Unwind_Context) -> libc::uintptr_t {
|
||||
}
|
||||
|
||||
type _Unwind_Word = libc::c_uint;
|
||||
extern {
|
||||
extern "C" {
|
||||
fn _Unwind_VRS_Get(ctx: *mut _Unwind_Context,
|
||||
klass: _Unwind_VRS_RegClass,
|
||||
word: _Unwind_Word,
|
||||
repr: _Unwind_VRS_DataRepresentation,
|
||||
data: *mut libc::c_void)
|
||||
-> _Unwind_VRS_Result;
|
||||
-> _Unwind_VRS_Result;
|
||||
}
|
||||
|
||||
let mut val: _Unwind_Word = 0;
|
||||
let ptr = &mut val as *mut _Unwind_Word;
|
||||
let _ = _Unwind_VRS_Get(ctx, _Unwind_VRS_RegClass::_UVRSC_CORE, 15,
|
||||
let _ = _Unwind_VRS_Get(ctx,
|
||||
_Unwind_VRS_RegClass::_UVRSC_CORE,
|
||||
15,
|
||||
_Unwind_VRS_DataRepresentation::_UVRSD_UINT32,
|
||||
ptr as *mut libc::c_void);
|
||||
(val & !1) as libc::uintptr_t
|
||||
@ -230,8 +226,7 @@ pub unsafe fn _Unwind_GetIP(ctx: *mut _Unwind_Context) -> libc::uintptr_t {
|
||||
all(target_os = "linux", target_arch = "arm")))]
|
||||
pub unsafe fn _Unwind_GetIPInfo(ctx: *mut _Unwind_Context,
|
||||
ip_before_insn: *mut libc::c_int)
|
||||
-> libc::uintptr_t
|
||||
{
|
||||
-> libc::uintptr_t {
|
||||
*ip_before_insn = 0;
|
||||
_Unwind_GetIP(ctx)
|
||||
}
|
||||
@ -240,8 +235,6 @@ pub unsafe fn _Unwind_GetIPInfo(ctx: *mut _Unwind_Context,
|
||||
// a no-op
|
||||
#[cfg(any(target_os = "android",
|
||||
all(target_os = "linux", target_arch = "arm")))]
|
||||
pub unsafe fn _Unwind_FindEnclosingFunction(pc: *mut libc::c_void)
|
||||
-> *mut libc::c_void
|
||||
{
|
||||
pub unsafe fn _Unwind_FindEnclosingFunction(pc: *mut libc::c_void) -> *mut libc::c_void {
|
||||
pc
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user