From df2c3a288a1f0218fe1abe34aa7b2287a39aa8f8 Mon Sep 17 00:00:00 2001 From: Luca Bruno Date: Thu, 22 Jan 2015 15:45:47 +0100 Subject: [PATCH 01/14] copyright: update paths and entries valgrind files moved and modpath.iss deleted. Both entries updated in COPYRIGHT file. Signed-off-by: Luca Bruno --- COPYRIGHT | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/COPYRIGHT b/COPYRIGHT index da8ac7b3adde7..d4ad98e6e8799 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -23,12 +23,12 @@ The following third party packages are included, and carry their own copyright notices and license terms: * Two header files that are part of the Valgrind - package. These files are found at src/rt/vg/valgrind.h and - src/rt/vg/memcheck.h, within this distribution. These files + package. These files are found at src/rt/valgrind/valgrind.h and + src/rt/valgrind/memcheck.h, within this distribution. These files are redistributed under the following terms, as noted in them: - for src/rt/vg/valgrind.h: + for src/rt/valgrind/valgrind.h: This file is part of Valgrind, a dynamic binary instrumentation framework. @@ -74,7 +74,7 @@ their own copyright notices and license terms: USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - for src/rt/vg/memcheck.h: + for src/rt/valgrind/memcheck.h: This file is part of MemCheck, a heavyweight Valgrind tool for detecting memory errors. @@ -120,18 +120,6 @@ their own copyright notices and license terms: USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -* The auxiliary file src/etc/pkg/modpath.iss contains a - library routine compiled, by Inno Setup, into the Windows - installer binary. This file is licensed under the LGPL, - version 3, but, in our legal interpretation, this does not - affect the aggregate "collected work" license of the Rust - distribution (MIT/ASL2) nor any other components of it. We - believe that the terms governing distribution of the - binary Windows installer built from modpath.iss are - therefore LGPL, but not the terms governing distribution - of any of the files installed by such an installer (such - as the Rust compiler or runtime libraries themselves). - * The src/rt/miniz.c file, carrying an implementation of RFC1950/RFC1951 DEFLATE, by Rich Geldreich . All uses of this file are From 0832364946654a576383bdc49245fb22445bf069 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 30 Jan 2015 18:02:36 -0800 Subject: [PATCH 02/14] std: Stabilize Atomic{Isize,Usize} methods These methods were intended to be stable as of #16258 but the tags have since been lost in various refactorings. This commit re-adds the `#[stable]` attributes to each of these functions. --- src/libcore/atomic.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/libcore/atomic.rs b/src/libcore/atomic.rs index cf2854be016e1..0f3823eb7a5b0 100644 --- a/src/libcore/atomic.rs +++ b/src/libcore/atomic.rs @@ -415,6 +415,7 @@ impl AtomicIsize { /// let atomic_forty_two = AtomicIsize::new(42); /// ``` #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn new(v: isize) -> AtomicIsize { AtomicIsize {v: UnsafeCell::new(v)} } @@ -437,6 +438,7 @@ impl AtomicIsize { /// let value = some_isize.load(Ordering::Relaxed); /// ``` #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn load(&self, order: Ordering) -> isize { unsafe { atomic_load(self.v.get(), order) } } @@ -459,6 +461,7 @@ impl AtomicIsize { /// /// Panics if `order` is `Acquire` or `AcqRel`. #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn store(&self, val: isize, order: Ordering) { unsafe { atomic_store(self.v.get(), val, order); } } @@ -477,6 +480,7 @@ impl AtomicIsize { /// let value = some_isize.swap(10, Ordering::Relaxed); /// ``` #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn swap(&self, val: isize, order: Ordering) -> isize { unsafe { atomic_swap(self.v.get(), val, order) } } @@ -498,6 +502,7 @@ impl AtomicIsize { /// let value = some_isize.compare_and_swap(5, 10, Ordering::Relaxed); /// ``` #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn compare_and_swap(&self, old: isize, new: isize, order: Ordering) -> isize { unsafe { atomic_compare_and_swap(self.v.get(), old, new, order) } } @@ -514,6 +519,7 @@ impl AtomicIsize { /// assert_eq!(10, foo.load(Ordering::SeqCst)); /// ``` #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn fetch_add(&self, val: isize, order: Ordering) -> isize { unsafe { atomic_add(self.v.get(), val, order) } } @@ -530,6 +536,7 @@ impl AtomicIsize { /// assert_eq!(-10, foo.load(Ordering::SeqCst)); /// ``` #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn fetch_sub(&self, val: isize, order: Ordering) -> isize { unsafe { atomic_sub(self.v.get(), val, order) } } @@ -545,6 +552,7 @@ impl AtomicIsize { /// assert_eq!(0b101101, foo.fetch_and(0b110011, Ordering::SeqCst)); /// assert_eq!(0b100001, foo.load(Ordering::SeqCst)); #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn fetch_and(&self, val: isize, order: Ordering) -> isize { unsafe { atomic_and(self.v.get(), val, order) } } @@ -560,6 +568,7 @@ impl AtomicIsize { /// assert_eq!(0b101101, foo.fetch_or(0b110011, Ordering::SeqCst)); /// assert_eq!(0b111111, foo.load(Ordering::SeqCst)); #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn fetch_or(&self, val: isize, order: Ordering) -> isize { unsafe { atomic_or(self.v.get(), val, order) } } @@ -575,6 +584,7 @@ impl AtomicIsize { /// assert_eq!(0b101101, foo.fetch_xor(0b110011, Ordering::SeqCst)); /// assert_eq!(0b011110, foo.load(Ordering::SeqCst)); #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn fetch_xor(&self, val: isize, order: Ordering) -> isize { unsafe { atomic_xor(self.v.get(), val, order) } } @@ -592,6 +602,7 @@ impl AtomicUsize { /// let atomic_forty_two = AtomicUsize::new(42); /// ``` #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn new(v: usize) -> AtomicUsize { AtomicUsize { v: UnsafeCell::new(v) } } @@ -614,6 +625,7 @@ impl AtomicUsize { /// let value = some_usize.load(Ordering::Relaxed); /// ``` #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn load(&self, order: Ordering) -> usize { unsafe { atomic_load(self.v.get(), order) } } @@ -636,6 +648,7 @@ impl AtomicUsize { /// /// Panics if `order` is `Acquire` or `AcqRel`. #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn store(&self, val: usize, order: Ordering) { unsafe { atomic_store(self.v.get(), val, order); } } @@ -654,6 +667,7 @@ impl AtomicUsize { /// let value = some_usize.swap(10, Ordering::Relaxed); /// ``` #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn swap(&self, val: usize, order: Ordering) -> usize { unsafe { atomic_swap(self.v.get(), val, order) } } @@ -675,6 +689,7 @@ impl AtomicUsize { /// let value = some_usize.compare_and_swap(5, 10, Ordering::Relaxed); /// ``` #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn compare_and_swap(&self, old: usize, new: usize, order: Ordering) -> usize { unsafe { atomic_compare_and_swap(self.v.get(), old, new, order) } } @@ -691,6 +706,7 @@ impl AtomicUsize { /// assert_eq!(10, foo.load(Ordering::SeqCst)); /// ``` #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn fetch_add(&self, val: usize, order: Ordering) -> usize { unsafe { atomic_add(self.v.get(), val, order) } } @@ -707,6 +723,7 @@ impl AtomicUsize { /// assert_eq!(0, foo.load(Ordering::SeqCst)); /// ``` #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn fetch_sub(&self, val: usize, order: Ordering) -> usize { unsafe { atomic_sub(self.v.get(), val, order) } } @@ -722,6 +739,7 @@ impl AtomicUsize { /// assert_eq!(0b101101, foo.fetch_and(0b110011, Ordering::SeqCst)); /// assert_eq!(0b100001, foo.load(Ordering::SeqCst)); #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn fetch_and(&self, val: usize, order: Ordering) -> usize { unsafe { atomic_and(self.v.get(), val, order) } } @@ -737,6 +755,7 @@ impl AtomicUsize { /// assert_eq!(0b101101, foo.fetch_or(0b110011, Ordering::SeqCst)); /// assert_eq!(0b111111, foo.load(Ordering::SeqCst)); #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn fetch_or(&self, val: usize, order: Ordering) -> usize { unsafe { atomic_or(self.v.get(), val, order) } } @@ -752,6 +771,7 @@ impl AtomicUsize { /// assert_eq!(0b101101, foo.fetch_xor(0b110011, Ordering::SeqCst)); /// assert_eq!(0b011110, foo.load(Ordering::SeqCst)); #[inline] + #[stable(feature = "rust1", since = "1.0.0")] pub fn fetch_xor(&self, val: usize, order: Ordering) -> usize { unsafe { atomic_xor(self.v.get(), val, order) } } From f9f7ad74cf6a46b3aa78a6240ad1404e76594026 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 30 Jan 2015 22:27:36 -0800 Subject: [PATCH 03/14] rustc: Make unused_features lint warn by default When it was un*known*_features it was reasonably to by deny by default. cc #21798 --- src/librustc/lint/builtin.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index ae537e557e7d0..41a4dd3657479 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -1984,7 +1984,7 @@ declare_lint! { declare_lint! { pub UNUSED_FEATURES, - Deny, + Warn, "unused or unknown features found in crate-level #[feature] directives" } From e9ade4826a60d907f5df03105db86a13d3dc8843 Mon Sep 17 00:00:00 2001 From: madmalik Date: Sat, 31 Jan 2015 12:27:57 +0100 Subject: [PATCH 04/14] updating the link to rustdoc http://doc.rust-lang.org/rustdoc.html states that its content was moved to http://doc.rust-lang.org/book/documentation.html --- src/doc/trpl/comments.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/trpl/comments.md b/src/doc/trpl/comments.md index 3c211b007cf90..66670c7c631cd 100644 --- a/src/doc/trpl/comments.md +++ b/src/doc/trpl/comments.md @@ -43,5 +43,5 @@ When writing doc comments, adding sections for any arguments, return values, and providing some examples of usage is very, very helpful. Don't worry about the `&str`, we'll get to it soon. -You can use the [`rustdoc`](../rustdoc.html) tool to generate HTML documentation +You can use the [`rustdoc`](documentation.html) tool to generate HTML documentation from these doc comments. From 64ca751eb000c498374435da666ddd1c878c03ad Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Sat, 31 Jan 2015 19:42:13 +0200 Subject: [PATCH 05/14] Mention the type in the overflowing literal lint Fixes #21807 --- src/librustc/lint/builtin.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index e8e8d35fe072a..bdc0ea12e2819 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -227,7 +227,7 @@ impl LintPass for TypeLimits { if (negative && v > (min.abs() as u64)) || (!negative && v > (max.abs() as u64)) { cx.span_lint(OVERFLOWING_LITERALS, e.span, - "literal out of range for its type"); + &*format!("literal out of range for {:?}", t)); return; } } @@ -246,7 +246,7 @@ impl LintPass for TypeLimits { }; if lit_val < min || lit_val > max { cx.span_lint(OVERFLOWING_LITERALS, e.span, - "literal out of range for its type"); + &*format!("literal out of range for {:?}", t)); } }, ty::ty_float(t) => { @@ -263,7 +263,7 @@ impl LintPass for TypeLimits { }; if lit_val < min || lit_val > max { cx.span_lint(OVERFLOWING_LITERALS, e.span, - "literal out of range for its type"); + &*format!("literal out of range for {:?}", t)); } }, _ => () From afa526c5710e45c9fb010bcd0a40c2867b29496d Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Sat, 31 Jan 2015 20:16:31 +0200 Subject: [PATCH 06/14] Update tests for overflowing literals Changed in 64ca751 --- src/test/compile-fail/lint-type-limits.rs | 4 +- src/test/compile-fail/lint-type-overflow.rs | 41 +++++++++++---------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/test/compile-fail/lint-type-limits.rs b/src/test/compile-fail/lint-type-limits.rs index 3eae12f234fe2..95d892010e726 100644 --- a/src/test/compile-fail/lint-type-limits.rs +++ b/src/test/compile-fail/lint-type-limits.rs @@ -26,7 +26,7 @@ fn bar() -> i8 { fn baz() -> bool { 128 > bar() //~ ERROR comparison is useless due to type limits - //~^ WARNING literal out of range for its type + //~^ WARNING literal out of range for i8 } fn bleh() { @@ -44,7 +44,7 @@ fn bleh() { fn qux() { let mut i = 1i8; while 200 != i { //~ ERROR comparison is useless due to type limits - //~^ WARNING literal out of range for its type + //~^ WARNING literal out of range for i8 i += 1; } } diff --git a/src/test/compile-fail/lint-type-overflow.rs b/src/test/compile-fail/lint-type-overflow.rs index 47dc93dae13e9..ed6a0bd37eb28 100644 --- a/src/test/compile-fail/lint-type-overflow.rs +++ b/src/test/compile-fail/lint-type-overflow.rs @@ -18,42 +18,43 @@ fn test(x: i8) { #[allow(unused_variables)] fn main() { let x1: u8 = 255; // should be OK - let x1: u8 = 256; //~ error: literal out of range for its type + let x1: u8 = 256; //~ error: literal out of range for u8 let x1 = 255_u8; // should be OK - let x1 = 256_u8; //~ error: literal out of range for its type + let x1 = 256_u8; //~ error: literal out of range for u8 let x2: i8 = -128; // should be OK - let x1: i8 = 128; //~ error: literal out of range for its type - let x2: i8 = --128; //~ error: literal out of range for its type + let x1: i8 = 128; //~ error: literal out of range for i8 + let x2: i8 = --128; //~ error: literal out of range for i8 - let x3: i8 = -129; //~ error: literal out of range for its type - let x3: i8 = -(129); //~ error: literal out of range for its type - let x3: i8 = -{129}; //~ error: literal out of range for its type + let x3: i8 = -129; //~ error: literal out of range for i8 + let x3: i8 = -(129); //~ error: literal out of range for i8 + let x3: i8 = -{129}; //~ error: literal out of range for i8 - test(1000); //~ error: literal out of range for its type + test(1000); //~ error: literal out of range for i8 - let x = 128_i8; //~ error: literal out of range for its type + let x = 128_i8; //~ error: literal out of range for i8 let x = 127_i8; let x = -128_i8; let x = -(128_i8); - let x = -129_i8; //~ error: literal out of range for its type + let x = -129_i8; //~ error: literal out of range for i8 let x: i32 = 2147483647; // should be OK let x = 2147483647_i32; // should be OK - let x: i32 = 2147483648; //~ error: literal out of range for its type - let x = 2147483648_i32; //~ error: literal out of range for its type + let x: i32 = 2147483648; //~ error: literal out of range for i32 + let x = 2147483648_i32; //~ error: literal out of range for i32 let x: i32 = -2147483648; // should be OK let x = -2147483648_i32; // should be OK - let x: i32 = -2147483649; //~ error: literal out of range for its type - let x = -2147483649_i32; //~ error: literal out of range for its type + let x: i32 = -2147483649; //~ error: literal out of range for i32 + let x = -2147483649_i32; //~ error: literal out of range for i32 + let x = 2147483648; //~ error: literal out of range for i32 - let x = 9223372036854775808_i64; //~ error: literal out of range for its type + let x = 9223372036854775808_i64; //~ error: literal out of range for i64 let x = -9223372036854775808_i64; // should be OK - let x = 18446744073709551615_i64; //~ error: literal out of range for its type + let x = 18446744073709551615_i64; //~ error: literal out of range for i64 - let x = -3.40282348e+38_f32; //~ error: literal out of range for its type - let x = 3.40282348e+38_f32; //~ error: literal out of range for its type - let x = -1.7976931348623159e+308_f64; //~ error: literal out of range for its type - let x = 1.7976931348623159e+308_f64; //~ error: literal out of range for its type + let x = -3.40282348e+38_f32; //~ error: literal out of range for f32 + let x = 3.40282348e+38_f32; //~ error: literal out of range for f32 + let x = -1.7976931348623159e+308_f64; //~ error: literal out of range for f64 + let x = 1.7976931348623159e+308_f64; //~ error: literal out of range for f64 } From 7eaa589fe519298893899a8581d57667f9427a11 Mon Sep 17 00:00:00 2001 From: Dan Yang Date: Sat, 31 Jan 2015 12:16:14 -0800 Subject: [PATCH 07/14] fix use decl code example in reference --- src/doc/reference.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index 936c0aac79f16..089db3f359c0f 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -1061,7 +1061,7 @@ mod foo { extern crate core; use foo::core::iter; // good: foo is at crate root -// use core::iter; // bad: native is not at the crate root +// use core::iter; // bad: core is not at the crate root use self::baz::foobaz; // good: self refers to module 'foo' use foo::bar::foobar; // good: foo is at crate root From cedc6753f2bb8aedf527245ba9874e85cf669ac2 Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Sat, 31 Jan 2015 14:54:43 -0800 Subject: [PATCH 08/14] Fix end of TtDelimited span --- src/libsyntax/parse/mod.rs | 23 +++++++++++++++++++++++ src/libsyntax/parse/parser.rs | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index e7be876edbbec..6e368bfa803a6 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -755,6 +755,7 @@ mod test { use ast; use abi; use attr::{first_attr_value_str_by_name, AttrMetaMethods}; + use parse; use parse::parser::Parser; use parse::token::{str_to_ident}; use print::pprust::item_to_string; @@ -1214,4 +1215,26 @@ mod test { let doc = first_attr_value_str_by_name(item.attrs.as_slice(), "doc").unwrap(); assert_eq!(doc.get(), "/** doc comment\n * with CRLF */"); } + + #[test] + fn ttdelim_span() { + let sess = parse::new_parse_sess(); + let expr = parse::parse_expr_from_source_str("foo".to_string(), + "foo!( fn main() { body } )".to_string(), vec![], &sess); + + let tts = match expr.node { + ast::ExprMac(ref mac) => { + let ast::MacInvocTT(_, ref tts, _) = mac.node; + tts.clone() + } + _ => panic!("not a macro"), + }; + + let span = tts.iter().rev().next().unwrap().get_span(); + + match sess.span_diagnostic.cm.span_to_snippet(span) { + Some(s) => assert_eq!(&s[], "{ body }"), + None => panic!("could not get snippet"), + } + } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index d99095eeba377..8e88f5a567985 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2735,7 +2735,7 @@ impl<'a> Parser<'a> { self.open_braces.pop().unwrap(); // Expand to cover the entire delimited token tree - let span = Span { hi: self.span.hi, ..pre_span }; + let span = Span { hi: close_span.hi, ..pre_span }; TtDelimited(span, Rc::new(Delimited { delim: delim, From b796c1d6141b0677b2d2401cf65215b5438901ef Mon Sep 17 00:00:00 2001 From: Nick Sarten Date: Sun, 1 Feb 2015 16:42:22 +1300 Subject: [PATCH 09/14] Updated unicode escape documentation to match current implementation. Unicode escapes were changed in [this RFC](https://github.com/rust-lang/rfcs/blob/28aeb3c391c9afd344f124d3a69bdc2a420638b2/text/0446-es6-unicode-escapes.md) to use the ES6 \u{00FFFF} syntax with a variable number of digits from 1-6, eliminating the need for two different syntaxes for unicode literals. --- src/doc/grammar.md | 3 +-- src/doc/reference.md | 16 ++++++---------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/doc/grammar.md b/src/doc/grammar.md index c2cbb3ae3fb2f..59a1c8f828b29 100644 --- a/src/doc/grammar.md +++ b/src/doc/grammar.md @@ -196,8 +196,7 @@ raw_string : '"' raw_string_body '"' | '#' raw_string '#' ; common_escape : '\x5c' | 'n' | 'r' | 't' | '0' | 'x' hex_digit 2 -unicode_escape : 'u' hex_digit 4 - | 'U' hex_digit 8 ; +unicode_escape : 'u' '{' hex_digit+ 6 '}'; hex_digit : 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' diff --git a/src/doc/reference.md b/src/doc/reference.md index 936c0aac79f16..156054871da5e 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -250,8 +250,7 @@ cases mentioned in [Number literals](#number-literals) below. ##### Unicode escapes | | Name | |---|------| -| `\u7FFF` | 16-bit character code (exactly 4 digits) | -| `\U7EEEFFFF` | 32-bit character code (exactly 8 digits) | +| `\u{7FFF}` | 24-bit Unicode character code (up to 6 digits) | ##### Numbers @@ -286,8 +285,8 @@ raw_string : '"' raw_string_body '"' | '#' raw_string '#' ; common_escape : '\x5c' | 'n' | 'r' | 't' | '0' | 'x' hex_digit 2 -unicode_escape : 'u' hex_digit 4 - | 'U' hex_digit 8 ; + +unicode_escape : 'u' '{' hex_digit+ 6 '}'; hex_digit : 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' @@ -320,12 +319,9 @@ following forms: * An _8-bit codepoint escape_ escape starts with `U+0078` (`x`) and is followed by exactly two _hex digits_. It denotes the Unicode codepoint equal to the provided hex value. -* A _16-bit codepoint escape_ starts with `U+0075` (`u`) and is followed - by exactly four _hex digits_. It denotes the Unicode codepoint equal to - the provided hex value. -* A _32-bit codepoint escape_ starts with `U+0055` (`U`) and is followed - by exactly eight _hex digits_. It denotes the Unicode codepoint equal to - the provided hex value. +* A _24-bit codepoint escape_ starts with `U+0075` (`u`) and is followed + by up to six _hex digits_ surrounded by braces `U+007B` (`{`) and `U+007D` + (`}`). It denotes the Unicode codepoint equal to the provided hex value. * A _whitespace escape_ is one of the characters `U+006E` (`n`), `U+0072` (`r`), or `U+0074` (`t`), denoting the unicode values `U+000A` (LF), `U+000D` (CR) or `U+0009` (HT) respectively. From 0828efd72f0c1a1823426f327cddfbced535117a Mon Sep 17 00:00:00 2001 From: Potpourri Date: Sun, 1 Feb 2015 00:59:58 +0300 Subject: [PATCH 10/14] Reject syntax like `use foo::bar::;` and `use foo:: as bar;` and keywords in view path idents --- src/libsyntax/parse/parser.rs | 11 ++++++++--- .../use-as-where-use-ends-with-mod-sep.rs | 11 +++++++++++ src/test/compile-fail/use-ends-with-mod-sep.rs | 11 +++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 src/test/compile-fail/use-as-where-use-ends-with-mod-sep.rs create mode 100644 src/test/compile-fail/use-ends-with-mod-sep.rs diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index d99095eeba377..e2b58e6d87ede 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -5912,9 +5912,9 @@ impl<'a> Parser<'a> { self.bump(); match self.token { - token::Ident(i, _) => { - self.bump(); - path.push(i); + token::Ident(..) => { + let ident = self.parse_ident(); + path.push(ident); } // foo::bar::{a,b,c} @@ -5954,6 +5954,11 @@ impl<'a> Parser<'a> { return P(spanned(lo, self.span.hi, ViewPathGlob(path))); } + // fall-through for case foo::bar::; + token::Semi => { + self.span_err(self.span, "expected identifier or `{` or `*`, found `;`"); + } + _ => break } } diff --git a/src/test/compile-fail/use-as-where-use-ends-with-mod-sep.rs b/src/test/compile-fail/use-as-where-use-ends-with-mod-sep.rs new file mode 100644 index 0000000000000..ef443fc125deb --- /dev/null +++ b/src/test/compile-fail/use-as-where-use-ends-with-mod-sep.rs @@ -0,0 +1,11 @@ +// Copyright 2015 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. + +use std::any:: as foo; //~ ERROR expected identifier or `{` or `*`, found `as` diff --git a/src/test/compile-fail/use-ends-with-mod-sep.rs b/src/test/compile-fail/use-ends-with-mod-sep.rs new file mode 100644 index 0000000000000..a375a5962a567 --- /dev/null +++ b/src/test/compile-fail/use-ends-with-mod-sep.rs @@ -0,0 +1,11 @@ +// Copyright 2015 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. + +use std::any::; //~ ERROR expected identifier or `{` or `*`, found `;` From 0e4448409ef61c703b98e4c5b2fd99447308942d Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 1 Feb 2015 12:15:36 -0800 Subject: [PATCH 11/14] std: Remove extra type params on iter adaptors Now that associated types are fully implemented the iterator adaptors only need type parameters which are associated with actual storage. All other type parameters can either be derived from these (e.g. they are an associated type) or can be bare on the `impl` block itself. This is a breaking change due to the removal of type parameters on these iterator adaptors, but code can fairly easily migrate by just deleting the relevant type parameters for each adaptor. Other behavior should not be affected. Closes #21839 [breaking-change] --- src/libcollections/btree/map.rs | 4 +- src/libcollections/btree/set.rs | 20 +- src/libcollections/vec_map.rs | 8 +- src/libcore/iter.rs | 350 ++++++++---------------- src/libcore/str/mod.rs | 4 +- src/librustc_trans/trans/basic_block.rs | 7 +- src/libstd/collections/hash/map.rs | 18 +- src/libstd/collections/hash/set.rs | 4 +- src/libstd/path/posix.rs | 2 +- src/libstd/path/windows.rs | 4 +- src/libsyntax/parse/mod.rs | 4 +- src/libunicode/u_str.rs | 2 +- 12 files changed, 137 insertions(+), 290 deletions(-) diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index ce5e8f07be1b2..b007f27598045 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -116,13 +116,13 @@ pub struct IntoIter { /// An iterator over a BTreeMap's keys. #[stable(feature = "rust1", since = "1.0.0")] pub struct Keys<'a, K: 'a, V: 'a> { - inner: Map<(&'a K, &'a V), &'a K, Iter<'a, K, V>, fn((&'a K, &'a V)) -> &'a K> + inner: Map, fn((&'a K, &'a V)) -> &'a K> } /// An iterator over a BTreeMap's values. #[stable(feature = "rust1", since = "1.0.0")] pub struct Values<'a, K: 'a, V: 'a> { - inner: Map<(&'a K, &'a V), &'a V, Iter<'a, K, V>, fn((&'a K, &'a V)) -> &'a V> + inner: Map, fn((&'a K, &'a V)) -> &'a V> } /// An iterator over a sub-range of BTreeMap's entries. diff --git a/src/libcollections/btree/set.rs b/src/libcollections/btree/set.rs index 72d5bf6d79932..1445db12a90d7 100644 --- a/src/libcollections/btree/set.rs +++ b/src/libcollections/btree/set.rs @@ -45,40 +45,40 @@ pub struct Iter<'a, T: 'a> { /// An owning iterator over a BTreeSet's items. #[stable(feature = "rust1", since = "1.0.0")] pub struct IntoIter { - iter: Map<(T, ()), T, ::btree_map::IntoIter, fn((T, ())) -> T> + iter: Map<::btree_map::IntoIter, fn((T, ())) -> T> } /// An iterator over a sub-range of BTreeSet's items. pub struct Range<'a, T: 'a> { - iter: Map<(&'a T, &'a ()), &'a T, ::btree_map::Range<'a, T, ()>, fn((&'a T, &'a ())) -> &'a T> + iter: Map<::btree_map::Range<'a, T, ()>, fn((&'a T, &'a ())) -> &'a T> } /// A lazy iterator producing elements in the set difference (in-order). #[stable(feature = "rust1", since = "1.0.0")] pub struct Difference<'a, T:'a> { - a: Peekable<&'a T, Iter<'a, T>>, - b: Peekable<&'a T, Iter<'a, T>>, + a: Peekable>, + b: Peekable>, } /// A lazy iterator producing elements in the set symmetric difference (in-order). #[stable(feature = "rust1", since = "1.0.0")] pub struct SymmetricDifference<'a, T:'a> { - a: Peekable<&'a T, Iter<'a, T>>, - b: Peekable<&'a T, Iter<'a, T>>, + a: Peekable>, + b: Peekable>, } /// A lazy iterator producing elements in the set intersection (in-order). #[stable(feature = "rust1", since = "1.0.0")] pub struct Intersection<'a, T:'a> { - a: Peekable<&'a T, Iter<'a, T>>, - b: Peekable<&'a T, Iter<'a, T>>, + a: Peekable>, + b: Peekable>, } /// A lazy iterator producing elements in the set union (in-order). #[stable(feature = "rust1", since = "1.0.0")] pub struct Union<'a, T:'a> { - a: Peekable<&'a T, Iter<'a, T>>, - b: Peekable<&'a T, Iter<'a, T>>, + a: Peekable>, + b: Peekable>, } impl BTreeSet { diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index f2a9bb4392ccc..b677b3613004f 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -687,7 +687,7 @@ double_ended_iterator! { impl IterMut -> (uint, &'a mut V), as_mut } /// An iterator over the keys of a map. #[stable(feature = "rust1", since = "1.0.0")] pub struct Keys<'a, V: 'a> { - iter: Map<(uint, &'a V), uint, Iter<'a, V>, fn((uint, &'a V)) -> uint> + iter: Map, fn((uint, &'a V)) -> uint> } // FIXME(#19839) Remove in favor of `#[derive(Clone)]` @@ -702,7 +702,7 @@ impl<'a, V> Clone for Keys<'a, V> { /// An iterator over the values of a map. #[stable(feature = "rust1", since = "1.0.0")] pub struct Values<'a, V: 'a> { - iter: Map<(uint, &'a V), &'a V, Iter<'a, V>, fn((uint, &'a V)) -> &'a V> + iter: Map, fn((uint, &'a V)) -> &'a V> } // FIXME(#19839) Remove in favor of `#[derive(Clone)]` @@ -718,8 +718,6 @@ impl<'a, V> Clone for Values<'a, V> { #[stable(feature = "rust1", since = "1.0.0")] pub struct IntoIter { iter: FilterMap< - (uint, Option), - (uint, V), Enumerate>>, fn((uint, Option)) -> Option<(uint, V)>> } @@ -727,8 +725,6 @@ pub struct IntoIter { #[unstable(feature = "collections")] pub struct Drain<'a, V> { iter: FilterMap< - (uint, Option), - (uint, V), Enumerate>>, fn((uint, Option)) -> Option<(uint, V)>> } diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 751b5959d8bd7..84db07266b847 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -239,9 +239,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn zip(self, other: U) -> Zip where - U: Iterator, - { + fn zip(self, other: U) -> Zip { Zip{a: self, b: other} } @@ -259,7 +257,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn map(self, f: F) -> Map where + fn map(self, f: F) -> Map where F: FnMut(Self::Item) -> B, { Map{iter: self, f: f} @@ -279,7 +277,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn filter

