From dddc4ca90b406e24e890bfdb1566cb8ea93c9c48 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 26 Aug 2015 13:13:18 +0200 Subject: [PATCH 01/17] Improve E0046 --- src/librustc_typeck/diagnostics.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 0223079b8bf39..802d3dbe39786 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -401,10 +401,35 @@ extern "C" { "##, E0046: r##" +Items are missing in a trait implementation. Erroneous code example: + +``` +trait Foo { + fn foo(); +} + +struct Bar; + +impl Foo for Bar {} +// error: not all trait items implemented, missing: `foo` +``` + When trying to make some type implement a trait `Foo`, you must, at minimum, provide implementations for all of `Foo`'s required methods (meaning the methods that do not have default implementations), as well as any required -trait items like associated types or constants. +trait items like associated types or constants. Example: + +``` +trait Foo { + fn foo(); +} + +struct Bar; + +impl Foo for Bar { + fn foo() {} // ok! +} +``` "##, E0049: r##" From 9e51cee69a24704facbdf0a9b0a8e4fe5f9c85ac Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 26 Aug 2015 13:22:55 +0200 Subject: [PATCH 02/17] Improve E0062 error explanation --- src/librustc_typeck/diagnostics.rs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 802d3dbe39786..5e86f1cbd5c18 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -640,8 +640,32 @@ variadic functions (except for its C-FFI). E0062: r##" This error indicates that during an attempt to build a struct or struct-like -enum variant, one of the fields was specified more than once. Each field should -be specified exactly one time. +enum variant, one of the fields was specified more than once. Erroneous code +example: + +``` +struct Foo { + x: i32 +} + +fn main() { + let x = Foo { x: 0, + x: 0, // error: field `x` specified more than once + }; +} +``` + +Each field should be specified exactly one time. Example: + +``` +struct Foo { + x: i32 +} + +fn main() { + let x = Foo { x: 0 }; // ok! +} +``` "##, E0063: r##" From 612221ff8035b21a343c73921334071346609eb9 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 26 Aug 2015 13:30:34 +0200 Subject: [PATCH 03/17] Improve E0063 error explanation --- src/librustc_typeck/diagnostics.rs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 5e86f1cbd5c18..d03751275c0f0 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -670,8 +670,31 @@ fn main() { E0063: r##" This error indicates that during an attempt to build a struct or struct-like -enum variant, one of the fields was not provided. Each field should be -specified exactly once. +enum variant, one of the fields was not provided. Erroneous code example: + +``` +struct Foo { + x: i32, + y: i32 +} + +fn main() { + let x = Foo { x: 0 }; // error: missing field: `y` +} +``` + +Each field should be specified exactly once. Example: + +``` +struct Foo { + x: i32, + y: i32 +} + +fn main() { + let x = Foo { x: 0, y: 0 }; // ok! +} +``` "##, E0066: r##" From 5d8dc9076bf387398eeac9c50109a15026e22b36 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 26 Aug 2015 13:38:27 +0200 Subject: [PATCH 04/17] Improve E0025 error explanation --- src/librustc_typeck/diagnostics.rs | 37 ++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index d03751275c0f0..100415c29c67f 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -73,10 +73,39 @@ the enum. "##, E0025: r##" -Each field of a struct can only be bound once in a pattern. Each occurrence of a -field name binds the value of that field, so to fix this error you will have to -remove or alter the duplicate uses of the field name. Perhaps you misspelt -another field name? +Each field of a struct can only be bound once in a pattern. Erroneous code +example: + +``` +struct Foo { + a: u8, + b: u8, +} + +fn main(){ + let x = Foo { a:1, b:2 }; + + let Foo { a: x, a: y } = x; + // error: field `a` bound multiple times in the pattern +} +``` + +Each occurrence of a field name binds the value of that field, so to fix this +error you will have to remove or alter the duplicate uses of the field name. +Perhaps you misspelled another field name? Example: + +``` +struct Foo { + a: u8, + b: u8, +} + +fn main(){ + let x = Foo { a:1, b:2 }; + + let Foo { a: x, b: y } = x; // ok! +} +``` "##, E0026: r##" From af02bccb41a2432d13686d0d5828118ea7d23bb2 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 26 Aug 2015 14:16:12 +0200 Subject: [PATCH 05/17] Fix typo in E0087 --- src/librustc_typeck/diagnostics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 100415c29c67f..2bf1c0bb4d356 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1126,7 +1126,7 @@ fn main() { } ``` -The number of supplied parameters much exactly match the number of defined type +The number of supplied parameters must exactly match the number of defined type parameters. "##, From 0c4faf2a0785ea00f8498289dd2a558627b5bc66 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 26 Aug 2015 14:21:03 +0200 Subject: [PATCH 06/17] Add erroneous code example for E0131 --- src/librustc_typeck/diagnostics.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 2bf1c0bb4d356..526a895592bf9 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1721,6 +1721,12 @@ extern { E0131: r##" It is not possible to define `main` with type parameters, or even with function parameters. When `main` is present, it must take no arguments and return `()`. +Erroneous code example: + +``` +fn main() { // error: main function is not allowed to have type parameters +} +``` "##, E0132: r##" From 9f15b281195b413791bbfd8a60a7448bb156e102 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 26 Aug 2015 14:21:46 +0200 Subject: [PATCH 07/17] Add missing ';' in E0132 --- src/librustc_typeck/diagnostics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 526a895592bf9..3c7f754aabc34 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1734,7 +1734,7 @@ It is not possible to declare type parameters on a function that has the `start` attribute. Such a function must have the following type signature: ``` -fn(isize, *const *const u8) -> isize +fn(isize, *const *const u8) -> isize; ``` "##, From dfb0677bee189fcd20c568009b620b9469d7becb Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 26 Aug 2015 14:23:51 +0200 Subject: [PATCH 08/17] Remove unnecessary whitespace --- src/librustc_typeck/diagnostics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 3c7f754aabc34..b50d2d9c26e89 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1886,7 +1886,7 @@ rfcs/blob/master/text/0019-opt-in-builtin-traits.md). E0193: r##" `where` clauses must use generic type parameters: it does not make sense to use -them otherwise. An example causing this error: +them otherwise. An example causing this error: ``` trait Foo { From 805e4e6fd1e5dccf20e58322e4d0540fdb871b9b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 26 Aug 2015 14:28:42 +0200 Subject: [PATCH 09/17] Remove unnecessary empty lines --- src/librustc_typeck/diagnostics.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index b50d2d9c26e89..a2b3a60028130 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1988,7 +1988,6 @@ unsafe impl Foo { } // converting it to this will fix it impl Foo { } ``` - "##, E0198: r##" @@ -2005,7 +2004,6 @@ unsafe impl !Clone for Foo { } // this will compile impl !Clone for Foo { } ``` - "##, E0199: r##" @@ -2023,7 +2021,6 @@ unsafe impl Bar for Foo { } // this will compile impl Bar for Foo { } ``` - "##, E0200: r##" @@ -2041,7 +2038,6 @@ impl Bar for Foo { } // this will compile unsafe impl Bar for Foo { } ``` - "##, E0201: r##" From acafe3b730cab343ce76c3c03bbf158393772782 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 26 Aug 2015 14:43:28 +0200 Subject: [PATCH 10/17] Add E0370 error explanation --- src/librustc_typeck/diagnostics.rs | 35 +++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index a2b3a60028130..c3cf54f4b82bf 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -84,7 +84,7 @@ struct Foo { fn main(){ let x = Foo { a:1, b:2 }; - + let Foo { a: x, a: y } = x; // error: field `a` bound multiple times in the pattern } @@ -102,7 +102,7 @@ struct Foo { fn main(){ let x = Foo { a:1, b:2 }; - + let Foo { a: x, b: y } = x; // ok! } ``` @@ -2820,6 +2820,36 @@ It is also possible to overload most operators for your own type by implementing traits from `std::ops`. "##, +E0370: r##" +The maximum value of an enum was reached, so it cannot be automatically +set in the next enum value. Erroneous code example: + +``` +enum Foo { + X = 0x7fffffffffffffff, + Y // error: enum discriminant overflowed on value after + // 9223372036854775807: i64; set explicitly via + // Y = -9223372036854775808 if that is desired outcome +} +``` + +To fix this, please set manually the next enum value or put the enum variant +with the maximum value at the end of the enum. Examples: + +``` +enum Foo { + X = 0x7fffffffffffffff, + Y = 0, // ok! +} + +// or: +enum Foo { + Y = 0, // ok! + X = 0x7fffffffffffffff, +} +``` +"##, + E0371: r##" When `Trait2` is a subtrait of `Trait1` (for example, when `Trait2` has a definition like `trait Trait2: Trait1 { ... }`), it is not allowed to implement @@ -3037,7 +3067,6 @@ register_diagnostics! { E0321, // extended coherence rules for defaulted traits violated E0328, // cannot implement Unsize explicitly E0329, // associated const depends on type parameter or Self. - E0370, // discriminant overflow E0374, // the trait `CoerceUnsized` may only be implemented for a coercion // between structures with one field being coerced, none found E0375, // the trait `CoerceUnsized` may only be implemented for a coercion From c891fae175ecb096a847877d2e4f238ceef9f34b Mon Sep 17 00:00:00 2001 From: Artem Shitov Date: Wed, 26 Aug 2015 16:20:57 +0300 Subject: [PATCH 11/17] Fix keyboard scrolling in rustbook --- src/rustbook/static/rustbook.css | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/rustbook/static/rustbook.css b/src/rustbook/static/rustbook.css index 3e0537c5551f6..84cccda8172be 100644 --- a/src/rustbook/static/rustbook.css +++ b/src/rustbook/static/rustbook.css @@ -27,7 +27,7 @@ h1, h2, h3, h4, h5, h6 { @media only screen { #toc { - position: absolute; + position: fixed; left: 0px; top: 0px; bottom: 0px; @@ -48,7 +48,6 @@ h1, h2, h3, h4, h5, h6 { left: 310px; right: 0px; top: 0px; - bottom: 0px; box-sizing: border-box; background: none repeat scroll 0% 0% #FFF; -webkit-overflow-scrolling: touch; From b39201637dcd8be3994b1755550d2ab4d63e3657 Mon Sep 17 00:00:00 2001 From: Artem Shitov Date: Wed, 26 Aug 2015 16:28:31 +0300 Subject: [PATCH 12/17] Remove redundant overflowing rule --- src/rustbook/static/rustbook.css | 1 - 1 file changed, 1 deletion(-) diff --git a/src/rustbook/static/rustbook.css b/src/rustbook/static/rustbook.css index 84cccda8172be..6b9e7aa58f247 100644 --- a/src/rustbook/static/rustbook.css +++ b/src/rustbook/static/rustbook.css @@ -44,7 +44,6 @@ h1, h2, h3, h4, h5, h6 { #page-wrapper { position: absolute; - overflow-y: auto; left: 310px; right: 0px; top: 0px; From 933eb3e320fe6e6c06d182f52c3e599b7e5a46c3 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Wed, 26 Aug 2015 23:15:51 +0200 Subject: [PATCH 13/17] path: the if-else block looked unusual --- src/libstd/path.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 71aed0408711e..08be959de086a 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -598,8 +598,11 @@ impl<'a> Components<'a> { /// how much of the prefix is left from the point of view of iteration? #[inline] fn prefix_remaining(&self) -> usize { - if self.front == State::Prefix { self.prefix_len() } - else { 0 } + if self.front == State::Prefix { + self.prefix_len() + } else { + 0 + } } // Given the iteration so far, how much of the pre-State::Body path is left? From a7313a0b891fb5fa62357527409bafde63aa44aa Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Thu, 27 Aug 2015 08:37:40 +0200 Subject: [PATCH 14/17] core: Implement IntoIterator for Option and Result references Fixes #27996. --- src/libcore/option.rs | 20 ++++++++++++++++++++ src/libcore/result.rs | 20 ++++++++++++++++++++ src/libcoretest/option.rs | 9 ++++++++- src/libcoretest/result.rs | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 1 deletion(-) diff --git a/src/libcore/option.rs b/src/libcore/option.rs index e64048c82d839..a36a120689cc6 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -779,6 +779,26 @@ impl IntoIterator for Option { } } +#[stable(since = "1.4.0", feature = "option_iter")] +impl<'a, T> IntoIterator for &'a Option { + type Item = &'a T; + type IntoIter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } +} + +#[stable(since = "1.4.0", feature = "option_iter")] +impl<'a, T> IntoIterator for &'a mut Option { + type Item = &'a mut T; + type IntoIter = IterMut<'a, T>; + + fn into_iter(mut self) -> IterMut<'a, T> { + self.iter_mut() + } +} + ///////////////////////////////////////////////////////////////////////////// // The Option Iterators ///////////////////////////////////////////////////////////////////////////// diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 8300faa5a16fe..2546d9cd63d83 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -815,6 +815,26 @@ impl IntoIterator for Result { } } +#[stable(since = "1.4.0", feature = "result_iter")] +impl<'a, T, E> IntoIterator for &'a Result { + type Item = &'a T; + type IntoIter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } +} + +#[stable(since = "1.4.0", feature = "result_iter")] +impl<'a, T, E> IntoIterator for &'a mut Result { + type Item = &'a mut T; + type IntoIter = IterMut<'a, T>; + + fn into_iter(mut self) -> IterMut<'a, T> { + self.iter_mut() + } +} + ///////////////////////////////////////////////////////////////////////////// // The Result Iterators ///////////////////////////////////////////////////////////////////////////// diff --git a/src/libcoretest/option.rs b/src/libcoretest/option.rs index 04271ed5dd1a1..3e564cf197061 100644 --- a/src/libcoretest/option.rs +++ b/src/libcoretest/option.rs @@ -180,11 +180,14 @@ fn test_iter() { assert_eq!(it.next(), Some(&val)); assert_eq!(it.size_hint(), (0, Some(0))); assert!(it.next().is_none()); + + let mut it = (&x).into_iter(); + assert_eq!(it.next(), Some(&val)); } #[test] fn test_mut_iter() { - let val = 5; + let mut val = 5; let new_val = 11; let mut x = Some(val); @@ -205,6 +208,10 @@ fn test_mut_iter() { assert!(it.next().is_none()); } assert_eq!(x, Some(new_val)); + + let mut y = Some(val); + let mut it = (&mut y).into_iter(); + assert_eq!(it.next(), Some(&mut val)); } #[test] diff --git a/src/libcoretest/result.rs b/src/libcoretest/result.rs index 02ea6b10e6e03..6e9f653dcd8ac 100644 --- a/src/libcoretest/result.rs +++ b/src/libcoretest/result.rs @@ -150,3 +150,36 @@ pub fn test_expect_err() { let err: Result = Err("All good"); err.expect("Got expected error"); } + +#[test] +pub fn test_iter() { + let ok: Result = Ok(100); + let mut it = ok.iter(); + assert_eq!(it.size_hint(), (1, Some(1))); + assert_eq!(it.next(), Some(&100)); + assert_eq!(it.size_hint(), (0, Some(0))); + assert!(it.next().is_none()); + assert_eq!((&ok).into_iter().next(), Some(&100)); + + let err: Result = Err("error"); + assert_eq!(err.iter().next(), None); +} + +#[test] +pub fn test_iter_mut() { + let mut ok: Result = Ok(100); + for loc in ok.iter_mut() { + *loc = 200; + } + assert_eq!(ok, Ok(200)); + for loc in &mut ok { + *loc = 300; + } + assert_eq!(ok, Ok(300)); + + let mut err: Result = Err("error"); + for loc in err.iter_mut() { + *loc = 200; + } + assert_eq!(err, Err("error")); +} From fbbd8741710c1f8b40a8ec3422672043bbeaaa05 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 27 Aug 2015 15:44:08 +0200 Subject: [PATCH 15/17] Comment out unused error codes in librustc_typeck/diagnostics.rs --- src/librustc_typeck/diagnostics.rs | 55 +++++++++++++++--------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index c3cf54f4b82bf..0dbfffe5c644a 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -678,9 +678,10 @@ struct Foo { } fn main() { - let x = Foo { x: 0, - x: 0, // error: field `x` specified more than once - }; + let x = Foo { + x: 0, + x: 0, // error: field `x` specified more than once + }; } ``` @@ -3002,44 +3003,44 @@ https://doc.rust-lang.org/std/marker/struct.PhantomData.html } register_diagnostics! { - E0068, - E0085, - E0086, +// E0068, +// E0085, +// E0086, E0090, E0103, // @GuillaumeGomez: I was unable to get this error, try your best! E0104, E0118, E0122, - E0123, - E0127, - E0129, - E0141, +// E0123, +// E0127, +// E0129, +// E0141, // E0159, // use of trait `{}` as struct constructor E0163, E0164, E0167, // E0168, - E0173, // manual implementations of unboxed closure traits are experimental +// E0173, // manual implementations of unboxed closure traits are experimental E0174, // explicit use of unboxed closure methods are experimental E0182, E0183, - E0187, // can't infer the kind of the closure - E0188, // can not cast a immutable reference to a mutable pointer - E0189, // deprecated: can only cast a boxed pointer to a boxed object - E0190, // deprecated: can only cast a &-pointer to an &-object +// E0187, // can't infer the kind of the closure +// E0188, // can not cast a immutable reference to a mutable pointer +// E0189, // deprecated: can only cast a boxed pointer to a boxed object +// E0190, // deprecated: can only cast a &-pointer to an &-object E0196, // cannot determine a type for this closure E0203, // type parameter has more than one relaxed default bound, // and only one is supported E0208, - E0209, // builtin traits can only be implemented on structs or enums +// E0209, // builtin traits can only be implemented on structs or enums E0212, // cannot extract an associated type from a higher-ranked trait bound - E0213, // associated types are not accepted in this context +// E0213, // associated types are not accepted in this context E0214, // parenthesized parameters may only be used with a trait // E0215, // angle-bracket notation is not stable with `Fn` // E0216, // parenthetical notation is only stable with `Fn` - E0217, // ambiguous associated type, defined in multiple supertraits - E0218, // no associated type defined - E0219, // associated type defined in higher-ranked supertrait +// E0217, // ambiguous associated type, defined in multiple supertraits +// E0218, // no associated type defined +// E0219, // associated type defined in higher-ranked supertrait // E0222, // Error code E0045 (variadic function must have C calling // convention) duplicate E0224, // at least one non-builtin train is required for an object type @@ -3049,20 +3050,20 @@ register_diagnostics! { E0229, // associated type bindings are not allowed here E0230, // there is no type parameter on trait E0231, // only named substitution parameters are allowed - E0233, - E0234, +// E0233, +// E0234, // E0235, // structure constructor specifies a structure of type but E0236, // no lang item for range syntax E0237, // no lang item for range syntax E0238, // parenthesized parameters may only be used with a trait - E0239, // `next` method of `Iterator` trait has unexpected type - E0240, - E0241, +// E0239, // `next` method of `Iterator` trait has unexpected type +// E0240, +// E0241, E0242, // internal error looking up a definition E0245, // not a trait - E0246, // invalid recursive type +// E0246, // invalid recursive type E0247, // found module name used as a type - E0319, // trait impls for defaulted traits allowed just for structs/enums +// E0319, // trait impls for defaulted traits allowed just for structs/enums E0320, // recursive overflow during dropck E0321, // extended coherence rules for defaulted traits violated E0328, // cannot implement Unsize explicitly From 21f209a28b7294fb7afe73cc5a37aad93d426b75 Mon Sep 17 00:00:00 2001 From: Andrew Paseltiner Date: Thu, 27 Aug 2015 13:30:37 -0400 Subject: [PATCH 16/17] remove calls to deprecated `iter::order` functions --- src/libcoretest/iter.rs | 53 ++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/src/libcoretest/iter.rs b/src/libcoretest/iter.rs index 87e69581c54b3..9def44191db05 100644 --- a/src/libcoretest/iter.rs +++ b/src/libcoretest/iter.rs @@ -9,7 +9,6 @@ // except according to those terms. use core::iter::*; -use core::iter::order::*; use core::{i8, i16, isize}; use core::usize; @@ -21,51 +20,51 @@ fn test_lt() { let xs = [1,2,3]; let ys = [1,2,0]; - assert!(!lt(xs.iter(), ys.iter())); - assert!(!le(xs.iter(), ys.iter())); - assert!( gt(xs.iter(), ys.iter())); - assert!( ge(xs.iter(), ys.iter())); + assert!(!xs.iter().lt(ys.iter())); + assert!(!xs.iter().le(ys.iter())); + assert!( xs.iter().gt(ys.iter())); + assert!( xs.iter().ge(ys.iter())); - assert!( lt(ys.iter(), xs.iter())); - assert!( le(ys.iter(), xs.iter())); - assert!(!gt(ys.iter(), xs.iter())); - assert!(!ge(ys.iter(), xs.iter())); + assert!( ys.iter().lt(xs.iter())); + assert!( ys.iter().le(xs.iter())); + assert!(!ys.iter().gt(xs.iter())); + assert!(!ys.iter().ge(xs.iter())); - assert!( lt(empty.iter(), xs.iter())); - assert!( le(empty.iter(), xs.iter())); - assert!(!gt(empty.iter(), xs.iter())); - assert!(!ge(empty.iter(), xs.iter())); + assert!( empty.iter().lt(xs.iter())); + assert!( empty.iter().le(xs.iter())); + assert!(!empty.iter().gt(xs.iter())); + assert!(!empty.iter().ge(xs.iter())); // Sequence with NaN let u = [1.0f64, 2.0]; let v = [0.0f64/0.0, 3.0]; - assert!(!lt(u.iter(), v.iter())); - assert!(!le(u.iter(), v.iter())); - assert!(!gt(u.iter(), v.iter())); - assert!(!ge(u.iter(), v.iter())); + assert!(!u.iter().lt(v.iter())); + assert!(!u.iter().le(v.iter())); + assert!(!u.iter().gt(v.iter())); + assert!(!u.iter().ge(v.iter())); let a = [0.0f64/0.0]; let b = [1.0f64]; let c = [2.0f64]; - assert!(lt(a.iter(), b.iter()) == (a[0] < b[0])); - assert!(le(a.iter(), b.iter()) == (a[0] <= b[0])); - assert!(gt(a.iter(), b.iter()) == (a[0] > b[0])); - assert!(ge(a.iter(), b.iter()) == (a[0] >= b[0])); + assert!(a.iter().lt(b.iter()) == (a[0] < b[0])); + assert!(a.iter().le(b.iter()) == (a[0] <= b[0])); + assert!(a.iter().gt(b.iter()) == (a[0] > b[0])); + assert!(a.iter().ge(b.iter()) == (a[0] >= b[0])); - assert!(lt(c.iter(), b.iter()) == (c[0] < b[0])); - assert!(le(c.iter(), b.iter()) == (c[0] <= b[0])); - assert!(gt(c.iter(), b.iter()) == (c[0] > b[0])); - assert!(ge(c.iter(), b.iter()) == (c[0] >= b[0])); + assert!(c.iter().lt(b.iter()) == (c[0] < b[0])); + assert!(c.iter().le(b.iter()) == (c[0] <= b[0])); + assert!(c.iter().gt(b.iter()) == (c[0] > b[0])); + assert!(c.iter().ge(b.iter()) == (c[0] >= b[0])); } #[test] fn test_multi_iter() { let xs = [1,2,3,4]; let ys = [4,3,2,1]; - assert!(eq(xs.iter(), ys.iter().rev())); - assert!(lt(xs.iter(), xs.iter().skip(2))); + assert!(xs.iter().eq(ys.iter().rev())); + assert!(xs.iter().lt(xs.iter().skip(2))); } #[test] From 59653c10a6f6683f0c5fa4aab75fe01207a4fa21 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Thu, 27 Aug 2015 14:14:03 -0400 Subject: [PATCH 17/17] Some extra examples for the unimplemented! macro --- src/libcore/macros.rs | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index 9f4d61a50d57a..21038f25be3cf 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -254,6 +254,51 @@ macro_rules! unreachable { /// A standardised placeholder for marking unfinished code. It panics with the /// message `"not yet implemented"` when executed. +/// +/// This can be useful if you are prototyping and are just looking to have your +/// code typecheck, or if you're implementing a trait that requires multiple +/// methods, and you're only planning on using one of them. +/// +/// # Examples +/// +/// Here's an example of some in-progress code. We have a trait `Foo`: +/// +/// ``` +/// trait Foo { +/// fn bar(&self); +/// fn baz(&self); +/// } +/// ``` +/// +/// We want to implement `Foo` on one of our types, but we also want to work on +/// just `bar()` first. In order for our code to compile, we need to implement +/// `baz()`, so we can use `unimplemented!`: +/// +/// ``` +/// # trait Foo { +/// # fn foo(&self); +/// # fn bar(&self); +/// # } +/// struct MyStruct; +/// +/// impl Foo for MyStruct { +/// fn foo(&self) { +/// // implementation goes here +/// } +/// +/// fn bar(&self) { +/// // let's not worry about implementing bar() for now +/// unimplemented!(); +/// } +/// } +/// +/// fn main() { +/// let s = MyStruct; +/// s.foo(); +/// +/// // we aren't even using bar() yet, so this is fine. +/// } +/// ``` #[macro_export] #[unstable(feature = "core", reason = "relationship with panic is unclear")]