From 0f9cb1b97cbb10eb400768c8e6a3851c93515470 Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Tue, 23 Aug 2016 02:05:53 +0200 Subject: [PATCH 1/6] Change a weird line break in `core::str` --- src/libcore/str/mod.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index fdcadd43a0f..c085c8103fa 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -388,8 +388,9 @@ pub fn next_code_point<'a, I: Iterator>(bytes: &mut I) -> Option< /// Reads the last code point out of a byte iterator (assuming a /// UTF-8-like encoding). #[inline] -fn next_code_point_reverse<'a, - I: DoubleEndedIterator>(bytes: &mut I) -> Option { +fn next_code_point_reverse<'a, I>(bytes: &mut I) -> Option + where I: DoubleEndedIterator, +{ // Decode UTF-8 let w = match bytes.next_back() { None => return None, From f863ea3d16fe0362249bd2f130a0b64022ca1b10 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 23 Aug 2016 00:38:26 +0000 Subject: [PATCH 2/6] Update rust-installer. Fixes #35840 --- src/rust-installer | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rust-installer b/src/rust-installer index c37d3747da7..755bc3db4ff 160000 --- a/src/rust-installer +++ b/src/rust-installer @@ -1 +1 @@ -Subproject commit c37d3747da75c280237dc2d6b925078e69555499 +Subproject commit 755bc3db4ff795865ea31b5b4f38ac920d8acacb From 66a2578064c2572a355f87f2405859a1c347b590 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Mon, 22 Aug 2016 20:39:20 -0400 Subject: [PATCH 3/6] Mark panicking tests as `should_panic` instead of `no_run`. --- src/doc/book/macros.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/book/macros.md b/src/doc/book/macros.md index 9f40829f423..78fe07ec1be 100644 --- a/src/doc/book/macros.md +++ b/src/doc/book/macros.md @@ -662,7 +662,7 @@ Here are some common macros you’ll see in Rust code. This macro causes the current thread to panic. You can give it a message to panic with: -```rust,no_run +```rust,should_panic panic!("oh no!"); ``` @@ -688,7 +688,7 @@ These two macros are used in tests. `assert!` takes a boolean. `assert_eq!` takes two values and checks them for equality. `true` passes, `false` `panic!`s. Like this: -```rust,no_run +```rust,should_panic // A-ok! assert!(true); From 2cad78d5eb6d7f185c75a53851adf2cb271f77b3 Mon Sep 17 00:00:00 2001 From: Matthew Piziak Date: Tue, 23 Aug 2016 12:09:06 -0400 Subject: [PATCH 4/6] replace `Div` example with something more evocative of division Analogous to PR #35860. r? @GuillaumeGomez --- src/libcore/ops.rs | 61 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 282f281047e..c9124249bf5 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -421,25 +421,68 @@ mul_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 } /// /// # Examples /// -/// A trivial implementation of `Div`. When `Foo / Foo` happens, it ends up -/// calling `div`, and therefore, `main` prints `Dividing!`. +/// Implementing a `Div`idable rational number struct: /// /// ``` /// use std::ops::Div; /// -/// struct Foo; +/// // The uniqueness of rational numbers in lowest terms is a consequence of +/// // the fundamental theorem of arithmetic. +/// #[derive(Eq)] +/// #[derive(PartialEq, Debug)] +/// struct Rational { +/// nominator: usize, +/// denominator: usize, +/// } /// -/// impl Div for Foo { -/// type Output = Foo; +/// impl Rational { +/// fn new(nominator: usize, denominator: usize) -> Self { +/// if denominator == 0 { +/// panic!("Zero is an invalid denominator!"); +/// } /// -/// fn div(self, _rhs: Foo) -> Foo { -/// println!("Dividing!"); -/// self +/// // Reduce to lowest terms by dividing by the greatest common +/// // divisor. +/// let gcd = gcd(nominator, denominator); +/// Rational { +/// nominator: nominator / gcd, +/// denominator: denominator / gcd, +/// } /// } /// } /// +/// impl Div for Rational { +/// // The division of rational numbers is a closed operation. +/// type Output = Self; +/// +/// fn div(self, rhs: Self) -> Self { +/// if rhs.nominator == 0 { +/// panic!("Cannot divide by zero-valued `Rational`!"); +/// } +/// +/// let nominator = self.nominator * rhs.denominator; +/// let denominator = self.denominator * rhs.nominator; +/// Rational::new(nominator, denominator) +/// } +/// } +/// +/// // Euclid's two-thousand-year-old algorithm for finding the greatest common +/// // divisor. +/// fn gcd(x: usize, y: usize) -> usize { +/// let mut x = x; +/// let mut y = y; +/// while y != 0 { +/// let t = y; +/// y = x % y; +/// x = t; +/// } +/// x +/// } +/// /// fn main() { -/// Foo / Foo; +/// assert_eq!(Rational::new(1, 2), Rational::new(2, 4)); +/// assert_eq!(Rational::new(1, 2) / Rational::new(3, 4), +/// Rational::new(2, 3)); /// } /// ``` /// From 5ec6f39a657771447786ef43a79b5b8e6bc329b4 Mon Sep 17 00:00:00 2001 From: Rahul Sharma Date: Wed, 10 Aug 2016 16:04:11 +0530 Subject: [PATCH 5/6] Update E0195 to new error format --- src/librustc_typeck/check/compare_method.rs | 7 ++++--- src/test/compile-fail/E0195.rs | 1 + src/test/compile-fail/issue-16048.rs | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index b971ae02cd0..d5cf45051af 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -411,10 +411,11 @@ pub fn compare_impl_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, // are zero. Since I don't quite know how to phrase things at // the moment, give a kind of vague error message. if trait_params.len() != impl_params.len() { - span_err!(ccx.tcx.sess, span, E0195, + struct_span_err!(ccx.tcx.sess, span, E0195, "lifetime parameters or bounds on method `{}` do \ - not match the trait declaration", - impl_m.name); + not match the trait declaration",impl_m.name) + .span_label(span, &format!("lifetimes do not match trait")) + .emit(); return false; } diff --git a/src/test/compile-fail/E0195.rs b/src/test/compile-fail/E0195.rs index 0630dfea5e6..06dd903b23d 100644 --- a/src/test/compile-fail/E0195.rs +++ b/src/test/compile-fail/E0195.rs @@ -16,6 +16,7 @@ struct Foo; impl Trait for Foo { fn bar<'a,'b>(x: &'a str, y: &'b str) { //~ ERROR E0195 + //~^ lifetimes do not match trait } } diff --git a/src/test/compile-fail/issue-16048.rs b/src/test/compile-fail/issue-16048.rs index ceac7e968f6..5012556dedd 100644 --- a/src/test/compile-fail/issue-16048.rs +++ b/src/test/compile-fail/issue-16048.rs @@ -29,6 +29,7 @@ impl<'a> Test<'a> for Foo<'a> { impl<'a> NoLifetime for Foo<'a> { fn get<'p, T : Test<'a>>(&self) -> T { //~^ ERROR E0195 +//~| lifetimes do not match trait return *self as T; } } From 59723c3c2037029643819835fc8437bb09f31f13 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Tue, 23 Aug 2016 22:31:44 +0200 Subject: [PATCH 6/6] doc: one line too many --- src/libcore/default.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libcore/default.rs b/src/libcore/default.rs index 485ddae07fb..a0dd38c983b 100644 --- a/src/libcore/default.rs +++ b/src/libcore/default.rs @@ -38,7 +38,6 @@ use marker::Sized; /// bar: f32, /// } /// -/// /// fn main() { /// let options: SomeOptions = Default::default(); /// }