From 238bb38a948ddf3d782f8138b39868cb08356c91 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 22 Feb 2018 13:53:59 -0500 Subject: [PATCH 01/31] First version --- src/libcore/cell.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index ec0d1b704dceb..75ed562ae5401 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -10,10 +10,24 @@ //! Shareable mutable containers. //! +//! Rust memory safety is based on this rule: Given an object `T`, is only possible to +//! have one of the following: +//! +//! - Having several inmutable references (`&T`) to the object (also know as Aliasing). +//! - Having one mutable reference (`&mut T`) to the object (also know as Mutability). +//! +//! This is enforced by the Rust compiler. However, there are situations where this rule is not +//! flexible enough. Sometimes is required to have multiple references to an object and yet +//! mutate it. +//! +//! Shareable mutable containers exist to permit mutability in presence of aliasing in a +//! controlled manner. Both `Cell` and `RefCell` allows to do this in a single threaded +//! way. For multiple threads is possible to use `Mutex`, `RwLock` or `AtomicXXX`. +//! //! Values of the `Cell` and `RefCell` types may be mutated through shared references (i.e. //! the common `&T` type), whereas most Rust types can only be mutated through unique (`&mut T`) //! references. We say that `Cell` and `RefCell` provide 'interior mutability', in contrast -//! with typical Rust types that exhibit 'inherited mutability'. +//! with typical Rust types that exhibit 'inherited mutability'. //! //! Cell types come in two flavors: `Cell` and `RefCell`. `Cell` implements interior //! mutability by moving values in and out of the `Cell`. To use references instead of values, From f9e049afc544e70dc595df67d878b52c098aaa9a Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 23 Feb 2018 12:57:18 -0500 Subject: [PATCH 02/31] add info about sync --- src/libcore/cell.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 75ed562ae5401..1067b6ff0c11e 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -22,7 +22,9 @@ //! //! Shareable mutable containers exist to permit mutability in presence of aliasing in a //! controlled manner. Both `Cell` and `RefCell` allows to do this in a single threaded -//! way. For multiple threads is possible to use `Mutex`, `RwLock` or `AtomicXXX`. +//! way, you can mutate them using an inmutable reference. However, neither `Cell` nor +//! `RefCell` are thread safe (they do not implement `Sync`), if you need to do Aliasing and +//! Mutation between multiple threads is possible to use `Mutex`, `RwLock` or `AtomicXXX`. //! //! Values of the `Cell` and `RefCell` types may be mutated through shared references (i.e. //! the common `&T` type), whereas most Rust types can only be mutated through unique (`&mut T`) From 58d1f839520b97ac06e48aeb49d814282b20056c Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 23 Feb 2018 13:00:26 -0500 Subject: [PATCH 03/31] remove redundant info --- src/libcore/cell.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 1067b6ff0c11e..b3a7d20c4aa5f 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -17,19 +17,19 @@ //! - Having one mutable reference (`&mut T`) to the object (also know as Mutability). //! //! This is enforced by the Rust compiler. However, there are situations where this rule is not -//! flexible enough. Sometimes is required to have multiple references to an object and yet +//! flexible enough. Sometimes is required to have multiple references to an object and yet //! mutate it. //! //! Shareable mutable containers exist to permit mutability in presence of aliasing in a //! controlled manner. Both `Cell` and `RefCell` allows to do this in a single threaded -//! way, you can mutate them using an inmutable reference. However, neither `Cell` nor -//! `RefCell` are thread safe (they do not implement `Sync`), if you need to do Aliasing and -//! Mutation between multiple threads is possible to use `Mutex`, `RwLock` or `AtomicXXX`. +//! way. However, neither `Cell` nor `RefCell` are thread safe (they do not implement +//! `Sync`), if you need to do Aliasing and Mutation between multiple threads is possible to use +//! `Mutex`, `RwLock` or `AtomicXXX`. //! //! Values of the `Cell` and `RefCell` types may be mutated through shared references (i.e. //! the common `&T` type), whereas most Rust types can only be mutated through unique (`&mut T`) //! references. We say that `Cell` and `RefCell` provide 'interior mutability', in contrast -//! with typical Rust types that exhibit 'inherited mutability'. +//! with typical Rust types that exhibit 'inherited mutability'. //! //! Cell types come in two flavors: `Cell` and `RefCell`. `Cell` implements interior //! mutability by moving values in and out of the `Cell`. To use references instead of values, From 43de01f97eeee13f9bf9f19b0b241e8368633d11 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 23 Feb 2018 15:12:28 -0500 Subject: [PATCH 04/31] cleaned trailing whitespaces --- src/libcore/cell.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index b3a7d20c4aa5f..6f0655f2033e1 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -20,9 +20,9 @@ //! flexible enough. Sometimes is required to have multiple references to an object and yet //! mutate it. //! -//! Shareable mutable containers exist to permit mutability in presence of aliasing in a +//! Shareable mutable containers exist to permit mutability in presence of aliasing in a //! controlled manner. Both `Cell` and `RefCell` allows to do this in a single threaded -//! way. However, neither `Cell` nor `RefCell` are thread safe (they do not implement +//! way. However, neither `Cell` nor `RefCell` are thread safe (they do not implement //! `Sync`), if you need to do Aliasing and Mutation between multiple threads is possible to use //! `Mutex`, `RwLock` or `AtomicXXX`. //! From 5344b07addf342334470778964d863d99eec7430 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 24 Feb 2018 16:50:44 +0100 Subject: [PATCH 05/31] Add new warning for CStr::from_ptr --- src/libstd/ffi/c_str.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 2519d83043553..c88c2bc913713 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -875,6 +875,8 @@ impl CStr { /// `ptr`. /// * There is no guarantee that the memory pointed to by `ptr` contains a /// valid nul terminator byte at the end of the string. + /// * It is not guaranteed that the memory pointed by `ptr` won't change + /// before the `CStr` has been destroyed. /// /// > **Note**: This operation is intended to be a 0-cost cast but it is /// > currently implemented with an up-front calculation of the length of From ce3ad263ff085ac15016430de5f4abb154427433 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sat, 24 Feb 2018 18:04:08 -0500 Subject: [PATCH 06/31] added link to sync containers --- src/libcore/cell.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 6f0655f2033e1..91074c18d771a 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -24,7 +24,8 @@ //! controlled manner. Both `Cell` and `RefCell` allows to do this in a single threaded //! way. However, neither `Cell` nor `RefCell` are thread safe (they do not implement //! `Sync`), if you need to do Aliasing and Mutation between multiple threads is possible to use -//! `Mutex`, `RwLock` or `AtomicXXX`. +//! [`Mutex`](../sync/struct.Mutex.html), [`RwLock`](../sync/struct.RwLock.html) or +//! [`atomic`](../sync/atomic/index.html) types. //! //! Values of the `Cell` and `RefCell` types may be mutated through shared references (i.e. //! the common `&T` type), whereas most Rust types can only be mutated through unique (`&mut T`) From 7ded7f764c2d590d0c3ad71b9ffbbcfaec2174fb Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sat, 24 Feb 2018 18:06:01 -0500 Subject: [PATCH 07/31] corrected grammar errors --- src/libcore/cell.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 91074c18d771a..858bdcbb72110 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -10,17 +10,17 @@ //! Shareable mutable containers. //! -//! Rust memory safety is based on this rule: Given an object `T`, is only possible to +//! Rust memory safety is based on this rule: Given an object `T`, it is only possible to //! have one of the following: //! -//! - Having several inmutable references (`&T`) to the object (also know as Aliasing). +//! - Having several immutable references (`&T`) to the object (also know as Aliasing). //! - Having one mutable reference (`&mut T`) to the object (also know as Mutability). //! //! This is enforced by the Rust compiler. However, there are situations where this rule is not -//! flexible enough. Sometimes is required to have multiple references to an object and yet +//! flexible enough. Sometimes it is required to have multiple references to an object and yet //! mutate it. //! -//! Shareable mutable containers exist to permit mutability in presence of aliasing in a +//! Shareable mutable containers exist to permit mutability in the presence of aliasing in a //! controlled manner. Both `Cell` and `RefCell` allows to do this in a single threaded //! way. However, neither `Cell` nor `RefCell` are thread safe (they do not implement //! `Sync`), if you need to do Aliasing and Mutation between multiple threads is possible to use From 397ce8a1aedd0734cbf9b7dfb36ea18fbe6a5d91 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sat, 24 Feb 2018 22:43:30 -0500 Subject: [PATCH 08/31] fixed links --- src/libcore/cell.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 858bdcbb72110..a946aca68d1b2 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -24,8 +24,8 @@ //! controlled manner. Both `Cell` and `RefCell` allows to do this in a single threaded //! way. However, neither `Cell` nor `RefCell` are thread safe (they do not implement //! `Sync`), if you need to do Aliasing and Mutation between multiple threads is possible to use -//! [`Mutex`](../sync/struct.Mutex.html), [`RwLock`](../sync/struct.RwLock.html) or -//! [`atomic`](../sync/atomic/index.html) types. +//! [`Mutex`](../../std/sync/struct.Mutex.html), [`RwLock`](../../std/sync/struct.RwLock.html) or +//! [`atomic`](../../core/sync/atomic/index.html) types. //! //! Values of the `Cell` and `RefCell` types may be mutated through shared references (i.e. //! the common `&T` type), whereas most Rust types can only be mutated through unique (`&mut T`) From 9091584def3b566f24f8fbeac495e6dc87178be8 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Mon, 26 Feb 2018 11:14:40 -0500 Subject: [PATCH 09/31] some grammar corrections --- src/libcore/cell.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index a946aca68d1b2..37f301c590928 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -13,18 +13,19 @@ //! Rust memory safety is based on this rule: Given an object `T`, it is only possible to //! have one of the following: //! -//! - Having several immutable references (`&T`) to the object (also know as Aliasing). -//! - Having one mutable reference (`&mut T`) to the object (also know as Mutability). +//! - Having several immutable references (`&T`) to the object (also known as **aliasing**). +//! - Having one mutable reference (`&mut T`) to the object (also known as **mutability**). //! //! This is enforced by the Rust compiler. However, there are situations where this rule is not //! flexible enough. Sometimes it is required to have multiple references to an object and yet //! mutate it. //! -//! Shareable mutable containers exist to permit mutability in the presence of aliasing in a -//! controlled manner. Both `Cell` and `RefCell` allows to do this in a single threaded +//! Shareable mutable containers exist to permit mutability in a controlled manner, even in the +//! presence of aliasing. Both `Cell` and `RefCell` allows to do this in a single threaded //! way. However, neither `Cell` nor `RefCell` are thread safe (they do not implement -//! `Sync`), if you need to do Aliasing and Mutation between multiple threads is possible to use -//! [`Mutex`](../../std/sync/struct.Mutex.html), [`RwLock`](../../std/sync/struct.RwLock.html) or +//! `Sync`). If you need to do aliasing and mutation between multiple threads it is possible to +//! use [`Mutex`](../../std/sync/struct.Mutex.html), +//! [`RwLock`](../../std/sync/struct.RwLock.html) or //! [`atomic`](../../core/sync/atomic/index.html) types. //! //! Values of the `Cell` and `RefCell` types may be mutated through shared references (i.e. From 02e021b6d4e1ae779dc538404a4fa0c54ed5f7ed Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Thu, 7 Apr 2016 18:16:40 +0100 Subject: [PATCH 10/31] Add bitreverse intrinsic --- src/libcore/intrinsics.rs | 4 ++++ src/librustc_trans/context.rs | 6 ++++++ src/librustc_trans/intrinsic.rs | 8 ++++++-- src/librustc_typeck/check/intrinsic.rs | 3 ++- src/test/run-pass/intrinsics-integer.rs | 10 ++++++++++ 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index a05d67a304fa0..830ebad065427 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -1292,6 +1292,10 @@ extern "rust-intrinsic" { /// Reverses the bytes in an integer type `T`. pub fn bswap(x: T) -> T; + /// Reverses the bits in an integer type `T`. + #[cfg(not(stage0))] + pub fn bitreverse(x: T) -> T; + /// Performs checked integer addition. /// The stabilized versions of this intrinsic are available on the integer /// primitives via the `overflowing_add` method. For example, diff --git a/src/librustc_trans/context.rs b/src/librustc_trans/context.rs index a285e5f263ab7..b93e8c2ad21ca 100644 --- a/src/librustc_trans/context.rs +++ b/src/librustc_trans/context.rs @@ -597,6 +597,12 @@ fn declare_intrinsic(cx: &CodegenCx, key: &str) -> Option { ifn!("llvm.bswap.i64", fn(t_i64) -> t_i64); ifn!("llvm.bswap.i128", fn(t_i128) -> t_i128); + ifn!("llvm.bitreverse.i8", fn(t_i8) -> t_i8); + ifn!("llvm.bitreverse.i16", fn(t_i16) -> t_i16); + ifn!("llvm.bitreverse.i32", fn(t_i32) -> t_i32); + ifn!("llvm.bitreverse.i64", fn(t_i64) -> t_i64); + ifn!("llvm.bitreverse.i128", fn(t_i128) -> t_i128); + ifn!("llvm.sadd.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1}); ifn!("llvm.sadd.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1}); ifn!("llvm.sadd.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1}); diff --git a/src/librustc_trans/intrinsic.rs b/src/librustc_trans/intrinsic.rs index b1f1fb52c907d..3f87ce7e04792 100644 --- a/src/librustc_trans/intrinsic.rs +++ b/src/librustc_trans/intrinsic.rs @@ -287,8 +287,8 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bx: &Builder<'a, 'tcx>, ], None) }, "ctlz" | "ctlz_nonzero" | "cttz" | "cttz_nonzero" | "ctpop" | "bswap" | - "add_with_overflow" | "sub_with_overflow" | "mul_with_overflow" | - "overflowing_add" | "overflowing_sub" | "overflowing_mul" | + "bitreverse" | "add_with_overflow" | "sub_with_overflow" | + "mul_with_overflow" | "overflowing_add" | "overflowing_sub" | "overflowing_mul" | "unchecked_div" | "unchecked_rem" | "unchecked_shl" | "unchecked_shr" => { let ty = arg_tys[0]; match int_type_width_signed(ty, cx) { @@ -315,6 +315,10 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bx: &Builder<'a, 'tcx>, &[args[0].immediate()], None) } } + "bitreverse" => { + bx.call(cx.get_intrinsic(&format!("llvm.bitreverse.i{}", width)), + &[args[0].immediate()], None) + } "add_with_overflow" | "sub_with_overflow" | "mul_with_overflow" => { let intrinsic = format!("llvm.{}{}.with.overflow.i{}", if signed { 's' } else { 'u' }, diff --git a/src/librustc_typeck/check/intrinsic.rs b/src/librustc_typeck/check/intrinsic.rs index 23243c3ad66c0..2e00040d99a73 100644 --- a/src/librustc_typeck/check/intrinsic.rs +++ b/src/librustc_typeck/check/intrinsic.rs @@ -275,7 +275,8 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, "volatile_store" => (1, vec![ tcx.mk_mut_ptr(param(0)), param(0) ], tcx.mk_nil()), - "ctpop" | "ctlz" | "ctlz_nonzero" | "cttz" | "cttz_nonzero" | "bswap" => + "ctpop" | "ctlz" | "ctlz_nonzero" | "cttz" | "cttz_nonzero" | + "bswap" | "bitreverse" => (1, vec![param(0)], param(0)), "add_with_overflow" | "sub_with_overflow" | "mul_with_overflow" => diff --git a/src/test/run-pass/intrinsics-integer.rs b/src/test/run-pass/intrinsics-integer.rs index 4896f02da20b0..6e0712f6767ba 100644 --- a/src/test/run-pass/intrinsics-integer.rs +++ b/src/test/run-pass/intrinsics-integer.rs @@ -18,6 +18,7 @@ mod rusti { pub fn cttz(x: T) -> T; pub fn cttz_nonzero(x: T) -> T; pub fn bswap(x: T) -> T; + pub fn bitreverse(x: T) -> T; } } @@ -138,5 +139,14 @@ pub fn main() { assert_eq!(bswap(0x0ABBCC0Di32), 0x0DCCBB0A); assert_eq!(bswap(0x0122334455667708u64), 0x0877665544332201); assert_eq!(bswap(0x0122334455667708i64), 0x0877665544332201); + + assert_eq!(bitreverse(0x0Au8), 0x50); + assert_eq!(bitreverse(0x0Ai8), 0x50); + assert_eq!(bitreverse(0x0A0Cu16), 0x3050); + assert_eq!(bitreverse(0x0A0Ci16), 0x3050); + assert_eq!(bitreverse(0x0ABBCC0Eu32), 0x7033DD50); + assert_eq!(bitreverse(0x0ABBCC0Ei32), 0x7033DD50); + assert_eq!(bitreverse(0x0122334455667708u64), 0x10EE66AA22CC4480); + assert_eq!(bitreverse(0x0122334455667708i64), 0x10EE66AA22CC4480); } } From df8dd3fd3ef2080c01360db38de610c13db1766e Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Wed, 28 Feb 2018 22:27:47 +0200 Subject: [PATCH 11/31] doc: no need for the references Also: - apply some rustfmt love - fix output of one example --- src/libcore/iter/iterator.rs | 53 +++++++++++++++--------------------- 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/src/libcore/iter/iterator.rs b/src/libcore/iter/iterator.rs index 9d8a71250f88a..722e50fe0f496 100644 --- a/src/libcore/iter/iterator.rs +++ b/src/libcore/iter/iterator.rs @@ -1180,19 +1180,19 @@ pub trait Iterator { /// /// // this iterator sequence is complex. /// let sum = a.iter() - /// .cloned() - /// .filter(|&x| x % 2 == 0) - /// .fold(0, |sum, i| sum + i); + /// .cloned() + /// .filter(|x| x % 2 == 0) + /// .fold(0, |sum, i| sum + i); /// /// println!("{}", sum); /// /// // let's add some inspect() calls to investigate what's happening /// let sum = a.iter() - /// .cloned() - /// .inspect(|x| println!("about to filter: {}", x)) - /// .filter(|&x| x % 2 == 0) - /// .inspect(|x| println!("made it through filter: {}", x)) - /// .fold(0, |sum, i| sum + i); + /// .cloned() + /// .inspect(|x| println!("about to filter: {}", x)) + /// .filter(|x| x % 2 == 0) + /// .inspect(|x| println!("made it through filter: {}", x)) + /// .fold(0, |sum, i| sum + i); /// /// println!("{}", sum); /// ``` @@ -1200,6 +1200,7 @@ pub trait Iterator { /// This will print: /// /// ```text + /// 6 /// about to filter: 1 /// about to filter: 4 /// made it through filter: 4 @@ -1230,8 +1231,7 @@ pub trait Iterator { /// /// let iter = a.into_iter(); /// - /// let sum: i32 = iter.take(5) - /// .fold(0, |acc, &i| acc + i ); + /// let sum: i32 = iter.take(5).fold(0, |acc, i| acc + i ); /// /// assert_eq!(sum, 6); /// @@ -1245,9 +1245,7 @@ pub trait Iterator { /// let mut iter = a.into_iter(); /// /// // instead, we add in a .by_ref() - /// let sum: i32 = iter.by_ref() - /// .take(2) - /// .fold(0, |acc, &i| acc + i ); + /// let sum: i32 = iter.by_ref().take(2).fold(0, |acc, i| acc + i ); /// /// assert_eq!(sum, 3); /// @@ -1304,9 +1302,7 @@ pub trait Iterator { /// /// let a = [1, 2, 3]; /// - /// let doubled: VecDeque = a.iter() - /// .map(|&x| x * 2) - /// .collect(); + /// let doubled: VecDeque = a.iter().map(|&x| x * 2).collect(); /// /// assert_eq!(2, doubled[0]); /// assert_eq!(4, doubled[1]); @@ -1318,9 +1314,7 @@ pub trait Iterator { /// ``` /// let a = [1, 2, 3]; /// - /// let doubled = a.iter() - /// .map(|&x| x * 2) - /// .collect::>(); + /// let doubled = a.iter().map(|x| x * 2).collect::>(); /// /// assert_eq!(vec![2, 4, 6], doubled); /// ``` @@ -1331,9 +1325,7 @@ pub trait Iterator { /// ``` /// let a = [1, 2, 3]; /// - /// let doubled = a.iter() - /// .map(|&x| x * 2) - /// .collect::>(); + /// let doubled = a.iter().map(|x| x * 2).collect::>(); /// /// assert_eq!(vec![2, 4, 6], doubled); /// ``` @@ -1344,9 +1336,9 @@ pub trait Iterator { /// let chars = ['g', 'd', 'k', 'k', 'n']; /// /// let hello: String = chars.iter() - /// .map(|&x| x as u8) - /// .map(|x| (x + 1) as char) - /// .collect(); + /// .map(|&x| x as u8) + /// .map(|x| (x + 1) as char) + /// .collect(); /// /// assert_eq!("hello", hello); /// ``` @@ -1393,8 +1385,9 @@ pub trait Iterator { /// ``` /// let a = [1, 2, 3]; /// - /// let (even, odd): (Vec, Vec) = a.into_iter() - /// .partition(|&n| n % 2 == 0); + /// let (even, odd): (Vec, Vec) = a + /// .into_iter() + /// .partition(|&n| n % 2 == 0); /// /// assert_eq!(even, vec![2]); /// assert_eq!(odd, vec![1, 3]); @@ -1457,8 +1450,7 @@ pub trait Iterator { /// let a = [1, 2, 3]; /// /// // the checked sum of all of the elements of the array - /// let sum = a.iter() - /// .try_fold(0i8, |acc, &x| acc.checked_add(x)); + /// let sum = a.iter().try_fold(0i8, |acc, &x| acc.checked_add(x)); /// /// assert_eq!(sum, Some(6)); /// ``` @@ -1556,8 +1548,7 @@ pub trait Iterator { /// let a = [1, 2, 3]; /// /// // the sum of all of the elements of the array - /// let sum = a.iter() - /// .fold(0, |acc, &x| acc + x); + /// let sum = a.iter().fold(0, |acc, x| acc + x); /// /// assert_eq!(sum, 6); /// ``` From e822e62ee80a9108bfdb7d0952c85fab2146f569 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Thu, 22 Feb 2018 15:53:22 +0100 Subject: [PATCH 12/31] Suggest type for overflowing bin/hex-literals --- src/librustc_lint/types.rs | 194 ++++++++++++++++++++++---- src/test/ui/lint/type-overflow.rs | 35 +++++ src/test/ui/lint/type-overflow.stderr | 70 ++++++++++ 3 files changed, 274 insertions(+), 25 deletions(-) create mode 100644 src/test/ui/lint/type-overflow.rs create mode 100644 src/test/ui/lint/type-overflow.stderr diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index ef9b3d38c637c..4fabb5bafbf89 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -150,11 +150,52 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { // Detect literal value out of range [min, max] inclusive // avoiding use of -min to prevent overflow/panic - if (negative && v > max + 1) || - (!negative && v > max) { - cx.span_lint(OVERFLOWING_LITERALS, - e.span, - &format!("literal out of range for {:?}", t)); + if (negative && v > max + 1) || (!negative && v > max) { + if let Some(repr_str) = get_bin_hex_repr(cx, lit) { + let bits = int_ty_bits(t, cx.sess().target.isize_ty); + let mut actually = v as i128; + if bits < 128 { + // v & 0b0..01..1, |1| = bits + let trimmed = v & ((1 << bits) - 1); + actually = if v & (1 << (bits - 1)) == 0 { + // positive + trimmed as i128 + } else { + // negative -> two's complement + (((-1 as i128 as u128) << bits) | trimmed) as i128 + }; + } + let mut err = cx.struct_span_lint( + OVERFLOWING_LITERALS, + e.span, + &format!("literal out of range for {:?}", t), + ); + err.note(&format!( + "the literal `{}` (decimal `{}`) does not fit into \ + an `{:?}` and will become `{}{:?}`.", + repr_str, v, t, actually, t + )); + let sugg_ty = get_fitting_type( + &cx.tables.node_id_to_type(e.hir_id).sty, + v, + negative, + ).map_or(String::new(), |ty| match ty { + ty::TyUint(t) => format!("Consider using `{:?}`", t), + ty::TyInt(t) => format!("Consider using `{:?}`", t), + _ => String::new(), + }); + if !sugg_ty.is_empty() { + err.help(&sugg_ty); + } + + err.emit(); + return; + } + cx.span_lint( + OVERFLOWING_LITERALS, + e.span, + &format!("literal out of range for {:?}", t), + ); return; } } @@ -180,37 +221,77 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { if let hir::ExprCast(..) = parent_expr.node { if let ty::TyChar = cx.tables.expr_ty(parent_expr).sty { let mut err = cx.struct_span_lint( - OVERFLOWING_LITERALS, - parent_expr.span, - "only u8 can be casted into char"); - err.span_suggestion(parent_expr.span, - &"use a char literal instead", - format!("'\\u{{{:X}}}'", lit_val)); + OVERFLOWING_LITERALS, + parent_expr.span, + "only u8 can be casted into char", + ); + err.span_suggestion( + parent_expr.span, + &"use a char literal instead", + format!("'\\u{{{:X}}}'", lit_val), + ); err.emit(); - return + return; } } } - cx.span_lint(OVERFLOWING_LITERALS, - e.span, - &format!("literal out of range for {:?}", t)); + if let Some(repr_str) = get_bin_hex_repr(cx, lit) { + let bits = uint_ty_bits(t, cx.sess().target.usize_ty); + // u128 cannot be greater than max -> compiler error + let actually = lit_val & ((1 << bits) - 1); + let mut err = cx.struct_span_lint( + OVERFLOWING_LITERALS, + e.span, + &format!("literal out of range for {:?}", t), + ); + err.note(&format!( + "the literal `{}` (decimal `{}`) does not fit into \ + an `{:?}` and will become `{}{:?}`.", + repr_str, lit_val, t, actually, t + )); + let sugg_ty = get_fitting_type( + &cx.tables.node_id_to_type(e.hir_id).sty, + lit_val, + false, + ).map_or( + String::new(), + |ty| { + if let ty::TyUint(t) = ty { + format!("Consider using `{:?}`", t) + } else { + String::new() + } + }, + ); + if !sugg_ty.is_empty() { + err.help(&sugg_ty); + } + + err.emit(); + return; + } + cx.span_lint( + OVERFLOWING_LITERALS, + e.span, + &format!("literal out of range for {:?}", t), + ); } } ty::TyFloat(t) => { let is_infinite = match lit.node { - ast::LitKind::Float(v, _) | - ast::LitKind::FloatUnsuffixed(v) => { - match t { - ast::FloatTy::F32 => v.as_str().parse().map(f32::is_infinite), - ast::FloatTy::F64 => v.as_str().parse().map(f64::is_infinite), - } - } + ast::LitKind::Float(v, _) | ast::LitKind::FloatUnsuffixed(v) => match t + { + ast::FloatTy::F32 => v.as_str().parse().map(f32::is_infinite), + ast::FloatTy::F64 => v.as_str().parse().map(f64::is_infinite), + }, _ => bug!(), }; if is_infinite == Ok(true) { - cx.span_lint(OVERFLOWING_LITERALS, - e.span, - &format!("literal out of range for {:?}", t)); + cx.span_lint( + OVERFLOWING_LITERALS, + e.span, + &format!("literal out of range for {:?}", t), + ); } } _ => (), @@ -338,6 +419,69 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { _ => false, } } + + fn get_bin_hex_repr(cx: &LateContext, lit: &ast::Lit) -> Option { + if let Some(src) = cx.sess().codemap().span_to_snippet(lit.span).ok() { + if let Some(firstch) = src.chars().next() { + if let Some(0) = char::to_digit(firstch, 10) { + if let Some(base) = src.chars().nth(1) { + if base == 'x' || base == 'b' { + return Some(src); + } + } + } + } + } + + None + } + + fn get_fitting_type<'a>( + t: &ty::TypeVariants, + val: u128, + negative: bool, + ) -> Option> { + use syntax::ast::IntTy::*; + use syntax::ast::UintTy::*; + macro_rules! find_fit { + ($ty:expr, $val:expr, $negative:expr, + $($type:ident => [$($utypes:expr),*] => [$($itypes:expr),*]),+) => { + { + let _neg = if negative { 1 } else { 0 }; + match $ty { + $($type => { + $(if !negative && val <= uint_ty_range($utypes).1 { + return Some(ty::TyUint($utypes)) + })* + $(if val <= int_ty_range($itypes).1 as u128 + _neg { + return Some(ty::TyInt($itypes)) + })* + None + },)* + _ => None + } + } + } + } + if let &ty::TyInt(i) = t { + return find_fit!(i, val, negative, + I8 => [U8] => [I16, I32, I64, I128], + I16 => [U16] => [I32, I64, I128], + I32 => [U32] => [I64, I128], + I64 => [U64] => [I128], + I128 => [U128] => []); + } + if let &ty::TyUint(u) = t { + return find_fit!(u, val, negative, + U8 => [U8, U16, U32, U64, U128] => [], + U16 => [U16, U32, U64, U128] => [], + U32 => [U32, U64, U128] => [], + U64 => [U64, U128] => [], + U128 => [U128] => []); + } + + None + } } } diff --git a/src/test/ui/lint/type-overflow.rs b/src/test/ui/lint/type-overflow.rs new file mode 100644 index 0000000000000..e414f43b3ffd7 --- /dev/null +++ b/src/test/ui/lint/type-overflow.rs @@ -0,0 +1,35 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// must-compile-successfully + +#![feature(i128_type)] + +fn main() { + let error = 255i8; //~WARNING literal out of range for i8 + + let ok = 0b1000_0001; // should be ok -> i32 + let ok = 0b0111_1111i8; // should be ok -> 127i8 + + let fail = 0b1000_0001i8; //~WARNING literal out of range for i8 + + let fail = 0x8000_0000_0000_0000i64; //~WARNING literal out of range for i64 + + let fail = 0x1_FFFF_FFFFu32; //~WARNING literal out of range for u32 + + let fail: i128 = 0x8000_0000_0000_0000_0000_0000_0000_0000; + //~^ WARNING literal out of range for i128 + + let fail = 0x8FFF_FFFF_FFFF_FFFE; //~WARNING literal out of range for i32 + + let fail: isize = 0x8000_0000_0000_0000; //~WARNING literal out of range for isize + + let fail = -0b1111_1111i8; //~WARNING literal out of range for i8 +} diff --git a/src/test/ui/lint/type-overflow.stderr b/src/test/ui/lint/type-overflow.stderr new file mode 100644 index 0000000000000..425f76da5cb4e --- /dev/null +++ b/src/test/ui/lint/type-overflow.stderr @@ -0,0 +1,70 @@ +warning: literal out of range for i8 + --> $DIR/type-overflow.rs:16:17 + | +16 | let error = 255i8; //~WARNING literal out of range for i8 + | ^^^^^ + | + = note: #[warn(overflowing_literals)] on by default + +warning: literal out of range for i8 + --> $DIR/type-overflow.rs:21:16 + | +21 | let fail = 0b1000_0001i8; //~WARNING literal out of range for i8 + | ^^^^^^^^^^^^^ + | + = note: the literal `0b1000_0001i8` (decimal `129`) does not fit into an `i8` and will become `-127i8`. + = help: Consider using `u8` + +warning: literal out of range for i64 + --> $DIR/type-overflow.rs:23:16 + | +23 | let fail = 0x8000_0000_0000_0000i64; //~WARNING literal out of range for i64 + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: the literal `0x8000_0000_0000_0000i64` (decimal `9223372036854775808`) does not fit into an `i64` and will become `-9223372036854775808i64`. + = help: Consider using `u64` + +warning: literal out of range for u32 + --> $DIR/type-overflow.rs:25:16 + | +25 | let fail = 0x1_FFFF_FFFFu32; //~WARNING literal out of range for u32 + | ^^^^^^^^^^^^^^^^ + | + = note: the literal `0x1_FFFF_FFFFu32` (decimal `8589934591`) does not fit into an `u32` and will become `4294967295u32`. + = help: Consider using `u64` + +warning: literal out of range for i128 + --> $DIR/type-overflow.rs:27:22 + | +27 | let fail: i128 = 0x8000_0000_0000_0000_0000_0000_0000_0000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: the literal `0x8000_0000_0000_0000_0000_0000_0000_0000` (decimal `170141183460469231731687303715884105728`) does not fit into an `i128` and will become `-170141183460469231731687303715884105728i128`. + = help: Consider using `u128` + +warning: literal out of range for i32 + --> $DIR/type-overflow.rs:30:16 + | +30 | let fail = 0x8FFF_FFFF_FFFF_FFFE; //~WARNING literal out of range for i32 + | ^^^^^^^^^^^^^^^^^^^^^ + | + = note: the literal `0x8FFF_FFFF_FFFF_FFFE` (decimal `10376293541461622782`) does not fit into an `i32` and will become `-2i32`. + = help: Consider using `i128` + +warning: literal out of range for isize + --> $DIR/type-overflow.rs:32:23 + | +32 | let fail: isize = 0x8000_0000_0000_0000; //~WARNING literal out of range for isize + | ^^^^^^^^^^^^^^^^^^^^^ + | + = note: the literal `0x8000_0000_0000_0000` (decimal `9223372036854775808`) does not fit into an `isize` and will become `-9223372036854775808isize`. + +warning: literal out of range for i8 + --> $DIR/type-overflow.rs:34:17 + | +34 | let fail = -0b1111_1111i8; //~WARNING literal out of range for i8 + | ^^^^^^^^^^^^^ + | + = note: the literal `0b1111_1111i8` (decimal `255`) does not fit into an `i8` and will become `-1i8`. + = help: Consider using `i16` + From 19c4771eeb5fc8fb18bb2e9a3f16ee474d8e67e3 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Thu, 22 Feb 2018 20:25:58 +0100 Subject: [PATCH 13/31] Implementing requested changes --- src/librustc_lint/types.rs | 141 +++++++++++++++---------------------- 1 file changed, 56 insertions(+), 85 deletions(-) diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index 4fabb5bafbf89..db9dfedc656ba 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -153,18 +153,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { if (negative && v > max + 1) || (!negative && v > max) { if let Some(repr_str) = get_bin_hex_repr(cx, lit) { let bits = int_ty_bits(t, cx.sess().target.isize_ty); - let mut actually = v as i128; - if bits < 128 { - // v & 0b0..01..1, |1| = bits - let trimmed = v & ((1 << bits) - 1); - actually = if v & (1 << (bits - 1)) == 0 { - // positive - trimmed as i128 - } else { - // negative -> two's complement - (((-1 as i128 as u128) << bits) | trimmed) as i128 - }; - } + let actually = + ((v << (128 - bits)) as i128) >> (128 - bits); let mut err = cx.struct_span_lint( OVERFLOWING_LITERALS, e.span, @@ -175,15 +165,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { an `{:?}` and will become `{}{:?}`.", repr_str, v, t, actually, t )); - let sugg_ty = get_fitting_type( + let sugg_ty = get_type_suggestion( &cx.tables.node_id_to_type(e.hir_id).sty, v, negative, - ).map_or(String::new(), |ty| match ty { - ty::TyUint(t) => format!("Consider using `{:?}`", t), - ty::TyInt(t) => format!("Consider using `{:?}`", t), - _ => String::new(), - }); + ); if !sugg_ty.is_empty() { err.help(&sugg_ty); } @@ -221,24 +207,20 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { if let hir::ExprCast(..) = parent_expr.node { if let ty::TyChar = cx.tables.expr_ty(parent_expr).sty { let mut err = cx.struct_span_lint( - OVERFLOWING_LITERALS, - parent_expr.span, - "only u8 can be casted into char", - ); - err.span_suggestion( - parent_expr.span, - &"use a char literal instead", - format!("'\\u{{{:X}}}'", lit_val), - ); + OVERFLOWING_LITERALS, + parent_expr.span, + "only u8 can be casted into char"); + err.span_suggestion(parent_expr.span, + &"use a char literal instead", + format!("'\\u{{{:X}}}'", lit_val)); err.emit(); - return; + return } } } if let Some(repr_str) = get_bin_hex_repr(cx, lit) { let bits = uint_ty_bits(t, cx.sess().target.usize_ty); - // u128 cannot be greater than max -> compiler error - let actually = lit_val & ((1 << bits) - 1); + let actually = (lit_val << (128 - bits)) >> (128 - bits); let mut err = cx.struct_span_lint( OVERFLOWING_LITERALS, e.span, @@ -249,19 +231,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { an `{:?}` and will become `{}{:?}`.", repr_str, lit_val, t, actually, t )); - let sugg_ty = get_fitting_type( + let sugg_ty = get_type_suggestion( &cx.tables.node_id_to_type(e.hir_id).sty, lit_val, false, - ).map_or( - String::new(), - |ty| { - if let ty::TyUint(t) = ty { - format!("Consider using `{:?}`", t) - } else { - String::new() - } - }, ); if !sugg_ty.is_empty() { err.help(&sugg_ty); @@ -279,19 +252,19 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { } ty::TyFloat(t) => { let is_infinite = match lit.node { - ast::LitKind::Float(v, _) | ast::LitKind::FloatUnsuffixed(v) => match t - { - ast::FloatTy::F32 => v.as_str().parse().map(f32::is_infinite), - ast::FloatTy::F64 => v.as_str().parse().map(f64::is_infinite), - }, + ast::LitKind::Float(v, _) | + ast::LitKind::FloatUnsuffixed(v) => { + match t { + ast::FloatTy::F32 => v.as_str().parse().map(f32::is_infinite), + ast::FloatTy::F64 => v.as_str().parse().map(f64::is_infinite), + } + } _ => bug!(), }; if is_infinite == Ok(true) { - cx.span_lint( - OVERFLOWING_LITERALS, - e.span, - &format!("literal out of range for {:?}", t), - ); + cx.span_lint(OVERFLOWING_LITERALS, + e.span, + &format!("literal out of range for {:?}", t)); } } _ => (), @@ -421,26 +394,27 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { } fn get_bin_hex_repr(cx: &LateContext, lit: &ast::Lit) -> Option { - if let Some(src) = cx.sess().codemap().span_to_snippet(lit.span).ok() { - if let Some(firstch) = src.chars().next() { - if let Some(0) = char::to_digit(firstch, 10) { - if let Some(base) = src.chars().nth(1) { - if base == 'x' || base == 'b' { - return Some(src); - } - } - } + let src = cx.sess().codemap().span_to_snippet(lit.span).ok()?; + let firstch = src.chars().next()?; + + if let Some(0) = char::to_digit(firstch, 10) { + match src.chars().nth(1) { + Some('x') | Some('b') => return Some(src), + _ => return None, } } None } - fn get_fitting_type<'a>( - t: &ty::TypeVariants, - val: u128, - negative: bool, - ) -> Option> { + // This function finds the next fitting type and generates a suggestion string. + // It searches for fitting types in the following way (`X < Y`): + // - `iX`: if literal fits in `uX` => `uX`, else => `iY` + // - `-iX` => `iY` + // - `uX` => `uY` + // + // No suggestion for: `isize`, `usize`. + fn get_type_suggestion<'a>(t: &ty::TypeVariants, val: u128, negative: bool) -> String { use syntax::ast::IntTy::*; use syntax::ast::UintTy::*; macro_rules! find_fit { @@ -451,36 +425,33 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { match $ty { $($type => { $(if !negative && val <= uint_ty_range($utypes).1 { - return Some(ty::TyUint($utypes)) + return format!("Consider using `{:?}`", $utypes) })* $(if val <= int_ty_range($itypes).1 as u128 + _neg { - return Some(ty::TyInt($itypes)) + return format!("Consider using `{:?}`", $itypes) })* - None + String::new() },)* - _ => None + _ => String::new() } } } } - if let &ty::TyInt(i) = t { - return find_fit!(i, val, negative, - I8 => [U8] => [I16, I32, I64, I128], - I16 => [U16] => [I32, I64, I128], - I32 => [U32] => [I64, I128], - I64 => [U64] => [I128], - I128 => [U128] => []); - } - if let &ty::TyUint(u) = t { - return find_fit!(u, val, negative, - U8 => [U8, U16, U32, U64, U128] => [], - U16 => [U16, U32, U64, U128] => [], - U32 => [U32, U64, U128] => [], - U64 => [U64, U128] => [], - U128 => [U128] => []); + match t { + &ty::TyInt(i) => find_fit!(i, val, negative, + I8 => [U8] => [I16, I32, I64, I128], + I16 => [U16] => [I32, I64, I128], + I32 => [U32] => [I64, I128], + I64 => [U64] => [I128], + I128 => [U128] => []), + &ty::TyUint(u) => find_fit!(u, val, negative, + U8 => [U8, U16, U32, U64, U128] => [], + U16 => [U16, U32, U64, U128] => [], + U32 => [U32, U64, U128] => [], + U64 => [U64, U128] => [], + U128 => [U128] => []), + _ => String::new(), } - - None } } } From 5c706196449f679b163a8a5fbfb08d842db07e29 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Sat, 24 Feb 2018 16:40:51 +0100 Subject: [PATCH 14/31] Rewrite error reporting as requested --- src/librustc_lint/types.rs | 114 ++++++++++++++++---------- src/test/ui/lint/type-overflow.stderr | 30 +++---- 2 files changed, 82 insertions(+), 62 deletions(-) diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index db9dfedc656ba..02aef271c37db 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -152,29 +152,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { // avoiding use of -min to prevent overflow/panic if (negative && v > max + 1) || (!negative && v > max) { if let Some(repr_str) = get_bin_hex_repr(cx, lit) { - let bits = int_ty_bits(t, cx.sess().target.isize_ty); - let actually = - ((v << (128 - bits)) as i128) >> (128 - bits); - let mut err = cx.struct_span_lint( - OVERFLOWING_LITERALS, - e.span, - &format!("literal out of range for {:?}", t), - ); - err.note(&format!( - "the literal `{}` (decimal `{}`) does not fit into \ - an `{:?}` and will become `{}{:?}`.", - repr_str, v, t, actually, t - )); - let sugg_ty = get_type_suggestion( - &cx.tables.node_id_to_type(e.hir_id).sty, + report_bin_hex_error( + cx, + e, + ty::TyInt(t), + repr_str, v, negative, ); - if !sugg_ty.is_empty() { - err.help(&sugg_ty); - } - - err.emit(); return; } cx.span_lint( @@ -219,28 +204,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { } } if let Some(repr_str) = get_bin_hex_repr(cx, lit) { - let bits = uint_ty_bits(t, cx.sess().target.usize_ty); - let actually = (lit_val << (128 - bits)) >> (128 - bits); - let mut err = cx.struct_span_lint( - OVERFLOWING_LITERALS, - e.span, - &format!("literal out of range for {:?}", t), - ); - err.note(&format!( - "the literal `{}` (decimal `{}`) does not fit into \ - an `{:?}` and will become `{}{:?}`.", - repr_str, lit_val, t, actually, t - )); - let sugg_ty = get_type_suggestion( - &cx.tables.node_id_to_type(e.hir_id).sty, + report_bin_hex_error( + cx, + e, + ty::TyUint(t), + repr_str, lit_val, false, ); - if !sugg_ty.is_empty() { - err.help(&sugg_ty); - } - - err.emit(); return; } cx.span_lint( @@ -414,7 +385,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { // - `uX` => `uY` // // No suggestion for: `isize`, `usize`. - fn get_type_suggestion<'a>(t: &ty::TypeVariants, val: u128, negative: bool) -> String { + fn get_type_suggestion<'a>( + t: &ty::TypeVariants, + val: u128, + negative: bool, + ) -> Option { use syntax::ast::IntTy::*; use syntax::ast::UintTy::*; macro_rules! find_fit { @@ -425,14 +400,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { match $ty { $($type => { $(if !negative && val <= uint_ty_range($utypes).1 { - return format!("Consider using `{:?}`", $utypes) + return Some(format!("{:?}", $utypes)) })* $(if val <= int_ty_range($itypes).1 as u128 + _neg { - return format!("Consider using `{:?}`", $itypes) + return Some(format!("{:?}", $itypes)) })* - String::new() + None },)* - _ => String::new() + _ => None } } } @@ -450,8 +425,57 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { U32 => [U32, U64, U128] => [], U64 => [U64, U128] => [], U128 => [U128] => []), - _ => String::new(), + _ => None, + } + } + + fn report_bin_hex_error( + cx: &LateContext, + expr: &hir::Expr, + ty: ty::TypeVariants, + repr_str: String, + val: u128, + negative: bool, + ) { + let (t, actually) = match ty { + ty::TyInt(t) => { + let bits = int_ty_bits(t, cx.sess().target.isize_ty); + let actually = (val << (128 - bits)) as i128 >> (128 - bits); + (format!("{:?}", t), actually.to_string()) + } + ty::TyUint(t) => { + let bits = uint_ty_bits(t, cx.sess().target.usize_ty); + let actually = (val << (128 - bits)) >> (128 - bits); + (format!("{:?}", t), actually.to_string()) + } + _ => bug!(), + }; + let mut err = cx.struct_span_lint( + OVERFLOWING_LITERALS, + expr.span, + &format!("literal out of range for {}", t), + ); + err.note(&format!( + "the literal `{}` (decimal `{}`) does not fit into \ + an `{}` and will become `{}{}`", + repr_str, val, t, actually, t + )); + if let Some(sugg_ty) = + get_type_suggestion(&cx.tables.node_id_to_type(expr.hir_id).sty, val, negative) + { + if let Some(pos) = repr_str.chars().position(|c| c == 'i' || c == 'u') { + let (sans_suffix, _) = repr_str.split_at(pos); + err.span_suggestion( + expr.span, + &format!("consider using `{}` instead", sugg_ty), + format!("{}{}", sans_suffix, sugg_ty), + ); + } else { + err.help(&format!("consider using `{}` instead", sugg_ty)); + } } + + err.emit(); } } } diff --git a/src/test/ui/lint/type-overflow.stderr b/src/test/ui/lint/type-overflow.stderr index 425f76da5cb4e..89718c7696a8d 100644 --- a/src/test/ui/lint/type-overflow.stderr +++ b/src/test/ui/lint/type-overflow.stderr @@ -10,28 +10,25 @@ warning: literal out of range for i8 --> $DIR/type-overflow.rs:21:16 | 21 | let fail = 0b1000_0001i8; //~WARNING literal out of range for i8 - | ^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^ help: consider using `u8` instead: `0b1000_0001u8` | - = note: the literal `0b1000_0001i8` (decimal `129`) does not fit into an `i8` and will become `-127i8`. - = help: Consider using `u8` + = note: the literal `0b1000_0001i8` (decimal `129`) does not fit into an `i8` and will become `-127i8` warning: literal out of range for i64 --> $DIR/type-overflow.rs:23:16 | 23 | let fail = 0x8000_0000_0000_0000i64; //~WARNING literal out of range for i64 - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `u64` instead: `0x8000_0000_0000_0000u64` | - = note: the literal `0x8000_0000_0000_0000i64` (decimal `9223372036854775808`) does not fit into an `i64` and will become `-9223372036854775808i64`. - = help: Consider using `u64` + = note: the literal `0x8000_0000_0000_0000i64` (decimal `9223372036854775808`) does not fit into an `i64` and will become `-9223372036854775808i64` warning: literal out of range for u32 --> $DIR/type-overflow.rs:25:16 | 25 | let fail = 0x1_FFFF_FFFFu32; //~WARNING literal out of range for u32 - | ^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ help: consider using `u64` instead: `0x1_FFFF_FFFFu64` | - = note: the literal `0x1_FFFF_FFFFu32` (decimal `8589934591`) does not fit into an `u32` and will become `4294967295u32`. - = help: Consider using `u64` + = note: the literal `0x1_FFFF_FFFFu32` (decimal `8589934591`) does not fit into an `u32` and will become `4294967295u32` warning: literal out of range for i128 --> $DIR/type-overflow.rs:27:22 @@ -39,8 +36,8 @@ warning: literal out of range for i128 27 | let fail: i128 = 0x8000_0000_0000_0000_0000_0000_0000_0000; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: the literal `0x8000_0000_0000_0000_0000_0000_0000_0000` (decimal `170141183460469231731687303715884105728`) does not fit into an `i128` and will become `-170141183460469231731687303715884105728i128`. - = help: Consider using `u128` + = note: the literal `0x8000_0000_0000_0000_0000_0000_0000_0000` (decimal `170141183460469231731687303715884105728`) does not fit into an `i128` and will become `-170141183460469231731687303715884105728i128` + = help: consider using `u128` instead warning: literal out of range for i32 --> $DIR/type-overflow.rs:30:16 @@ -48,8 +45,8 @@ warning: literal out of range for i32 30 | let fail = 0x8FFF_FFFF_FFFF_FFFE; //~WARNING literal out of range for i32 | ^^^^^^^^^^^^^^^^^^^^^ | - = note: the literal `0x8FFF_FFFF_FFFF_FFFE` (decimal `10376293541461622782`) does not fit into an `i32` and will become `-2i32`. - = help: Consider using `i128` + = note: the literal `0x8FFF_FFFF_FFFF_FFFE` (decimal `10376293541461622782`) does not fit into an `i32` and will become `-2i32` + = help: consider using `i128` instead warning: literal out of range for isize --> $DIR/type-overflow.rs:32:23 @@ -57,14 +54,13 @@ warning: literal out of range for isize 32 | let fail: isize = 0x8000_0000_0000_0000; //~WARNING literal out of range for isize | ^^^^^^^^^^^^^^^^^^^^^ | - = note: the literal `0x8000_0000_0000_0000` (decimal `9223372036854775808`) does not fit into an `isize` and will become `-9223372036854775808isize`. + = note: the literal `0x8000_0000_0000_0000` (decimal `9223372036854775808`) does not fit into an `isize` and will become `-9223372036854775808isize` warning: literal out of range for i8 --> $DIR/type-overflow.rs:34:17 | 34 | let fail = -0b1111_1111i8; //~WARNING literal out of range for i8 - | ^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^ help: consider using `i16` instead: `0b1111_1111i16` | - = note: the literal `0b1111_1111i8` (decimal `255`) does not fit into an `i8` and will become `-1i8`. - = help: Consider using `i16` + = note: the literal `0b1111_1111i8` (decimal `255`) does not fit into an `i8` and will become `-1i8` From f45f760f624b34a7fa70fe925303808d4713641a Mon Sep 17 00:00:00 2001 From: flip1995 Date: Thu, 1 Mar 2018 01:49:36 +0100 Subject: [PATCH 15/31] Adapt stderr of UI test to PR #48449 --- src/test/ui/lint/type-overflow.stderr | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/test/ui/lint/type-overflow.stderr b/src/test/ui/lint/type-overflow.stderr index 89718c7696a8d..4ede25b9d03e7 100644 --- a/src/test/ui/lint/type-overflow.stderr +++ b/src/test/ui/lint/type-overflow.stderr @@ -1,7 +1,7 @@ warning: literal out of range for i8 --> $DIR/type-overflow.rs:16:17 | -16 | let error = 255i8; //~WARNING literal out of range for i8 +LL | let error = 255i8; //~WARNING literal out of range for i8 | ^^^^^ | = note: #[warn(overflowing_literals)] on by default @@ -9,7 +9,7 @@ warning: literal out of range for i8 warning: literal out of range for i8 --> $DIR/type-overflow.rs:21:16 | -21 | let fail = 0b1000_0001i8; //~WARNING literal out of range for i8 +LL | let fail = 0b1000_0001i8; //~WARNING literal out of range for i8 | ^^^^^^^^^^^^^ help: consider using `u8` instead: `0b1000_0001u8` | = note: the literal `0b1000_0001i8` (decimal `129`) does not fit into an `i8` and will become `-127i8` @@ -17,7 +17,7 @@ warning: literal out of range for i8 warning: literal out of range for i64 --> $DIR/type-overflow.rs:23:16 | -23 | let fail = 0x8000_0000_0000_0000i64; //~WARNING literal out of range for i64 +LL | let fail = 0x8000_0000_0000_0000i64; //~WARNING literal out of range for i64 | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `u64` instead: `0x8000_0000_0000_0000u64` | = note: the literal `0x8000_0000_0000_0000i64` (decimal `9223372036854775808`) does not fit into an `i64` and will become `-9223372036854775808i64` @@ -25,7 +25,7 @@ warning: literal out of range for i64 warning: literal out of range for u32 --> $DIR/type-overflow.rs:25:16 | -25 | let fail = 0x1_FFFF_FFFFu32; //~WARNING literal out of range for u32 +LL | let fail = 0x1_FFFF_FFFFu32; //~WARNING literal out of range for u32 | ^^^^^^^^^^^^^^^^ help: consider using `u64` instead: `0x1_FFFF_FFFFu64` | = note: the literal `0x1_FFFF_FFFFu32` (decimal `8589934591`) does not fit into an `u32` and will become `4294967295u32` @@ -33,7 +33,7 @@ warning: literal out of range for u32 warning: literal out of range for i128 --> $DIR/type-overflow.rs:27:22 | -27 | let fail: i128 = 0x8000_0000_0000_0000_0000_0000_0000_0000; +LL | let fail: i128 = 0x8000_0000_0000_0000_0000_0000_0000_0000; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the literal `0x8000_0000_0000_0000_0000_0000_0000_0000` (decimal `170141183460469231731687303715884105728`) does not fit into an `i128` and will become `-170141183460469231731687303715884105728i128` @@ -42,7 +42,7 @@ warning: literal out of range for i128 warning: literal out of range for i32 --> $DIR/type-overflow.rs:30:16 | -30 | let fail = 0x8FFF_FFFF_FFFF_FFFE; //~WARNING literal out of range for i32 +LL | let fail = 0x8FFF_FFFF_FFFF_FFFE; //~WARNING literal out of range for i32 | ^^^^^^^^^^^^^^^^^^^^^ | = note: the literal `0x8FFF_FFFF_FFFF_FFFE` (decimal `10376293541461622782`) does not fit into an `i32` and will become `-2i32` @@ -51,7 +51,7 @@ warning: literal out of range for i32 warning: literal out of range for isize --> $DIR/type-overflow.rs:32:23 | -32 | let fail: isize = 0x8000_0000_0000_0000; //~WARNING literal out of range for isize +LL | let fail: isize = 0x8000_0000_0000_0000; //~WARNING literal out of range for isize | ^^^^^^^^^^^^^^^^^^^^^ | = note: the literal `0x8000_0000_0000_0000` (decimal `9223372036854775808`) does not fit into an `isize` and will become `-9223372036854775808isize` @@ -59,7 +59,7 @@ warning: literal out of range for isize warning: literal out of range for i8 --> $DIR/type-overflow.rs:34:17 | -34 | let fail = -0b1111_1111i8; //~WARNING literal out of range for i8 +LL | let fail = -0b1111_1111i8; //~WARNING literal out of range for i8 | ^^^^^^^^^^^^^ help: consider using `i16` instead: `0b1111_1111i16` | = note: the literal `0b1111_1111i8` (decimal `255`) does not fit into an `i8` and will become `-1i8` From f7693c06338c825d0d49eb1373e2039416b38389 Mon Sep 17 00:00:00 2001 From: Lukas Lueg Date: Wed, 21 Feb 2018 16:12:23 +0100 Subject: [PATCH 16/31] Fix spelling s/casted/cast/ --- src/libcore/char.rs | 4 ++-- src/librustc_lint/types.rs | 2 +- src/libsyntax/parse/parser.rs | 2 +- src/test/run-pass/extern-types-pointer-cast.rs | 2 +- src/test/ui/cast_char.rs | 4 ++-- src/test/ui/cast_char.stderr | 4 ++-- src/test/ui/issue-22644.stderr | 16 ++++++++-------- src/test/ui/issue-42954.stderr | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/libcore/char.rs b/src/libcore/char.rs index 7215bd2a47684..55d4b590f9133 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -79,7 +79,7 @@ pub const MAX: char = '\u{10ffff}'; /// Converts a `u32` to a `char`. /// -/// Note that all [`char`]s are valid [`u32`]s, and can be casted to one with +/// Note that all [`char`]s are valid [`u32`]s, and can be cast to one with /// [`as`]: /// /// ``` @@ -131,7 +131,7 @@ pub fn from_u32(i: u32) -> Option { /// Converts a `u32` to a `char`, ignoring validity. /// -/// Note that all [`char`]s are valid [`u32`]s, and can be casted to one with +/// Note that all [`char`]s are valid [`u32`]s, and can be cast to one with /// [`as`]: /// /// ``` diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index f734f3182a931..2207bbd1ca05e 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -184,7 +184,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { let mut err = cx.struct_span_lint( OVERFLOWING_LITERALS, parent_expr.span, - "only u8 can be casted into char"); + "only u8 can be cast into char"); err.span_suggestion(parent_expr.span, &"use a char literal instead", format!("'\\u{{{:X}}}'", lit_val)); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 7915109ce3af8..fdeed5391f772 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3094,7 +3094,7 @@ impl<'a> Parser<'a> { let expr_str = self.sess.codemap().span_to_snippet(expr.span) .unwrap_or(pprust::expr_to_string(&expr)); err.span_suggestion(expr.span, - &format!("try {} the casted value", op_verb), + &format!("try {} the cast value", op_verb), format!("({})", expr_str)); err.emit(); diff --git a/src/test/run-pass/extern-types-pointer-cast.rs b/src/test/run-pass/extern-types-pointer-cast.rs index 628a570665a33..0dede8eb70de0 100644 --- a/src/test/run-pass/extern-types-pointer-cast.rs +++ b/src/test/run-pass/extern-types-pointer-cast.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// Test that pointers to extern types can be casted from/to usize, +// Test that pointers to extern types can be cast from/to usize, // despite being !Sized. #![feature(extern_types)] diff --git a/src/test/ui/cast_char.rs b/src/test/ui/cast_char.rs index cd8ade5e51a1b..4dfa5037bc555 100644 --- a/src/test/ui/cast_char.rs +++ b/src/test/ui/cast_char.rs @@ -12,9 +12,9 @@ fn main() { const XYZ: char = 0x1F888 as char; - //~^ ERROR only u8 can be casted into char + //~^ ERROR only u8 can be cast into char const XY: char = 129160 as char; - //~^ ERROR only u8 can be casted into char + //~^ ERROR only u8 can be cast into char const ZYX: char = '\u{01F888}'; println!("{}", XYZ); } diff --git a/src/test/ui/cast_char.stderr b/src/test/ui/cast_char.stderr index e42a38dace9d2..5da763992e35b 100644 --- a/src/test/ui/cast_char.stderr +++ b/src/test/ui/cast_char.stderr @@ -1,4 +1,4 @@ -error: only u8 can be casted into char +error: only u8 can be cast into char --> $DIR/cast_char.rs:14:23 | 14 | const XYZ: char = 0x1F888 as char; @@ -10,7 +10,7 @@ note: lint level defined here 11 | #![deny(overflowing_literals)] | ^^^^^^^^^^^^^^^^^^^^ -error: only u8 can be casted into char +error: only u8 can be cast into char --> $DIR/cast_char.rs:16:22 | 16 | const XY: char = 129160 as char; diff --git a/src/test/ui/issue-22644.stderr b/src/test/ui/issue-22644.stderr index 91107fbe35610..60ad222c7ab12 100644 --- a/src/test/ui/issue-22644.stderr +++ b/src/test/ui/issue-22644.stderr @@ -5,7 +5,7 @@ error: `<` is interpreted as a start of generic arguments for `usize`, not a com | ---------- ^ --------- interpreted as generic arguments | | | | | not interpreted as comparison - | help: try comparing the casted value: `(a as usize)` + | help: try comparing the cast value: `(a as usize)` error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison --> $DIR/issue-22644.rs:17:33 @@ -14,7 +14,7 @@ error: `<` is interpreted as a start of generic arguments for `usize`, not a com | ---------- ^ -------------------- interpreted as generic arguments | | | | | not interpreted as comparison - | help: try comparing the casted value: `(a as usize)` + | help: try comparing the cast value: `(a as usize)` error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison --> $DIR/issue-22644.rs:19:31 @@ -23,7 +23,7 @@ error: `<` is interpreted as a start of generic arguments for `usize`, not a com | ---------- ^ - interpreted as generic arguments | | | | | not interpreted as comparison - | help: try comparing the casted value: `(a as usize)` + | help: try comparing the cast value: `(a as usize)` error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison --> $DIR/issue-22644.rs:21:31 @@ -32,7 +32,7 @@ error: `<` is interpreted as a start of generic arguments for `usize`, not a com | -------- ^ -------------------- interpreted as generic arguments | | | | | not interpreted as comparison - | help: try comparing the casted value: `(a: usize)` + | help: try comparing the cast value: `(a: usize)` error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison --> $DIR/issue-22644.rs:23:29 @@ -41,7 +41,7 @@ error: `<` is interpreted as a start of generic arguments for `usize`, not a com | -------- ^ - interpreted as generic arguments | | | | | not interpreted as comparison - | help: try comparing the casted value: `(a: usize)` + | help: try comparing the cast value: `(a: usize)` error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison --> $DIR/issue-22644.rs:28:20 @@ -50,7 +50,7 @@ error: `<` is interpreted as a start of generic arguments for `usize`, not a com | ^ not interpreted as comparison 29 | 4); | - interpreted as generic arguments -help: try comparing the casted value +help: try comparing the cast value | 25 | println!("{}", (a 26 | as @@ -64,7 +64,7 @@ error: `<` is interpreted as a start of generic arguments for `usize`, not a com | ^ not interpreted as comparison 38 | 5); | - interpreted as generic arguments -help: try comparing the casted value +help: try comparing the cast value | 30 | println!("{}", (a 31 | @@ -81,7 +81,7 @@ error: `<` is interpreted as a start of generic arguments for `usize`, not a shi | ---------- ^^ --------- interpreted as generic arguments | | | | | not interpreted as shift - | help: try shifting the casted value: `(a as usize)` + | help: try shifting the cast value: `(a as usize)` error: expected type, found `4` --> $DIR/issue-22644.rs:42:28 diff --git a/src/test/ui/issue-42954.stderr b/src/test/ui/issue-42954.stderr index d0fc410c474a4..205fa82274a69 100644 --- a/src/test/ui/issue-42954.stderr +++ b/src/test/ui/issue-42954.stderr @@ -5,7 +5,7 @@ error: `<` is interpreted as a start of generic arguments for `u32`, not a compa | --------- ^ - interpreted as generic arguments | | | | | not interpreted as comparison - | help: try comparing the casted value: `($i as u32)` + | help: try comparing the cast value: `($i as u32)` ... 19 | is_plainly_printable!(c); | ------------------------- in this macro invocation From 08504fbb0b05abdd9543f08102b0d6275dde210c Mon Sep 17 00:00:00 2001 From: Shotaro Yamada Date: Fri, 2 Mar 2018 13:50:59 +0900 Subject: [PATCH 17/31] Optimize str::repeat --- src/liballoc/lib.rs | 1 + src/liballoc/str.rs | 37 ++++++++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index d250cfe1880fc..cb43d5bee78ca 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -124,6 +124,7 @@ #![feature(allocator_internals)] #![feature(on_unimplemented)] #![feature(exact_chunks)] +#![feature(pointer_methods)] #![cfg_attr(not(test), feature(fused, fn_traits, placement_new_protocol, swap_with_slice, i128))] #![cfg_attr(test, feature(test, box_heap))] diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index a00e3d17dd00f..08ba4a180ed53 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -43,6 +43,7 @@ use core::str as core_str; use core::str::pattern::Pattern; use core::str::pattern::{Searcher, ReverseSearcher, DoubleEndedSearcher}; use core::mem; +use core::ptr; use core::iter::FusedIterator; use std_unicode::str::{UnicodeStr, Utf16Encoder}; @@ -2066,9 +2067,39 @@ impl str { /// ``` #[stable(feature = "repeat_str", since = "1.16.0")] pub fn repeat(&self, n: usize) -> String { - let mut s = String::with_capacity(self.len() * n); - s.extend((0..n).map(|_| self)); - s + if n == 0 { + return String::new(); + } + + // n = 2^j + k (2^j > k) + + // 2^j: + let mut s = Vec::with_capacity(self.len() * n); + s.extend(self.as_bytes()); + let mut m = n >> 1; + while m > 0 { + let len = s.len(); + unsafe { + ptr::copy_nonoverlapping(s.as_ptr(), (s.as_mut_ptr() as *mut u8).add(len), len); + s.set_len(len * 2); + } + m >>= 1; + } + + // k: + let res_len = n * self.len(); + if res_len > s.len() { + unsafe { + ptr::copy_nonoverlapping( + s.as_ptr(), + (s.as_mut_ptr() as *mut u8).add(s.len()), + res_len - s.len(), + ); + s.set_len(res_len); + } + } + + unsafe { String::from_utf8_unchecked(s) } } /// Checks if all characters in this string are within the ASCII range. From 15ecf0694811cf9ab3273c14a97f6f05b22a9b5b Mon Sep 17 00:00:00 2001 From: flip1995 Date: Fri, 2 Mar 2018 13:33:06 +0100 Subject: [PATCH 18/31] Remove isize test --- src/test/ui/lint/type-overflow.rs | 2 -- src/test/ui/lint/type-overflow.stderr | 10 +--------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/src/test/ui/lint/type-overflow.rs b/src/test/ui/lint/type-overflow.rs index e414f43b3ffd7..495989587e585 100644 --- a/src/test/ui/lint/type-overflow.rs +++ b/src/test/ui/lint/type-overflow.rs @@ -29,7 +29,5 @@ fn main() { let fail = 0x8FFF_FFFF_FFFF_FFFE; //~WARNING literal out of range for i32 - let fail: isize = 0x8000_0000_0000_0000; //~WARNING literal out of range for isize - let fail = -0b1111_1111i8; //~WARNING literal out of range for i8 } diff --git a/src/test/ui/lint/type-overflow.stderr b/src/test/ui/lint/type-overflow.stderr index 4ede25b9d03e7..d3fcb1335e209 100644 --- a/src/test/ui/lint/type-overflow.stderr +++ b/src/test/ui/lint/type-overflow.stderr @@ -48,16 +48,8 @@ LL | let fail = 0x8FFF_FFFF_FFFF_FFFE; //~WARNING literal out of range for i = note: the literal `0x8FFF_FFFF_FFFF_FFFE` (decimal `10376293541461622782`) does not fit into an `i32` and will become `-2i32` = help: consider using `i128` instead -warning: literal out of range for isize - --> $DIR/type-overflow.rs:32:23 - | -LL | let fail: isize = 0x8000_0000_0000_0000; //~WARNING literal out of range for isize - | ^^^^^^^^^^^^^^^^^^^^^ - | - = note: the literal `0x8000_0000_0000_0000` (decimal `9223372036854775808`) does not fit into an `isize` and will become `-9223372036854775808isize` - warning: literal out of range for i8 - --> $DIR/type-overflow.rs:34:17 + --> $DIR/type-overflow.rs:32:17 | LL | let fail = -0b1111_1111i8; //~WARNING literal out of range for i8 | ^^^^^^^^^^^^^ help: consider using `i16` instead: `0b1111_1111i16` From bc651cac8d671aee9be876b71d0fa86f94f56b0f Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Mon, 15 Jan 2018 19:59:10 +0100 Subject: [PATCH 19/31] core: Stabilize FusedIterator FusedIterator is a marker trait that promises that the implementing iterator continues to return `None` from `.next()` once it has returned `None` once (and/or `.next_back()`, if implemented). The effects of FusedIterator are already widely available through `.fuse()`, but with stable `FusedIterator`, stable Rust users can implement this trait for their iterators when appropriate. --- src/liballoc/binary_heap.rs | 6 ++--- src/liballoc/boxed.rs | 2 +- src/liballoc/btree/map.rs | 16 ++++++------ src/liballoc/btree/set.rs | 14 +++++----- src/liballoc/lib.rs | 3 +-- src/liballoc/linked_list.rs | 6 ++--- src/liballoc/str.rs | 2 +- src/liballoc/string.rs | 2 +- src/liballoc/vec.rs | 4 +-- src/liballoc/vec_deque.rs | 8 +++--- src/libcore/char.rs | 8 +++--- src/libcore/iter/mod.rs | 42 +++++++++++++++--------------- src/libcore/iter/range.rs | 6 ++--- src/libcore/iter/sources.rs | 6 ++--- src/libcore/iter/traits.rs | 4 +-- src/libcore/option.rs | 6 ++--- src/libcore/result.rs | 6 ++--- src/libcore/slice/mod.rs | 24 ++++++++--------- src/libcore/str/mod.rs | 14 +++++----- src/libstd/ascii.rs | 2 +- src/libstd/collections/hash/map.rs | 14 +++++----- src/libstd/collections/hash/set.rs | 14 +++++----- src/libstd/lib.rs | 1 - src/libstd/path.rs | 4 +-- src/libstd_unicode/char.rs | 4 +-- src/libstd_unicode/lib.rs | 1 - src/libstd_unicode/u_str.rs | 4 +-- src/test/run-pass/issue-36053.rs | 1 - 28 files changed, 110 insertions(+), 114 deletions(-) diff --git a/src/liballoc/binary_heap.rs b/src/liballoc/binary_heap.rs index 3041f85cd4c3a..a5694a90dbc9a 100644 --- a/src/liballoc/binary_heap.rs +++ b/src/liballoc/binary_heap.rs @@ -964,7 +964,7 @@ impl<'a, T> ExactSizeIterator for Iter<'a, T> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, T> FusedIterator for Iter<'a, T> {} /// An owning iterator over the elements of a `BinaryHeap`. @@ -1019,7 +1019,7 @@ impl ExactSizeIterator for IntoIter { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for IntoIter {} /// A draining iterator over the elements of a `BinaryHeap`. @@ -1065,7 +1065,7 @@ impl<'a, T: 'a> ExactSizeIterator for Drain<'a, T> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, T: 'a> FusedIterator for Drain<'a, T> {} #[stable(feature = "binary_heap_extras_15", since = "1.5.0")] diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 75a59de337cef..6b000b6fa91ba 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -722,7 +722,7 @@ impl ExactSizeIterator for Box { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for Box {} diff --git a/src/liballoc/btree/map.rs b/src/liballoc/btree/map.rs index 618ef81fdd981..7b7a6374db9bb 100644 --- a/src/liballoc/btree/map.rs +++ b/src/liballoc/btree/map.rs @@ -1156,7 +1156,7 @@ impl<'a, K: 'a, V: 'a> Iterator for Iter<'a, K, V> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, K, V> FusedIterator for Iter<'a, K, V> {} #[stable(feature = "rust1", since = "1.0.0")] @@ -1235,7 +1235,7 @@ impl<'a, K: 'a, V: 'a> ExactSizeIterator for IterMut<'a, K, V> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, K, V> FusedIterator for IterMut<'a, K, V> {} #[stable(feature = "rust1", since = "1.0.0")] @@ -1365,7 +1365,7 @@ impl ExactSizeIterator for IntoIter { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for IntoIter {} #[stable(feature = "rust1", since = "1.0.0")] @@ -1395,7 +1395,7 @@ impl<'a, K, V> ExactSizeIterator for Keys<'a, K, V> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, K, V> FusedIterator for Keys<'a, K, V> {} #[stable(feature = "rust1", since = "1.0.0")] @@ -1432,7 +1432,7 @@ impl<'a, K, V> ExactSizeIterator for Values<'a, K, V> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, K, V> FusedIterator for Values<'a, K, V> {} #[stable(feature = "rust1", since = "1.0.0")] @@ -1482,7 +1482,7 @@ impl<'a, K, V> ExactSizeIterator for ValuesMut<'a, K, V> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, K, V> FusedIterator for ValuesMut<'a, K, V> {} @@ -1561,7 +1561,7 @@ impl<'a, K, V> Range<'a, K, V> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, K, V> FusedIterator for Range<'a, K, V> {} #[stable(feature = "btree_range", since = "1.17.0")] @@ -1630,7 +1630,7 @@ impl<'a, K, V> DoubleEndedIterator for RangeMut<'a, K, V> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, K, V> FusedIterator for RangeMut<'a, K, V> {} impl<'a, K, V> RangeMut<'a, K, V> { diff --git a/src/liballoc/btree/set.rs b/src/liballoc/btree/set.rs index 327eaaf465130..34cb7a08ed706 100644 --- a/src/liballoc/btree/set.rs +++ b/src/liballoc/btree/set.rs @@ -946,7 +946,7 @@ impl<'a, T> ExactSizeIterator for Iter<'a, T> { fn len(&self) -> usize { self.iter.len() } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, T> FusedIterator for Iter<'a, T> {} #[stable(feature = "rust1", since = "1.0.0")] @@ -971,7 +971,7 @@ impl ExactSizeIterator for IntoIter { fn len(&self) -> usize { self.iter.len() } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for IntoIter {} #[stable(feature = "btree_range", since = "1.17.0")] @@ -997,7 +997,7 @@ impl<'a, T> DoubleEndedIterator for Range<'a, T> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, T> FusedIterator for Range<'a, T> {} /// Compare `x` and `y`, but return `short` if x is None and `long` if y is None @@ -1044,7 +1044,7 @@ impl<'a, T: Ord> Iterator for Difference<'a, T> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, T: Ord> FusedIterator for Difference<'a, T> {} #[stable(feature = "rust1", since = "1.0.0")] @@ -1078,7 +1078,7 @@ impl<'a, T: Ord> Iterator for SymmetricDifference<'a, T> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, T: Ord> FusedIterator for SymmetricDifference<'a, T> {} #[stable(feature = "rust1", since = "1.0.0")] @@ -1116,7 +1116,7 @@ impl<'a, T: Ord> Iterator for Intersection<'a, T> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, T: Ord> FusedIterator for Intersection<'a, T> {} #[stable(feature = "rust1", since = "1.0.0")] @@ -1150,5 +1150,5 @@ impl<'a, T: Ord> Iterator for Union<'a, T> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, T: Ord> FusedIterator for Union<'a, T> {} diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index d250cfe1880fc..2212b62dfd8f7 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -96,7 +96,6 @@ #![feature(fmt_internals)] #![feature(from_ref)] #![feature(fundamental)] -#![feature(fused)] #![feature(generic_param_attrs)] #![feature(i128_type)] #![feature(inclusive_range)] @@ -125,7 +124,7 @@ #![feature(on_unimplemented)] #![feature(exact_chunks)] -#![cfg_attr(not(test), feature(fused, fn_traits, placement_new_protocol, swap_with_slice, i128))] +#![cfg_attr(not(test), feature(fn_traits, placement_new_protocol, swap_with_slice, i128))] #![cfg_attr(test, feature(test, box_heap))] // Allow testing this library diff --git a/src/liballoc/linked_list.rs b/src/liballoc/linked_list.rs index ec579e3fd68d6..87939fddfc81f 100644 --- a/src/liballoc/linked_list.rs +++ b/src/liballoc/linked_list.rs @@ -897,7 +897,7 @@ impl<'a, T> DoubleEndedIterator for Iter<'a, T> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> ExactSizeIterator for Iter<'a, T> {} -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, T> FusedIterator for Iter<'a, T> {} #[stable(feature = "rust1", since = "1.0.0")] @@ -946,7 +946,7 @@ impl<'a, T> DoubleEndedIterator for IterMut<'a, T> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> ExactSizeIterator for IterMut<'a, T> {} -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, T> FusedIterator for IterMut<'a, T> {} impl<'a, T> IterMut<'a, T> { @@ -1117,7 +1117,7 @@ impl DoubleEndedIterator for IntoIter { #[stable(feature = "rust1", since = "1.0.0")] impl ExactSizeIterator for IntoIter {} -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for IntoIter {} #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index a00e3d17dd00f..1a431bb269420 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -171,7 +171,7 @@ impl<'a> Iterator for EncodeUtf16<'a> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a> FusedIterator for EncodeUtf16<'a> {} #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 409d2ab287e7c..1fcabd8a4278c 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -2254,5 +2254,5 @@ impl<'a> DoubleEndedIterator for Drain<'a> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a> FusedIterator for Drain<'a> {} diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 3c9b6b94b4405..03c9750fb3928 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -2389,7 +2389,7 @@ impl ExactSizeIterator for IntoIter { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for IntoIter {} #[unstable(feature = "trusted_len", issue = "37572")] @@ -2495,7 +2495,7 @@ impl<'a, T> ExactSizeIterator for Drain<'a, T> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, T> FusedIterator for Drain<'a, T> {} /// A place for insertion at the back of a `Vec`. diff --git a/src/liballoc/vec_deque.rs b/src/liballoc/vec_deque.rs index 8b686365e6929..3d7549abe6ff5 100644 --- a/src/liballoc/vec_deque.rs +++ b/src/liballoc/vec_deque.rs @@ -1991,7 +1991,7 @@ impl<'a, T> ExactSizeIterator for Iter<'a, T> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, T> FusedIterator for Iter<'a, T> {} @@ -2084,7 +2084,7 @@ impl<'a, T> ExactSizeIterator for IterMut<'a, T> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, T> FusedIterator for IterMut<'a, T> {} /// An owning iterator over the elements of a `VecDeque`. @@ -2140,7 +2140,7 @@ impl ExactSizeIterator for IntoIter { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for IntoIter {} /// A draining iterator over the elements of a `VecDeque`. @@ -2247,7 +2247,7 @@ impl<'a, T: 'a> DoubleEndedIterator for Drain<'a, T> { #[stable(feature = "drain", since = "1.6.0")] impl<'a, T: 'a> ExactSizeIterator for Drain<'a, T> {} -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, T: 'a> FusedIterator for Drain<'a, T> {} #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/char.rs b/src/libcore/char.rs index 7215bd2a47684..3ff31a7a92815 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -643,7 +643,7 @@ impl ExactSizeIterator for EscapeUnicode { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for EscapeUnicode {} #[stable(feature = "char_struct_display", since = "1.16.0")] @@ -756,7 +756,7 @@ impl ExactSizeIterator for EscapeDefault { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for EscapeDefault {} #[stable(feature = "char_struct_display", since = "1.16.0")] @@ -790,7 +790,7 @@ impl Iterator for EscapeDebug { #[stable(feature = "char_escape_debug", since = "1.20.0")] impl ExactSizeIterator for EscapeDebug { } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for EscapeDebug {} #[stable(feature = "char_escape_debug", since = "1.20.0")] @@ -904,5 +904,5 @@ impl> Iterator for DecodeUtf8 { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl> FusedIterator for DecodeUtf8 {} diff --git a/src/libcore/iter/mod.rs b/src/libcore/iter/mod.rs index 257d7d6caaaf8..9a8f7fc4e6abd 100644 --- a/src/libcore/iter/mod.rs +++ b/src/libcore/iter/mod.rs @@ -344,7 +344,7 @@ pub use self::sources::{Once, once}; pub use self::traits::{FromIterator, IntoIterator, DoubleEndedIterator, Extend}; #[stable(feature = "rust1", since = "1.0.0")] pub use self::traits::{ExactSizeIterator, Sum, Product}; -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] pub use self::traits::FusedIterator; #[unstable(feature = "trusted_len", issue = "37572")] pub use self::traits::TrustedLen; @@ -506,7 +506,7 @@ impl ExactSizeIterator for Rev } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for Rev where I: FusedIterator + DoubleEndedIterator {} @@ -589,7 +589,7 @@ impl<'a, I, T: 'a> ExactSizeIterator for Cloned } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, I, T: 'a> FusedIterator for Cloned where I: FusedIterator, T: Clone {} @@ -662,7 +662,7 @@ impl Iterator for Cycle where I: Clone + Iterator { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for Cycle where I: Clone + Iterator {} /// An iterator for stepping iterators by a custom amount. @@ -1002,7 +1002,7 @@ impl DoubleEndedIterator for Chain where } // Note: *both* must be fused to handle double-ended iterators. -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for Chain where A: FusedIterator, B: FusedIterator, @@ -1262,7 +1262,7 @@ unsafe impl TrustedRandomAccess for Zip } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for Zip where A: FusedIterator, B: FusedIterator, {} @@ -1404,7 +1404,7 @@ impl ExactSizeIterator for Map } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for Map where F: FnMut(I::Item) -> B {} @@ -1553,7 +1553,7 @@ impl DoubleEndedIterator for Filter } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for Filter where P: FnMut(&I::Item) -> bool {} @@ -1663,7 +1663,7 @@ impl DoubleEndedIterator for FilterMap } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for FilterMap where F: FnMut(I::Item) -> Option {} @@ -1818,7 +1818,7 @@ unsafe impl TrustedRandomAccess for Enumerate } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for Enumerate where I: FusedIterator {} #[unstable(feature = "trusted_len", issue = "37572")] @@ -1938,7 +1938,7 @@ impl Iterator for Peekable { #[stable(feature = "rust1", since = "1.0.0")] impl ExactSizeIterator for Peekable {} -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for Peekable {} impl Peekable { @@ -2072,7 +2072,7 @@ impl Iterator for SkipWhile } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for SkipWhile where I: FusedIterator, P: FnMut(&I::Item) -> bool {} @@ -2151,7 +2151,7 @@ impl Iterator for TakeWhile } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for TakeWhile where I: FusedIterator, P: FnMut(&I::Item) -> bool {} @@ -2290,7 +2290,7 @@ impl DoubleEndedIterator for Skip where I: DoubleEndedIterator + ExactSize } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for Skip where I: FusedIterator {} /// An iterator that only iterates over the first `n` iterations of `iter`. @@ -2371,7 +2371,7 @@ impl Iterator for Take where I: Iterator{ #[stable(feature = "rust1", since = "1.0.0")] impl ExactSizeIterator for Take where I: ExactSizeIterator {} -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for Take where I: FusedIterator {} #[unstable(feature = "trusted_len", issue = "37572")] @@ -2517,7 +2517,7 @@ impl DoubleEndedIterator for FlatMap } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for FlatMap where I: FusedIterator, U: IntoIterator, F: FnMut(I::Item) -> U {} @@ -2605,7 +2605,7 @@ impl DoubleEndedIterator for Flatten } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for Flatten where I: FusedIterator, U: Iterator, I::Item: IntoIterator {} @@ -2765,7 +2765,7 @@ pub struct Fuse { done: bool } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for Fuse where I: Iterator {} #[stable(feature = "rust1", since = "1.0.0")] @@ -2896,7 +2896,7 @@ unsafe impl TrustedRandomAccess for Fuse } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl Iterator for Fuse where I: FusedIterator { #[inline] fn next(&mut self) -> Option<::Item> { @@ -2938,7 +2938,7 @@ impl Iterator for Fuse where I: FusedIterator { } } -#[unstable(feature = "fused", reason = "recently added", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl DoubleEndedIterator for Fuse where I: DoubleEndedIterator + FusedIterator { @@ -3082,6 +3082,6 @@ impl ExactSizeIterator for Inspect } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for Inspect where F: FnMut(&I::Item) {} diff --git a/src/libcore/iter/range.rs b/src/libcore/iter/range.rs index 65b38c94dda3f..7f3b227e8b733 100644 --- a/src/libcore/iter/range.rs +++ b/src/libcore/iter/range.rs @@ -295,7 +295,7 @@ impl DoubleEndedIterator for ops::Range { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for ops::Range {} #[stable(feature = "rust1", since = "1.0.0")] @@ -322,7 +322,7 @@ impl Iterator for ops::RangeFrom { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for ops::RangeFrom {} #[unstable(feature = "trusted_len", issue = "37572")] @@ -463,5 +463,5 @@ impl DoubleEndedIterator for ops::RangeInclusive { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for ops::RangeInclusive {} diff --git a/src/libcore/iter/sources.rs b/src/libcore/iter/sources.rs index dfd42f3e73301..149dff83bc0e1 100644 --- a/src/libcore/iter/sources.rs +++ b/src/libcore/iter/sources.rs @@ -41,7 +41,7 @@ impl DoubleEndedIterator for Repeat { fn next_back(&mut self) -> Option { Some(self.element.clone()) } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for Repeat {} #[unstable(feature = "trusted_len", issue = "37572")] @@ -259,7 +259,7 @@ impl ExactSizeIterator for Empty { #[unstable(feature = "trusted_len", issue = "37572")] unsafe impl TrustedLen for Empty {} -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for Empty {} // not #[derive] because that adds a Clone bound on T, @@ -340,7 +340,7 @@ impl ExactSizeIterator for Once { #[unstable(feature = "trusted_len", issue = "37572")] unsafe impl TrustedLen for Once {} -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for Once {} /// Creates an iterator that yields an element exactly once. diff --git a/src/libcore/iter/traits.rs b/src/libcore/iter/traits.rs index 860742d9eab60..a86f4e74706e2 100644 --- a/src/libcore/iter/traits.rs +++ b/src/libcore/iter/traits.rs @@ -959,10 +959,10 @@ impl Product> for Result /// [`None`]: ../../std/option/enum.Option.html#variant.None /// [`Iterator::fuse`]: ../../std/iter/trait.Iterator.html#method.fuse /// [`Fuse`]: ../../std/iter/struct.Fuse.html -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] pub trait FusedIterator: Iterator {} -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, I: FusedIterator + ?Sized> FusedIterator for &'a mut I {} /// An iterator that reports an accurate length using size_hint. diff --git a/src/libcore/option.rs b/src/libcore/option.rs index b8fe28d0f0d71..99c1d7d9b3619 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -1051,7 +1051,7 @@ impl<'a, A> DoubleEndedIterator for Iter<'a, A> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, A> ExactSizeIterator for Iter<'a, A> {} -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, A> FusedIterator for Iter<'a, A> {} #[unstable(feature = "trusted_len", issue = "37572")] @@ -1096,7 +1096,7 @@ impl<'a, A> DoubleEndedIterator for IterMut<'a, A> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, A> ExactSizeIterator for IterMut<'a, A> {} -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, A> FusedIterator for IterMut<'a, A> {} #[unstable(feature = "trusted_len", issue = "37572")] unsafe impl<'a, A> TrustedLen for IterMut<'a, A> {} @@ -1133,7 +1133,7 @@ impl DoubleEndedIterator for IntoIter { #[stable(feature = "rust1", since = "1.0.0")] impl ExactSizeIterator for IntoIter {} -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for IntoIter {} #[unstable(feature = "trusted_len", issue = "37572")] diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 3801db94e15d5..5131fc837ef29 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -1038,7 +1038,7 @@ impl<'a, T> DoubleEndedIterator for Iter<'a, T> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> ExactSizeIterator for Iter<'a, T> {} -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, T> FusedIterator for Iter<'a, T> {} #[unstable(feature = "trusted_len", issue = "37572")] @@ -1082,7 +1082,7 @@ impl<'a, T> DoubleEndedIterator for IterMut<'a, T> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> ExactSizeIterator for IterMut<'a, T> {} -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, T> FusedIterator for IterMut<'a, T> {} #[unstable(feature = "trusted_len", issue = "37572")] @@ -1125,7 +1125,7 @@ impl DoubleEndedIterator for IntoIter { #[stable(feature = "rust1", since = "1.0.0")] impl ExactSizeIterator for IntoIter {} -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for IntoIter {} #[unstable(feature = "trusted_len", issue = "37572")] diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index a43ed65907f83..02207f1738f12 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -1461,7 +1461,7 @@ impl<'a, T> ExactSizeIterator for Iter<'a, T> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, T> FusedIterator for Iter<'a, T> {} #[unstable(feature = "trusted_len", issue = "37572")] @@ -1589,7 +1589,7 @@ impl<'a, T> ExactSizeIterator for IterMut<'a, T> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, T> FusedIterator for IterMut<'a, T> {} #[unstable(feature = "trusted_len", issue = "37572")] @@ -1737,7 +1737,7 @@ impl<'a, T, P> SplitIter for Split<'a, T, P> where P: FnMut(&T) -> bool { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, T, P> FusedIterator for Split<'a, T, P> where P: FnMut(&T) -> bool {} /// An iterator over the subslices of the vector which are separated @@ -1835,7 +1835,7 @@ impl<'a, T, P> DoubleEndedIterator for SplitMut<'a, T, P> where } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, T, P> FusedIterator for SplitMut<'a, T, P> where P: FnMut(&T) -> bool {} /// An iterator over subslices separated by elements that match a predicate @@ -1892,7 +1892,7 @@ impl<'a, T, P> SplitIter for RSplit<'a, T, P> where P: FnMut(&T) -> bool { } } -//#[unstable(feature = "fused", issue = "35602")] +//#[stable(feature = "fused", since = "1.25.0")] #[unstable(feature = "slice_rsplit", issue = "41020")] impl<'a, T, P> FusedIterator for RSplit<'a, T, P> where P: FnMut(&T) -> bool {} @@ -1951,7 +1951,7 @@ impl<'a, T, P> DoubleEndedIterator for RSplitMut<'a, T, P> where } } -//#[unstable(feature = "fused", issue = "35602")] +//#[stable(feature = "fused", since = "1.25.0")] #[unstable(feature = "slice_rsplit", issue = "41020")] impl<'a, T, P> FusedIterator for RSplitMut<'a, T, P> where P: FnMut(&T) -> bool {} @@ -2088,7 +2088,7 @@ macro_rules! forward_iterator { } } - #[unstable(feature = "fused", issue = "35602")] + #[stable(feature = "fused", since = "1.25.0")] impl<'a, $elem, P> FusedIterator for $name<'a, $elem, P> where P: FnMut(&T) -> bool {} } @@ -2194,7 +2194,7 @@ impl<'a, T> DoubleEndedIterator for Windows<'a, T> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> ExactSizeIterator for Windows<'a, T> {} -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, T> FusedIterator for Windows<'a, T> {} #[doc(hidden)] @@ -2313,7 +2313,7 @@ impl<'a, T> DoubleEndedIterator for Chunks<'a, T> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> ExactSizeIterator for Chunks<'a, T> {} -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, T> FusedIterator for Chunks<'a, T> {} #[doc(hidden)] @@ -2429,7 +2429,7 @@ impl<'a, T> DoubleEndedIterator for ChunksMut<'a, T> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> ExactSizeIterator for ChunksMut<'a, T> {} -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, T> FusedIterator for ChunksMut<'a, T> {} #[doc(hidden)] @@ -2539,7 +2539,7 @@ impl<'a, T> ExactSizeIterator for ExactChunks<'a, T> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, T> FusedIterator for ExactChunks<'a, T> {} #[doc(hidden)] @@ -2636,7 +2636,7 @@ impl<'a, T> ExactSizeIterator for ExactChunksMut<'a, T> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, T> FusedIterator for ExactChunksMut<'a, T> {} #[doc(hidden)] diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 765b369e4b25d..7e919b653f21e 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -609,7 +609,7 @@ impl<'a> DoubleEndedIterator for Chars<'a> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a> FusedIterator for Chars<'a> {} impl<'a> Chars<'a> { @@ -702,7 +702,7 @@ impl<'a> DoubleEndedIterator for CharIndices<'a> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a> FusedIterator for CharIndices<'a> {} impl<'a> CharIndices<'a> { @@ -817,7 +817,7 @@ impl<'a> ExactSizeIterator for Bytes<'a> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a> FusedIterator for Bytes<'a> {} #[unstable(feature = "trusted_len", issue = "37572")] @@ -977,10 +977,10 @@ macro_rules! generate_pattern_iterators { } } - #[unstable(feature = "fused", issue = "35602")] + #[stable(feature = "fused", since = "1.25.0")] impl<'a, P: Pattern<'a>> FusedIterator for $forward_iterator<'a, P> {} - #[unstable(feature = "fused", issue = "35602")] + #[stable(feature = "fused", since = "1.25.0")] impl<'a, P: Pattern<'a>> FusedIterator for $reverse_iterator<'a, P> where P::Searcher: ReverseSearcher<'a> {} @@ -1337,7 +1337,7 @@ impl<'a> DoubleEndedIterator for Lines<'a> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a> FusedIterator for Lines<'a> {} /// Created with the method [`lines_any`]. @@ -1403,7 +1403,7 @@ impl<'a> DoubleEndedIterator for LinesAny<'a> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] #[allow(deprecated)] impl<'a> FusedIterator for LinesAny<'a> {} diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index 430c9df396a5e..ce3e38de7eb1f 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -590,7 +590,7 @@ impl DoubleEndedIterator for EscapeDefault { } #[stable(feature = "rust1", since = "1.0.0")] impl ExactSizeIterator for EscapeDefault {} -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for EscapeDefault {} #[stable(feature = "std_debug", since = "1.16.0")] diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 4dfdc23ebee53..9e48efeb1136c 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1750,7 +1750,7 @@ impl<'a, K, V> ExactSizeIterator for Iter<'a, K, V> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, K, V> FusedIterator for Iter<'a, K, V> {} #[stable(feature = "rust1", since = "1.0.0")] @@ -1773,7 +1773,7 @@ impl<'a, K, V> ExactSizeIterator for IterMut<'a, K, V> { self.inner.len() } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, K, V> FusedIterator for IterMut<'a, K, V> {} #[stable(feature = "std_debug", since = "1.16.0")] @@ -1808,7 +1808,7 @@ impl ExactSizeIterator for IntoIter { self.inner.len() } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for IntoIter {} #[stable(feature = "std_debug", since = "1.16.0")] @@ -1840,7 +1840,7 @@ impl<'a, K, V> ExactSizeIterator for Keys<'a, K, V> { self.inner.len() } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, K, V> FusedIterator for Keys<'a, K, V> {} #[stable(feature = "rust1", since = "1.0.0")] @@ -1863,7 +1863,7 @@ impl<'a, K, V> ExactSizeIterator for Values<'a, K, V> { self.inner.len() } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, K, V> FusedIterator for Values<'a, K, V> {} #[stable(feature = "map_values_mut", since = "1.10.0")] @@ -1886,7 +1886,7 @@ impl<'a, K, V> ExactSizeIterator for ValuesMut<'a, K, V> { self.inner.len() } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, K, V> FusedIterator for ValuesMut<'a, K, V> {} #[stable(feature = "std_debug", since = "1.16.0")] @@ -1921,7 +1921,7 @@ impl<'a, K, V> ExactSizeIterator for Drain<'a, K, V> { self.inner.len() } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, K, V> FusedIterator for Drain<'a, K, V> {} #[stable(feature = "std_debug", since = "1.16.0")] diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index e9427fb40a016..7a46603b2db50 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -1097,7 +1097,7 @@ impl<'a, K> ExactSizeIterator for Iter<'a, K> { self.iter.len() } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, K> FusedIterator for Iter<'a, K> {} #[stable(feature = "std_debug", since = "1.16.0")] @@ -1124,7 +1124,7 @@ impl ExactSizeIterator for IntoIter { self.iter.len() } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for IntoIter {} #[stable(feature = "std_debug", since = "1.16.0")] @@ -1155,7 +1155,7 @@ impl<'a, K> ExactSizeIterator for Drain<'a, K> { self.iter.len() } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, K> FusedIterator for Drain<'a, K> {} #[stable(feature = "std_debug", since = "1.16.0")] @@ -1208,7 +1208,7 @@ impl<'a, T, S> fmt::Debug for Intersection<'a, T, S> } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, T, S> FusedIterator for Intersection<'a, T, S> where T: Eq + Hash, S: BuildHasher @@ -1244,7 +1244,7 @@ impl<'a, T, S> Iterator for Difference<'a, T, S> } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, T, S> FusedIterator for Difference<'a, T, S> where T: Eq + Hash, S: BuildHasher @@ -1283,7 +1283,7 @@ impl<'a, T, S> Iterator for SymmetricDifference<'a, T, S> } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, T, S> FusedIterator for SymmetricDifference<'a, T, S> where T: Eq + Hash, S: BuildHasher @@ -1307,7 +1307,7 @@ impl<'a, T, S> Clone for Union<'a, T, S> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a, T, S> FusedIterator for Union<'a, T, S> where T: Eq + Hash, S: BuildHasher diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index d7d856fe3ad06..82c4443a45e6d 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -266,7 +266,6 @@ #![feature(float_from_str_radix)] #![feature(fn_traits)] #![feature(fnbox)] -#![feature(fused)] #![feature(generic_param_attrs)] #![feature(hashmap_hasher)] #![feature(heap_api)] diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 1608a752a463f..0c54fb00d2d7a 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -905,7 +905,7 @@ impl<'a> DoubleEndedIterator for Iter<'a> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a> FusedIterator for Iter<'a> {} #[stable(feature = "rust1", since = "1.0.0")] @@ -1008,7 +1008,7 @@ impl<'a> DoubleEndedIterator for Components<'a> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a> FusedIterator for Components<'a> {} #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libstd_unicode/char.rs b/src/libstd_unicode/char.rs index 844ff7a3c1252..2bbbf6c06559c 100644 --- a/src/libstd_unicode/char.rs +++ b/src/libstd_unicode/char.rs @@ -70,7 +70,7 @@ impl Iterator for ToLowercase { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for ToLowercase {} /// Returns an iterator that yields the uppercase equivalent of a `char`. @@ -92,7 +92,7 @@ impl Iterator for ToUppercase { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for ToUppercase {} #[derive(Debug)] diff --git a/src/libstd_unicode/lib.rs b/src/libstd_unicode/lib.rs index dcae7d0af4095..f155b62e3cc72 100644 --- a/src/libstd_unicode/lib.rs +++ b/src/libstd_unicode/lib.rs @@ -36,7 +36,6 @@ #![feature(str_internals)] #![feature(decode_utf8)] #![feature(fn_traits)] -#![feature(fused)] #![feature(lang_items)] #![feature(non_exhaustive)] #![feature(staged_api)] diff --git a/src/libstd_unicode/u_str.rs b/src/libstd_unicode/u_str.rs index 5d1611acb7ee6..ed2f205b580ba 100644 --- a/src/libstd_unicode/u_str.rs +++ b/src/libstd_unicode/u_str.rs @@ -127,7 +127,7 @@ impl Iterator for Utf16Encoder } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for Utf16Encoder where I: FusedIterator {} @@ -186,5 +186,5 @@ impl<'a> DoubleEndedIterator for SplitWhitespace<'a> { } } -#[unstable(feature = "fused", issue = "35602")] +#[stable(feature = "fused", since = "1.25.0")] impl<'a> FusedIterator for SplitWhitespace<'a> {} diff --git a/src/test/run-pass/issue-36053.rs b/src/test/run-pass/issue-36053.rs index 2411996cf054b..ece58eedc56ee 100644 --- a/src/test/run-pass/issue-36053.rs +++ b/src/test/run-pass/issue-36053.rs @@ -14,7 +14,6 @@ // `FusedIterator` in std but I was not able to isolate that into an // external crate. -#![feature(fused)] use std::iter::FusedIterator; struct Thing<'a>(&'a str); From c7c23fe9482c129855a667909ff58969f6efe1f6 Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Sat, 3 Mar 2018 14:15:28 +0100 Subject: [PATCH 20/31] core: Update stability attributes for FusedIterator --- src/liballoc/binary_heap.rs | 6 ++--- src/liballoc/boxed.rs | 2 +- src/liballoc/btree/map.rs | 16 ++++++------ src/liballoc/btree/set.rs | 14 +++++----- src/liballoc/linked_list.rs | 6 ++--- src/liballoc/str.rs | 2 +- src/liballoc/string.rs | 2 +- src/liballoc/vec.rs | 4 +-- src/liballoc/vec_deque.rs | 8 +++--- src/libcore/char.rs | 8 +++--- src/libcore/iter/mod.rs | 42 +++++++++++++++--------------- src/libcore/iter/range.rs | 6 ++--- src/libcore/iter/sources.rs | 8 +++--- src/libcore/iter/traits.rs | 4 +-- src/libcore/option.rs | 6 ++--- src/libcore/result.rs | 6 ++--- src/libcore/slice/mod.rs | 22 +++++++--------- src/libcore/str/mod.rs | 14 +++++----- src/libstd/ascii.rs | 2 +- src/libstd/collections/hash/map.rs | 14 +++++----- src/libstd/collections/hash/set.rs | 14 +++++----- src/libstd/path.rs | 6 ++--- src/libstd_unicode/char.rs | 4 +-- src/libstd_unicode/u_str.rs | 3 +-- 24 files changed, 108 insertions(+), 111 deletions(-) diff --git a/src/liballoc/binary_heap.rs b/src/liballoc/binary_heap.rs index a5694a90dbc9a..8aaac5d6e08a5 100644 --- a/src/liballoc/binary_heap.rs +++ b/src/liballoc/binary_heap.rs @@ -964,7 +964,7 @@ impl<'a, T> ExactSizeIterator for Iter<'a, T> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, T> FusedIterator for Iter<'a, T> {} /// An owning iterator over the elements of a `BinaryHeap`. @@ -1019,7 +1019,7 @@ impl ExactSizeIterator for IntoIter { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for IntoIter {} /// A draining iterator over the elements of a `BinaryHeap`. @@ -1065,7 +1065,7 @@ impl<'a, T: 'a> ExactSizeIterator for Drain<'a, T> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, T: 'a> FusedIterator for Drain<'a, T> {} #[stable(feature = "binary_heap_extras_15", since = "1.5.0")] diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 6b000b6fa91ba..b776556d59f11 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -722,7 +722,7 @@ impl ExactSizeIterator for Box { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for Box {} diff --git a/src/liballoc/btree/map.rs b/src/liballoc/btree/map.rs index 7b7a6374db9bb..ed9c8c18f0d6d 100644 --- a/src/liballoc/btree/map.rs +++ b/src/liballoc/btree/map.rs @@ -1156,7 +1156,7 @@ impl<'a, K: 'a, V: 'a> Iterator for Iter<'a, K, V> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, K, V> FusedIterator for Iter<'a, K, V> {} #[stable(feature = "rust1", since = "1.0.0")] @@ -1235,7 +1235,7 @@ impl<'a, K: 'a, V: 'a> ExactSizeIterator for IterMut<'a, K, V> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, K, V> FusedIterator for IterMut<'a, K, V> {} #[stable(feature = "rust1", since = "1.0.0")] @@ -1365,7 +1365,7 @@ impl ExactSizeIterator for IntoIter { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for IntoIter {} #[stable(feature = "rust1", since = "1.0.0")] @@ -1395,7 +1395,7 @@ impl<'a, K, V> ExactSizeIterator for Keys<'a, K, V> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, K, V> FusedIterator for Keys<'a, K, V> {} #[stable(feature = "rust1", since = "1.0.0")] @@ -1432,7 +1432,7 @@ impl<'a, K, V> ExactSizeIterator for Values<'a, K, V> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, K, V> FusedIterator for Values<'a, K, V> {} #[stable(feature = "rust1", since = "1.0.0")] @@ -1482,7 +1482,7 @@ impl<'a, K, V> ExactSizeIterator for ValuesMut<'a, K, V> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, K, V> FusedIterator for ValuesMut<'a, K, V> {} @@ -1561,7 +1561,7 @@ impl<'a, K, V> Range<'a, K, V> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, K, V> FusedIterator for Range<'a, K, V> {} #[stable(feature = "btree_range", since = "1.17.0")] @@ -1630,7 +1630,7 @@ impl<'a, K, V> DoubleEndedIterator for RangeMut<'a, K, V> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, K, V> FusedIterator for RangeMut<'a, K, V> {} impl<'a, K, V> RangeMut<'a, K, V> { diff --git a/src/liballoc/btree/set.rs b/src/liballoc/btree/set.rs index 34cb7a08ed706..2e3157147a085 100644 --- a/src/liballoc/btree/set.rs +++ b/src/liballoc/btree/set.rs @@ -946,7 +946,7 @@ impl<'a, T> ExactSizeIterator for Iter<'a, T> { fn len(&self) -> usize { self.iter.len() } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, T> FusedIterator for Iter<'a, T> {} #[stable(feature = "rust1", since = "1.0.0")] @@ -971,7 +971,7 @@ impl ExactSizeIterator for IntoIter { fn len(&self) -> usize { self.iter.len() } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for IntoIter {} #[stable(feature = "btree_range", since = "1.17.0")] @@ -997,7 +997,7 @@ impl<'a, T> DoubleEndedIterator for Range<'a, T> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, T> FusedIterator for Range<'a, T> {} /// Compare `x` and `y`, but return `short` if x is None and `long` if y is None @@ -1044,7 +1044,7 @@ impl<'a, T: Ord> Iterator for Difference<'a, T> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, T: Ord> FusedIterator for Difference<'a, T> {} #[stable(feature = "rust1", since = "1.0.0")] @@ -1078,7 +1078,7 @@ impl<'a, T: Ord> Iterator for SymmetricDifference<'a, T> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, T: Ord> FusedIterator for SymmetricDifference<'a, T> {} #[stable(feature = "rust1", since = "1.0.0")] @@ -1116,7 +1116,7 @@ impl<'a, T: Ord> Iterator for Intersection<'a, T> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, T: Ord> FusedIterator for Intersection<'a, T> {} #[stable(feature = "rust1", since = "1.0.0")] @@ -1150,5 +1150,5 @@ impl<'a, T: Ord> Iterator for Union<'a, T> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, T: Ord> FusedIterator for Union<'a, T> {} diff --git a/src/liballoc/linked_list.rs b/src/liballoc/linked_list.rs index 87939fddfc81f..097d2e414f5cc 100644 --- a/src/liballoc/linked_list.rs +++ b/src/liballoc/linked_list.rs @@ -897,7 +897,7 @@ impl<'a, T> DoubleEndedIterator for Iter<'a, T> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> ExactSizeIterator for Iter<'a, T> {} -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, T> FusedIterator for Iter<'a, T> {} #[stable(feature = "rust1", since = "1.0.0")] @@ -946,7 +946,7 @@ impl<'a, T> DoubleEndedIterator for IterMut<'a, T> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> ExactSizeIterator for IterMut<'a, T> {} -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, T> FusedIterator for IterMut<'a, T> {} impl<'a, T> IterMut<'a, T> { @@ -1117,7 +1117,7 @@ impl DoubleEndedIterator for IntoIter { #[stable(feature = "rust1", since = "1.0.0")] impl ExactSizeIterator for IntoIter {} -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for IntoIter {} #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index 1a431bb269420..82f8476d670a3 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -171,7 +171,7 @@ impl<'a> Iterator for EncodeUtf16<'a> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a> FusedIterator for EncodeUtf16<'a> {} #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 1fcabd8a4278c..370fb6b4e890f 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -2254,5 +2254,5 @@ impl<'a> DoubleEndedIterator for Drain<'a> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a> FusedIterator for Drain<'a> {} diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 03c9750fb3928..9e5672ef148c4 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -2389,7 +2389,7 @@ impl ExactSizeIterator for IntoIter { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for IntoIter {} #[unstable(feature = "trusted_len", issue = "37572")] @@ -2495,7 +2495,7 @@ impl<'a, T> ExactSizeIterator for Drain<'a, T> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, T> FusedIterator for Drain<'a, T> {} /// A place for insertion at the back of a `Vec`. diff --git a/src/liballoc/vec_deque.rs b/src/liballoc/vec_deque.rs index 3d7549abe6ff5..68add3cbd51f8 100644 --- a/src/liballoc/vec_deque.rs +++ b/src/liballoc/vec_deque.rs @@ -1991,7 +1991,7 @@ impl<'a, T> ExactSizeIterator for Iter<'a, T> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, T> FusedIterator for Iter<'a, T> {} @@ -2084,7 +2084,7 @@ impl<'a, T> ExactSizeIterator for IterMut<'a, T> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, T> FusedIterator for IterMut<'a, T> {} /// An owning iterator over the elements of a `VecDeque`. @@ -2140,7 +2140,7 @@ impl ExactSizeIterator for IntoIter { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for IntoIter {} /// A draining iterator over the elements of a `VecDeque`. @@ -2247,7 +2247,7 @@ impl<'a, T: 'a> DoubleEndedIterator for Drain<'a, T> { #[stable(feature = "drain", since = "1.6.0")] impl<'a, T: 'a> ExactSizeIterator for Drain<'a, T> {} -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, T: 'a> FusedIterator for Drain<'a, T> {} #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/char.rs b/src/libcore/char.rs index 3ff31a7a92815..c90cca7dbe443 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -643,7 +643,7 @@ impl ExactSizeIterator for EscapeUnicode { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for EscapeUnicode {} #[stable(feature = "char_struct_display", since = "1.16.0")] @@ -756,7 +756,7 @@ impl ExactSizeIterator for EscapeDefault { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for EscapeDefault {} #[stable(feature = "char_struct_display", since = "1.16.0")] @@ -790,7 +790,7 @@ impl Iterator for EscapeDebug { #[stable(feature = "char_escape_debug", since = "1.20.0")] impl ExactSizeIterator for EscapeDebug { } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for EscapeDebug {} #[stable(feature = "char_escape_debug", since = "1.20.0")] @@ -904,5 +904,5 @@ impl> Iterator for DecodeUtf8 { } } -#[stable(feature = "fused", since = "1.25.0")] +#[unstable(feature = "decode_utf8", issue = "33906")] impl> FusedIterator for DecodeUtf8 {} diff --git a/src/libcore/iter/mod.rs b/src/libcore/iter/mod.rs index 9a8f7fc4e6abd..a6802d606ca8c 100644 --- a/src/libcore/iter/mod.rs +++ b/src/libcore/iter/mod.rs @@ -344,7 +344,7 @@ pub use self::sources::{Once, once}; pub use self::traits::{FromIterator, IntoIterator, DoubleEndedIterator, Extend}; #[stable(feature = "rust1", since = "1.0.0")] pub use self::traits::{ExactSizeIterator, Sum, Product}; -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] pub use self::traits::FusedIterator; #[unstable(feature = "trusted_len", issue = "37572")] pub use self::traits::TrustedLen; @@ -506,7 +506,7 @@ impl ExactSizeIterator for Rev } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for Rev where I: FusedIterator + DoubleEndedIterator {} @@ -589,7 +589,7 @@ impl<'a, I, T: 'a> ExactSizeIterator for Cloned } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, I, T: 'a> FusedIterator for Cloned where I: FusedIterator, T: Clone {} @@ -662,7 +662,7 @@ impl Iterator for Cycle where I: Clone + Iterator { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for Cycle where I: Clone + Iterator {} /// An iterator for stepping iterators by a custom amount. @@ -1002,7 +1002,7 @@ impl DoubleEndedIterator for Chain where } // Note: *both* must be fused to handle double-ended iterators. -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for Chain where A: FusedIterator, B: FusedIterator, @@ -1262,7 +1262,7 @@ unsafe impl TrustedRandomAccess for Zip } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for Zip where A: FusedIterator, B: FusedIterator, {} @@ -1404,7 +1404,7 @@ impl ExactSizeIterator for Map } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for Map where F: FnMut(I::Item) -> B {} @@ -1553,7 +1553,7 @@ impl DoubleEndedIterator for Filter } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for Filter where P: FnMut(&I::Item) -> bool {} @@ -1663,7 +1663,7 @@ impl DoubleEndedIterator for FilterMap } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for FilterMap where F: FnMut(I::Item) -> Option {} @@ -1818,7 +1818,7 @@ unsafe impl TrustedRandomAccess for Enumerate } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for Enumerate where I: FusedIterator {} #[unstable(feature = "trusted_len", issue = "37572")] @@ -1938,7 +1938,7 @@ impl Iterator for Peekable { #[stable(feature = "rust1", since = "1.0.0")] impl ExactSizeIterator for Peekable {} -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for Peekable {} impl Peekable { @@ -2072,7 +2072,7 @@ impl Iterator for SkipWhile } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for SkipWhile where I: FusedIterator, P: FnMut(&I::Item) -> bool {} @@ -2151,7 +2151,7 @@ impl Iterator for TakeWhile } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for TakeWhile where I: FusedIterator, P: FnMut(&I::Item) -> bool {} @@ -2290,7 +2290,7 @@ impl DoubleEndedIterator for Skip where I: DoubleEndedIterator + ExactSize } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for Skip where I: FusedIterator {} /// An iterator that only iterates over the first `n` iterations of `iter`. @@ -2371,7 +2371,7 @@ impl Iterator for Take where I: Iterator{ #[stable(feature = "rust1", since = "1.0.0")] impl ExactSizeIterator for Take where I: ExactSizeIterator {} -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for Take where I: FusedIterator {} #[unstable(feature = "trusted_len", issue = "37572")] @@ -2517,7 +2517,7 @@ impl DoubleEndedIterator for FlatMap } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for FlatMap where I: FusedIterator, U: IntoIterator, F: FnMut(I::Item) -> U {} @@ -2605,7 +2605,7 @@ impl DoubleEndedIterator for Flatten } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for Flatten where I: FusedIterator, U: Iterator, I::Item: IntoIterator {} @@ -2765,7 +2765,7 @@ pub struct Fuse { done: bool } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for Fuse where I: Iterator {} #[stable(feature = "rust1", since = "1.0.0")] @@ -2896,7 +2896,7 @@ unsafe impl TrustedRandomAccess for Fuse } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl Iterator for Fuse where I: FusedIterator { #[inline] fn next(&mut self) -> Option<::Item> { @@ -2938,7 +2938,7 @@ impl Iterator for Fuse where I: FusedIterator { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl DoubleEndedIterator for Fuse where I: DoubleEndedIterator + FusedIterator { @@ -3082,6 +3082,6 @@ impl ExactSizeIterator for Inspect } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for Inspect where F: FnMut(&I::Item) {} diff --git a/src/libcore/iter/range.rs b/src/libcore/iter/range.rs index 7f3b227e8b733..9a3fd215dcfeb 100644 --- a/src/libcore/iter/range.rs +++ b/src/libcore/iter/range.rs @@ -295,7 +295,7 @@ impl DoubleEndedIterator for ops::Range { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for ops::Range {} #[stable(feature = "rust1", since = "1.0.0")] @@ -322,7 +322,7 @@ impl Iterator for ops::RangeFrom { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for ops::RangeFrom {} #[unstable(feature = "trusted_len", issue = "37572")] @@ -463,5 +463,5 @@ impl DoubleEndedIterator for ops::RangeInclusive { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for ops::RangeInclusive {} diff --git a/src/libcore/iter/sources.rs b/src/libcore/iter/sources.rs index 149dff83bc0e1..0fc1a3aa8ac06 100644 --- a/src/libcore/iter/sources.rs +++ b/src/libcore/iter/sources.rs @@ -41,7 +41,7 @@ impl DoubleEndedIterator for Repeat { fn next_back(&mut self) -> Option { Some(self.element.clone()) } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for Repeat {} #[unstable(feature = "trusted_len", issue = "37572")] @@ -135,7 +135,7 @@ impl A> DoubleEndedIterator for RepeatWith { fn next_back(&mut self) -> Option { self.next() } } -#[unstable(feature = "fused", issue = "35602")] +#[unstable(feature = "iterator_repeat_with", issue = "48169")] impl A> FusedIterator for RepeatWith {} #[unstable(feature = "trusted_len", issue = "37572")] @@ -259,7 +259,7 @@ impl ExactSizeIterator for Empty { #[unstable(feature = "trusted_len", issue = "37572")] unsafe impl TrustedLen for Empty {} -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for Empty {} // not #[derive] because that adds a Clone bound on T, @@ -340,7 +340,7 @@ impl ExactSizeIterator for Once { #[unstable(feature = "trusted_len", issue = "37572")] unsafe impl TrustedLen for Once {} -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for Once {} /// Creates an iterator that yields an element exactly once. diff --git a/src/libcore/iter/traits.rs b/src/libcore/iter/traits.rs index a86f4e74706e2..0267fcd375453 100644 --- a/src/libcore/iter/traits.rs +++ b/src/libcore/iter/traits.rs @@ -959,10 +959,10 @@ impl Product> for Result /// [`None`]: ../../std/option/enum.Option.html#variant.None /// [`Iterator::fuse`]: ../../std/iter/trait.Iterator.html#method.fuse /// [`Fuse`]: ../../std/iter/struct.Fuse.html -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] pub trait FusedIterator: Iterator {} -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, I: FusedIterator + ?Sized> FusedIterator for &'a mut I {} /// An iterator that reports an accurate length using size_hint. diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 99c1d7d9b3619..b66aad246fe05 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -1051,7 +1051,7 @@ impl<'a, A> DoubleEndedIterator for Iter<'a, A> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, A> ExactSizeIterator for Iter<'a, A> {} -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, A> FusedIterator for Iter<'a, A> {} #[unstable(feature = "trusted_len", issue = "37572")] @@ -1096,7 +1096,7 @@ impl<'a, A> DoubleEndedIterator for IterMut<'a, A> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, A> ExactSizeIterator for IterMut<'a, A> {} -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, A> FusedIterator for IterMut<'a, A> {} #[unstable(feature = "trusted_len", issue = "37572")] unsafe impl<'a, A> TrustedLen for IterMut<'a, A> {} @@ -1133,7 +1133,7 @@ impl DoubleEndedIterator for IntoIter { #[stable(feature = "rust1", since = "1.0.0")] impl ExactSizeIterator for IntoIter {} -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for IntoIter {} #[unstable(feature = "trusted_len", issue = "37572")] diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 5131fc837ef29..c152d4979b90e 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -1038,7 +1038,7 @@ impl<'a, T> DoubleEndedIterator for Iter<'a, T> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> ExactSizeIterator for Iter<'a, T> {} -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, T> FusedIterator for Iter<'a, T> {} #[unstable(feature = "trusted_len", issue = "37572")] @@ -1082,7 +1082,7 @@ impl<'a, T> DoubleEndedIterator for IterMut<'a, T> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> ExactSizeIterator for IterMut<'a, T> {} -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, T> FusedIterator for IterMut<'a, T> {} #[unstable(feature = "trusted_len", issue = "37572")] @@ -1125,7 +1125,7 @@ impl DoubleEndedIterator for IntoIter { #[stable(feature = "rust1", since = "1.0.0")] impl ExactSizeIterator for IntoIter {} -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for IntoIter {} #[unstable(feature = "trusted_len", issue = "37572")] diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 02207f1738f12..4f1ee2d949191 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -1461,7 +1461,7 @@ impl<'a, T> ExactSizeIterator for Iter<'a, T> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, T> FusedIterator for Iter<'a, T> {} #[unstable(feature = "trusted_len", issue = "37572")] @@ -1589,7 +1589,7 @@ impl<'a, T> ExactSizeIterator for IterMut<'a, T> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, T> FusedIterator for IterMut<'a, T> {} #[unstable(feature = "trusted_len", issue = "37572")] @@ -1737,7 +1737,7 @@ impl<'a, T, P> SplitIter for Split<'a, T, P> where P: FnMut(&T) -> bool { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, T, P> FusedIterator for Split<'a, T, P> where P: FnMut(&T) -> bool {} /// An iterator over the subslices of the vector which are separated @@ -1835,7 +1835,7 @@ impl<'a, T, P> DoubleEndedIterator for SplitMut<'a, T, P> where } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, T, P> FusedIterator for SplitMut<'a, T, P> where P: FnMut(&T) -> bool {} /// An iterator over subslices separated by elements that match a predicate @@ -1892,7 +1892,6 @@ impl<'a, T, P> SplitIter for RSplit<'a, T, P> where P: FnMut(&T) -> bool { } } -//#[stable(feature = "fused", since = "1.25.0")] #[unstable(feature = "slice_rsplit", issue = "41020")] impl<'a, T, P> FusedIterator for RSplit<'a, T, P> where P: FnMut(&T) -> bool {} @@ -1951,7 +1950,6 @@ impl<'a, T, P> DoubleEndedIterator for RSplitMut<'a, T, P> where } } -//#[stable(feature = "fused", since = "1.25.0")] #[unstable(feature = "slice_rsplit", issue = "41020")] impl<'a, T, P> FusedIterator for RSplitMut<'a, T, P> where P: FnMut(&T) -> bool {} @@ -2088,7 +2086,7 @@ macro_rules! forward_iterator { } } - #[stable(feature = "fused", since = "1.25.0")] + #[stable(feature = "fused", since = "1.26.0")] impl<'a, $elem, P> FusedIterator for $name<'a, $elem, P> where P: FnMut(&T) -> bool {} } @@ -2194,7 +2192,7 @@ impl<'a, T> DoubleEndedIterator for Windows<'a, T> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> ExactSizeIterator for Windows<'a, T> {} -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, T> FusedIterator for Windows<'a, T> {} #[doc(hidden)] @@ -2313,7 +2311,7 @@ impl<'a, T> DoubleEndedIterator for Chunks<'a, T> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> ExactSizeIterator for Chunks<'a, T> {} -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, T> FusedIterator for Chunks<'a, T> {} #[doc(hidden)] @@ -2429,7 +2427,7 @@ impl<'a, T> DoubleEndedIterator for ChunksMut<'a, T> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> ExactSizeIterator for ChunksMut<'a, T> {} -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, T> FusedIterator for ChunksMut<'a, T> {} #[doc(hidden)] @@ -2539,7 +2537,7 @@ impl<'a, T> ExactSizeIterator for ExactChunks<'a, T> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[unstable(feature = "exact_chunks", issue = "47115")] impl<'a, T> FusedIterator for ExactChunks<'a, T> {} #[doc(hidden)] @@ -2636,7 +2634,7 @@ impl<'a, T> ExactSizeIterator for ExactChunksMut<'a, T> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[unstable(feature = "exact_chunks", issue = "47115")] impl<'a, T> FusedIterator for ExactChunksMut<'a, T> {} #[doc(hidden)] diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 7e919b653f21e..e225c9522bc06 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -609,7 +609,7 @@ impl<'a> DoubleEndedIterator for Chars<'a> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a> FusedIterator for Chars<'a> {} impl<'a> Chars<'a> { @@ -702,7 +702,7 @@ impl<'a> DoubleEndedIterator for CharIndices<'a> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a> FusedIterator for CharIndices<'a> {} impl<'a> CharIndices<'a> { @@ -817,7 +817,7 @@ impl<'a> ExactSizeIterator for Bytes<'a> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a> FusedIterator for Bytes<'a> {} #[unstable(feature = "trusted_len", issue = "37572")] @@ -977,10 +977,10 @@ macro_rules! generate_pattern_iterators { } } - #[stable(feature = "fused", since = "1.25.0")] + #[stable(feature = "fused", since = "1.26.0")] impl<'a, P: Pattern<'a>> FusedIterator for $forward_iterator<'a, P> {} - #[stable(feature = "fused", since = "1.25.0")] + #[stable(feature = "fused", since = "1.26.0")] impl<'a, P: Pattern<'a>> FusedIterator for $reverse_iterator<'a, P> where P::Searcher: ReverseSearcher<'a> {} @@ -1337,7 +1337,7 @@ impl<'a> DoubleEndedIterator for Lines<'a> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a> FusedIterator for Lines<'a> {} /// Created with the method [`lines_any`]. @@ -1403,7 +1403,7 @@ impl<'a> DoubleEndedIterator for LinesAny<'a> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] #[allow(deprecated)] impl<'a> FusedIterator for LinesAny<'a> {} diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index ce3e38de7eb1f..d5bf9e9bb2f68 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -590,7 +590,7 @@ impl DoubleEndedIterator for EscapeDefault { } #[stable(feature = "rust1", since = "1.0.0")] impl ExactSizeIterator for EscapeDefault {} -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for EscapeDefault {} #[stable(feature = "std_debug", since = "1.16.0")] diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 9e48efeb1136c..e86264569a037 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1750,7 +1750,7 @@ impl<'a, K, V> ExactSizeIterator for Iter<'a, K, V> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, K, V> FusedIterator for Iter<'a, K, V> {} #[stable(feature = "rust1", since = "1.0.0")] @@ -1773,7 +1773,7 @@ impl<'a, K, V> ExactSizeIterator for IterMut<'a, K, V> { self.inner.len() } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, K, V> FusedIterator for IterMut<'a, K, V> {} #[stable(feature = "std_debug", since = "1.16.0")] @@ -1808,7 +1808,7 @@ impl ExactSizeIterator for IntoIter { self.inner.len() } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for IntoIter {} #[stable(feature = "std_debug", since = "1.16.0")] @@ -1840,7 +1840,7 @@ impl<'a, K, V> ExactSizeIterator for Keys<'a, K, V> { self.inner.len() } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, K, V> FusedIterator for Keys<'a, K, V> {} #[stable(feature = "rust1", since = "1.0.0")] @@ -1863,7 +1863,7 @@ impl<'a, K, V> ExactSizeIterator for Values<'a, K, V> { self.inner.len() } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, K, V> FusedIterator for Values<'a, K, V> {} #[stable(feature = "map_values_mut", since = "1.10.0")] @@ -1886,7 +1886,7 @@ impl<'a, K, V> ExactSizeIterator for ValuesMut<'a, K, V> { self.inner.len() } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, K, V> FusedIterator for ValuesMut<'a, K, V> {} #[stable(feature = "std_debug", since = "1.16.0")] @@ -1921,7 +1921,7 @@ impl<'a, K, V> ExactSizeIterator for Drain<'a, K, V> { self.inner.len() } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, K, V> FusedIterator for Drain<'a, K, V> {} #[stable(feature = "std_debug", since = "1.16.0")] diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 7a46603b2db50..f41b7a62918a2 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -1097,7 +1097,7 @@ impl<'a, K> ExactSizeIterator for Iter<'a, K> { self.iter.len() } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, K> FusedIterator for Iter<'a, K> {} #[stable(feature = "std_debug", since = "1.16.0")] @@ -1124,7 +1124,7 @@ impl ExactSizeIterator for IntoIter { self.iter.len() } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for IntoIter {} #[stable(feature = "std_debug", since = "1.16.0")] @@ -1155,7 +1155,7 @@ impl<'a, K> ExactSizeIterator for Drain<'a, K> { self.iter.len() } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, K> FusedIterator for Drain<'a, K> {} #[stable(feature = "std_debug", since = "1.16.0")] @@ -1208,7 +1208,7 @@ impl<'a, T, S> fmt::Debug for Intersection<'a, T, S> } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, T, S> FusedIterator for Intersection<'a, T, S> where T: Eq + Hash, S: BuildHasher @@ -1244,7 +1244,7 @@ impl<'a, T, S> Iterator for Difference<'a, T, S> } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, T, S> FusedIterator for Difference<'a, T, S> where T: Eq + Hash, S: BuildHasher @@ -1283,7 +1283,7 @@ impl<'a, T, S> Iterator for SymmetricDifference<'a, T, S> } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, T, S> FusedIterator for SymmetricDifference<'a, T, S> where T: Eq + Hash, S: BuildHasher @@ -1307,7 +1307,7 @@ impl<'a, T, S> Clone for Union<'a, T, S> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a, T, S> FusedIterator for Union<'a, T, S> where T: Eq + Hash, S: BuildHasher diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 0c54fb00d2d7a..cd2af99d6ac1f 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -905,7 +905,7 @@ impl<'a> DoubleEndedIterator for Iter<'a> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a> FusedIterator for Iter<'a> {} #[stable(feature = "rust1", since = "1.0.0")] @@ -1008,7 +1008,7 @@ impl<'a> DoubleEndedIterator for Components<'a> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a> FusedIterator for Components<'a> {} #[stable(feature = "rust1", since = "1.0.0")] @@ -1076,7 +1076,7 @@ impl<'a> Iterator for Ancestors<'a> { } } -#[unstable(feature = "fused", issue = "35602")] +#[unstable(feature = "path_ancestors", issue = "48581")] impl<'a> FusedIterator for Ancestors<'a> {} //////////////////////////////////////////////////////////////////////////////// diff --git a/src/libstd_unicode/char.rs b/src/libstd_unicode/char.rs index 2bbbf6c06559c..8d3df749ed7dd 100644 --- a/src/libstd_unicode/char.rs +++ b/src/libstd_unicode/char.rs @@ -70,7 +70,7 @@ impl Iterator for ToLowercase { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for ToLowercase {} /// Returns an iterator that yields the uppercase equivalent of a `char`. @@ -92,7 +92,7 @@ impl Iterator for ToUppercase { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for ToUppercase {} #[derive(Debug)] diff --git a/src/libstd_unicode/u_str.rs b/src/libstd_unicode/u_str.rs index ed2f205b580ba..a72e1210d93f6 100644 --- a/src/libstd_unicode/u_str.rs +++ b/src/libstd_unicode/u_str.rs @@ -127,7 +127,6 @@ impl Iterator for Utf16Encoder } } -#[stable(feature = "fused", since = "1.25.0")] impl FusedIterator for Utf16Encoder where I: FusedIterator {} @@ -186,5 +185,5 @@ impl<'a> DoubleEndedIterator for SplitWhitespace<'a> { } } -#[stable(feature = "fused", since = "1.25.0")] +#[stable(feature = "fused", since = "1.26.0")] impl<'a> FusedIterator for SplitWhitespace<'a> {} From fc33b2567cac0ae453807f4118872ab81a16ddf7 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Sat, 3 Mar 2018 21:55:04 +0100 Subject: [PATCH 21/31] Improve getting literal representation --- src/librustc_lint/types.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index 02aef271c37db..e778b2d386105 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -368,7 +368,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { let src = cx.sess().codemap().span_to_snippet(lit.span).ok()?; let firstch = src.chars().next()?; - if let Some(0) = char::to_digit(firstch, 10) { + if firstch == '0' { match src.chars().nth(1) { Some('x') | Some('b') => return Some(src), _ => return None, From 683bdc7f0a20236c7dd5a8a731951ef5db14b3be Mon Sep 17 00:00:00 2001 From: Shotaro Yamada Date: Sun, 4 Mar 2018 09:00:09 +0900 Subject: [PATCH 22/31] Add comments --- src/liballoc/str.rs | 60 ++++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index 08ba4a180ed53..6d153bf02b3ba 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -2071,35 +2071,55 @@ impl str { return String::new(); } - // n = 2^j + k (2^j > k) - - // 2^j: - let mut s = Vec::with_capacity(self.len() * n); - s.extend(self.as_bytes()); - let mut m = n >> 1; - while m > 0 { - let len = s.len(); - unsafe { - ptr::copy_nonoverlapping(s.as_ptr(), (s.as_mut_ptr() as *mut u8).add(len), len); - s.set_len(len * 2); + // If `n` is larger than zero, it can be split as + // `n = 2^expn + rem (2^expn > rem, expn >= 0, rem >= 0)`. + // `2^expn` is the number represented by the leftmost '1' bit of `n`, + // and `rem` is the remaining part of `n`. + + // Using `Vec` to access `set_len()`. + let mut buf = Vec::with_capacity(self.len() * n); + + // `2^expn` repetition is done by doubling `buf` `expn`-times. + buf.extend(self.as_bytes()); + { + let mut m = n >> 1; + // If `m > 0`, there are remaining bits up to the leftmost '1'. + while m > 0 { + // `buf.extend(buf)`: + unsafe { + ptr::copy_nonoverlapping( + buf.as_ptr(), + (buf.as_mut_ptr() as *mut u8).add(buf.len()), + buf.len(), + ); + // `buf` has capacity of `self.len() * n`. + let buf_len = buf.len(); + buf.set_len(buf_len * 2); + } + + m >>= 1; } - m >>= 1; } - // k: - let res_len = n * self.len(); - if res_len > s.len() { + // `rem` (`= n - 2^expn`) repetition is done by copying + // first `rem` repetitions from `buf` itself. + let rem_len = self.len() * n - buf.len(); // `self.len() * rem` + if rem_len > 0 { + // `buf.extend(buf[0 .. rem_len])`: unsafe { + // This is non-overlapping since `2^expn > rem`. ptr::copy_nonoverlapping( - s.as_ptr(), - (s.as_mut_ptr() as *mut u8).add(s.len()), - res_len - s.len(), + buf.as_ptr(), + (buf.as_mut_ptr() as *mut u8).add(buf.len()), + rem_len, ); - s.set_len(res_len); + // `buf.len() + rem_len` equals to `buf.capacity()` (`self.len() * n`). + let buf_len = buf.len(); + buf.set_len(buf_len + rem_len); } } - unsafe { String::from_utf8_unchecked(s) } + unsafe { String::from_utf8_unchecked(buf) } } /// Checks if all characters in this string are within the ASCII range. From 3d58543d49266a7ec3eb5f5f2ffaf902fce17c53 Mon Sep 17 00:00:00 2001 From: Shotaro Yamada Date: Sun, 4 Mar 2018 09:43:29 +0900 Subject: [PATCH 23/31] Avoid unnecessary calculation --- src/liballoc/str.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index 6d153bf02b3ba..64e815b1fbaa5 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -2113,9 +2113,9 @@ impl str { (buf.as_mut_ptr() as *mut u8).add(buf.len()), rem_len, ); - // `buf.len() + rem_len` equals to `buf.capacity()` (`self.len() * n`). - let buf_len = buf.len(); - buf.set_len(buf_len + rem_len); + // `buf.len() + rem_len` equals to `buf.capacity()` (`= self.len() * n`). + let buf_cap = buf.capacity(); + buf.set_len(buf_cap); } } From 0b0e1b71d5818438f062b35b5890ce72a38f2678 Mon Sep 17 00:00:00 2001 From: "leonardo.yvens" Date: Sun, 4 Mar 2018 08:12:03 -0300 Subject: [PATCH 24/31] Refactor contrived match. --- src/librustc_mir/transform/lower_128bit.rs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/librustc_mir/transform/lower_128bit.rs b/src/librustc_mir/transform/lower_128bit.rs index 981b0b854bdab..83cd7bf549d55 100644 --- a/src/librustc_mir/transform/lower_128bit.rs +++ b/src/librustc_mir/transform/lower_128bit.rs @@ -77,19 +77,12 @@ impl Lower128Bit { }; let bin_statement = block.statements.pop().unwrap(); - let (source_info, place, lhs, mut rhs) = match bin_statement { - Statement { - source_info, - kind: StatementKind::Assign( - place, - Rvalue::BinaryOp(_, lhs, rhs)) - } => (source_info, place, lhs, rhs), - Statement { - source_info, - kind: StatementKind::Assign( - place, - Rvalue::CheckedBinaryOp(_, lhs, rhs)) - } => (source_info, place, lhs, rhs), + let source_info = bin_statement.source_info; + let (place, lhs, mut rhs) = match bin_statement.kind { + StatementKind::Assign(place, Rvalue::BinaryOp(_, lhs, rhs)) + | StatementKind::Assign(place, Rvalue::CheckedBinaryOp(_, lhs, rhs)) => { + (place, lhs, rhs) + } _ => bug!("Statement doesn't match pattern any more?"), }; From 1c191b209b3af4f23e4bb1c249e0f259f2ee0390 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 26 Feb 2018 15:04:40 +0100 Subject: [PATCH 25/31] Add note for unterminated raw string error --- src/libsyntax/parse/lexer/mod.rs | 33 ++++++++++++++++++++++++-------- src/test/ui/raw_string.rs | 14 ++++++++++++++ src/test/ui/raw_string.stderr | 8 ++++++++ 3 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 src/test/ui/raw_string.rs create mode 100644 src/test/ui/raw_string.stderr diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index b5368b3ecabdd..94195ccc72c49 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -132,6 +132,18 @@ impl<'a> StringReader<'a> { self.advance_token()?; Ok(ret_val) } + + fn fail_unterminated_raw_string(&self, pos: BytePos, hash_count: usize) { + let mut err = self.struct_span_fatal(pos, pos, "unterminated raw string"); + err.span_label(self.mk_sp(pos, pos), "unterminated raw string"); + if hash_count > 0 { + err.note(&format!("this raw string should be terminated with `\"{}`", + "#".repeat(hash_count))); + } + err.emit(); + FatalError.raise(); + } + fn fatal(&self, m: &str) -> FatalError { self.fatal_span(self.peek_span, m) } @@ -269,6 +281,15 @@ impl<'a> StringReader<'a> { Self::push_escaped_char_for_msg(&mut m, c); self.fatal_span_(from_pos, to_pos, &m[..]) } + + fn struct_span_fatal(&self, + from_pos: BytePos, + to_pos: BytePos, + m: &str) + -> DiagnosticBuilder<'a> { + self.sess.span_diagnostic.struct_span_fatal(self.mk_sp(from_pos, to_pos), m) + } + fn struct_fatal_span_char(&self, from_pos: BytePos, to_pos: BytePos, @@ -1404,8 +1425,7 @@ impl<'a> StringReader<'a> { } if self.is_eof() { - let last_bpos = self.pos; - self.fatal_span_(start_bpos, last_bpos, "unterminated raw string").raise(); + self.fail_unterminated_raw_string(start_bpos, hash_count); } else if !self.ch_is('"') { let last_bpos = self.pos; let curr_char = self.ch.unwrap(); @@ -1421,8 +1441,7 @@ impl<'a> StringReader<'a> { let mut valid = true; 'outer: loop { if self.is_eof() { - let last_bpos = self.pos; - self.fatal_span_(start_bpos, last_bpos, "unterminated raw string").raise(); + self.fail_unterminated_raw_string(start_bpos, hash_count); } // if self.ch_is('"') { // content_end_bpos = self.pos; @@ -1636,8 +1655,7 @@ impl<'a> StringReader<'a> { } if self.is_eof() { - let pos = self.pos; - self.fatal_span_(start_bpos, pos, "unterminated raw string").raise(); + self.fail_unterminated_raw_string(start_bpos, hash_count); } else if !self.ch_is('"') { let pos = self.pos; let ch = self.ch.unwrap(); @@ -1653,8 +1671,7 @@ impl<'a> StringReader<'a> { 'outer: loop { match self.ch { None => { - let pos = self.pos; - self.fatal_span_(start_bpos, pos, "unterminated raw string").raise() + self.fail_unterminated_raw_string(start_bpos, hash_count); } Some('"') => { content_end_bpos = self.pos; diff --git a/src/test/ui/raw_string.rs b/src/test/ui/raw_string.rs new file mode 100644 index 0000000000000..f1eb91d44fda0 --- /dev/null +++ b/src/test/ui/raw_string.rs @@ -0,0 +1,14 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let x = r##"lol"#; + //~^ ERROR unterminated raw string +} diff --git a/src/test/ui/raw_string.stderr b/src/test/ui/raw_string.stderr new file mode 100644 index 0000000000000..b8aa596ef953a --- /dev/null +++ b/src/test/ui/raw_string.stderr @@ -0,0 +1,8 @@ +error: unterminated raw string + --> $DIR/raw_string.rs:12:13 + | +LL | let x = r##"lol"#; + | ^ unterminated raw string + | + = note: this raw string should be terminated with `"##` + From 16ac85ce4dce1e185f2e6ce27df3833e07a9e502 Mon Sep 17 00:00:00 2001 From: debris Date: Sun, 4 Mar 2018 14:58:10 +0100 Subject: [PATCH 26/31] Remove useless powerpc64 entry from ARCH_TABLE, closes #47737 --- src/test/codegen/abi-main-signature-16bit-c-int.rs | 1 - src/test/codegen/fastcall-inreg.rs | 2 -- src/test/codegen/global_asm.rs | 2 -- src/test/codegen/global_asm_include.rs | 2 -- src/test/codegen/global_asm_x2.rs | 2 -- src/test/codegen/repr-transparent-aggregates-1.rs | 1 - src/tools/compiletest/src/util.rs | 1 - 7 files changed, 11 deletions(-) diff --git a/src/test/codegen/abi-main-signature-16bit-c-int.rs b/src/test/codegen/abi-main-signature-16bit-c-int.rs index fbe2fd10e7a14..1e02fe4befdf5 100644 --- a/src/test/codegen/abi-main-signature-16bit-c-int.rs +++ b/src/test/codegen/abi-main-signature-16bit-c-int.rs @@ -18,7 +18,6 @@ // ignore-hexagon // ignore-mips // ignore-powerpc -// ignore-powerpc64 // ignore-s390x // ignore-sparc // ignore-wasm32 diff --git a/src/test/codegen/fastcall-inreg.rs b/src/test/codegen/fastcall-inreg.rs index 346c5da8d1b8d..b24899cc363a0 100644 --- a/src/test/codegen/fastcall-inreg.rs +++ b/src/test/codegen/fastcall-inreg.rs @@ -25,8 +25,6 @@ // ignore-mips64 // ignore-mips64el // ignore-msp430 -// ignore-powerpc64 -// ignore-powerpc64le // ignore-powerpc // ignore-r600 // ignore-amdgcn diff --git a/src/test/codegen/global_asm.rs b/src/test/codegen/global_asm.rs index 5bd0c1b4076ee..5661592d0c7b2 100644 --- a/src/test/codegen/global_asm.rs +++ b/src/test/codegen/global_asm.rs @@ -21,8 +21,6 @@ // ignore-mips64 // ignore-mips64el // ignore-msp430 -// ignore-powerpc64 -// ignore-powerpc64le // ignore-powerpc // ignore-r600 // ignore-amdgcn diff --git a/src/test/codegen/global_asm_include.rs b/src/test/codegen/global_asm_include.rs index 401b1fad566d5..d8b5db12404ac 100644 --- a/src/test/codegen/global_asm_include.rs +++ b/src/test/codegen/global_asm_include.rs @@ -21,8 +21,6 @@ // ignore-mips64 // ignore-mips64el // ignore-msp430 -// ignore-powerpc64 -// ignore-powerpc64le // ignore-powerpc // ignore-r600 // ignore-amdgcn diff --git a/src/test/codegen/global_asm_x2.rs b/src/test/codegen/global_asm_x2.rs index 8b59165e9e61b..caa0506550dde 100644 --- a/src/test/codegen/global_asm_x2.rs +++ b/src/test/codegen/global_asm_x2.rs @@ -21,8 +21,6 @@ // ignore-mips64 // ignore-mips64el // ignore-msp430 -// ignore-powerpc64 -// ignore-powerpc64le // ignore-powerpc // ignore-r600 // ignore-amdgcn diff --git a/src/test/codegen/repr-transparent-aggregates-1.rs b/src/test/codegen/repr-transparent-aggregates-1.rs index 2eeed2b788ce2..655e67cf7eefe 100644 --- a/src/test/codegen/repr-transparent-aggregates-1.rs +++ b/src/test/codegen/repr-transparent-aggregates-1.rs @@ -14,7 +14,6 @@ // ignore-mips // ignore-mips64 // ignore-powerpc -// ignore-powerpc64 // See repr-transparent.rs #![crate_type="lib"] diff --git a/src/tools/compiletest/src/util.rs b/src/tools/compiletest/src/util.rs index 3c9dae915b5a2..cf63cb2e5d901 100644 --- a/src/tools/compiletest/src/util.rs +++ b/src/tools/compiletest/src/util.rs @@ -43,7 +43,6 @@ const ARCH_TABLE: &'static [(&'static str, &'static str)] = &[ ("mips", "mips"), ("msp430", "msp430"), ("powerpc", "powerpc"), - ("powerpc64", "powerpc64"), ("s390x", "s390x"), ("sparc", "sparc"), ("x86_64", "x86_64"), From 88f32d15afac7bc5cff5daca7a0ac80fdedb6dce Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Mon, 5 Mar 2018 18:37:05 +0100 Subject: [PATCH 27/31] Remove a couple of `isize` references from hashmap docs Also fix a spelling mistake. --- src/libstd/collections/hash/map.rs | 54 +++++++++++++++--------------- src/libstd/collections/hash/set.rs | 4 +-- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 4dfdc23ebee53..b023fec810ec3 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -620,7 +620,7 @@ impl HashMap { /// /// ``` /// use std::collections::HashMap; - /// let mut map: HashMap<&str, isize> = HashMap::new(); + /// let mut map: HashMap<&str, i32> = HashMap::new(); /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] @@ -637,7 +637,7 @@ impl HashMap { /// /// ``` /// use std::collections::HashMap; - /// let mut map: HashMap<&str, isize> = HashMap::with_capacity(10); + /// let mut map: HashMap<&str, i32> = HashMap::with_capacity(10); /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] @@ -724,7 +724,7 @@ impl HashMap /// use std::collections::hash_map::RandomState; /// /// let hasher = RandomState::new(); - /// let map: HashMap = HashMap::with_hasher(hasher); + /// let map: HashMap = HashMap::with_hasher(hasher); /// let hasher: &RandomState = map.hasher(); /// ``` #[stable(feature = "hashmap_public_hasher", since = "1.9.0")] @@ -741,7 +741,7 @@ impl HashMap /// /// ``` /// use std::collections::HashMap; - /// let map: HashMap = HashMap::with_capacity(100); + /// let map: HashMap = HashMap::with_capacity(100); /// assert!(map.capacity() >= 100); /// ``` #[inline] @@ -770,7 +770,7 @@ impl HashMap /// /// ``` /// use std::collections::HashMap; - /// let mut map: HashMap<&str, isize> = HashMap::new(); + /// let mut map: HashMap<&str, i32> = HashMap::new(); /// map.reserve(10); /// ``` #[stable(feature = "rust1", since = "1.0.0")] @@ -849,7 +849,7 @@ impl HashMap /// ``` /// use std::collections::HashMap; /// - /// let mut map: HashMap = HashMap::with_capacity(100); + /// let mut map: HashMap = HashMap::with_capacity(100); /// map.insert(1, 2); /// map.insert(3, 4); /// assert!(map.capacity() >= 100); @@ -1306,7 +1306,7 @@ impl HashMap /// ``` /// use std::collections::HashMap; /// - /// let mut map: HashMap = (0..8).map(|x|(x, x*10)).collect(); + /// let mut map: HashMap = (0..8).map(|x|(x, x*10)).collect(); /// map.retain(|&k, _| k % 2 == 0); /// assert_eq!(map.len(), 4); /// ``` @@ -1722,7 +1722,7 @@ impl IntoIterator for HashMap /// map.insert("c", 3); /// /// // Not possible with .iter() - /// let vec: Vec<(&str, isize)> = map.into_iter().collect(); + /// let vec: Vec<(&str, i32)> = map.into_iter().collect(); /// ``` fn into_iter(self) -> IntoIter { IntoIter { inner: self.table.into_iter() } @@ -2786,24 +2786,24 @@ mod test_map { assert_eq!(m2.len(), 2); } - thread_local! { static DROP_VECTOR: RefCell> = RefCell::new(Vec::new()) } + thread_local! { static DROP_VECTOR: RefCell> = RefCell::new(Vec::new()) } #[derive(Hash, PartialEq, Eq)] - struct Dropable { + struct Droppable { k: usize, } - impl Dropable { - fn new(k: usize) -> Dropable { + impl Droppable { + fn new(k: usize) -> Droppable { DROP_VECTOR.with(|slot| { slot.borrow_mut()[k] += 1; }); - Dropable { k: k } + Droppable { k: k } } } - impl Drop for Dropable { + impl Drop for Droppable { fn drop(&mut self) { DROP_VECTOR.with(|slot| { slot.borrow_mut()[self.k] -= 1; @@ -2811,9 +2811,9 @@ mod test_map { } } - impl Clone for Dropable { - fn clone(&self) -> Dropable { - Dropable::new(self.k) + impl Clone for Droppable { + fn clone(&self) -> Droppable { + Droppable::new(self.k) } } @@ -2833,8 +2833,8 @@ mod test_map { }); for i in 0..100 { - let d1 = Dropable::new(i); - let d2 = Dropable::new(i + 100); + let d1 = Droppable::new(i); + let d2 = Droppable::new(i + 100); m.insert(d1, d2); } @@ -2845,7 +2845,7 @@ mod test_map { }); for i in 0..50 { - let k = Dropable::new(i); + let k = Droppable::new(i); let v = m.remove(&k); assert!(v.is_some()); @@ -2892,8 +2892,8 @@ mod test_map { }); for i in 0..100 { - let d1 = Dropable::new(i); - let d2 = Dropable::new(i + 100); + let d1 = Droppable::new(i); + let d2 = Droppable::new(i + 100); hm.insert(d1, d2); } @@ -2943,13 +2943,13 @@ mod test_map { #[test] fn test_empty_remove() { - let mut m: HashMap = HashMap::new(); + let mut m: HashMap = HashMap::new(); assert_eq!(m.remove(&0), None); } #[test] fn test_empty_entry() { - let mut m: HashMap = HashMap::new(); + let mut m: HashMap = HashMap::new(); match m.entry(0) { Occupied(_) => panic!(), Vacant(_) => {} @@ -2960,7 +2960,7 @@ mod test_map { #[test] fn test_empty_iter() { - let mut m: HashMap = HashMap::new(); + let mut m: HashMap = HashMap::new(); assert_eq!(m.drain().next(), None); assert_eq!(m.keys().next(), None); assert_eq!(m.values().next(), None); @@ -3461,7 +3461,7 @@ mod test_map { fn test_entry_take_doesnt_corrupt() { #![allow(deprecated)] //rand // Test for #19292 - fn check(m: &HashMap) { + fn check(m: &HashMap) { for k in m.keys() { assert!(m.contains_key(k), "{} is in keys() but not in the map?", k); @@ -3570,7 +3570,7 @@ mod test_map { #[test] fn test_retain() { - let mut map: HashMap = (0..100).map(|x|(x, x*10)).collect(); + let mut map: HashMap = (0..100).map(|x|(x, x*10)).collect(); map.retain(|&k, _| k % 2 == 0); assert_eq!(map.len(), 50); diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index e9427fb40a016..67d413b5a38c4 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -724,7 +724,7 @@ impl HashSet /// use std::collections::HashSet; /// /// let xs = [1,2,3,4,5,6]; - /// let mut set: HashSet = xs.iter().cloned().collect(); + /// let mut set: HashSet = xs.iter().cloned().collect(); /// set.retain(|&k| k % 2 == 0); /// assert_eq!(set.len(), 3); /// ``` @@ -1745,7 +1745,7 @@ mod test_set { #[test] fn test_retain() { let xs = [1, 2, 3, 4, 5, 6]; - let mut set: HashSet = xs.iter().cloned().collect(); + let mut set: HashSet = xs.iter().cloned().collect(); set.retain(|&k| k % 2 == 0); assert_eq!(set.len(), 3); assert!(set.contains(&2)); From 2e7e68b76223b9f14b54852584a5334f33a8798d Mon Sep 17 00:00:00 2001 From: "leonardo.yvens" Date: Mon, 5 Mar 2018 15:58:54 -0300 Subject: [PATCH 28/31] while let all the things --- src/librustc/hir/print.rs | 9 ++------ src/librustc/middle/reachable.rs | 6 +---- .../obligation_forest/mod.rs | 8 +------ src/libstd/sys_common/wtf8.rs | 23 ++++++++----------- src/libsyntax_ext/format.rs | 17 +++++--------- src/libsyntax_pos/lib.rs | 7 +----- 6 files changed, 20 insertions(+), 50 deletions(-) diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index ed8cea3eb6563..d91aa3a385193 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -2208,13 +2208,8 @@ impl<'a> State<'a> { if self.next_comment().is_none() { self.s.hardbreak()?; } - loop { - match self.next_comment() { - Some(ref cmnt) => { - self.print_comment(cmnt)?; - } - _ => break, - } + while let Some(ref cmnt) = self.next_comment() { + self.print_comment(cmnt)? } Ok(()) } diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 749685182a8f4..5658b5b683291 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -206,11 +206,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { // Step 2: Mark all symbols that the symbols on the worklist touch. fn propagate(&mut self) { let mut scanned = FxHashSet(); - loop { - let search_item = match self.worklist.pop() { - Some(item) => item, - None => break, - }; + while let Some(search_item) = self.worklist.pop() { if !scanned.insert(search_item) { continue } diff --git a/src/librustc_data_structures/obligation_forest/mod.rs b/src/librustc_data_structures/obligation_forest/mod.rs index 02cae52166ac3..42a17d33fa6f5 100644 --- a/src/librustc_data_structures/obligation_forest/mod.rs +++ b/src/librustc_data_structures/obligation_forest/mod.rs @@ -415,13 +415,7 @@ impl ObligationForest { } } - loop { - // non-standard `while let` to bypass #6393 - let i = match error_stack.pop() { - Some(i) => i, - None => break - }; - + while let Some(i) = error_stack.pop() { let node = &self.nodes[i]; match node.state.get() { diff --git a/src/libstd/sys_common/wtf8.rs b/src/libstd/sys_common/wtf8.rs index 46d554d6411be..9fff8b91f96f3 100644 --- a/src/libstd/sys_common/wtf8.rs +++ b/src/libstd/sys_common/wtf8.rs @@ -428,20 +428,15 @@ impl fmt::Debug for Wtf8 { formatter.write_str("\"")?; let mut pos = 0; - loop { - match self.next_surrogate(pos) { - None => break, - Some((surrogate_pos, surrogate)) => { - write_str_escaped( - formatter, - unsafe { str::from_utf8_unchecked( - &self.bytes[pos .. surrogate_pos] - )}, - )?; - write!(formatter, "\\u{{{:x}}}", surrogate)?; - pos = surrogate_pos + 3; - } - } + while let Some((surrogate_pos, surrogate)) = self.next_surrogate(pos) { + write_str_escaped( + formatter, + unsafe { str::from_utf8_unchecked( + &self.bytes[pos .. surrogate_pos] + )}, + )?; + write!(formatter, "\\u{{{:x}}}", surrogate)?; + pos = surrogate_pos + 3; } write_str_escaped( formatter, diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index a7822414c6959..8fd95aa1ca861 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -732,18 +732,13 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, let mut parser = parse::Parser::new(fmt_str); let mut pieces = vec![]; - loop { - match parser.next() { - Some(mut piece) => { - if !parser.errors.is_empty() { - break; - } - cx.verify_piece(&piece); - cx.resolve_name_inplace(&mut piece); - pieces.push(piece); - } - None => break, + while let Some(mut piece) = parser.next() { + if !parser.errors.is_empty() { + break; } + cx.verify_piece(&piece); + cx.resolve_name_inplace(&mut piece); + pieces.push(piece); } let numbered_position_args = pieces.iter().any(|arg: &parse::Piece| { diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index 9f746adbe6573..ed9eb5d5c9261 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -322,12 +322,7 @@ impl Span { pub fn macro_backtrace(mut self) -> Vec { let mut prev_span = DUMMY_SP; let mut result = vec![]; - loop { - let info = match self.ctxt().outer().expn_info() { - Some(info) => info, - None => break, - }; - + while let Some(info) = self.ctxt().outer().expn_info() { let (pre, post) = match info.callee.format { ExpnFormat::MacroAttribute(..) => ("#[", "]"), ExpnFormat::MacroBang(..) => ("", "!"), From 2ec47e07ee933f9497185fc111b3501b8648aef5 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Mon, 5 Mar 2018 20:24:05 -0500 Subject: [PATCH 29/31] Remove seemingly unused sugarise-doc-comments Python script. This Python script converts documentation comments from the `#[doc = "..."]` attribute to the `///` syntax. It was added six years ago, presumably to help with the transition when `///` was implemented and hasn't really been touched since. I don't think there's much value in keeping it around at this point. --- src/etc/sugarise-doc-comments.py | 93 -------------------------------- 1 file changed, 93 deletions(-) delete mode 100755 src/etc/sugarise-doc-comments.py diff --git a/src/etc/sugarise-doc-comments.py b/src/etc/sugarise-doc-comments.py deleted file mode 100755 index ac2223f4acef3..0000000000000 --- a/src/etc/sugarise-doc-comments.py +++ /dev/null @@ -1,93 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT -# file at the top-level directory of this distribution and at -# http://rust-lang.org/COPYRIGHT. -# -# Licensed under the Apache License, Version 2.0 or the MIT license -# , at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. - -# -# this script attempts to turn doc comment attributes (#[doc = "..."]) -# into sugared-doc-comments (/** ... */ and /// ...) -# -# it sugarises all .rs/.rc files underneath the working directory -# - -import sys -import os -import fnmatch -import re - - -DOC_PATTERN = '^(?P[\\t ]*)#\\[(\\s*)doc(\\s*)=' + \ - '(\\s*)"(?P(\\"|[^"])*?)"(\\s*)\\]' + \ - '(?P;)?' - -ESCAPES = [("\\'", "'"), - ('\\"', '"'), - ("\\n", "\n"), - ("\\r", "\r"), - ("\\t", "\t")] - - -def unescape(s): - for (find, repl) in ESCAPES: - s = s.replace(find, repl) - return s - - -def block_trim(s): - lns = s.splitlines() - - # remove leading/trailing whitespace-lines - while lns and not lns[0].strip(): - lns = lns[1:] - while lns and not lns[-1].strip(): - lns = lns[:-1] - - # remove leading horizontal whitespace - n = sys.maxsize - for ln in lns: - if ln.strip(): - n = min(n, len(re.search('^\s*', ln).group())) - if n != sys.maxsize: - lns = [ln[n:] for ln in lns] - - # strip trailing whitespace - lns = [ln.rstrip() for ln in lns] - - return lns - - -def replace_doc(m): - indent = m.group('indent') - text = block_trim(unescape(m.group('text'))) - - if len(text) > 1: - inner = '!' if m.group('semi') else '*' - starify = lambda s: indent + ' *' + (' ' + s if s else '') - text = '\n'.join(map(starify, text)) - repl = indent + '/*' + inner + '\n' + text + '\n' + indent + ' */' - else: - inner = '!' if m.group('semi') else '/' - repl = indent + '//' + inner + ' ' + text[0] - - return repl - - -def sugarise_file(path): - s = open(path).read() - - r = re.compile(DOC_PATTERN, re.MULTILINE | re.DOTALL) - ns = re.sub(r, replace_doc, s) - - if s != ns: - open(path, 'w').write(ns) - -for (dirpath, dirnames, filenames) in os.walk('.'): - for name in fnmatch.filter(filenames, '*.r[sc]'): - sugarise_file(os.path.join(dirpath, name)) From 24fb4b766952edbd9daf71dc74dcdc62a7511711 Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Tue, 27 Feb 2018 04:34:55 +0000 Subject: [PATCH 30/31] Add reverse_bits to integer types --- src/libcore/num/mod.rs | 54 ++++++++++++++++++++++++++++ src/libcore/tests/lib.rs | 1 + src/libcore/tests/num/uint_macros.rs | 11 ++++++ 3 files changed, 66 insertions(+) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 59a67fff48cfe..a46ac2b5f0fee 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -321,6 +321,33 @@ $EndFeature, " (self as $UnsignedT).swap_bytes() as Self } + /// Reverses the bit pattern of the integer. + /// + /// # Examples + /// + /// Please note that this example is shared between integer types. + /// Which explains why `i16` is used here. + /// + /// Basic usage: + /// + /// ``` + /// #![feature(reverse_bits)] + /// + /// let n: i16 = 0b0000000_01010101; + /// assert_eq!(n, 85); + /// + /// let m = n.reverse_bits(); + /// + /// assert_eq!(m as u16, 0b10101010_00000000); + /// assert_eq!(m, -22016); + /// ``` + #[unstable(feature = "reverse_bits", issue = "48763")] + #[cfg(not(stage0))] + #[inline] + pub fn reverse_bits(self) -> Self { + (self as $UnsignedT).reverse_bits() as Self + } + doc_comment! { concat!("Converts an integer from big endian to the target's endianness. @@ -1773,6 +1800,33 @@ assert_eq!(n.trailing_zeros(), 3);", $EndFeature, " unsafe { intrinsics::bswap(self as $ActualT) as Self } } + /// Reverses the bit pattern of the integer. + /// + /// # Examples + /// + /// Basic usage: + /// + /// Please note that this example is shared between integer types. + /// Which explains why `u16` is used here. + /// + /// ``` + /// #![feature(reverse_bits)] + /// + /// let n: u16 = 0b0000000_01010101; + /// assert_eq!(n, 85); + /// + /// let m = n.reverse_bits(); + /// + /// assert_eq!(m, 0b10101010_00000000); + /// assert_eq!(m, 43520); + /// ``` + #[unstable(feature = "reverse_bits", issue = "48763")] + #[cfg(not(stage0))] + #[inline] + pub fn reverse_bits(self) -> Self { + unsafe { intrinsics::bitreverse(self as $ActualT) as Self } + } + doc_comment! { concat!("Converts an integer from big endian to the target's endianness. diff --git a/src/libcore/tests/lib.rs b/src/libcore/tests/lib.rs index 0049ed66a102a..a9c5683e0ef7b 100644 --- a/src/libcore/tests/lib.rs +++ b/src/libcore/tests/lib.rs @@ -46,6 +46,7 @@ #![feature(try_trait)] #![feature(exact_chunks)] #![feature(atomic_nand)] +#![feature(reverse_bits)] extern crate core; extern crate test; diff --git a/src/libcore/tests/num/uint_macros.rs b/src/libcore/tests/num/uint_macros.rs index daa1cc3a7f4fb..ca6906f731047 100644 --- a/src/libcore/tests/num/uint_macros.rs +++ b/src/libcore/tests/num/uint_macros.rs @@ -97,6 +97,17 @@ mod tests { assert_eq!(_1.swap_bytes(), _1); } + #[test] + fn test_reverse_bits() { + assert_eq!(A.reverse_bits().reverse_bits(), A); + assert_eq!(B.reverse_bits().reverse_bits(), B); + assert_eq!(C.reverse_bits().reverse_bits(), C); + + // Swapping these should make no difference + assert_eq!(_0.reverse_bits(), _0); + assert_eq!(_1.reverse_bits(), _1); + } + #[test] fn test_le() { assert_eq!($T::from_le(A.to_le()), A); From 88aec91017bf7def8401f47f3f90acd25882a2da Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Wed, 28 Feb 2018 13:56:54 +0000 Subject: [PATCH 31/31] Add i128 tests for intrinsics --- src/test/run-pass/intrinsics-integer.rs | 27 ++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/test/run-pass/intrinsics-integer.rs b/src/test/run-pass/intrinsics-integer.rs index 6e0712f6767ba..bfa3a1e128a9a 100644 --- a/src/test/run-pass/intrinsics-integer.rs +++ b/src/test/run-pass/intrinsics-integer.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(intrinsics)] +#![feature(intrinsics, i128_type)] mod rusti { extern "rust-intrinsic" { @@ -30,106 +30,127 @@ pub fn main() { assert_eq!(ctpop(0u16), 0); assert_eq!(ctpop(0i16), 0); assert_eq!(ctpop(0u32), 0); assert_eq!(ctpop(0i32), 0); assert_eq!(ctpop(0u64), 0); assert_eq!(ctpop(0i64), 0); + assert_eq!(ctpop(0u128), 0); assert_eq!(ctpop(0i128), 0); assert_eq!(ctpop(1u8), 1); assert_eq!(ctpop(1i8), 1); assert_eq!(ctpop(1u16), 1); assert_eq!(ctpop(1i16), 1); assert_eq!(ctpop(1u32), 1); assert_eq!(ctpop(1i32), 1); assert_eq!(ctpop(1u64), 1); assert_eq!(ctpop(1i64), 1); + assert_eq!(ctpop(1u128), 1); assert_eq!(ctpop(1i128), 1); assert_eq!(ctpop(10u8), 2); assert_eq!(ctpop(10i8), 2); assert_eq!(ctpop(10u16), 2); assert_eq!(ctpop(10i16), 2); assert_eq!(ctpop(10u32), 2); assert_eq!(ctpop(10i32), 2); assert_eq!(ctpop(10u64), 2); assert_eq!(ctpop(10i64), 2); + assert_eq!(ctpop(10u128), 2); assert_eq!(ctpop(10i128), 2); assert_eq!(ctpop(100u8), 3); assert_eq!(ctpop(100i8), 3); assert_eq!(ctpop(100u16), 3); assert_eq!(ctpop(100i16), 3); assert_eq!(ctpop(100u32), 3); assert_eq!(ctpop(100i32), 3); assert_eq!(ctpop(100u64), 3); assert_eq!(ctpop(100i64), 3); + assert_eq!(ctpop(100u128), 3); assert_eq!(ctpop(100i128), 3); assert_eq!(ctpop(-1i8 as u8), 8); assert_eq!(ctpop(-1i8), 8); assert_eq!(ctpop(-1i16 as u16), 16); assert_eq!(ctpop(-1i16), 16); assert_eq!(ctpop(-1i32 as u32), 32); assert_eq!(ctpop(-1i32), 32); assert_eq!(ctpop(-1i64 as u64), 64); assert_eq!(ctpop(-1i64), 64); + assert_eq!(ctpop(-1i128 as u128), 128); assert_eq!(ctpop(-1i128), 128); assert_eq!(ctlz(0u8), 8); assert_eq!(ctlz(0i8), 8); assert_eq!(ctlz(0u16), 16); assert_eq!(ctlz(0i16), 16); assert_eq!(ctlz(0u32), 32); assert_eq!(ctlz(0i32), 32); assert_eq!(ctlz(0u64), 64); assert_eq!(ctlz(0i64), 64); + assert_eq!(ctlz(0u128), 128); assert_eq!(ctlz(0i128), 128); assert_eq!(ctlz(1u8), 7); assert_eq!(ctlz(1i8), 7); assert_eq!(ctlz(1u16), 15); assert_eq!(ctlz(1i16), 15); assert_eq!(ctlz(1u32), 31); assert_eq!(ctlz(1i32), 31); assert_eq!(ctlz(1u64), 63); assert_eq!(ctlz(1i64), 63); + assert_eq!(ctlz(1u128), 127); assert_eq!(ctlz(1i128), 127); assert_eq!(ctlz(10u8), 4); assert_eq!(ctlz(10i8), 4); assert_eq!(ctlz(10u16), 12); assert_eq!(ctlz(10i16), 12); assert_eq!(ctlz(10u32), 28); assert_eq!(ctlz(10i32), 28); assert_eq!(ctlz(10u64), 60); assert_eq!(ctlz(10i64), 60); + assert_eq!(ctlz(10u128), 124); assert_eq!(ctlz(10i128), 124); assert_eq!(ctlz(100u8), 1); assert_eq!(ctlz(100i8), 1); assert_eq!(ctlz(100u16), 9); assert_eq!(ctlz(100i16), 9); assert_eq!(ctlz(100u32), 25); assert_eq!(ctlz(100i32), 25); assert_eq!(ctlz(100u64), 57); assert_eq!(ctlz(100i64), 57); + assert_eq!(ctlz(100u128), 121); assert_eq!(ctlz(100i128), 121); assert_eq!(ctlz_nonzero(1u8), 7); assert_eq!(ctlz_nonzero(1i8), 7); assert_eq!(ctlz_nonzero(1u16), 15); assert_eq!(ctlz_nonzero(1i16), 15); assert_eq!(ctlz_nonzero(1u32), 31); assert_eq!(ctlz_nonzero(1i32), 31); assert_eq!(ctlz_nonzero(1u64), 63); assert_eq!(ctlz_nonzero(1i64), 63); + assert_eq!(ctlz_nonzero(1u128), 127); assert_eq!(ctlz_nonzero(1i128), 127); assert_eq!(ctlz_nonzero(10u8), 4); assert_eq!(ctlz_nonzero(10i8), 4); assert_eq!(ctlz_nonzero(10u16), 12); assert_eq!(ctlz_nonzero(10i16), 12); assert_eq!(ctlz_nonzero(10u32), 28); assert_eq!(ctlz_nonzero(10i32), 28); assert_eq!(ctlz_nonzero(10u64), 60); assert_eq!(ctlz_nonzero(10i64), 60); + assert_eq!(ctlz_nonzero(10u128), 124); assert_eq!(ctlz_nonzero(10i128), 124); assert_eq!(ctlz_nonzero(100u8), 1); assert_eq!(ctlz_nonzero(100i8), 1); assert_eq!(ctlz_nonzero(100u16), 9); assert_eq!(ctlz_nonzero(100i16), 9); assert_eq!(ctlz_nonzero(100u32), 25); assert_eq!(ctlz_nonzero(100i32), 25); assert_eq!(ctlz_nonzero(100u64), 57); assert_eq!(ctlz_nonzero(100i64), 57); + assert_eq!(ctlz_nonzero(100u128), 121); assert_eq!(ctlz_nonzero(100i128), 121); assert_eq!(cttz(-1i8 as u8), 0); assert_eq!(cttz(-1i8), 0); assert_eq!(cttz(-1i16 as u16), 0); assert_eq!(cttz(-1i16), 0); assert_eq!(cttz(-1i32 as u32), 0); assert_eq!(cttz(-1i32), 0); assert_eq!(cttz(-1i64 as u64), 0); assert_eq!(cttz(-1i64), 0); + assert_eq!(cttz(-1i128 as u128), 0); assert_eq!(cttz(-1i128), 0); assert_eq!(cttz(0u8), 8); assert_eq!(cttz(0i8), 8); assert_eq!(cttz(0u16), 16); assert_eq!(cttz(0i16), 16); assert_eq!(cttz(0u32), 32); assert_eq!(cttz(0i32), 32); assert_eq!(cttz(0u64), 64); assert_eq!(cttz(0i64), 64); + assert_eq!(cttz(0u128), 128); assert_eq!(cttz(0i128), 128); assert_eq!(cttz(1u8), 0); assert_eq!(cttz(1i8), 0); assert_eq!(cttz(1u16), 0); assert_eq!(cttz(1i16), 0); assert_eq!(cttz(1u32), 0); assert_eq!(cttz(1i32), 0); assert_eq!(cttz(1u64), 0); assert_eq!(cttz(1i64), 0); + assert_eq!(cttz(1u128), 0); assert_eq!(cttz(1i128), 0); assert_eq!(cttz(10u8), 1); assert_eq!(cttz(10i8), 1); assert_eq!(cttz(10u16), 1); assert_eq!(cttz(10i16), 1); assert_eq!(cttz(10u32), 1); assert_eq!(cttz(10i32), 1); assert_eq!(cttz(10u64), 1); assert_eq!(cttz(10i64), 1); + assert_eq!(cttz(10u128), 1); assert_eq!(cttz(10i128), 1); assert_eq!(cttz(100u8), 2); assert_eq!(cttz(100i8), 2); assert_eq!(cttz(100u16), 2); assert_eq!(cttz(100i16), 2); assert_eq!(cttz(100u32), 2); assert_eq!(cttz(100i32), 2); assert_eq!(cttz(100u64), 2); assert_eq!(cttz(100i64), 2); + assert_eq!(cttz(100u128), 2); assert_eq!(cttz(100i128), 2); assert_eq!(cttz_nonzero(-1i8 as u8), 0); assert_eq!(cttz_nonzero(-1i8), 0); assert_eq!(cttz_nonzero(-1i16 as u16), 0); assert_eq!(cttz_nonzero(-1i16), 0); assert_eq!(cttz_nonzero(-1i32 as u32), 0); assert_eq!(cttz_nonzero(-1i32), 0); assert_eq!(cttz_nonzero(-1i64 as u64), 0); assert_eq!(cttz_nonzero(-1i64), 0); + assert_eq!(cttz_nonzero(-1i128 as u128), 0); assert_eq!(cttz_nonzero(-1i128), 0); assert_eq!(cttz_nonzero(1u8), 0); assert_eq!(cttz_nonzero(1i8), 0); assert_eq!(cttz_nonzero(1u16), 0); assert_eq!(cttz_nonzero(1i16), 0); assert_eq!(cttz_nonzero(1u32), 0); assert_eq!(cttz_nonzero(1i32), 0); assert_eq!(cttz_nonzero(1u64), 0); assert_eq!(cttz_nonzero(1i64), 0); + assert_eq!(cttz_nonzero(1u128), 0); assert_eq!(cttz_nonzero(1i128), 0); assert_eq!(cttz_nonzero(10u8), 1); assert_eq!(cttz_nonzero(10i8), 1); assert_eq!(cttz_nonzero(10u16), 1); assert_eq!(cttz_nonzero(10i16), 1); assert_eq!(cttz_nonzero(10u32), 1); assert_eq!(cttz_nonzero(10i32), 1); assert_eq!(cttz_nonzero(10u64), 1); assert_eq!(cttz_nonzero(10i64), 1); + assert_eq!(cttz_nonzero(10u128), 1); assert_eq!(cttz_nonzero(10i128), 1); assert_eq!(cttz_nonzero(100u8), 2); assert_eq!(cttz_nonzero(100i8), 2); assert_eq!(cttz_nonzero(100u16), 2); assert_eq!(cttz_nonzero(100i16), 2); assert_eq!(cttz_nonzero(100u32), 2); assert_eq!(cttz_nonzero(100i32), 2); assert_eq!(cttz_nonzero(100u64), 2); assert_eq!(cttz_nonzero(100i64), 2); + assert_eq!(cttz_nonzero(100u128), 2); assert_eq!(cttz_nonzero(100i128), 2); assert_eq!(bswap(0x0Au8), 0x0A); // no-op assert_eq!(bswap(0x0Ai8), 0x0A); // no-op @@ -139,6 +160,8 @@ pub fn main() { assert_eq!(bswap(0x0ABBCC0Di32), 0x0DCCBB0A); assert_eq!(bswap(0x0122334455667708u64), 0x0877665544332201); assert_eq!(bswap(0x0122334455667708i64), 0x0877665544332201); + assert_eq!(bswap(0x0122334455667708u128), 0x08776655443322010000000000000000); + assert_eq!(bswap(0x0122334455667708i128), 0x08776655443322010000000000000000); assert_eq!(bitreverse(0x0Au8), 0x50); assert_eq!(bitreverse(0x0Ai8), 0x50); @@ -148,5 +171,7 @@ pub fn main() { assert_eq!(bitreverse(0x0ABBCC0Ei32), 0x7033DD50); assert_eq!(bitreverse(0x0122334455667708u64), 0x10EE66AA22CC4480); assert_eq!(bitreverse(0x0122334455667708i64), 0x10EE66AA22CC4480); + assert_eq!(bitreverse(0x0122334455667708u128), 0x10EE66AA22CC44800000000000000000); + assert_eq!(bitreverse(0x0122334455667708i128), 0x10EE66AA22CC44800000000000000000); } }