From 6d6c360ca9a60ea76460053a33bb6070315e9fee Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 13 Feb 2015 14:36:59 -0500 Subject: [PATCH] Audit integer type usage in `core::option` --- src/libcore/option.rs | 56 +++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 2f261b0628fa..bd70216d9031 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -60,19 +60,19 @@ //! the optional owned box, `Option>`. //! //! The following example uses `Option` to create an optional box of -//! `int`. Notice that in order to use the inner `int` value first the +//! `i32`. Notice that in order to use the inner `i32` value first the //! `check_optional` function needs to use pattern matching to //! determine whether the box has a value (i.e. it is `Some(...)`) or //! not (`None`). //! //! ``` -//! let optional: Option> = None; +//! let optional: Option> = None; //! check_optional(&optional); //! -//! let optional: Option> = Some(Box::new(9000)); +//! let optional: Option> = Some(Box::new(9000)); //! check_optional(&optional); //! -//! fn check_optional(optional: &Option>) { +//! fn check_optional(optional: &Option>) { //! match *optional { //! Some(ref p) => println!("have value {}", p), //! None => println!("have no value") @@ -108,7 +108,7 @@ //! Initialize a result to `None` before a loop: //! //! ``` -//! enum Kingdom { Plant(uint, &'static str), Animal(uint, &'static str) } +//! enum Kingdom { Plant(usize, &'static str), Animal(usize, &'static str) } //! //! // A list of data to search through. //! let all_the_big_things = [ @@ -188,10 +188,10 @@ impl Option { /// # Example /// /// ``` - /// let x: Option = Some(2); + /// let x: Option = Some(2); /// assert_eq!(x.is_some(), true); /// - /// let x: Option = None; + /// let x: Option = None; /// assert_eq!(x.is_some(), false); /// ``` #[inline] @@ -208,10 +208,10 @@ impl Option { /// # Example /// /// ``` - /// let x: Option = Some(2); + /// let x: Option = Some(2); /// assert_eq!(x.is_none(), false); /// - /// let x: Option = None; + /// let x: Option = None; /// assert_eq!(x.is_none(), true); /// ``` #[inline] @@ -228,7 +228,7 @@ impl Option { /// /// # Example /// - /// Convert an `Option` into an `Option`, preserving the original. + /// Convert an `Option` into an `Option`, preserving the original. /// The `map` method takes the `self` argument by value, consuming the original, /// so this technique uses `as_ref` to first take an `Option` to a reference /// to the value inside the original. @@ -237,7 +237,7 @@ impl Option { /// let num_as_str: Option = Some("10".to_string()); /// // First, cast `Option` to `Option<&String>` with `as_ref`, /// // then consume *that* with `map`, leaving `num_as_str` on the stack. - /// let num_as_int: Option = num_as_str.as_ref().map(|n| n.len()); + /// let num_as_int: Option = num_as_str.as_ref().map(|n| n.len()); /// println!("still can print num_as_str: {:?}", num_as_str); /// ``` #[inline] @@ -406,12 +406,12 @@ impl Option { /// /// # Example /// - /// Convert an `Option` into an `Option`, consuming the original: + /// Convert an `Option` into an `Option`, consuming the original: /// /// ``` /// let num_as_str: Option = Some("10".to_string()); /// // `Option::map` takes self *by value*, consuming `num_as_str` - /// let num_as_int: Option = num_as_str.map(|n| n.len()); + /// let num_as_int: Option = num_as_str.map(|n| n.len()); /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] @@ -518,7 +518,7 @@ impl Option { /// let x = Some(4); /// assert_eq!(x.iter().next(), Some(&4)); /// - /// let x: Option = None; + /// let x: Option = None; /// assert_eq!(x.iter().next(), None); /// ``` #[inline] @@ -539,7 +539,7 @@ impl Option { /// } /// assert_eq!(x, Some(42)); /// - /// let mut x: Option = None; + /// let mut x: Option = None; /// assert_eq!(x.iter_mut().next(), None); /// ``` #[inline] @@ -581,7 +581,7 @@ impl Option { /// let y: Option<&str> = None; /// assert_eq!(x.and(y), None); /// - /// let x: Option = None; + /// let x: Option = None; /// let y = Some("foo"); /// assert_eq!(x.and(y), None); /// @@ -589,7 +589,7 @@ impl Option { /// let y = Some("foo"); /// assert_eq!(x.and(y), Some("foo")); /// - /// let x: Option = None; + /// let x: Option = None; /// let y: Option<&str> = None; /// assert_eq!(x.and(y), None); /// ``` @@ -608,8 +608,8 @@ impl Option { /// # Example /// /// ``` - /// fn sq(x: uint) -> Option { Some(x * x) } - /// fn nope(_: uint) -> Option { None } + /// fn sq(x: usize) -> Option { Some(x * x) } + /// fn nope(_: usize) -> Option { None } /// /// assert_eq!(Some(2).and_then(sq).and_then(sq), Some(16)); /// assert_eq!(Some(2).and_then(sq).and_then(nope), None); @@ -642,7 +642,7 @@ impl Option { /// let y = Some(100); /// assert_eq!(x.or(y), Some(2)); /// - /// let x: Option = None; + /// let x: Option = None; /// let y = None; /// assert_eq!(x.or(y), None); /// ``` @@ -690,7 +690,7 @@ impl Option { /// x.take(); /// assert_eq!(x, None); /// - /// let mut x: Option = None; + /// let mut x: Option = None; /// x.take(); /// assert_eq!(x, None); /// ``` @@ -789,7 +789,7 @@ impl Iterator for Item { } #[inline] - fn size_hint(&self) -> (uint, Option) { + fn size_hint(&self) -> (usize, Option) { match self.opt { Some(_) => (1, Some(1)), None => (0, Some(0)), @@ -817,7 +817,7 @@ impl<'a, A> Iterator for Iter<'a, A> { #[inline] fn next(&mut self) -> Option<&'a A> { self.inner.next() } #[inline] - fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } + fn size_hint(&self) -> (usize, Option) { self.inner.size_hint() } } #[stable(feature = "rust1", since = "1.0.0")] @@ -847,7 +847,7 @@ impl<'a, A> Iterator for IterMut<'a, A> { #[inline] fn next(&mut self) -> Option<&'a mut A> { self.inner.next() } #[inline] - fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } + fn size_hint(&self) -> (usize, Option) { self.inner.size_hint() } } #[stable(feature = "rust1", since = "1.0.0")] @@ -870,7 +870,7 @@ impl Iterator for IntoIter { #[inline] fn next(&mut self) -> Option { self.inner.next() } #[inline] - fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } + fn size_hint(&self) -> (usize, Option) { self.inner.size_hint() } } #[stable(feature = "rust1", since = "1.0.0")] @@ -896,11 +896,11 @@ impl> FromIterator> for Option { /// checking for overflow: /// /// ```rust - /// use std::uint; + /// use std::u16; /// /// let v = vec!(1, 2); - /// let res: Option> = v.iter().map(|&x: &uint| - /// if x == uint::MAX { None } + /// let res: Option> = v.iter().map(|&x: &u16| + /// if x == u16::MAX { None } /// else { Some(x + 1) } /// ).collect(); /// assert!(res == Some(vec!(2, 3)));