From 6ff04ffdfe6e32b864347d721dccd266e7253ec8 Mon Sep 17 00:00:00 2001 From: Michael Lamparski Date: Sat, 25 Nov 2017 12:06:20 -0500 Subject: [PATCH 1/9] Make builtin macro doc stubs more accurate See #46242. --- src/libstd/macros.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 9d0373404aa..7d62f94056f 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -325,9 +325,10 @@ pub mod builtin { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[macro_export] - macro_rules! format_args { ($fmt:expr, $($args:tt)*) => ({ - /* compiler built-in */ - }) } + macro_rules! format_args { + ($fmt:expr) => ({ /* compiler built-in */ }); + ($fmt:expr, $($args:tt)*) => ({ /* compiler built-in */ }); + } /// Inspect an environment variable at compile time. /// @@ -348,7 +349,10 @@ pub mod builtin { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[macro_export] - macro_rules! env { ($name:expr) => ({ /* compiler built-in */ }) } + macro_rules! env { + ($name:expr) => ({ /* compiler built-in */ }); + ($name:expr,) => ({ /* compiler built-in */ }); + } /// Optionally inspect an environment variable at compile time. /// @@ -400,7 +404,8 @@ pub mod builtin { #[unstable(feature = "concat_idents_macro", issue = "29599")] #[macro_export] macro_rules! concat_idents { - ($($e:ident),*) => ({ /* compiler built-in */ }) + ($($e:ident),*) => ({ /* compiler built-in */ }); + ($($e:ident,)*) => ({ /* compiler built-in */ }); } /// Concatenates literals into a static string slice. @@ -420,7 +425,10 @@ pub mod builtin { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[macro_export] - macro_rules! concat { ($($e:expr),*) => ({ /* compiler built-in */ }) } + macro_rules! concat { + ($($e:expr),*) => ({ /* compiler built-in */ }); + ($($e:expr,)*) => ({ /* compiler built-in */ }); + } /// A macro which expands to the line number on which it was invoked. /// From 31b8a15e7026eb882aeda7b7b1c704f444da4e81 Mon Sep 17 00:00:00 2001 From: Michael Lamparski Date: Sun, 26 Nov 2017 19:59:21 -0500 Subject: [PATCH 2/9] Update libcore macro stubs like libstd --- src/libcore/macros.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index 122baec8e58..6e3dbcbec9d 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -612,9 +612,10 @@ mod builtin { #[stable(feature = "rust1", since = "1.0.0")] #[macro_export] #[cfg(dox)] - macro_rules! format_args { ($fmt:expr, $($args:tt)*) => ({ - /* compiler built-in */ - }) } + macro_rules! format_args { + ($fmt:expr) => ({ /* compiler built-in */ }); + ($fmt:expr, $($args:tt)*) => ({ /* compiler built-in */ }); + } /// Inspect an environment variable at compile time. /// @@ -624,7 +625,10 @@ mod builtin { #[stable(feature = "rust1", since = "1.0.0")] #[macro_export] #[cfg(dox)] - macro_rules! env { ($name:expr) => ({ /* compiler built-in */ }) } + macro_rules! env { + ($name:expr) => ({ /* compiler built-in */ }); + ($name:expr,) => ({ /* compiler built-in */ }); + } /// Optionally inspect an environment variable at compile time. /// @@ -645,7 +649,8 @@ mod builtin { #[macro_export] #[cfg(dox)] macro_rules! concat_idents { - ($($e:ident),*) => ({ /* compiler built-in */ }) + ($($e:ident),*) => ({ /* compiler built-in */ }); + ($($e:ident,)*) => ({ /* compiler built-in */ }); } /// Concatenates literals into a static string slice. @@ -656,7 +661,10 @@ mod builtin { #[stable(feature = "rust1", since = "1.0.0")] #[macro_export] #[cfg(dox)] - macro_rules! concat { ($($e:expr),*) => ({ /* compiler built-in */ }) } + macro_rules! concat { + ($($e:expr),*) => ({ /* compiler built-in */ }); + ($($e:expr,)*) => ({ /* compiler built-in */ }); + } /// A macro which expands to the line number on which it was invoked. /// From 47acc4bd8440b82ee6709221299fe37bde1f9533 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 1 Dec 2017 11:33:42 -0700 Subject: [PATCH 3/9] Fix documentation for DecodeUtf16Error Fixes #46307 --- src/libstd_unicode/char.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd_unicode/char.rs b/src/libstd_unicode/char.rs index 0faf5bd9121..04df610d4c9 100644 --- a/src/libstd_unicode/char.rs +++ b/src/libstd_unicode/char.rs @@ -1461,7 +1461,7 @@ pub struct DecodeUtf16 buf: Option, } -/// An iterator that decodes UTF-16 encoded code points from an iterator of `u16`s. +/// An error that can be returned when decoding UTF-16 code points. #[stable(feature = "decode_utf16", since = "1.9.0")] #[derive(Debug, Clone, Eq, PartialEq)] pub struct DecodeUtf16Error { From a4b4a733285259261f421ae7de42399315a7ec94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Santoro?= Date: Mon, 13 Nov 2017 13:48:26 +0000 Subject: [PATCH 4/9] Use more convenient and UNIX-agnostic shebang When using bash-specific features, scripts using env to call bash are more convenient, as bash be installed in different places according the OS. Same applies for other languages' interpreters. --- src/etc/test-float-parse/runtests.py | 2 +- src/test/ui/update-all-references.sh | 2 +- src/test/ui/update-references.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/etc/test-float-parse/runtests.py b/src/etc/test-float-parse/runtests.py index 75c92b9b15c..d520c9bd5c3 100644 --- a/src/etc/test-float-parse/runtests.py +++ b/src/etc/test-float-parse/runtests.py @@ -1,4 +1,4 @@ -#!/usr/bin/python2.7 +#!/usr/bin/env python2.7 # # Copyright 2015 The Rust Project Developers. See the COPYRIGHT # file at the top-level directory of this distribution and at diff --git a/src/test/ui/update-all-references.sh b/src/test/ui/update-all-references.sh index ddd69c399a5..bfc6f923f9d 100755 --- a/src/test/ui/update-all-references.sh +++ b/src/test/ui/update-all-references.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2015 The Rust Project Developers. See the COPYRIGHT # file at the top-level directory of this distribution and at diff --git a/src/test/ui/update-references.sh b/src/test/ui/update-references.sh index aa99d35f7aa..b9ded7d1e95 100755 --- a/src/test/ui/update-references.sh +++ b/src/test/ui/update-references.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2015 The Rust Project Developers. See the COPYRIGHT # file at the top-level directory of this distribution and at From 60a842f5291391ba4a67048f9e3d63312032df77 Mon Sep 17 00:00:00 2001 From: est31 Date: Sat, 2 Dec 2017 11:51:45 +0100 Subject: [PATCH 5/9] Remove an unstable and dead compiler flag The last use has been removed by commit fb9ca16b3b7cf034f885de28879c4d50261ce3ef . --- src/librustc/session/config.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 6dade7694ab..b8a05cd0fe6 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1047,8 +1047,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, save_analysis: bool = (false, parse_bool, [UNTRACKED], "write syntax and type analysis (in JSON format) information, in \ addition to normal output"), - print_move_fragments: bool = (false, parse_bool, [UNTRACKED], - "print out move-fragment data for every fn"), flowgraph_print_loans: bool = (false, parse_bool, [UNTRACKED], "include loan analysis data in --unpretty flowgraph output"), flowgraph_print_moves: bool = (false, parse_bool, [UNTRACKED], @@ -2672,8 +2670,6 @@ mod tests { assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash()); opts.debugging_opts.save_analysis = true; assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash()); - opts.debugging_opts.print_move_fragments = true; - assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash()); opts.debugging_opts.flowgraph_print_loans = true; assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash()); opts.debugging_opts.flowgraph_print_moves = true; From 6afff9699a910f72c38e153a4a595e76aee40186 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 2 Dec 2017 22:14:19 +0100 Subject: [PATCH 6/9] Fix search results overlap --- src/librustdoc/html/static/rustdoc.css | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 7efe7e1ae3e..679f5f6e3fd 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -179,6 +179,7 @@ nav.sub { top: 0; height: 100vh; overflow: auto; + z-index: 1; } .sidebar .current { From 17d6631c02a297b187d75817b4cfe4d2b3c6c9de Mon Sep 17 00:00:00 2001 From: Shotaro Yamada Date: Sun, 3 Dec 2017 17:38:56 +0900 Subject: [PATCH 7/9] Fix MIR CopyPropagation regression --- src/librustc_mir/transform/copy_prop.rs | 11 ++-- src/test/mir-opt/copy_propagation_arg.rs | 76 ++++++++++++++++-------- 2 files changed, 57 insertions(+), 30 deletions(-) diff --git a/src/librustc_mir/transform/copy_prop.rs b/src/librustc_mir/transform/copy_prop.rs index 6047b4e174a..95fe99a1bec 100644 --- a/src/librustc_mir/transform/copy_prop.rs +++ b/src/librustc_mir/transform/copy_prop.rs @@ -239,10 +239,13 @@ impl<'tcx> Action<'tcx> { // USE(SRC); let src_def_count = src_use_info.def_count_not_including_drop(); // allow function arguments to be propagated - if src_def_count > 1 || - (src_def_count == 0 && mir.local_kind(src_local) != LocalKind::Arg) { - debug!(" Can't copy-propagate local: {} defs of src", - src_use_info.def_count_not_including_drop()); + let is_arg = mir.local_kind(src_local) == LocalKind::Arg; + if (is_arg && src_def_count != 0) || (!is_arg && src_def_count != 1) { + debug!( + " Can't copy-propagate local: {} defs of src{}", + src_def_count, + if is_arg { " (argument)" } else { "" }, + ); return None } diff --git a/src/test/mir-opt/copy_propagation_arg.rs b/src/test/mir-opt/copy_propagation_arg.rs index 017fac6a6a1..35bb231df5a 100644 --- a/src/test/mir-opt/copy_propagation_arg.rs +++ b/src/test/mir-opt/copy_propagation_arg.rs @@ -30,42 +30,43 @@ fn baz(mut x: i32) { x = x; } +fn arg_src(mut x: i32) -> i32 { + let y = x; + x = 123; // Don't propagate this assignment to `y` + y +} + fn main() { // Make sure the function actually gets instantiated. foo(0); bar(0); baz(0); + arg_src(0); } // END RUST SOURCE // START rustc.foo.CopyPropagation.before.mir // bb0: { -// StorageLive(_2); -// StorageLive(_3); +// ... // _3 = _1; // _2 = const dummy(move _3) -> bb1; // } // bb1: { -// StorageDead(_3); +// ... // _1 = move _2; -// StorageDead(_2); -// _0 = (); -// return; +// ... // } // END rustc.foo.CopyPropagation.before.mir // START rustc.foo.CopyPropagation.after.mir // bb0: { -// StorageLive(_2); -// nop; -// nop; -// _2 = const dummy(move _1) -> bb1; +// ... +// _3 = _1; +// _2 = const dummy(move _3) -> bb1; // } // bb1: { -// nop; +// ... // _1 = move _2; -// StorageDead(_2); -// _0 = (); -// return; +// ... // } // END rustc.foo.CopyPropagation.after.mir // START rustc.bar.CopyPropagation.before.mir @@ -83,15 +84,14 @@ fn main() { // END rustc.bar.CopyPropagation.before.mir // START rustc.bar.CopyPropagation.after.mir // bb0: { -// nop; -// nop; -// _2 = const dummy(move _1) -> bb1; +// ... +// _3 = _1; +// _2 = const dummy(move _3) -> bb1; // } // bb1: { -// nop; +// ... // _1 = const 5u8; -// _0 = (); -// return; +// ... // } // END rustc.bar.CopyPropagation.after.mir // START rustc.baz.CopyPropagation.before.mir @@ -106,11 +106,35 @@ fn main() { // END rustc.baz.CopyPropagation.before.mir // START rustc.baz.CopyPropagation.after.mir // bb0: { -// nop; -// nop; -// nop; -// nop; -// _0 = (); -// return; +// ... +// _2 = _1; +// _1 = move _2; +// ... // } // END rustc.baz.CopyPropagation.after.mir +// START rustc.arg_src.CopyPropagation.before.mir +// bb0: { +// ... +// _3 = _1; +// _2 = move _3; +// ... +// _1 = const 123i32; +// ... +// _4 = _2; +// _0 = move _4; +// ... +// return; +// } +// END rustc.arg_src.CopyPropagation.before.mir +// START rustc.arg_src.CopyPropagation.after.mir +// bb0: { +// ... +// _3 = _1; +// ... +// _1 = const 123i32; +// ... +// _0 = move _3; +// ... +// return; +// } +// END rustc.arg_src.CopyPropagation.after.mir From cac199fb27a66147f1883bb54028cc9b2d0db28b Mon Sep 17 00:00:00 2001 From: Kenjiro Nakayama Date: Sun, 3 Dec 2017 18:13:54 +0900 Subject: [PATCH 8/9] Fix invalid link to lint_plugin_test.rs --- src/doc/unstable-book/src/language-features/plugin.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/unstable-book/src/language-features/plugin.md b/src/doc/unstable-book/src/language-features/plugin.md index 4b8603e3c44..1cece930eea 100644 --- a/src/doc/unstable-book/src/language-features/plugin.md +++ b/src/doc/unstable-book/src/language-features/plugin.md @@ -177,7 +177,7 @@ quasiquote as an ordinary plugin library. Plugins can extend [Rust's lint infrastructure](../reference/attributes.html#lint-check-attributes) with additional checks for code style, safety, etc. Now let's write a plugin -[`lint_plugin_test.rs`](https://github.com/rust-lang/rust/blob/master/src/test/run-pass-fulldeps/auxiliary/lint_plugin_test.rs) +[`lint_plugin_test.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui-fulldeps/auxiliary/lint_plugin_test.rs) that warns about any item named `lintme`. ```rust,ignore From a2d87d83bfdffe3d9ba78c93d5da2b39148b01e1 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 3 Dec 2017 11:24:00 -0500 Subject: [PATCH 9/9] =?UTF-8?q?Consistent=20parameter=20name=20for=20numer?= =?UTF-8?q?ic=20=E2=80=98checked=E2=80=99=20operations.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some checked operations use `rhs` as a parameter name, and some use `other`. For the sake of consistency, unify everything under the `rhs` name. Fixes https://github.com/rust-lang/rust/issues/46308. --- src/libcore/num/mod.rs | 138 ++++++++++++++++++++--------------------- 1 file changed, 69 insertions(+), 69 deletions(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 5b9dd4b1c69..7c7562eac51 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -380,7 +380,7 @@ macro_rules! int_impl { if cfg!(target_endian = "little") { self } else { self.swap_bytes() } } - /// Checked integer addition. Computes `self + other`, returning `None` + /// Checked integer addition. Computes `self + rhs`, returning `None` /// if overflow occurred. /// /// # Examples @@ -393,12 +393,12 @@ macro_rules! int_impl { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn checked_add(self, other: Self) -> Option { - let (a, b) = self.overflowing_add(other); + pub fn checked_add(self, rhs: Self) -> Option { + let (a, b) = self.overflowing_add(rhs); if b {None} else {Some(a)} } - /// Checked integer subtraction. Computes `self - other`, returning + /// Checked integer subtraction. Computes `self - rhs`, returning /// `None` if underflow occurred. /// /// # Examples @@ -411,12 +411,12 @@ macro_rules! int_impl { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn checked_sub(self, other: Self) -> Option { - let (a, b) = self.overflowing_sub(other); + pub fn checked_sub(self, rhs: Self) -> Option { + let (a, b) = self.overflowing_sub(rhs); if b {None} else {Some(a)} } - /// Checked integer multiplication. Computes `self * other`, returning + /// Checked integer multiplication. Computes `self * rhs`, returning /// `None` if underflow or overflow occurred. /// /// # Examples @@ -429,13 +429,13 @@ macro_rules! int_impl { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn checked_mul(self, other: Self) -> Option { - let (a, b) = self.overflowing_mul(other); + pub fn checked_mul(self, rhs: Self) -> Option { + let (a, b) = self.overflowing_mul(rhs); if b {None} else {Some(a)} } - /// Checked integer division. Computes `self / other`, returning `None` - /// if `other == 0` or the operation results in underflow or overflow. + /// Checked integer division. Computes `self / rhs`, returning `None` + /// if `rhs == 0` or the operation results in underflow or overflow. /// /// # Examples /// @@ -448,16 +448,16 @@ macro_rules! int_impl { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn checked_div(self, other: Self) -> Option { - if other == 0 || (self == Self::min_value() && other == -1) { + pub fn checked_div(self, rhs: Self) -> Option { + if rhs == 0 || (self == Self::min_value() && rhs == -1) { None } else { - Some(unsafe { intrinsics::unchecked_div(self, other) }) + Some(unsafe { intrinsics::unchecked_div(self, rhs) }) } } - /// Checked integer remainder. Computes `self % other`, returning `None` - /// if `other == 0` or the operation results in underflow or overflow. + /// Checked integer remainder. Computes `self % rhs`, returning `None` + /// if `rhs == 0` or the operation results in underflow or overflow. /// /// # Examples /// @@ -472,11 +472,11 @@ macro_rules! int_impl { /// ``` #[stable(feature = "wrapping", since = "1.7.0")] #[inline] - pub fn checked_rem(self, other: Self) -> Option { - if other == 0 || (self == Self::min_value() && other == -1) { + pub fn checked_rem(self, rhs: Self) -> Option { + if rhs == 0 || (self == Self::min_value() && rhs == -1) { None } else { - Some(unsafe { intrinsics::unchecked_rem(self, other) }) + Some(unsafe { intrinsics::unchecked_rem(self, rhs) }) } } @@ -559,7 +559,7 @@ macro_rules! int_impl { } } - /// Saturating integer addition. Computes `self + other`, saturating at + /// Saturating integer addition. Computes `self + rhs`, saturating at /// the numeric bounds instead of overflowing. /// /// # Examples @@ -572,15 +572,15 @@ macro_rules! int_impl { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn saturating_add(self, other: Self) -> Self { - match self.checked_add(other) { + pub fn saturating_add(self, rhs: Self) -> Self { + match self.checked_add(rhs) { Some(x) => x, - None if other >= 0 => Self::max_value(), + None if rhs >= 0 => Self::max_value(), None => Self::min_value(), } } - /// Saturating integer subtraction. Computes `self - other`, saturating + /// Saturating integer subtraction. Computes `self - rhs`, saturating /// at the numeric bounds instead of overflowing. /// /// # Examples @@ -593,15 +593,15 @@ macro_rules! int_impl { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn saturating_sub(self, other: Self) -> Self { - match self.checked_sub(other) { + pub fn saturating_sub(self, rhs: Self) -> Self { + match self.checked_sub(rhs) { Some(x) => x, - None if other >= 0 => Self::min_value(), + None if rhs >= 0 => Self::min_value(), None => Self::max_value(), } } - /// Saturating integer multiplication. Computes `self * other`, + /// Saturating integer multiplication. Computes `self * rhs`, /// saturating at the numeric bounds instead of overflowing. /// /// # Examples @@ -617,9 +617,9 @@ macro_rules! int_impl { /// ``` #[stable(feature = "wrapping", since = "1.7.0")] #[inline] - pub fn saturating_mul(self, other: Self) -> Self { - self.checked_mul(other).unwrap_or_else(|| { - if (self < 0 && other < 0) || (self > 0 && other > 0) { + pub fn saturating_mul(self, rhs: Self) -> Self { + self.checked_mul(rhs).unwrap_or_else(|| { + if (self < 0 && rhs < 0) || (self > 0 && rhs > 0) { Self::max_value() } else { Self::min_value() @@ -627,7 +627,7 @@ macro_rules! int_impl { }) } - /// Wrapping (modular) addition. Computes `self + other`, + /// Wrapping (modular) addition. Computes `self + rhs`, /// wrapping around at the boundary of the type. /// /// # Examples @@ -646,7 +646,7 @@ macro_rules! int_impl { } } - /// Wrapping (modular) subtraction. Computes `self - other`, + /// Wrapping (modular) subtraction. Computes `self - rhs`, /// wrapping around at the boundary of the type. /// /// # Examples @@ -666,7 +666,7 @@ macro_rules! int_impl { } /// Wrapping (modular) multiplication. Computes `self * - /// other`, wrapping around at the boundary of the type. + /// rhs`, wrapping around at the boundary of the type. /// /// # Examples /// @@ -684,7 +684,7 @@ macro_rules! int_impl { } } - /// Wrapping (modular) division. Computes `self / other`, + /// Wrapping (modular) division. Computes `self / rhs`, /// wrapping around at the boundary of the type. /// /// The only case where such wrapping can occur is when one @@ -712,7 +712,7 @@ macro_rules! int_impl { self.overflowing_div(rhs).0 } - /// Wrapping (modular) remainder. Computes `self % other`, + /// Wrapping (modular) remainder. Computes `self % rhs`, /// wrapping around at the boundary of the type. /// /// Such wrap-around never actually occurs mathematically; @@ -1573,7 +1573,7 @@ macro_rules! uint_impl { if cfg!(target_endian = "little") { self } else { self.swap_bytes() } } - /// Checked integer addition. Computes `self + other`, returning `None` + /// Checked integer addition. Computes `self + rhs`, returning `None` /// if overflow occurred. /// /// # Examples @@ -1586,12 +1586,12 @@ macro_rules! uint_impl { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn checked_add(self, other: Self) -> Option { - let (a, b) = self.overflowing_add(other); + pub fn checked_add(self, rhs: Self) -> Option { + let (a, b) = self.overflowing_add(rhs); if b {None} else {Some(a)} } - /// Checked integer subtraction. Computes `self - other`, returning + /// Checked integer subtraction. Computes `self - rhs`, returning /// `None` if underflow occurred. /// /// # Examples @@ -1604,12 +1604,12 @@ macro_rules! uint_impl { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn checked_sub(self, other: Self) -> Option { - let (a, b) = self.overflowing_sub(other); + pub fn checked_sub(self, rhs: Self) -> Option { + let (a, b) = self.overflowing_sub(rhs); if b {None} else {Some(a)} } - /// Checked integer multiplication. Computes `self * other`, returning + /// Checked integer multiplication. Computes `self * rhs`, returning /// `None` if underflow or overflow occurred. /// /// # Examples @@ -1622,13 +1622,13 @@ macro_rules! uint_impl { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn checked_mul(self, other: Self) -> Option { - let (a, b) = self.overflowing_mul(other); + pub fn checked_mul(self, rhs: Self) -> Option { + let (a, b) = self.overflowing_mul(rhs); if b {None} else {Some(a)} } - /// Checked integer division. Computes `self / other`, returning `None` - /// if `other == 0` or the operation results in underflow or overflow. + /// Checked integer division. Computes `self / rhs`, returning `None` + /// if `rhs == 0` or the operation results in underflow or overflow. /// /// # Examples /// @@ -1640,15 +1640,15 @@ macro_rules! uint_impl { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn checked_div(self, other: Self) -> Option { - match other { + pub fn checked_div(self, rhs: Self) -> Option { + match rhs { 0 => None, - other => Some(unsafe { intrinsics::unchecked_div(self, other) }), + rhs => Some(unsafe { intrinsics::unchecked_div(self, rhs) }), } } - /// Checked integer remainder. Computes `self % other`, returning `None` - /// if `other == 0` or the operation results in underflow or overflow. + /// Checked integer remainder. Computes `self % rhs`, returning `None` + /// if `rhs == 0` or the operation results in underflow or overflow. /// /// # Examples /// @@ -1660,11 +1660,11 @@ macro_rules! uint_impl { /// ``` #[stable(feature = "wrapping", since = "1.7.0")] #[inline] - pub fn checked_rem(self, other: Self) -> Option { - if other == 0 { + pub fn checked_rem(self, rhs: Self) -> Option { + if rhs == 0 { None } else { - Some(unsafe { intrinsics::unchecked_rem(self, other) }) + Some(unsafe { intrinsics::unchecked_rem(self, rhs) }) } } @@ -1724,7 +1724,7 @@ macro_rules! uint_impl { if b {None} else {Some(a)} } - /// Saturating integer addition. Computes `self + other`, saturating at + /// Saturating integer addition. Computes `self + rhs`, saturating at /// the numeric bounds instead of overflowing. /// /// # Examples @@ -1737,14 +1737,14 @@ macro_rules! uint_impl { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn saturating_add(self, other: Self) -> Self { - match self.checked_add(other) { + pub fn saturating_add(self, rhs: Self) -> Self { + match self.checked_add(rhs) { Some(x) => x, None => Self::max_value(), } } - /// Saturating integer subtraction. Computes `self - other`, saturating + /// Saturating integer subtraction. Computes `self - rhs`, saturating /// at the numeric bounds instead of overflowing. /// /// # Examples @@ -1757,14 +1757,14 @@ macro_rules! uint_impl { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn saturating_sub(self, other: Self) -> Self { - match self.checked_sub(other) { + pub fn saturating_sub(self, rhs: Self) -> Self { + match self.checked_sub(rhs) { Some(x) => x, None => Self::min_value(), } } - /// Saturating integer multiplication. Computes `self * other`, + /// Saturating integer multiplication. Computes `self * rhs`, /// saturating at the numeric bounds instead of overflowing. /// /// # Examples @@ -1779,11 +1779,11 @@ macro_rules! uint_impl { /// ``` #[stable(feature = "wrapping", since = "1.7.0")] #[inline] - pub fn saturating_mul(self, other: Self) -> Self { - self.checked_mul(other).unwrap_or(Self::max_value()) + pub fn saturating_mul(self, rhs: Self) -> Self { + self.checked_mul(rhs).unwrap_or(Self::max_value()) } - /// Wrapping (modular) addition. Computes `self + other`, + /// Wrapping (modular) addition. Computes `self + rhs`, /// wrapping around at the boundary of the type. /// /// # Examples @@ -1802,7 +1802,7 @@ macro_rules! uint_impl { } } - /// Wrapping (modular) subtraction. Computes `self - other`, + /// Wrapping (modular) subtraction. Computes `self - rhs`, /// wrapping around at the boundary of the type. /// /// # Examples @@ -1822,7 +1822,7 @@ macro_rules! uint_impl { } /// Wrapping (modular) multiplication. Computes `self * - /// other`, wrapping around at the boundary of the type. + /// rhs`, wrapping around at the boundary of the type. /// /// # Examples /// @@ -1840,7 +1840,7 @@ macro_rules! uint_impl { } } - /// Wrapping (modular) division. Computes `self / other`. + /// Wrapping (modular) division. Computes `self / rhs`. /// Wrapped division on unsigned types is just normal division. /// There's no way wrapping could ever happen. /// This function exists, so that all operations @@ -1859,7 +1859,7 @@ macro_rules! uint_impl { self / rhs } - /// Wrapping (modular) remainder. Computes `self % other`. + /// Wrapping (modular) remainder. Computes `self % rhs`. /// Wrapped remainder calculation on unsigned types is /// just the regular remainder calculation. /// There's no way wrapping could ever happen.