From abe99612835091672924d250451d8bd3e61aa206 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 22 May 2016 19:00:20 +0200 Subject: [PATCH 01/11] * Fix compile_fail tag (in some cases, it compiled whereas it wasn't expected to and was still considered 'ok') * Fix error explanations tests/tags --- src/librustc/diagnostics.rs | 4 +++- src/librustc_borrowck/diagnostics.rs | 2 +- src/librustc_const_eval/diagnostics.rs | 4 +++- src/librustc_privacy/diagnostics.rs | 6 +++++- src/librustc_resolve/diagnostics.rs | 2 +- src/librustc_trans/diagnostics.rs | 4 ++-- src/librustc_typeck/diagnostics.rs | 13 +++++++------ src/librustdoc/test.rs | 8 ++++++-- 8 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index c64f0ddac50..34080a24d9d 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -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; } diff --git a/src/librustc_borrowck/diagnostics.rs b/src/librustc_borrowck/diagnostics.rs index 116e3476897..0624d72dd59 100644 --- a/src/librustc_borrowck/diagnostics.rs +++ b/src/librustc_borrowck/diagnostics.rs @@ -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, } diff --git a/src/librustc_const_eval/diagnostics.rs b/src/librustc_const_eval/diagnostics.rs index 457d25923c6..8b1d7bed7c4 100644 --- a/src/librustc_const_eval/diagnostics.rs +++ b/src/librustc_const_eval/diagnostics.rs @@ -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 { diff --git a/src/librustc_privacy/diagnostics.rs b/src/librustc_privacy/diagnostics.rs index 1b49409970d..d33bc52c5a7 100644 --- a/src/librustc_privacy/diagnostics.rs +++ b/src/librustc_privacy/diagnostics.rs @@ -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 } diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index 35148622052..b576f77dbd7 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -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; diff --git a/src/librustc_trans/diagnostics.rs b/src/librustc_trans/diagnostics.rs index d9de673db27..d36878b0332 100644 --- a/src/librustc_trans/diagnostics.rs +++ b/src/librustc_trans/diagnostics.rs @@ -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" { diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 40b9b0e01ab..75dcfb2c4f9 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -956,7 +956,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 } // error ``` @@ -977,7 +977,7 @@ are generic. This will cause an error: -```compile_fail +```ignore #![feature(repr_simd)] #[repr(simd)] @@ -1168,7 +1168,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, @@ -1179,7 +1179,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 } @@ -2081,7 +2081,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); } @@ -3145,7 +3145,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 { @@ -3332,6 +3332,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 diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 2754f77444c..53201a9580e 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -271,8 +271,12 @@ fn runtest(test: &str, cratename: &str, cfgs: Vec, 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"), _ => {} From a850d407b203d695a9d19979b4183578171f1226 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 27 May 2016 21:16:58 +0200 Subject: [PATCH 02/11] Improve E0132 error explanation --- src/librustc_typeck/diagnostics.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 7598751c8fe..eee53f30428 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1864,12 +1864,35 @@ fn main() { // 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() {} +``` + 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##" From a1e240ccec087c64d0adf27d9c4cc96ab104d551 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 27 May 2016 21:45:15 +0200 Subject: [PATCH 03/11] Improve E0137 error explanatIon --- src/librustc/diagnostics.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index c64f0ddac50..56d57d39be6 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -392,9 +392,30 @@ 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##" From 360d7234c7ce1392c2730fba2e7d9b33f3ff9e5f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 27 May 2016 21:47:59 +0200 Subject: [PATCH 04/11] Improve E0138 error explanation --- src/librustc/diagnostics.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 56d57d39be6..7c350987aa1 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -419,9 +419,32 @@ 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 {} // ok! +``` "##, // FIXME link this to the relevant turpl chapters for instilling fear of the From c848ca1f8df4ac550c83cbe22ff46c107dd86002 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 27 May 2016 21:36:40 +0200 Subject: [PATCH 05/11] Improve E0133 error explanation --- src/librustc/diagnostics.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index c64f0ddac50..2b2525b1045 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -364,6 +364,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 +390,7 @@ unsafe instructions with an `unsafe` block. For instance: unsafe fn f() { return; } fn main() { - unsafe { f(); } + unsafe { f(); } // ok! } ``` From 4fa84830f8a91a2a8db988afec96b416ae2654c0 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 27 May 2016 21:57:06 +0200 Subject: [PATCH 06/11] improve E0152 error explanation --- src/librustc/diagnostics.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 7c350987aa1..a410a5949bd 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -525,6 +525,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. From 3fd0e4c7f2eafa4382ff33a3274cec03e8b207f2 Mon Sep 17 00:00:00 2001 From: Srinivas Reddy Thatiparthy Date: Sat, 28 May 2016 02:25:16 +0530 Subject: [PATCH 07/11] rustfmt liballoc folder --- src/liballoc/arc.rs | 22 +++++++++++++--------- src/liballoc/boxed.rs | 5 +++-- src/liballoc/boxed_test.rs | 2 +- src/liballoc/heap.rs | 2 +- src/liballoc/rc.rs | 8 ++++---- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index d0a51e320cc..729d9218a29 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -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 Weak { #[stable(feature = "downgraded_weak", since = "1.10.0")] pub fn new() -> Weak { 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 Weak { // 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; diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 10e4ea1c3f0..51523ca8dc6 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -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 { #[unstable(feature = "fnbox", reason = "will be deprecated if and when Box becomes usable", issue = "28796")] -impl FnBox for F where F: FnOnce +impl FnBox for F + where F: FnOnce { type Output = F::Output; diff --git a/src/liballoc/boxed_test.rs b/src/liballoc/boxed_test.rs index 120301afa44..8d68ce3c1f6 100644 --- a/src/liballoc/boxed_test.rs +++ b/src/liballoc/boxed_test.rs @@ -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; diff --git a/src/liballoc/heap.rs b/src/liballoc/heap.rs index 08b403a60f3..bfed8a8e83a 100644 --- a/src/liballoc/heap.rs +++ b/src/liballoc/heap.rs @@ -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" { diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index b92f5af05e3..cf4fb459bc1 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -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; From feb0b27e41b4048ce30f23231b787e7c2d2e27d3 Mon Sep 17 00:00:00 2001 From: Ty Coghlan Date: Thu, 26 May 2016 18:17:30 -0400 Subject: [PATCH 08/11] Added examples/docs to split in str.rs Added documentation clarifying the behavior of split when used with the empty string and contiguous separators. --- src/libcollections/str.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 2059943bfdf..f3770816cb6 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -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(); From 72baa41b88fb0baed65c35e7cf2217f53ab4b7b7 Mon Sep 17 00:00:00 2001 From: Srinivas Reddy Thatiparthy Date: Sun, 29 May 2016 08:40:34 +0530 Subject: [PATCH 09/11] run rustfmt on librand folder --- src/librand/chacha.rs | 8 +++++--- src/librand/distributions/exponential.rs | 6 +++--- src/librand/distributions/gamma.rs | 8 ++++---- src/librand/distributions/mod.rs | 10 +++++----- src/librand/distributions/normal.rs | 8 ++++---- src/librand/distributions/range.rs | 4 ++-- src/librand/isaac.rs | 16 ++++++++++------ src/librand/lib.rs | 10 +++++----- src/librand/reseeding.rs | 11 ++++++----- 9 files changed, 44 insertions(+), 37 deletions(-) diff --git a/src/librand/chacha.rs b/src/librand/chacha.rs index cd099c69005..5fba44a1c38 100644 --- a/src/librand/chacha.rs +++ b/src/librand/chacha.rs @@ -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::().take(8).collect::>(); 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))); } diff --git a/src/librand/distributions/exponential.rs b/src/librand/distributions/exponential.rs index 12dbbfdb0ed..5a8558efc02 100644 --- a/src/librand/distributions/exponential.rs +++ b/src/librand/distributions/exponential.rs @@ -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 for Exp { #[cfg(test)] mod tests { - use distributions::{Sample, IndependentSample}; + use distributions::{IndependentSample, Sample}; use super::Exp; #[test] diff --git a/src/librand/distributions/gamma.rs b/src/librand/distributions/gamma.rs index cf488236560..9ca13e85b53 100644 --- a/src/librand/distributions/gamma.rs +++ b/src/librand/distributions/gamma.rs @@ -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 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() { diff --git a/src/librand/distributions/mod.rs b/src/librand/distributions/mod.rs index 2557d39c550..36c9f783ff5 100644 --- a/src/librand/distributions/mod.rs +++ b/src/librand/distributions/mod.rs @@ -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(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); diff --git a/src/librand/distributions/normal.rs b/src/librand/distributions/normal.rs index 86840c568e0..811d5b14c71 100644 --- a/src/librand/distributions/normal.rs +++ b/src/librand/distributions/normal.rs @@ -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 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() { diff --git a/src/librand/distributions/range.rs b/src/librand/distributions/range.rs index f94ef059dae..ba8554a979b 100644 --- a/src/librand/distributions/range.rs +++ b/src/librand/distributions/range.rs @@ -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] diff --git a/src/librand/isaac.rs b/src/librand/isaac.rs index 28eff87bde3..e8cc7b5cc2d 100644 --- a/src/librand/isaac.rs +++ b/src/librand/isaac.rs @@ -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; type w64 = w; @@ -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::().take(256).collect::>(); 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::().take(256).collect::>(); 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))); } diff --git a/src/librand/lib.rs b/src/librand/lib.rs index d8517fb4c57..c31a0ed5320 100644 --- a/src/librand/lib.rs +++ b/src/librand/lib.rs @@ -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(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 diff --git a/src/librand/reseeding.rs b/src/librand/reseeding.rs index db5e0213726..c7d560eb1f8 100644 --- a/src/librand/reseeding.rs +++ b/src/librand/reseeding.rs @@ -83,8 +83,8 @@ impl, Rsdr: Reseeder + 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 { 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))); } From 5ed45ef354ff2247b604bcb26a64f918dabf7325 Mon Sep 17 00:00:00 2001 From: Srinivas Reddy Thatiparthy Date: Sun, 29 May 2016 08:47:51 +0530 Subject: [PATCH 10/11] run rustfmt on libunwind --- src/libunwind/lib.rs | 1 - src/libunwind/libunwind.rs | 47 ++++++++++++++++---------------------- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/src/libunwind/lib.rs b/src/libunwind/lib.rs index 3ff61fd93d7..add45ccb362 100644 --- a/src/libunwind/lib.rs +++ b/src/libunwind/lib.rs @@ -27,4 +27,3 @@ extern crate libc; mod libunwind; #[cfg(not(target_env = "msvc"))] pub use libunwind::*; - diff --git a/src/libunwind/libunwind.rs b/src/libunwind/libunwind.rs index ce74e5de3d4..aadfe202afe 100644 --- a/src/libunwind/libunwind.rs +++ b/src/libunwind/libunwind.rs @@ -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 } From 31b9060ede89c7c11d7d829c3d4b50649bb7f07e Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 27 May 2016 22:05:10 +0200 Subject: [PATCH 11/11] Improve E0161 error explanation --- src/librustc/diagnostics.rs | 3 +-- src/librustc_passes/diagnostics.rs | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index a410a5949bd..d838de4a331 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -438,12 +438,11 @@ 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. Example: - ``` #![feature(start)] #[start] -fn foo(argc: isize, argv: *const *const u8) -> isize {} // ok! +fn foo(argc: isize, argv: *const *const u8) -> isize { 0 } // ok! ``` "##, diff --git a/src/librustc_passes/diagnostics.rs b/src/librustc_passes/diagnostics.rs index 77f896e011b..cba8bd73c01 100644 --- a/src/librustc_passes/diagnostics.rs +++ b/src/librustc_passes/diagnostics.rs @@ -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##"