Snap for 12153948 from 3e51e4fe0b0e0bdb67821bec7cf38d33c94aca56 to simpleperf-release

Change-Id: I03a9137eff03c4fd8e670b4e8167a90bc79d63eb
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
new file mode 100644
index 0000000..b1dbb27
--- /dev/null
+++ b/.cargo_vcs_info.json
@@ -0,0 +1,6 @@
+{
+  "git": {
+    "sha1": "91fdc06356c0c868cb88b5a180859023c57e6e50"
+  },
+  "path_in_vcs": ""
+}
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..fa8d85a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+Cargo.lock
+target
diff --git a/Android.bp b/Android.bp
index 7e859b3..d4ae441 100644
--- a/Android.bp
+++ b/Android.bp
@@ -27,9 +27,9 @@
     host_supported: true,
     crate_name: "num_complex",
     cargo_env_compat: true,
-    cargo_pkg_version: "0.4.5",
-    srcs: ["src/lib.rs"],
-    edition: "2018",
+    cargo_pkg_version: "0.4.6",
+    crate_root: "src/lib.rs",
+    edition: "2021",
     features: [
         "default",
         "std",
@@ -48,14 +48,14 @@
     host_supported: true,
     crate_name: "num_complex",
     cargo_env_compat: true,
-    cargo_pkg_version: "0.4.5",
-    srcs: ["src/lib.rs"],
+    cargo_pkg_version: "0.4.6",
+    crate_root: "src/lib.rs",
     test_suites: ["general-tests"],
     auto_gen_config: true,
     test_options: {
         unit_test: true,
     },
-    edition: "2018",
+    edition: "2021",
     features: [
         "default",
         "std",
diff --git a/Cargo.toml b/Cargo.toml
index 0f3fa9c..bb9792a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -10,9 +10,10 @@
 # See Cargo.toml.orig for the original contents.
 
 [package]
-edition = "2018"
+edition = "2021"
+rust-version = "1.60"
 name = "num-complex"
-version = "0.4.5"
+version = "0.4.6"
 authors = ["The Rust Project Developers"]
 exclude = [
     "/ci/*",
@@ -55,7 +56,7 @@
 optional = true
 
 [dependencies.num-traits]
-version = "0.2.11"
+version = "0.2.18"
 features = ["i128"]
 default-features = false
 
@@ -75,6 +76,11 @@
 default-features = false
 
 [features]
+bytecheck = ["dep:bytecheck"]
+bytemuck = ["dep:bytemuck"]
 default = ["std"]
 libm = ["num-traits/libm"]
+rand = ["dep:rand"]
+rkyv = ["dep:rkyv"]
+serde = ["dep:serde"]
 std = ["num-traits/std"]
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
new file mode 100644
index 0000000..987784c
--- /dev/null
+++ b/Cargo.toml.orig
@@ -0,0 +1,59 @@
+[package]
+authors = ["The Rust Project Developers"]
+description = "Complex numbers implementation for Rust"
+documentation = "https://docs.rs/num-complex"
+homepage = "https://github.com/rust-num/num-complex"
+keywords = ["mathematics", "numerics"]
+categories = ["algorithms", "data-structures", "science", "no-std"]
+license = "MIT OR Apache-2.0"
+name = "num-complex"
+repository = "https://github.com/rust-num/num-complex"
+version = "0.4.6"
+readme = "README.md"
+exclude = ["/ci/*", "/.github/*"]
+edition = "2021"
+rust-version = "1.60"
+
+[package.metadata.docs.rs]
+features = ["bytemuck", "std", "serde", "rkyv/size_64", "bytecheck", "rand"]
+
+[dependencies]
+
+[dependencies.bytemuck]
+optional = true
+version = "1"
+
+[dependencies.num-traits]
+version = "0.2.18"
+default-features = false
+features = ["i128"]
+
+[dependencies.serde]
+optional = true
+version = "1.0"
+default-features = false
+
+[dependencies.rkyv]
+optional = true
+version = "0.7"
+default-features = false
+
+[dependencies.bytecheck]
+optional = true
+version = "0.6"
+default-features = false
+
+[dependencies.rand]
+optional = true
+version = "0.8"
+default-features = false
+
+[features]
+default = ["std"]
+std = ["num-traits/std"]
+libm = ["num-traits/libm"]
+bytecheck = ["dep:bytecheck"]
+bytemuck = ["dep:bytemuck"]
+rand = ["dep:rand"]
+rkyv = ["dep:rkyv"]
+serde = ["dep:serde"]
diff --git a/METADATA b/METADATA
index 72c846f..0ccae32 100644
--- a/METADATA
+++ b/METADATA
@@ -1,21 +1,25 @@
+# This project was upgraded with external_updater.
+# Usage: tools/external_updater/updater.sh update external/rust/crates/num-complex
+# For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md
+
 name: "num-complex"
 description: "Complex numbers implementation for Rust"
 third_party {
+  license_type: NOTICE
+  last_upgrade_date {
+    year: 2024
+    month: 7
+    day: 25
+  }
   identifier {
     type: "crates.io"
-    value: "num-complex"
+    value: "https://static.crates.io/crates/num-complex/num-complex-0.4.6.crate"
+    version: "0.4.5"
   }
   identifier {
     type: "Archive"
     value: "https://static.crates.io/crates/num-complex/num-complex-0.4.5.crate"
+    version: "0.4.6"
     primary_source: true
   }
-  version: "0.4.5"
-  # Dual-licensed, using the least restrictive per go/thirdpartylicenses#same.
-  license_type: NOTICE
-  last_upgrade_date {
-    year: 2024
-    month: 5
-    day: 7
-  }
 }
diff --git a/README.md b/README.md
index fdb1d38..6075cd6 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
 
 [![crate](https://img.shields.io/crates/v/num-complex.svg)](https://crates.io/crates/num-complex)
 [![documentation](https://docs.rs/num-complex/badge.svg)](https://docs.rs/num-complex)
-[![minimum rustc 1.31](https://img.shields.io/badge/rustc-1.31+-red.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html)
+[![minimum rustc 1.60](https://img.shields.io/badge/rustc-1.60+-red.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html)
 [![build status](https://github.com/rust-num/num-complex/workflows/master/badge.svg)](https://github.com/rust-num/num-complex/actions)
 
 `Complex` numbers for Rust.
@@ -37,7 +37,7 @@
 
 ## Compatibility
 
-The `num-complex` crate is tested for rustc 1.31 and greater.
+The `num-complex` crate is tested for rustc 1.60 and greater.
 
 ## License
 
diff --git a/RELEASES.md b/RELEASES.md
index dbd18d2..89a51e2 100644
--- a/RELEASES.md
+++ b/RELEASES.md
@@ -1,3 +1,15 @@
+# Release 0.4.6 (2024-05-07)
+
+- [Upgrade to 2021 edition, **MSRV 1.60**][121]
+- [Add `const ZERO`/`ONE`/`I` and implement `ConstZero` and `ConstOne`][125]
+- [Add `c32` and `c64` functions to help construct `Complex` values][126]
+
+**Contributors**: @cuviper
+
+[121]: https://github.com/rust-num/num-complex/pull/121
+[125]: https://github.com/rust-num/num-complex/pull/125
+[126]: https://github.com/rust-num/num-complex/pull/126
+
 # Release 0.4.5 (2024-02-06)
 
 - [Relaxed `T` bounds on `serde::Deserialize` for `Complex<T>`.][119]
diff --git a/src/crand.rs b/src/crand.rs
index 5edf8a7..12d55e0 100644
--- a/src/crand.rs
+++ b/src/crand.rs
@@ -70,7 +70,8 @@
         }
 
         fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand::Error> {
-            Ok(self.fill_bytes(dest))
+            self.fill_bytes(dest);
+            Ok(())
         }
     }
 
@@ -94,7 +95,7 @@
     let mut rng = test_rng();
     let dist = ComplexDistribution::new(Standard, Standard);
     for _ in 0..100 {
-        let c: Complex<f64> = rng.sample(&dist);
+        let c: Complex<f64> = rng.sample(dist);
         assert!(c.re >= 0.0 && c.re < 1.0);
         assert!(c.im >= 0.0 && c.im < 1.0);
     }
@@ -110,7 +111,7 @@
     let dist = ComplexDistribution::new(re, im);
     for _ in 0..100 {
         // no type annotation required, since `Uniform` only produces one type.
-        let c = rng.sample(&dist);
+        let c = rng.sample(dist);
         assert!(c.re >= -100.0 && c.re < 0.0);
         assert!(c.im >= 0.0 && c.im < 100.0);
     }
@@ -125,7 +126,7 @@
     let dist = ComplexDistribution::new(re, Standard);
     for _ in 0..100 {
         // no type annotation required, since `Uniform` only produces one type.
-        let c = rng.sample(&dist);
+        let c = rng.sample(dist);
         assert!(c.re >= -100.0 && c.re < 0.0);
         assert!(c.im >= 0.0 && c.im < 1.0);
     }
@@ -141,7 +142,7 @@
     let dist = ComplexDistribution::new(re, im);
     for _ in 0..100 {
         // no type annotation required, since `Uniform` only produces one type.
-        let c = rng.sample(&dist);
+        let c = rng.sample(dist);
         assert!(c.re >= -100 && c.re < 0);
         assert!(c.im >= 0 && c.im < 100);
     }
diff --git a/src/lib.rs b/src/lib.rs
index 13a884b..661b67b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -12,7 +12,7 @@
 //!
 //! ## Compatibility
 //!
-//! The `num-complex` crate is tested for rustc 1.31 and greater.
+//! The `num-complex` crate is tested for rustc 1.60 and greater.
 
 #![doc(html_root_url = "https://docs.rs/num-complex/0.4")]
 #![no_std]
@@ -30,7 +30,7 @@
 #[cfg(feature = "std")]
 use std::error::Error;
 
-use num_traits::{Inv, MulAdd, Num, One, Pow, Signed, Zero};
+use num_traits::{ConstOne, ConstZero, Inv, MulAdd, Num, One, Pow, Signed, Zero};
 
 use num_traits::float::FloatCore;
 #[cfg(any(feature = "std", feature = "libm"))]
@@ -92,11 +92,42 @@
     pub im: T,
 }
 
+/// Alias for a [`Complex<f32>`]
 pub type Complex32 = Complex<f32>;
+
+/// Create a new [`Complex<f32>`] with arguments that can convert [`Into<f32>`].
+///
+/// ```
+/// use num_complex::{c32, Complex32};
+/// assert_eq!(c32(1u8, 2), Complex32::new(1.0, 2.0));
+/// ```
+///
+/// Note: ambiguous integer literals in Rust will [default] to `i32`, which does **not** implement
+/// `Into<f32>`, so a call like `c32(1, 2)` will result in a type error. The example above uses a
+/// suffixed `1u8` to set its type, and then the `2` can be inferred as the same type.
+///
+/// [default]: https://doc.rust-lang.org/reference/expressions/literal-expr.html#integer-literal-expressions
+#[inline]
+pub fn c32<T: Into<f32>>(re: T, im: T) -> Complex32 {
+    Complex::new(re.into(), im.into())
+}
+
+/// Alias for a [`Complex<f64>`]
 pub type Complex64 = Complex<f64>;
 
+/// Create a new [`Complex<f64>`] with arguments that can convert [`Into<f64>`].
+///
+/// ```
+/// use num_complex::{c64, Complex64};
+/// assert_eq!(c64(1, 2), Complex64::new(1.0, 2.0));
+/// ```
+#[inline]
+pub fn c64<T: Into<f64>>(re: T, im: T) -> Complex64 {
+    Complex::new(re.into(), im.into())
+}
+
 impl<T> Complex<T> {
-    /// Create a new Complex
+    /// Create a new `Complex`
     #[inline]
     pub const fn new(re: T, im: T) -> Self {
         Complex { re, im }
@@ -104,7 +135,9 @@
 }
 
 impl<T: Clone + Num> Complex<T> {
-    /// Returns imaginary unit
+    /// Returns the imaginary unit.
+    ///
+    /// See also [`Complex::I`].
     #[inline]
     pub fn i() -> Self {
         Self::new(T::zero(), T::one())
@@ -213,13 +246,11 @@
                 if !im.is_finite() {
                     return Self::new(T::zero(), T::zero());
                 }
-            } else {
-                if im == T::zero() || !im.is_finite() {
-                    if im.is_infinite() {
-                        im = T::nan();
-                    }
-                    return Self::new(re, im);
+            } else if im == T::zero() || !im.is_finite() {
+                if im.is_infinite() {
+                    im = T::nan();
                 }
+                return Self::new(re, im);
             }
         } else if re.is_nan() && im == T::zero() {
             return self;
@@ -975,7 +1006,7 @@
 
     #[inline]
     fn inv(self) -> Self::Output {
-        (&self).inv()
+        Complex::inv(&self)
     }
 }
 
@@ -984,7 +1015,7 @@
 
     #[inline]
     fn inv(self) -> Self::Output {
-        self.inv()
+        Complex::inv(self)
     }
 }
 
@@ -1148,6 +1179,15 @@
 real_arithmetic!(usize, u8, u16, u32, u64, u128, isize, i8, i16, i32, i64, i128, f32, f64);
 
 // constants
+impl<T: ConstZero> Complex<T> {
+    /// A constant `Complex` 0.
+    pub const ZERO: Self = Self::new(T::ZERO, T::ZERO);
+}
+
+impl<T: Clone + Num + ConstZero> ConstZero for Complex<T> {
+    const ZERO: Self = Self::ZERO;
+}
+
 impl<T: Clone + Num> Zero for Complex<T> {
     #[inline]
     fn zero() -> Self {
@@ -1166,6 +1206,18 @@
     }
 }
 
+impl<T: ConstOne + ConstZero> Complex<T> {
+    /// A constant `Complex` 1.
+    pub const ONE: Self = Self::new(T::ONE, T::ZERO);
+
+    /// A constant `Complex` _i_, the imaginary unit.
+    pub const I: Self = Self::new(T::ZERO, T::ONE);
+}
+
+impl<T: Clone + Num + ConstOne + ConstZero> ConstOne for Complex<T> {
+    const ONE: Self = Self::ONE;
+}
+
 impl<T: Clone + Num> One for Complex<T> {
     #[inline]
     fn one() -> Self {
@@ -1338,7 +1390,6 @@
     }
 }
 
-#[allow(deprecated)] // `trim_left_matches` and `trim_right_matches` since 1.33
 fn from_str_generic<T, E, F>(s: &str, from: F) -> Result<Complex<T>, ParseComplexError<E>>
 where
     F: Fn(&str) -> Result<T, E>,
@@ -1360,8 +1411,8 @@
         // ignore '+'/'-' if part of an exponent
         if (c == b'+' || c == b'-') && !(p == b'e' || p == b'E') {
             // trim whitespace around the separator
-            a = &s[..=i].trim_right_matches(char::is_whitespace);
-            b = &s[i + 2..].trim_left_matches(char::is_whitespace);
+            a = s[..=i].trim_end_matches(char::is_whitespace);
+            b = s[i + 2..].trim_start_matches(char::is_whitespace);
             neg_b = c == b'-';
 
             if b.is_empty() || (neg_b && b.starts_with('-')) {