From 117512348b1f63443508cc4acf3cb8ec48918ebe Mon Sep 17 00:00:00 2001 From: Luke Gallagher Date: Sat, 11 Apr 2015 17:13:24 +1000 Subject: [PATCH 1/4] Add tests for #16602 Closes #16602 --- src/test/run-pass/issue-16602-1.rs | 15 +++++++++++++ src/test/run-pass/issue-16602-2.rs | 21 ++++++++++++++++++ src/test/run-pass/issue-16602-3.rs | 34 ++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 src/test/run-pass/issue-16602-1.rs create mode 100644 src/test/run-pass/issue-16602-2.rs create mode 100644 src/test/run-pass/issue-16602-3.rs diff --git a/src/test/run-pass/issue-16602-1.rs b/src/test/run-pass/issue-16602-1.rs new file mode 100644 index 0000000000000..ee638edad6cb5 --- /dev/null +++ b/src/test/run-pass/issue-16602-1.rs @@ -0,0 +1,15 @@ +// 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. + +fn main() { + let mut t = [1; 2]; + t = [t[1] * 2, t[0] * 2]; + assert_eq!(&t[..], &[2, 2]); +} diff --git a/src/test/run-pass/issue-16602-2.rs b/src/test/run-pass/issue-16602-2.rs new file mode 100644 index 0000000000000..742eb6c280e39 --- /dev/null +++ b/src/test/run-pass/issue-16602-2.rs @@ -0,0 +1,21 @@ +// 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. + +struct A { + pub x: u32, + pub y: u32, +} + +fn main() { + let mut a = A { x: 1, y: 1 }; + a = A { x: a.y * 2, y: a.x * 2 }; + assert_eq!(a.x, 2); + assert_eq!(a.y, 2); +} diff --git a/src/test/run-pass/issue-16602-3.rs b/src/test/run-pass/issue-16602-3.rs new file mode 100644 index 0000000000000..d29932dcf6836 --- /dev/null +++ b/src/test/run-pass/issue-16602-3.rs @@ -0,0 +1,34 @@ +// 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. + +#[derive(Debug)] +enum Foo { + Bar(u32, u32), + Baz(&'static u32, &'static u32) +} + +static NUM: u32 = 100; + +fn main () { + let mut b = Foo::Baz(&NUM, &NUM); + b = Foo::Bar(f(&b), g(&b)); +} + +static FNUM: u32 = 1; + +fn f (b: &Foo) -> u32 { + FNUM +} + +static GNUM: u32 = 2; + +fn g (b: &Foo) -> u32 { + GNUM +} From 91ca622cdf8502c37a867bea02f400a8ae5e9d4c Mon Sep 17 00:00:00 2001 From: Michael Alexander Date: Sun, 12 Apr 2015 10:42:05 +0800 Subject: [PATCH 2/4] Updated dead link in Traits chapter of book to point to Trait Objects chapter. --- src/doc/trpl/traits.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/trpl/traits.md b/src/doc/trpl/traits.md index 2986de4179b89..25f5c7cacc771 100644 --- a/src/doc/trpl/traits.md +++ b/src/doc/trpl/traits.md @@ -273,8 +273,8 @@ not, because both the trait and the type aren't in our crate. One last thing about traits: generic functions with a trait bound use *monomorphization* (*mono*: one, *morph*: form), so they are statically -dispatched. What's that mean? Check out the chapter on [static and dynamic -dispatch](static-and-dynamic-dispatch.html) for more. +dispatched. What's that mean? Check out the chapter on [trait +objects](trait-objects.html) for more. ## Multiple trait bounds From 5c80b7aabbbcd140dfefee745a8bad41262ac753 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Thu, 9 Apr 2015 08:59:48 -0700 Subject: [PATCH 3/4] Simplify iterator logic for Fuse --- src/libcore/iter.rs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 527a7297f85b9..9f378748d2007 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -2197,13 +2197,9 @@ impl Iterator for Fuse where I: Iterator { if self.done { None } else { - match self.iter.next() { - None => { - self.done = true; - None - } - x => x - } + let next = self.iter.next(); + self.done = next.is_none(); + next } } @@ -2224,13 +2220,9 @@ impl DoubleEndedIterator for Fuse where I: DoubleEndedIterator { if self.done { None } else { - match self.iter.next_back() { - None => { - self.done = true; - None - } - x => x - } + let next = self.iter.next_back(); + self.done = next.is_none(); + next } } } From 11c184616842e26836ed541e9ec1236f85c63334 Mon Sep 17 00:00:00 2001 From: Igor Strebezhev Date: Sun, 12 Apr 2015 14:48:19 +0400 Subject: [PATCH 4/4] mod.rs documentary fix Docs meant that Option is returned though the function returns Result. --- src/libcore/num/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 4e4a928d91f72..3fd179cf86f3a 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -2705,7 +2705,7 @@ macro_rules! from_str_radix_float_impl { /// /// # Return value /// - /// `Err(ParseIntError)` if the string did not represent a valid number. Otherwise, + /// `Err(ParseFloatError)` if the string did not represent a valid number. /// Otherwise, `Ok(n)` where `n` is the floating-point number represented by `src`. #[inline] #[allow(deprecated)] @@ -2734,7 +2734,7 @@ macro_rules! from_str_radix_float_impl { /// /// # Return value /// - /// `Err(ParseIntError)` if the string did not represent a valid number. Otherwise, + /// `Err(ParseFloatError)` if the string did not represent a valid number. /// Otherwise, `Ok(n)` where `n` is the floating-point number represented by `src`. fn from_str_radix(src: &str, radix: u32) -> Result<$T, ParseFloatError> {