(self, predicate: P) -> Filter where + fn filter

(self, predicate: P) -> Filter where P: FnMut(&Self::Item) -> bool, { Filter{iter: self, predicate: predicate} @@ -299,7 +297,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn filter_map(self, f: F) -> FilterMap where + fn filter_map(self, f: F) -> FilterMap where F: FnMut(Self::Item) -> Option, { FilterMap { iter: self, f: f } @@ -342,7 +340,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn peekable(self) -> Peekable { + fn peekable(self) -> Peekable { Peekable{iter: self, peeked: None} } @@ -362,7 +360,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn skip_while

(self, predicate: P) -> SkipWhile where + fn skip_while

(self, predicate: P) -> SkipWhile where P: FnMut(&Self::Item) -> bool, { SkipWhile{iter: self, flag: false, predicate: predicate} @@ -383,7 +381,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn take_while

(self, predicate: P) -> TakeWhile where + fn take_while

(self, predicate: P) -> TakeWhile where P: FnMut(&Self::Item) -> bool, { TakeWhile{iter: self, flag: false, predicate: predicate} @@ -448,12 +446,8 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn scan( - self, - initial_state: St, - f: F, - ) -> Scan where - F: FnMut(&mut St, Self::Item) -> Option, + fn scan(self, initial_state: St, f: F) -> Scan + where F: FnMut(&mut St, Self::Item) -> Option, { Scan{iter: self, f: f, state: initial_state} } @@ -474,9 +468,8 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn flat_map(self, f: F) -> FlatMap where - U: Iterator, - F: FnMut(Self::Item) -> U, + fn flat_map(self, f: F) -> FlatMap + where U: Iterator, F: FnMut(Self::Item) -> U, { FlatMap{iter: self, f: f, frontiter: None, backiter: None } } @@ -534,7 +527,7 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn inspect(self, f: F) -> Inspect where + fn inspect(self, f: F) -> Inspect where F: FnMut(&Self::Item), { Inspect{iter: self, f: f} @@ -1077,16 +1070,14 @@ pub trait ExactSizeIterator: Iterator { #[stable(feature = "rust1", since = "1.0.0")] impl ExactSizeIterator for Enumerate where I: ExactSizeIterator {} #[stable(feature = "rust1", since = "1.0.0")] -impl ExactSizeIterator for Inspect where - I: ExactSizeIterator, - F: FnMut(&A), +impl ExactSizeIterator for Inspect where + F: FnMut(&I::Item), {} #[stable(feature = "rust1", since = "1.0.0")] impl ExactSizeIterator for Rev where I: ExactSizeIterator + DoubleEndedIterator {} #[stable(feature = "rust1", since = "1.0.0")] -impl ExactSizeIterator for Map where - I: ExactSizeIterator, - F: FnMut(A) -> B, +impl ExactSizeIterator for Map where + F: FnMut(I::Item) -> B, {} #[stable(feature = "rust1", since = "1.0.0")] impl ExactSizeIterator for Zip where A: ExactSizeIterator, B: ExactSizeIterator {} @@ -1561,28 +1552,15 @@ impl RandomAccessIterator for Zip where /// An iterator that maps the values of `iter` with `f` #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] -pub struct Map, F: FnMut(A) -> B> { +#[derive(Clone)] +pub struct Map { iter: I, f: F, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` -#[stable(feature = "rust1", since = "1.0.0")] -impl Clone for Map where - I: Clone + Iterator, - F: Clone + FnMut(A) -> B, -{ - fn clone(&self) -> Map { - Map { - iter: self.iter.clone(), - f: self.f.clone(), - } - } -} - -impl Map where I: Iterator, F: FnMut(A) -> B { +impl Map where F: FnMut(I::Item) -> B { #[inline] - fn do_map(&mut self, elt: Option) -> Option { + fn do_map(&mut self, elt: Option) -> Option { match elt { Some(a) => Some((self.f)(a)), _ => None @@ -1591,7 +1569,7 @@ impl Map where I: Iterator, F: FnMut(A) -> B { } #[stable(feature = "rust1", since = "1.0.0")] -impl Iterator for Map where I: Iterator, F: FnMut(A) -> B { +impl Iterator for Map where F: FnMut(I::Item) -> B { type Item = B; #[inline] @@ -1607,9 +1585,8 @@ impl Iterator for Map where I: Iterator, F: FnMu } #[stable(feature = "rust1", since = "1.0.0")] -impl DoubleEndedIterator for Map where - I: DoubleEndedIterator, - F: FnMut(A) -> B, +impl DoubleEndedIterator for Map where + F: FnMut(I::Item) -> B, { #[inline] fn next_back(&mut self) -> Option { @@ -1619,9 +1596,8 @@ impl DoubleEndedIterator for Map where } #[unstable(feature = "core", reason = "trait is experimental")] -impl RandomAccessIterator for Map where - I: RandomAccessIterator, - F: FnMut(A) -> B, +impl RandomAccessIterator for Map where + F: FnMut(I::Item) -> B, { #[inline] fn indexable(&self) -> usize { @@ -1638,31 +1614,18 @@ impl RandomAccessIterator for Map where /// An iterator that filters the elements of `iter` with `predicate` #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] -pub struct Filter where I: Iterator, P: FnMut(&A) -> bool { +#[derive(Clone)] +pub struct Filter { iter: I, predicate: P, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` -#[stable(feature = "rust1", since = "1.0.0")] -impl Clone for Filter where - I: Clone + Iterator, - P: Clone + FnMut(&A) -> bool, -{ - fn clone(&self) -> Filter { - Filter { - iter: self.iter.clone(), - predicate: self.predicate.clone(), - } - } -} - #[stable(feature = "rust1", since = "1.0.0")] -impl Iterator for Filter where I: Iterator, P: FnMut(&A) -> bool { - type Item = A; +impl Iterator for Filter where P: FnMut(&I::Item) -> bool { + type Item = I::Item; #[inline] - fn next(&mut self) -> Option { + fn next(&mut self) -> Option { for x in self.iter.by_ref() { if (self.predicate)(&x) { return Some(x); @@ -1681,12 +1644,11 @@ impl Iterator for Filter where I: Iterator, P: FnMut(& } #[stable(feature = "rust1", since = "1.0.0")] -impl DoubleEndedIterator for Filter where - I: DoubleEndedIterator, - P: FnMut(&A) -> bool, +impl DoubleEndedIterator for Filter + where P: FnMut(&I::Item) -> bool, { #[inline] - fn next_back(&mut self) -> Option { + fn next_back(&mut self) -> Option { for x in self.iter.by_ref().rev() { if (self.predicate)(&x) { return Some(x); @@ -1699,29 +1661,15 @@ impl DoubleEndedIterator for Filter where /// An iterator that uses `f` to both filter and map elements from `iter` #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] -pub struct FilterMap where I: Iterator, F: FnMut(A) -> Option { +#[derive(Clone)] +pub struct FilterMap { iter: I, f: F, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` #[stable(feature = "rust1", since = "1.0.0")] -impl Clone for FilterMap where - I: Clone + Iterator, - F: Clone + FnMut(A) -> Option, -{ - fn clone(&self) -> FilterMap { - FilterMap { - iter: self.iter.clone(), - f: self.f.clone(), - } - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -impl Iterator for FilterMap where - I: Iterator, - F: FnMut(A) -> Option, +impl Iterator for FilterMap + where F: FnMut(I::Item) -> Option, { type Item = B; @@ -1744,9 +1692,8 @@ impl Iterator for FilterMap where } #[stable(feature = "rust1", since = "1.0.0")] -impl DoubleEndedIterator for FilterMap where - I: DoubleEndedIterator, - F: FnMut(A) -> Option, +impl DoubleEndedIterator for FilterMap + where F: FnMut(I::Item) -> Option, { #[inline] fn next_back(&mut self) -> Option { @@ -1824,20 +1771,28 @@ impl RandomAccessIterator for Enumerate where I: RandomAccessIterator { } /// An iterator with a `peek()` that returns an optional reference to the next element. -#[derive(Clone)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] -pub struct Peekable where I: Iterator { +pub struct Peekable { iter: I, - peeked: Option, + peeked: Option, +} + +impl Clone for Peekable where I::Item: Clone { + fn clone(&self) -> Peekable { + Peekable { + iter: self.iter.clone(), + peeked: self.peeked.clone(), + } + } } #[stable(feature = "rust1", since = "1.0.0")] -impl Iterator for Peekable where I: Iterator { - type Item = T; +impl Iterator for Peekable { + type Item = I::Item; #[inline] - fn next(&mut self) -> Option { + fn next(&mut self) -> Option { if self.peeked.is_some() { self.peeked.take() } else { self.iter.next() } } @@ -1859,14 +1814,14 @@ impl Iterator for Peekable where I: Iterator { } #[stable(feature = "rust1", since = "1.0.0")] -impl ExactSizeIterator for Peekable where I: ExactSizeIterator {} +impl ExactSizeIterator for Peekable {} #[stable(feature = "rust1", since = "1.0.0")] -impl Peekable where I: Iterator { - /// Return a reference to the next element of the iterator with out advancing it, - /// or None if the iterator is exhausted. +impl Peekable { + /// Return a reference to the next element of the iterator with out + /// advancing it, or None if the iterator is exhausted. #[inline] - pub fn peek(&mut self) -> Option<&T> { + pub fn peek(&mut self) -> Option<&I::Item> { if self.peeked.is_none() { self.peeked = self.iter.next(); } @@ -1886,33 +1841,21 @@ impl Peekable where I: Iterator { /// An iterator that rejects elements while `predicate` is true #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] -pub struct SkipWhile where I: Iterator, P: FnMut(&A) -> bool { +#[derive(Clone)] +pub struct SkipWhile { iter: I, flag: bool, predicate: P, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` #[stable(feature = "rust1", since = "1.0.0")] -impl Clone for SkipWhile where - I: Clone + Iterator, - P: Clone + FnMut(&A) -> bool, +impl Iterator for SkipWhile + where P: FnMut(&I::Item) -> bool { - fn clone(&self) -> SkipWhile { - SkipWhile { - iter: self.iter.clone(), - flag: self.flag, - predicate: self.predicate.clone(), - } - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -impl Iterator for SkipWhile where I: Iterator, P: FnMut(&A) -> bool { - type Item = A; + type Item = I::Item; #[inline] - fn next(&mut self) -> Option { + fn next(&mut self) -> Option { for x in self.iter.by_ref() { if self.flag || !(self.predicate)(&x) { self.flag = true; @@ -1932,33 +1875,21 @@ impl Iterator for SkipWhile where I: Iterator, P: FnMu /// An iterator that only accepts elements while `predicate` is true #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] -pub struct TakeWhile where I: Iterator, P: FnMut(&A) -> bool { +#[derive(Clone)] +pub struct TakeWhile { iter: I, flag: bool, predicate: P, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` #[stable(feature = "rust1", since = "1.0.0")] -impl Clone for TakeWhile where - I: Clone + Iterator, - P: Clone + FnMut(&A) -> bool, +impl Iterator for TakeWhile + where P: FnMut(&I::Item) -> bool { - fn clone(&self) -> TakeWhile { - TakeWhile { - iter: self.iter.clone(), - flag: self.flag, - predicate: self.predicate.clone(), - } - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -impl Iterator for TakeWhile where I: Iterator, P: FnMut(&A) -> bool { - type Item = A; + type Item = I::Item; #[inline] - fn next(&mut self) -> Option { + fn next(&mut self) -> Option { if self.flag { None } else { @@ -2118,7 +2049,8 @@ impl ExactSizeIterator for Take where I: ExactSizeIterator {} /// An iterator to maintain state while iterating another iterator #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] -pub struct Scan where I: Iterator, F: FnMut(&mut St, A) -> Option { +#[derive(Clone)] +pub struct Scan { iter: I, f: F, @@ -2126,26 +2058,9 @@ pub struct Scan where I: Iterator, F: FnMut(&mut St, A) -> Optio pub state: St, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` #[stable(feature = "rust1", since = "1.0.0")] -impl Clone for Scan where - I: Clone + Iterator, - St: Clone, - F: Clone + FnMut(&mut St, A) -> Option, -{ - fn clone(&self) -> Scan { - Scan { - iter: self.iter.clone(), - f: self.f.clone(), - state: self.state.clone(), - } - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -impl Iterator for Scan where - I: Iterator, - F: FnMut(&mut St, A) -> Option, +impl Iterator for Scan where + F: FnMut(&mut St, I::Item) -> Option, { type Item = B; @@ -2166,44 +2081,22 @@ impl Iterator for Scan where /// #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] -pub struct FlatMap where - I: Iterator, - U: Iterator, - F: FnMut(A) -> U, -{ +#[derive(Clone)] +pub struct FlatMap { iter: I, f: F, frontiter: Option, backiter: Option, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` -#[stable(feature = "rust1", since = "1.0.0")] -impl Clone for FlatMap where - I: Clone + Iterator, - U: Clone + Iterator, - F: Clone + FnMut(A) -> U, -{ - fn clone(&self) -> FlatMap { - FlatMap { - iter: self.iter.clone(), - f: self.f.clone(), - frontiter: self.frontiter.clone(), - backiter: self.backiter.clone(), - } - } -} - #[stable(feature = "rust1", since = "1.0.0")] -impl Iterator for FlatMap where - I: Iterator, - U: Iterator, - F: FnMut(A) -> U, +impl Iterator for FlatMap + where F: FnMut(I::Item) -> U, { - type Item = B; + type Item = U::Item; #[inline] - fn next(&mut self) -> Option { + fn next(&mut self) -> Option { loop { for inner in self.frontiter.iter_mut() { for x in inner.by_ref() { @@ -2230,13 +2123,12 @@ impl Iterator for FlatMap where } #[stable(feature = "rust1", since = "1.0.0")] -impl DoubleEndedIterator for FlatMap where - I: DoubleEndedIterator, - U: DoubleEndedIterator, - F: FnMut(A) -> U, +impl DoubleEndedIterator + for FlatMap + where F: FnMut(I::Item) -> U { #[inline] - fn next_back(&mut self) -> Option { + fn next_back(&mut self) -> Option { loop { for inner in self.backiter.iter_mut() { match inner.next_back() { @@ -2340,28 +2232,15 @@ impl Fuse { /// element before yielding it. #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] -pub struct Inspect where I: Iterator, F: FnMut(&A) { +#[derive(Clone)] +pub struct Inspect { iter: I, f: F, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` -#[stable(feature = "rust1", since = "1.0.0")] -impl Clone for Inspect where - I: Clone + Iterator, - F: Clone + FnMut(&A), -{ - fn clone(&self) -> Inspect { - Inspect { - iter: self.iter.clone(), - f: self.f.clone(), - } - } -} - -impl Inspect where I: Iterator, F: FnMut(&A) { +impl Inspect where F: FnMut(&I::Item) { #[inline] - fn do_inspect(&mut self, elt: Option) -> Option { + fn do_inspect(&mut self, elt: Option) -> Option { match elt { Some(ref a) => (self.f)(a), None => () @@ -2372,11 +2251,11 @@ impl Inspect where I: Iterator, F: FnMut(&A) { } #[stable(feature = "rust1", since = "1.0.0")] -impl Iterator for Inspect where I: Iterator, F: FnMut(&A) { - type Item = A; +impl Iterator for Inspect where F: FnMut(&I::Item) { + type Item = I::Item; #[inline] - fn next(&mut self) -> Option { + fn next(&mut self) -> Option { let next = self.iter.next(); self.do_inspect(next) } @@ -2388,21 +2267,19 @@ impl Iterator for Inspect where I: Iterator, F: FnMut( } #[stable(feature = "rust1", since = "1.0.0")] -impl DoubleEndedIterator for Inspect where - I: DoubleEndedIterator, - F: FnMut(&A), +impl DoubleEndedIterator for Inspect + where F: FnMut(&I::Item), { #[inline] - fn next_back(&mut self) -> Option { + fn next_back(&mut self) -> Option { let next = self.iter.next_back(); self.do_inspect(next) } } #[unstable(feature = "core", reason = "trait is experimental")] -impl RandomAccessIterator for Inspect where - I: RandomAccessIterator, - F: FnMut(&A), +impl RandomAccessIterator for Inspect + where F: FnMut(&I::Item), { #[inline] fn indexable(&self) -> usize { @@ -2410,7 +2287,7 @@ impl RandomAccessIterator for Inspect where } #[inline] - fn idx(&mut self, index: usize) -> Option { + fn idx(&mut self, index: usize) -> Option { let element = self.iter.idx(index); self.do_inspect(element) } @@ -2426,9 +2303,11 @@ impl RandomAccessIterator for Inspect where /// use std::iter::Unfold; /// use std::num::Int; // For `.checked_add()` /// -/// // This iterator will yield up to the last Fibonacci number before the max value of `u32`. -/// // You can simply change `u32` to `u64` in this line if you want higher values than that. -/// let mut fibonacci = Unfold::new((Some(0u32), Some(1u32)), |&mut (ref mut x2, ref mut x1)| { +/// // This iterator will yield up to the last Fibonacci number before the max +/// // value of `u32`. You can simply change `u32` to `u64` in this line if +/// // you want higher values than that. +/// let mut fibonacci = Unfold::new((Some(0u32), Some(1u32)), +/// |&mut (ref mut x2, ref mut x1)| { /// // Attempt to get the next Fibonacci number /// // `x1` will be `None` if previously overflowed. /// let next = match (*x2, *x1) { @@ -2449,32 +2328,19 @@ impl RandomAccessIterator for Inspect where /// } /// ``` #[unstable(feature = "core")] -pub struct Unfold where F: FnMut(&mut St) -> Option { +#[derive(Clone)] +pub struct Unfold { f: F, /// Internal state that will be passed to the closure on the next iteration pub state: St, } -// FIXME(#19839) Remove in favor of `#[derive(Clone)]` -#[stable(feature = "rust1", since = "1.0.0")] -impl Clone for Unfold where - F: Clone + FnMut(&mut St) -> Option, - St: Clone, -{ - fn clone(&self) -> Unfold { - Unfold { - f: self.f.clone(), - state: self.state.clone(), - } - } -} - #[unstable(feature = "core")] -impl Unfold where F: FnMut(&mut St) -> Option { +impl Unfold where F: FnMut(&mut St) -> Option { /// Creates a new iterator with the specified closure as the "iterator /// function" and an initial state to eventually pass to the closure #[inline] - pub fn new(initial_state: St, f: F) -> Unfold { + pub fn new(initial_state: St, f: F) -> Unfold { Unfold { f: f, state: initial_state @@ -2483,7 +2349,7 @@ impl Unfold where F: FnMut(&mut St) -> Option { } #[stable(feature = "rust1", since = "1.0.0")] -impl Iterator for Unfold where F: FnMut(&mut St) -> Option { +impl Iterator for Unfold where F: FnMut(&mut St) -> Option { type Item = A; #[inline] @@ -2921,7 +2787,7 @@ type IterateState = (F, Option, bool); /// An iterator that repeatedly applies a given function, starting /// from a given seed value. #[unstable(feature = "core")] -pub type Iterate = Unfold, fn(&mut IterateState) -> Option>; +pub type Iterate = Unfold, fn(&mut IterateState) -> Option>; /// Create a new iterator that produces an infinite sequence of /// repeated applications of the given function `f`. diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index cb7af3b3d35a1..85b4a2026447f 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -478,7 +478,7 @@ impl<'a> DoubleEndedIterator for CharIndices<'a> { /// Created with `StrExt::bytes` #[stable(feature = "rust1", since = "1.0.0")] #[derive(Clone)] -pub struct Bytes<'a>(Map<&'a u8, u8, slice::Iter<'a, u8>, BytesDeref>); +pub struct Bytes<'a>(Map, BytesDeref>); delegate_iter!{exact u8 : Bytes<'a>} /// A temporary fn new type that ensures that the `Bytes` iterator @@ -526,7 +526,7 @@ pub struct Lines<'a> { /// An iterator over the lines of a string, separated by either `\n` or (`\r\n`). #[stable(feature = "rust1", since = "1.0.0")] pub struct LinesAny<'a> { - inner: Map<&'a str, &'a str, Lines<'a>, fn(&str) -> &str>, + inner: Map, fn(&str) -> &str>, } impl<'a, Sep> CharSplits<'a, Sep> { diff --git a/src/librustc_trans/trans/basic_block.rs b/src/librustc_trans/trans/basic_block.rs index d3ff432b5e418..f11c3154274e7 100644 --- a/src/librustc_trans/trans/basic_block.rs +++ b/src/librustc_trans/trans/basic_block.rs @@ -16,12 +16,7 @@ use std::iter::{Filter, Map}; #[derive(Copy)] pub struct BasicBlock(pub BasicBlockRef); -pub type Preds = Map< - Value, - BasicBlock, - Filter bool>, - fn(Value) -> BasicBlock, ->; +pub type Preds = Map bool>, fn(Value) -> BasicBlock>; /// Wrapper for LLVM BasicBlockRef impl BasicBlock { diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 3e2c7627dbe55..852d5a86fc0e1 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1300,18 +1300,13 @@ pub struct IterMut<'a, K: 'a, V: 'a> { /// HashMap move iterator. #[stable(feature = "rust1", since = "1.0.0")] pub struct IntoIter { - inner: iter::Map< - (SafeHash, K, V), - (K, V), - table::IntoIter, - fn((SafeHash, K, V)) -> (K, V), - > + inner: iter::Map, fn((SafeHash, K, V)) -> (K, V)> } /// HashMap keys iterator. #[stable(feature = "rust1", since = "1.0.0")] pub struct Keys<'a, K: 'a, V: 'a> { - inner: Map<(&'a K, &'a V), &'a K, Iter<'a, K, V>, fn((&'a K, &'a V)) -> &'a K> + inner: Map, fn((&'a K, &'a V)) -> &'a K> } // FIXME(#19839) Remove in favor of `#[derive(Clone)]` @@ -1326,7 +1321,7 @@ impl<'a, K, V> Clone for Keys<'a, K, V> { /// HashMap values iterator. #[stable(feature = "rust1", since = "1.0.0")] pub struct Values<'a, K: 'a, V: 'a> { - inner: Map<(&'a K, &'a V), &'a V, Iter<'a, K, V>, fn((&'a K, &'a V)) -> &'a V> + inner: Map, fn((&'a K, &'a V)) -> &'a V> } // FIXME(#19839) Remove in favor of `#[derive(Clone)]` @@ -1342,12 +1337,7 @@ impl<'a, K, V> Clone for Values<'a, K, V> { #[unstable(feature = "std_misc", reason = "matches collection reform specification, waiting for dust to settle")] pub struct Drain<'a, K: 'a, V: 'a> { - inner: iter::Map< - (SafeHash, K, V), - (K, V), - table::Drain<'a, K, V>, - fn((SafeHash, K, V)) -> (K, V), - > + inner: iter::Map, fn((SafeHash, K, V)) -> (K, V)> } /// A view into a single occupied location in a HashMap. diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index c6dcb0d230ff7..e6b06e5ef1f87 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -794,13 +794,13 @@ pub struct Iter<'a, K: 'a> { /// HashSet move iterator #[stable(feature = "rust1", since = "1.0.0")] pub struct IntoIter { - iter: Map<(K, ()), K, map::IntoIter, fn((K, ())) -> K> + iter: Map, fn((K, ())) -> K> } /// HashSet drain iterator #[stable(feature = "rust1", since = "1.0.0")] pub struct Drain<'a, K: 'a> { - iter: Map<(K, ()), K, map::Drain<'a, K, ()>, fn((K, ())) -> K>, + iter: Map, fn((K, ())) -> K>, } /// Intersection iterator diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 6a0c8a9301070..69f815e3f8b77 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -31,7 +31,7 @@ pub type Components<'a> = Split<'a, u8, fn(&u8) -> bool>; /// Iterator that yields successive components of a Path as Option<&str> pub type StrComponents<'a> = - Map<&'a [u8], Option<&'a str>, Components<'a>, fn(&[u8]) -> Option<&str>>; + Map, fn(&[u8]) -> Option<&str>>; /// Represents a POSIX file path #[derive(Clone)] diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index b524b89ef9fb2..750af47ff8c10 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -40,11 +40,11 @@ use super::{contains_nul, BytesContainer, GenericPath, GenericPathUnsafe}; /// Each component is yielded as Option<&str> for compatibility with PosixPath, but /// every component in WindowsPath is guaranteed to be Some. pub type StrComponents<'a> = - Map<&'a str, Option<&'a str>, SplitTerminator<'a, char>, fn(&'a str) -> Option<&'a str>>; + Map, fn(&'a str) -> Option<&'a str>>; /// Iterator that yields successive components of a Path as &[u8] pub type Components<'a> = - Map, &'a [u8], StrComponents<'a>, fn(Option<&str>) -> &[u8]>; + Map, fn(Option<&str>) -> &[u8]>; /// Represents a Windows path // Notes for Windows path impl: diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 8ac5b6e52747a..3e8eab39d8877 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -436,7 +436,7 @@ pub fn str_lit(lit: &str) -> String { let error = |&: i| format!("lexer should have rejected {} at {}", lit, i); /// Eat everything up to a non-whitespace - fn eat<'a>(it: &mut iter::Peekable<(usize, char), str::CharIndices<'a>>) { + fn eat<'a>(it: &mut iter::Peekable>) { loop { match it.peek().map(|x| x.1) { Some(' ') | Some('\n') | Some('\r') | Some('\t') => { @@ -605,7 +605,7 @@ pub fn binary_lit(lit: &str) -> Rc> { let error = |&: i| format!("lexer should have rejected {} at {}", lit, i); /// Eat everything up to a non-whitespace - fn eat<'a, I: Iterator>(it: &mut iter::Peekable<(usize, u8), I>) { + fn eat<'a, I: Iterator>(it: &mut iter::Peekable) { loop { match it.peek().map(|x| x.1) { Some(b' ') | Some(b'\n') | Some(b'\r') | Some(b'\t') => { diff --git a/src/libunicode/u_str.rs b/src/libunicode/u_str.rs index 9a757c0c980dd..0e3aacbc09a9a 100644 --- a/src/libunicode/u_str.rs +++ b/src/libunicode/u_str.rs @@ -32,7 +32,7 @@ use tables::grapheme::GraphemeCat; /// An iterator over the words of a string, separated by a sequence of whitespace #[stable(feature = "rust1", since = "1.0.0")] pub struct Words<'a> { - inner: Filter<&'a str, Split<'a, fn(char) -> bool>, fn(&&str) -> bool>, + inner: Filter bool>, fn(&&str) -> bool>, } /// Methods for Unicode string slices From 8d57f8c0a04e1afa7c13b75137c658b6048f7d8b Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Mon, 2 Feb 2015 03:45:52 +0530 Subject: [PATCH 12/14] Fix stale doc link (guide -> book) --- src/libtest/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index f22c58c54a685..1bb841120c7ce 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -16,7 +16,7 @@ //! benchmarks themselves) should be done via the `#[test]` and //! `#[bench]` attributes. //! -//! See the [Testing Guide](../guide-testing.html) for more details. +//! See the [Testing Chapter](../book/testing.html) of the book for more details. // Currently, not much of this is meant for users. It is intended to // support the simplest interface possible for representing and From 0187ea61a66be23741830c8bc3c2262556e1dd56 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 1 Feb 2015 14:25:55 -0800 Subject: [PATCH 13/14] rustc: Change an unconditional `warn` to a `note` There [have been reports][issue] of an unconditional warning causing tooling to go awry. This isn't actually a warning per se, it's more of a note anyway! [issue]: https://github.com/rust-lang/cargo/issues/1260 Closes rust-lang/cargo#1260 --- src/librustc_trans/back/link.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index 93a2b6eaa4f02..590632d7140e0 100644 --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -740,7 +740,7 @@ fn link_staticlib(sess: &Session, obj_filename: &Path, out_filename: &Path) { let _ = ab.build(); if !all_native_libs.is_empty() { - sess.warn("link against the following native artifacts when linking against \ + sess.note("link against the following native artifacts when linking against \ this static library"); sess.note("the order and any duplication can be significant on some platforms, \ and so may need to be preserved"); From cf26c36d276817c18f9153a7303bab9152ae5853 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 3 Feb 2015 00:48:05 +0530 Subject: [PATCH 14/14] fix test --- src/test/compile-fail/lint-unknown-feature-default.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/compile-fail/lint-unknown-feature-default.rs b/src/test/compile-fail/lint-unknown-feature-default.rs index d5e9cc630c359..36e5ad35b2bce 100644 --- a/src/test/compile-fail/lint-unknown-feature-default.rs +++ b/src/test/compile-fail/lint-unknown-feature-default.rs @@ -10,6 +10,8 @@ // Tests the default for the unused_features lint +#![deny(unused_features)] + #![feature(this_is_not_a_feature)] //~ ERROR: unused or unknown feature fn main() { }