From d1da91933c0786b9e02147bdbb7b1c3be4195aea Mon Sep 17 00:00:00 2001 From: Adam Kern Date: Mon, 26 May 2025 13:27:47 -0400 Subject: [PATCH 1/8] MSRV-compatible update --- Cargo.lock | 142 +++++++++++++++++++++++++++++------------------------ 1 file changed, 78 insertions(+), 64 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a4c37d21b..057a36d03 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,9 +16,9 @@ checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" [[package]] name = "anyhow" -version = "1.0.97" +version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f" +checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" [[package]] name = "approx" @@ -49,9 +49,9 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "bitflags" -version = "2.9.0" +version = "2.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" +checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" dependencies = [ "serde", ] @@ -118,9 +118,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.16" +version = "1.2.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be714c154be609ec7f5dad223a33bf1482fff90472de28f7362806e6d4832b8c" +checksum = "16595d3be041c03b09d08d0858631facccee9221e579704070e6e9e4915d3bc7" dependencies = [ "shlex", ] @@ -240,9 +240,9 @@ checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" [[package]] name = "errno" -version = "0.3.10" +version = "0.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" +checksum = "cea14ef9355e3beab063703aa9dab15afd25f0667c341310c1e5274bb1d0da18" dependencies = [ "libc", "windows-sys 0.59.0", @@ -302,9 +302,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" dependencies = [ "cfg-if", "libc", @@ -313,14 +313,14 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.3.1" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a49c392881ce6d5c3b8cb70f98717b7c07aabbdff06687b9030dbfbe2725f8" +checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" dependencies = [ "cfg-if", "libc", - "wasi 0.13.3+wasi-0.2.2", - "windows-targets 0.52.6", + "r-efi", + "wasi 0.14.2+wasi-0.2.4", ] [[package]] @@ -353,9 +353,9 @@ dependencies = [ [[package]] name = "idna_mapping" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5422cc5bc64289a77dbb45e970b86b5e9a04cb500abc7240505aedc1bf40f38" +checksum = "11c13906586a4b339310541a274dd927aff6fcbb5b8e3af90634c4b31681c792" dependencies = [ "unicode-joining-type", ] @@ -377,15 +377,15 @@ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" [[package]] name = "libc" -version = "0.2.171" +version = "0.2.172" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6" +checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" [[package]] name = "libm" -version = "0.2.11" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" +checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" [[package]] name = "libredox" @@ -400,21 +400,21 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe7db12097d22ec582439daf8618b8fdd1a7bef6270e9af3b1ebcd30893cf413" +checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" [[package]] name = "log" -version = "0.4.26" +version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30bde2b3dc3671ae49d8e2e9f044c7c005836e7a023ee57cffa25ab82764bb9e" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" [[package]] name = "matrixmultiply" -version = "0.3.9" +version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9380b911e3e96d10c1f415da0876389aaf1b56759054eeb0de7df940c456ba1a" +checksum = "a06de3016e9fae57a36fd14dba131fccf49f74b40b7fbdb472f96e361ec71a08" dependencies = [ "autocfg", "num_cpus", @@ -431,9 +431,9 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "miniz_oxide" -version = "0.8.5" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e3e04debbb59698c15bacbb6d93584a8c0ca9cc3213cb423d31f760d8843ce5" +checksum = "3be647b768db090acb35d5ec5db2b0e1f1de11133ca123b9eacf5137868f892a" dependencies = [ "adler2", ] @@ -491,7 +491,7 @@ version = "0.15.0" dependencies = [ "ndarray", "quickcheck", - "rand 0.9.0", + "rand 0.9.1", "rand_distr", "rand_isaac", ] @@ -554,7 +554,7 @@ dependencies = [ "num-complex", "num-traits", "openblas-src", - "rand 0.9.0", + "rand 0.9.1", "rand_distr", ] @@ -688,9 +688,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.94" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" dependencies = [ "unicode-ident", ] @@ -713,6 +713,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "r-efi" +version = "5.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5" + [[package]] name = "rand" version = "0.8.5" @@ -724,13 +730,12 @@ dependencies = [ [[package]] name = "rand" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94" +checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97" dependencies = [ "rand_chacha", "rand_core 0.9.3", - "zerocopy", ] [[package]] @@ -749,7 +754,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.15", + "getrandom 0.2.16", ] [[package]] @@ -758,7 +763,7 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" dependencies = [ - "getrandom 0.3.1", + "getrandom 0.3.3", ] [[package]] @@ -768,7 +773,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a8615d50dcf34fa31f7ab52692afec947c4dd0ab803cc87cb3b0b4570ff7463" dependencies = [ "num-traits", - "rand 0.9.0", + "rand 0.9.1", ] [[package]] @@ -808,9 +813,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.10" +version = "0.5.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b8c0c260b63a8219631167be35e6a988e9554dbd323f8bd08439c8ed1302bd1" +checksum = "928fca9cf2aa042393a8325b9ead81d2f0df4cb12e1e24cef072922ccd99c5af" dependencies = [ "bitflags", ] @@ -821,7 +826,7 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" dependencies = [ - "getrandom 0.2.15", + "getrandom 0.2.16", "libredox", "thiserror 1.0.69", ] @@ -839,9 +844,9 @@ dependencies = [ [[package]] name = "rmp-serde" -version = "1.1.2" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bffea85eea980d8a74453e5d02a8d93028f3c34725de143085a844ebe953258a" +checksum = "938a142ab806f18b88a97b0dea523d39e0fd730a064b035726adcfc58a8a5188" dependencies = [ "byteorder", "rmp", @@ -862,9 +867,9 @@ dependencies = [ [[package]] name = "rustix" -version = "1.0.2" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7178faa4b75a30e269c71e61c353ce2748cf3d76f0c44c393f4e60abf49b825" +checksum = "c71e83d6afe7ff64890ec6b71d6a69bb8a610ab78ce364b3352876bb4c801266" dependencies = [ "bitflags", "errno", @@ -897,9 +902,12 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "917ce264624a4b4db1c364dcc35bfca9ded014d0a958cd47ad3e960e988ea51c" +checksum = "229a4a4c221013e7e1f1a043678c5cc39fe5171437c88fb47151a21e6f5b5c79" +dependencies = [ + "zeroize", +] [[package]] name = "ryu" @@ -991,15 +999,15 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "smallvec" -version = "1.14.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcf8323ef1faaee30a44a340193b1ac6814fd9b7b4e88e9d4519a3e4abe1cfd" +checksum = "8917285742e9f3e1683f0a9c4e6b57960b7314d0b08d30d1ecd426713ee2eee9" [[package]] name = "syn" -version = "2.0.100" +version = "2.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" +checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf" dependencies = [ "proc-macro2", "quote", @@ -1019,12 +1027,12 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.19.0" +version = "3.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "488960f40a3fd53d72c2a29a58722561dee8afdd175bd88e3db4677d7b2ba600" +checksum = "e8a64e3985349f2441a1a9ef0b853f869006c3855f2cda6862a94d26ebb9d6a1" dependencies = [ "fastrand", - "getrandom 0.3.1", + "getrandom 0.3.3", "once_cell", "rustix", "windows-sys 0.59.0", @@ -1108,9 +1116,9 @@ checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" [[package]] name = "unicode-joining-type" -version = "0.7.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22f8cb47ccb8bc750808755af3071da4a10dcd147b68fc874b7ae4b12543f6f5" +checksum = "d8d00a78170970967fdb83f9d49b92f959ab2bb829186b113e4f4604ad98e180" [[package]] name = "unicode-normalization" @@ -1167,9 +1175,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasi" -version = "0.13.3+wasi-0.2.2" +version = "0.14.2+wasi-0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26816d2e1a4a36a2940b96c5296ce403917633dff8f3440e9b236ed6f6bacad2" +checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3" dependencies = [ "wit-bindgen-rt", ] @@ -1315,9 +1323,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "wit-bindgen-rt" -version = "0.33.0" +version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3268f3d866458b787f390cf61f4bbb563b922d091359f9608842999eaee3943c" +checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" dependencies = [ "bitflags", ] @@ -1334,20 +1342,26 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.23" +version = "0.8.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd97444d05a4328b90e75e503a34bad781f14e28a823ad3557f0750df1ebcbc6" +checksum = "a1702d9583232ddb9174e01bb7c15a2ab8fb1bc6f227aa1233858c351a3ba0cb" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.23" +version = "0.8.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6352c01d0edd5db859a63e2605f4ea3183ddbd15e2c4a9e7d32184df75e4f154" +checksum = "28a6e20d751156648aa063f3800b706ee209a32c0b4d9f24be3d980b01be55ef" dependencies = [ "proc-macro2", "quote", "syn", ] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" From b42a559cbb13987c8278a2305d6c6c7dd253b744 Mon Sep 17 00:00:00 2001 From: Adam Kern Date: Mon, 26 May 2025 13:31:09 -0400 Subject: [PATCH 2/8] Update to 2021 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 98326a598..14226986e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "ndarray" version = "0.16.1" -edition = "2018" +edition = "2021" rust-version = "1.64" authors = [ "Ulrik Sverdrup \"bluss\"", From 5dc894e49e0e688751c478dc9d6709a08bdd776b Mon Sep 17 00:00:00 2001 From: Adam Kern Date: Mon, 26 May 2025 13:37:40 -0400 Subject: [PATCH 3/8] Initial output of cargo fix --edition to 2024 --- benches/bench1.rs | 2 +- examples/bounds_check_elim.rs | 14 ++++++------ src/array_approx.rs | 2 +- src/array_serde.rs | 13 ++++------- src/data_traits.rs | 32 +++++++++++++-------------- src/dimension/conversion.rs | 4 ++-- src/dimension/dim.rs | 6 +++--- src/dimension/dimension_trait.rs | 6 +++--- src/dimension/macros.rs | 4 ++-- src/dimension/ndindex.rs | 2 +- src/dimension/ops.rs | 6 +++--- src/dimension/remove_axis.rs | 2 +- src/dimension/reshape.rs | 4 ++-- src/extension/nonnull.rs | 4 ++-- src/free_functions.rs | 16 +++++++------- src/impl_constructors.rs | 14 ++++++------ src/impl_methods.rs | 32 +++++++++++++-------------- src/impl_ops.rs | 10 ++++----- src/impl_owned_array.rs | 4 ++-- src/impl_raw_views.rs | 36 +++++++++++++++---------------- src/impl_special_element_types.rs | 4 ++-- src/impl_views/constructors.rs | 24 ++++++++++----------- src/impl_views/conversions.rs | 4 ++-- src/impl_views/indexing.rs | 8 +++---- src/indexes.rs | 2 +- src/iterators/macros.rs | 12 +++++------ src/iterators/mod.rs | 24 ++++++++++----------- src/iterators/windows.rs | 8 +++---- src/itertools.rs | 10 ++++----- src/layout/mod.rs | 4 ++-- src/linalg/impl_linalg.rs | 4 ++-- src/macro_utils.rs | 4 ++-- src/slice.rs | 22 +++++++++---------- src/stacking.rs | 8 +++---- src/zip/mod.rs | 34 +++++++++++++++-------------- src/zip/ndproducer.rs | 32 +++++++++++++-------------- src/zip/zipmacro.rs | 10 ++++----- tests/array.rs | 12 +++++------ tests/dimension.rs | 6 +++--- tests/iterators.rs | 6 +++--- 40 files changed, 224 insertions(+), 227 deletions(-) diff --git a/benches/bench1.rs b/benches/bench1.rs index c07b8e3d9..4ee86d7d8 100644 --- a/benches/bench1.rs +++ b/benches/bench1.rs @@ -795,7 +795,7 @@ fn bench_col_iter(bench: &mut test::Bencher) } macro_rules! mat_mul { - ($modname:ident, $ty:ident, $(($name:ident, $m:expr, $n:expr, $k:expr))+) => { + ($modname:ident, $ty:ident, $(($name:ident, $m:expr_2021, $n:expr_2021, $k:expr_2021))+) => { mod $modname { use test::{black_box, Bencher}; use ndarray::Array; diff --git a/examples/bounds_check_elim.rs b/examples/bounds_check_elim.rs index f1a91cca0..e2bb94017 100644 --- a/examples/bounds_check_elim.rs +++ b/examples/bounds_check_elim.rs @@ -34,7 +34,7 @@ pub fn testvec_as_slice(a: &Vec) -> f64 { } */ -#[no_mangle] +#[unsafe(no_mangle)] pub fn test1d_single(a: &Array1, i: usize) -> f64 { if i < a.len() { @@ -44,7 +44,7 @@ pub fn test1d_single(a: &Array1, i: usize) -> f64 } } -#[no_mangle] +#[unsafe(no_mangle)] pub fn test1d_single_mut(a: &mut Array1, i: usize) -> f64 { if i < a.len() { @@ -54,7 +54,7 @@ pub fn test1d_single_mut(a: &mut Array1, i: usize) -> f64 } } -#[no_mangle] +#[unsafe(no_mangle)] pub fn test1d_len_of(a: &Array1) -> f64 { let a = a; @@ -65,7 +65,7 @@ pub fn test1d_len_of(a: &Array1) -> f64 sum } -#[no_mangle] +#[unsafe(no_mangle)] pub fn test1d_range(a: &Array1) -> f64 { let mut sum = 0.; @@ -75,7 +75,7 @@ pub fn test1d_range(a: &Array1) -> f64 sum } -#[no_mangle] +#[unsafe(no_mangle)] pub fn test1d_while(a: &Array1) -> f64 { let mut sum = 0.; @@ -87,7 +87,7 @@ pub fn test1d_while(a: &Array1) -> f64 sum } -#[no_mangle] +#[unsafe(no_mangle)] pub fn test2d_ranges(a: &Array2) -> f64 { let mut sum = 0.; @@ -99,7 +99,7 @@ pub fn test2d_ranges(a: &Array2) -> f64 sum } -#[no_mangle] +#[unsafe(no_mangle)] pub fn test2d_whiles(a: &Array2) -> f64 { let mut sum = 0.; diff --git a/src/array_approx.rs b/src/array_approx.rs index 958f6f6ba..d7aa575f0 100644 --- a/src/array_approx.rs +++ b/src/array_approx.rs @@ -29,7 +29,7 @@ mod approx_methods } macro_rules! impl_approx_traits { - ($approx:ident, $doc:expr) => { + ($approx:ident, $doc:expr_2021) => { mod $approx { use crate::imp_prelude::*; use crate::Zip; diff --git a/src/array_serde.rs b/src/array_serde.rs index 5d51a8011..6c167b777 100644 --- a/src/array_serde.rs +++ b/src/array_serde.rs @@ -237,10 +237,9 @@ where } }; - if let Ok(array) = ArrayBase::from_shape_vec(dim, data) { - Ok(array) - } else { - Err(de::Error::custom("data and dimension must match in size")) + match ArrayBase::from_shape_vec(dim, data) { + Ok(array) => Ok(array), + _ => Err(de::Error::custom("data and dimension must match in size")), } } @@ -282,10 +281,6 @@ where None => return Err(de::Error::missing_field("dim")), }; - if let Ok(array) = ArrayBase::from_shape_vec(dim, data) { - Ok(array) - } else { - Err(de::Error::custom("data and dimension must match in size")) - } + ArrayBase::from_shape_vec(dim, data).map_err(|_| de::Error::custom("data and dimension must match in size")) } } diff --git a/src/data_traits.rs b/src/data_traits.rs index 4266e4017..7e2ec8010 100644 --- a/src/data_traits.rs +++ b/src/data_traits.rs @@ -89,11 +89,11 @@ pub unsafe trait RawDataClone: RawData #[doc(hidden)] unsafe fn clone_from_with_ptr(&mut self, other: &Self, ptr: NonNull) -> NonNull - { + { unsafe { let (data, ptr) = other.clone_with_ptr(ptr); *self = data; ptr - } + }} } /// Array representation trait. @@ -388,7 +388,7 @@ unsafe impl RawDataClone for OwnedRepr where A: Clone { unsafe fn clone_with_ptr(&self, ptr: NonNull) -> (Self, NonNull) - { + { unsafe { let mut u = self.clone(); let mut new_ptr = u.as_nonnull_mut(); if size_of::() != 0 { @@ -396,10 +396,10 @@ where A: Clone new_ptr = new_ptr.offset(our_off); } (u, new_ptr) - } + }} unsafe fn clone_from_with_ptr(&mut self, other: &Self, ptr: NonNull) -> NonNull - { + { unsafe { let our_off = if size_of::() != 0 { (ptr.as_ptr() as isize - other.as_ptr() as isize) / mem::size_of::() as isize } else { @@ -407,7 +407,7 @@ where A: Clone }; self.clone_from(other); self.as_nonnull_mut().offset(our_off) - } + }} } unsafe impl RawData for ViewRepr<&A> @@ -622,7 +622,7 @@ unsafe impl RawDataClone for CowRepr<'_, A> where A: Clone { unsafe fn clone_with_ptr(&self, ptr: NonNull) -> (Self, NonNull) - { + { unsafe { match self { CowRepr::View(view) => { let (new_view, ptr) = view.clone_with_ptr(ptr); @@ -633,10 +633,10 @@ where A: Clone (CowRepr::Owned(new_data), ptr) } } - } + }} unsafe fn clone_from_with_ptr(&mut self, other: &Self, ptr: NonNull) -> NonNull - { + { unsafe { match (&mut *self, other) { (CowRepr::View(self_), CowRepr::View(other)) => self_.clone_from_with_ptr(other, ptr), (CowRepr::Owned(self_), CowRepr::Owned(other)) => self_.clone_from_with_ptr(other, ptr), @@ -651,7 +651,7 @@ where A: Clone ptr } } - } + }} } unsafe impl<'a, A> Data for CowRepr<'a, A> @@ -731,9 +731,9 @@ impl RawDataSubst for OwnedRepr type Output = OwnedRepr; unsafe fn data_subst(self) -> Self::Output - { + { unsafe { self.data_subst() - } + }} } impl RawDataSubst for OwnedArcRepr @@ -741,9 +741,9 @@ impl RawDataSubst for OwnedArcRepr type Output = OwnedArcRepr; unsafe fn data_subst(self) -> Self::Output - { + { unsafe { OwnedArcRepr(Arc::from_raw(Arc::into_raw(self.0) as *const OwnedRepr)) - } + }} } impl RawDataSubst for RawViewRepr<*const A> @@ -791,10 +791,10 @@ impl<'a, A: 'a, B: 'a> RawDataSubst for CowRepr<'a, A> type Output = CowRepr<'a, B>; unsafe fn data_subst(self) -> Self::Output - { + { unsafe { match self { CowRepr::View(view) => CowRepr::View(view.data_subst()), CowRepr::Owned(owned) => CowRepr::Owned(owned.data_subst()), } - } + }} } diff --git a/src/dimension/conversion.rs b/src/dimension/conversion.rs index 0cf2e1296..3982a58ae 100644 --- a/src/dimension/conversion.rs +++ b/src/dimension/conversion.rs @@ -106,13 +106,13 @@ macro_rules! tuple_type { } macro_rules! tuple_expr { - ([$self_:expr] $($index:tt)*) => ( + ([$self_:expr_2021] $($index:tt)*) => ( ( $($self_[$index], )* ) ); } macro_rules! array_expr { - ([$self_:expr] $($index:tt)*) => ( + ([$self_:expr_2021] $($index:tt)*) => ( [$($self_ . $index, )*] ); } diff --git a/src/dimension/dim.rs b/src/dimension/dim.rs index 96e433bb3..b001f8432 100644 --- a/src/dimension/dim.rs +++ b/src/dimension/dim.rs @@ -169,17 +169,17 @@ macro_rules! impl_scalar_op { } macro_rules! add { - ($x:expr, $y:expr) => { + ($x:expr_2021, $y:expr_2021) => { $x += $y; }; } macro_rules! sub { - ($x:expr, $y:expr) => { + ($x:expr_2021, $y:expr_2021) => { $x -= $y; }; } macro_rules! mul { - ($x:expr, $y:expr) => { + ($x:expr_2021, $y:expr_2021) => { $x *= $y; }; } diff --git a/src/dimension/dimension_trait.rs b/src/dimension/dimension_trait.rs index 3544a7f3c..43cdb9eff 100644 --- a/src/dimension/dimension_trait.rs +++ b/src/dimension/dimension_trait.rs @@ -402,7 +402,7 @@ pub trait Dimension: // Dimension impls macro_rules! impl_insert_axis_array( - ($n:expr) => ( + ($n:expr_2021) => ( #[inline] fn insert_axis(&self, axis: Axis) -> Self::Larger { debug_assert!(axis.index() <= $n); @@ -878,7 +878,7 @@ impl Dimension for Dim<[Ix; 3]> let mut stride = *self; let mut order = Ix3(0, 1, 2); macro_rules! swap { - ($stride:expr, $order:expr, $x:expr, $y:expr) => { + ($stride:expr_2021, $order:expr_2021, $x:expr_2021, $y:expr_2021) => { if ($stride[$x] as isize).abs() > ($stride[$y] as isize).abs() { $stride.swap($x, $y); $order.ixm().swap($x, $y); @@ -904,7 +904,7 @@ impl Dimension for Dim<[Ix; 3]> } macro_rules! large_dim { - ($n:expr, $name:ident, $pattern:ty, $larger:ty, { $($insert_axis:tt)* }) => ( + ($n:expr_2021, $name:ident, $pattern:ty, $larger:ty, { $($insert_axis:tt)* }) => ( impl Dimension for Dim<[Ix; $n]> { const NDIM: Option = Some($n); type Pattern = $pattern; diff --git a/src/dimension/macros.rs b/src/dimension/macros.rs index 9a576e347..67c64e629 100644 --- a/src/dimension/macros.rs +++ b/src/dimension/macros.rs @@ -1,12 +1,12 @@ /// Indexing macro for Dim<[usize; N]> this /// gets the index at `$i` in the underlying array macro_rules! get { - ($dim:expr, $i:expr) => { + ($dim:expr_2021, $i:expr_2021) => { (*$dim.ix())[$i] }; } macro_rules! getm { - ($dim:expr, $i:expr) => { + ($dim:expr_2021, $i:expr_2021) => { (*$dim.ixm())[$i] }; } diff --git a/src/dimension/ndindex.rs b/src/dimension/ndindex.rs index ca2a3ea69..dba3a23f0 100644 --- a/src/dimension/ndindex.rs +++ b/src/dimension/ndindex.rs @@ -160,7 +160,7 @@ unsafe impl NdIndex for Ix } macro_rules! ndindex_with_array { - ($([$n:expr, $ix_n:ident $($index:tt)*])+) => { + ($([$n:expr_2021, $ix_n:ident $($index:tt)*])+) => { $( // implement NdIndex for [Ix; 2] and so on unsafe impl NdIndex<$ix_n> for [Ix; $n] { diff --git a/src/dimension/ops.rs b/src/dimension/ops.rs index 1365ab488..817c17253 100644 --- a/src/dimension/ops.rs +++ b/src/dimension/ops.rs @@ -8,7 +8,7 @@ pub trait DimAdd } macro_rules! impl_dimadd_const_out_const { - ($lhs:expr, $rhs:expr) => { + ($lhs:expr_2021, $rhs:expr_2021) => { impl DimAdd> for Dim<[usize; $lhs]> { type Output = Dim<[usize; $lhs + $rhs]>; } @@ -16,12 +16,12 @@ macro_rules! impl_dimadd_const_out_const { } macro_rules! impl_dimadd_const_out_dyn { - ($lhs:expr, IxDyn) => { + ($lhs:expr_2021, IxDyn) => { impl DimAdd for Dim<[usize; $lhs]> { type Output = IxDyn; } }; - ($lhs:expr, $rhs:expr) => { + ($lhs:expr_2021, $rhs:expr_2021) => { impl DimAdd> for Dim<[usize; $lhs]> { type Output = IxDyn; } diff --git a/src/dimension/remove_axis.rs b/src/dimension/remove_axis.rs index cbb039fc5..10fed2bd1 100644 --- a/src/dimension/remove_axis.rs +++ b/src/dimension/remove_axis.rs @@ -43,7 +43,7 @@ impl RemoveAxis for Dim<[Ix; 2]> } macro_rules! impl_remove_axis_array( - ($($n:expr),*) => ( + ($($n:expr_2021),*) => ( $( impl RemoveAxis for Dim<[Ix; $n]> { diff --git a/src/dimension/reshape.rs b/src/dimension/reshape.rs index abcec4993..c209d3290 100644 --- a/src/dimension/reshape.rs +++ b/src/dimension/reshape.rs @@ -151,13 +151,13 @@ fn test_reshape() use crate::Dim; macro_rules! test_reshape { - (fail $order:ident from $from:expr, $stride:expr, to $to:expr) => { + (fail $order:ident from $from:expr_2021, $stride:expr_2021, to $to:expr_2021) => { let res = reshape_dim(&Dim($from), &Dim($stride), &Dim($to), Order::$order); println!("Reshape {:?} {:?} to {:?}, order {:?}\n => {:?}", $from, $stride, $to, Order::$order, res); let _res = res.expect_err("Expected failed reshape"); }; - (ok $order:ident from $from:expr, $stride:expr, to $to:expr, $to_stride:expr) => {{ + (ok $order:ident from $from:expr_2021, $stride:expr_2021, to $to:expr_2021, $to_stride:expr_2021) => {{ let res = reshape_dim(&Dim($from), &Dim($stride), &Dim($to), Order::$order); println!("Reshape {:?} {:?} to {:?}, order {:?}\n => {:?}", $from, $stride, $to, Order::$order, res); diff --git a/src/extension/nonnull.rs b/src/extension/nonnull.rs index 08f80927e..f3049cbc1 100644 --- a/src/extension/nonnull.rs +++ b/src/extension/nonnull.rs @@ -16,7 +16,7 @@ pub(crate) fn nonnull_from_vec_data(v: &mut Vec) -> NonNull /// but treat this as an unconditional conversion. #[inline] pub(crate) unsafe fn nonnull_debug_checked_from_ptr(ptr: *mut T) -> NonNull -{ +{ unsafe { debug_assert!(!ptr.is_null()); NonNull::new_unchecked(ptr) -} +}} diff --git a/src/free_functions.rs b/src/free_functions.rs index a2ad6137c..4b0676dd2 100644 --- a/src/free_functions.rs +++ b/src/free_functions.rs @@ -63,25 +63,25 @@ use crate::{imp_prelude::*, LayoutRef}; /// ``` #[macro_export] macro_rules! array { - ($([$([$([$([$([$([$($x:expr),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ + ($([$([$([$([$([$([$($x:expr_2021),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ compile_error!("Arrays of 7 dimensions or more (or ndarrays of Rust arrays) cannot be constructed with the array! macro."); }}; - ($([$([$([$([$([$($x:expr),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ + ($([$([$([$([$([$($x:expr_2021),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ $crate::Array6::from(vec![$([$([$([$([$([$($x,)*],)*],)*],)*],)*],)*]) }}; - ($([$([$([$([$($x:expr),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ + ($([$([$([$([$($x:expr_2021),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ $crate::Array5::from(vec![$([$([$([$([$($x,)*],)*],)*],)*],)*]) }}; - ($([$([$([$($x:expr),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ + ($([$([$([$($x:expr_2021),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ $crate::Array4::from(vec![$([$([$([$($x,)*],)*],)*],)*]) }}; - ($([$([$($x:expr),* $(,)*]),+ $(,)*]),+ $(,)*) => {{ + ($([$([$($x:expr_2021),* $(,)*]),+ $(,)*]),+ $(,)*) => {{ $crate::Array3::from(vec![$([$([$($x,)*],)*],)*]) }}; - ($([$($x:expr),* $(,)*]),+ $(,)*) => {{ + ($([$($x:expr_2021),* $(,)*]),+ $(,)*) => {{ $crate::Array2::from(vec![$([$($x,)*],)*]) }}; - ($($x:expr),* $(,)*) => {{ + ($($x:expr_2021),* $(,)*) => {{ $crate::Array::from(vec![$($x,)*]) }}; } @@ -421,7 +421,7 @@ mod meshgrid_impl } macro_rules! meshgrid_body { - ($count:literal, $indexing:expr, $(($arr:expr, $idx:literal)),+) => { + ($count:literal, $indexing:expr_2021, $(($arr:expr_2021, $idx:literal)),+) => { { let shape = construct_shape([$($arr),+], $indexing); ( diff --git a/src/impl_constructors.rs b/src/impl_constructors.rs index c1e5b1b8b..781d74cc6 100644 --- a/src/impl_constructors.rs +++ b/src/impl_constructors.rs @@ -271,7 +271,7 @@ macro_rules! size_of_shape_checked_unwrap { #[cfg(debug_assertions)] macro_rules! size_of_shape_checked_unwrap { - ($dim:expr) => { + ($dim:expr_2021) => { match dimension::size_of_shape_checked($dim) { Ok(sz) => sz, Err(_) => panic!( @@ -504,21 +504,21 @@ where /// indices. pub unsafe fn from_shape_vec_unchecked(shape: Sh, v: Vec) -> Self where Sh: Into> - { + { unsafe { let shape = shape.into(); let dim = shape.dim; let strides = shape.strides.strides_for_dim(&dim); Self::from_vec_dim_stride_unchecked(dim, strides, v) - } + }} unsafe fn from_vec_dim_stride_unchecked(dim: D, strides: D, mut v: Vec) -> Self - { + { unsafe { // debug check for issues that indicates wrong use of this constructor debug_assert!(dimension::can_index_slice(&v, &dim, &strides, CanIndexCheckMode::OwnedMutable).is_ok()); let ptr = nonnull_from_vec_data(&mut v).add(offset_from_low_addr_ptr_to_logical_ptr(&dim, &strides)); ArrayBase::from_data_ptr(DataOwned::new(v), ptr).with_strides_dim(strides, dim) - } + }} /// Creates an array from an iterator, mapped by `map` and interpret it according to the /// provided shape and strides. @@ -531,13 +531,13 @@ where Sh: Into>, I: TrustedIterator + ExactSizeIterator, F: FnMut(I::Item) -> A, - { + { unsafe { let shape = shape.into(); let dim = shape.dim; let strides = shape.strides.strides_for_dim(&dim); let v = to_vec_mapped(iter, map); Self::from_vec_dim_stride_unchecked(dim, strides, v) - } + }} /// Create an array with uninitialized elements, shape `shape`. /// diff --git a/src/impl_methods.rs b/src/impl_methods.rs index 7291f07cb..eb41cae7a 100644 --- a/src/impl_methods.rs +++ b/src/impl_methods.rs @@ -895,11 +895,11 @@ impl ArrayRef #[inline] pub unsafe fn uget(&self, index: I) -> &A where I: NdIndex - { + { unsafe { arraytraits::debug_bounds_check(self, &index); let off = index.index_unchecked(&self.strides); &*self.ptr.as_ptr().offset(off) - } + }} /// Perform *unchecked* array indexing. /// @@ -918,12 +918,12 @@ impl ArrayRef #[inline] pub unsafe fn uget_mut(&mut self, index: I) -> &mut A where I: NdIndex - { + { unsafe { // debug_assert!(self.data.is_unique()); arraytraits::debug_bounds_check(self, &index); let off = index.index_unchecked(&self.strides); &mut *self.ptr.as_ptr().offset(off) - } + }} /// Swap elements at indices `index1` and `index2`. /// @@ -964,14 +964,14 @@ impl ArrayRef /// for `Array` and `ArrayViewMut`, but not for `ArcArray` or `CowArray`.) pub unsafe fn uswap(&mut self, index1: I, index2: I) where I: NdIndex - { + { unsafe { // debug_assert!(self.data.is_unique()); arraytraits::debug_bounds_check(self, &index1); arraytraits::debug_bounds_check(self, &index2); let off1 = index1.index_unchecked(&self.strides); let off2 = index2.index_unchecked(&self.strides); std::ptr::swap(self.ptr.as_ptr().offset(off1), self.ptr.as_ptr().offset(off2)); - } + }} // `get` for zero-dimensional arrays // panics if dimension is not zero. otherwise an element is always present. @@ -1760,9 +1760,9 @@ where #[inline] pub(crate) unsafe fn raw_view_mut_unchecked(&mut self) -> RawArrayViewMut where S: DataOwned - { + { unsafe { RawArrayViewMut::new(self.ptr, self.dim.clone(), self.strides.clone()) - } + }} /// Return the array’s data as a slice, if it is contiguous and in standard order. /// Return `None` otherwise. @@ -2442,21 +2442,21 @@ impl ArrayRef self.view() .into_dimensionality::<>::Output>() .unwrap() - } else if let Some(view1) = self.broadcast(shape.clone()) { + } else { match self.broadcast(shape.clone()) { Some(view1) => { view1 - } else { + } _ => { return Err(from_kind(ErrorKind::IncompatibleShape)); - }; + }}}; let view2 = if shape.slice() == other.dim.slice() { other .view() .into_dimensionality::<>::Output>() .unwrap() - } else if let Some(view2) = other.broadcast(shape) { + } else { match other.broadcast(shape) { Some(view2) => { view2 - } else { + } _ => { return Err(from_kind(ErrorKind::IncompatibleShape)); - }; + }}}; Ok((view1, view2)) } } @@ -3350,12 +3350,12 @@ impl ArrayRef #[track_caller] #[inline] unsafe fn unlimited_transmute(data: A) -> B -{ +{ unsafe { // safe when sizes are equal and caller guarantees that representations are equal assert_eq!(size_of::(), size_of::()); let old_data = ManuallyDrop::new(data); (&*old_data as *const A as *const B).read() -} +}} type DimMaxOf = >::Output; diff --git a/src/impl_ops.rs b/src/impl_ops.rs index 53f49cc43..01845f04e 100644 --- a/src/impl_ops.rs +++ b/src/impl_ops.rs @@ -51,7 +51,7 @@ impl ScalarOperand for Complex {} impl ScalarOperand for Complex {} macro_rules! impl_binary_op( - ($trt:ident, $operator:tt, $mth:ident, $iop:tt, $doc:expr) => ( + ($trt:ident, $operator:tt, $mth:ident, $iop:tt, $doc:expr_2021) => ( /// Perform elementwise #[doc=$doc] /// between `self` and `rhs`, @@ -337,10 +337,10 @@ impl<'a, A, D, B> $trt for &'a ArrayRef // Pick the expression $a for commutative and $b for ordered binop macro_rules! if_commutative { - (Commute { $a:expr } or { $b:expr }) => { + (Commute { $a:expr_2021 } or { $b:expr_2021 }) => { $a }; - (Ordered { $a:expr } or { $b:expr }) => { + (Ordered { $a:expr_2021 } or { $b:expr_2021 }) => { $b }; } @@ -348,7 +348,7 @@ macro_rules! if_commutative { macro_rules! impl_scalar_lhs_op { // $commutative flag. Reuse the self + scalar impl if we can. // We can do this safely since these are the primitive numeric types - ($scalar:ty, $commutative:ident, $operator:tt, $trt:ident, $mth:ident, $doc:expr) => ( + ($scalar:ty, $commutative:ident, $operator:tt, $trt:ident, $mth:ident, $doc:expr_2021) => ( // these have no doc -- they are not visible in rustdoc // Perform elementwise // between the scalar `self` and array `rhs`, @@ -595,7 +595,7 @@ mod assign_ops use crate::imp_prelude::*; macro_rules! impl_assign_op { - ($trt:ident, $method:ident, $doc:expr) => { + ($trt:ident, $method:ident, $doc:expr_2021) => { use std::ops::$trt; #[doc=$doc] diff --git a/src/impl_owned_array.rs b/src/impl_owned_array.rs index 023e9ebb4..3bfaae0e6 100644 --- a/src/impl_owned_array.rs +++ b/src/impl_owned_array.rs @@ -870,7 +870,7 @@ where D: Dimension pub(crate) unsafe fn drop_unreachable_raw( mut self_: RawArrayViewMut, data_ptr: NonNull, data_len: usize, ) where D: Dimension -{ +{ unsafe { let self_len = self_.len(); for i in 0..self_.ndim() { @@ -935,7 +935,7 @@ pub(crate) unsafe fn drop_unreachable_raw( assert_eq!(data_len, dropped_elements + self_len, "Internal error: inconsistency in move_into"); -} +}} /// Sort axes to standard order, i.e Axis(0) has biggest stride and Axis(n - 1) least stride /// diff --git a/src/impl_raw_views.rs b/src/impl_raw_views.rs index 5bb2a0e42..a51678761 100644 --- a/src/impl_raw_views.rs +++ b/src/impl_raw_views.rs @@ -17,15 +17,15 @@ where D: Dimension /// meet all of the invariants of the `ArrayBase` type. #[inline] pub(crate) unsafe fn new(ptr: NonNull, dim: D, strides: D) -> Self - { + { unsafe { RawArrayView::from_data_ptr(RawViewRepr::new(), ptr).with_strides_dim(strides, dim) - } + }} #[inline] unsafe fn new_(ptr: *const A, dim: D, strides: D) -> Self - { + { unsafe { Self::new(nonnull_debug_checked_from_ptr(ptr as *mut A), dim, strides) - } + }} /// Create an `RawArrayView` from shape information and a raw pointer /// to the elements. @@ -70,7 +70,7 @@ where D: Dimension #[inline] pub unsafe fn from_shape_ptr(shape: Sh, ptr: *const A) -> Self where Sh: Into> - { + { unsafe { let shape = shape.into(); let dim = shape.dim; if cfg!(debug_assertions) { @@ -84,7 +84,7 @@ where D: Dimension } let strides = shape.strides.strides_for_dim(&dim); RawArrayView::new_(ptr, dim, strides) - } + }} /// Converts to a read-only view of the array. /// @@ -96,13 +96,13 @@ where D: Dimension /// correct lifetime. #[inline] pub unsafe fn deref_into_view<'a>(self) -> ArrayView<'a, A, D> - { + { unsafe { debug_assert!( is_aligned(self.layout.ptr.as_ptr()), "The pointer must be aligned." ); ArrayView::new(self.layout.ptr, self.layout.dim, self.layout.strides) - } + }} /// Split the array view along `axis` and return one array pointer strictly /// before the split and one array pointer after the split. @@ -233,15 +233,15 @@ where D: Dimension /// meet all of the invariants of the `ArrayBase` type. #[inline] pub(crate) unsafe fn new(ptr: NonNull, dim: D, strides: D) -> Self - { + { unsafe { RawArrayViewMut::from_data_ptr(RawViewRepr::new(), ptr).with_strides_dim(strides, dim) - } + }} #[inline] unsafe fn new_(ptr: *mut A, dim: D, strides: D) -> Self - { + { unsafe { Self::new(nonnull_debug_checked_from_ptr(ptr), dim, strides) - } + }} /// Create an `RawArrayViewMut` from shape information and a raw /// pointer to the elements. @@ -286,7 +286,7 @@ where D: Dimension #[inline] pub unsafe fn from_shape_ptr(shape: Sh, ptr: *mut A) -> Self where Sh: Into> - { + { unsafe { let shape = shape.into(); let dim = shape.dim; if cfg!(debug_assertions) { @@ -302,7 +302,7 @@ where D: Dimension } let strides = shape.strides.strides_for_dim(&dim); RawArrayViewMut::new_(ptr, dim, strides) - } + }} /// Converts to a non-mutable `RawArrayView`. #[inline] @@ -321,13 +321,13 @@ where D: Dimension /// correct lifetime. #[inline] pub unsafe fn deref_into_view<'a>(self) -> ArrayView<'a, A, D> - { + { unsafe { debug_assert!( is_aligned(self.layout.ptr.as_ptr()), "The pointer must be aligned." ); ArrayView::new(self.layout.ptr, self.layout.dim, self.layout.strides) - } + }} /// Converts to a mutable view of the array. /// @@ -339,13 +339,13 @@ where D: Dimension /// correct lifetime. #[inline] pub unsafe fn deref_into_view_mut<'a>(self) -> ArrayViewMut<'a, A, D> - { + { unsafe { debug_assert!( is_aligned(self.layout.ptr.as_ptr()), "The pointer must be aligned." ); ArrayViewMut::new(self.layout.ptr, self.layout.dim, self.layout.strides) - } + }} /// Split the array view along `axis` and return one array pointer strictly /// before the split and one array pointer after the split. diff --git a/src/impl_special_element_types.rs b/src/impl_special_element_types.rs index 42b524bc2..3193888aa 100644 --- a/src/impl_special_element_types.rs +++ b/src/impl_special_element_types.rs @@ -33,7 +33,7 @@ where /// array's storage; it is for example possible to slice these in place, but that must /// only be done after all elements have been initialized. pub unsafe fn assume_init(self) -> ArrayBase<>::Output, D> - { + { unsafe { let ArrayBase { data, layout: LayoutRef { ptr, dim, strides }, @@ -43,5 +43,5 @@ where let data = S::data_subst(data); let ptr = ptr.cast::(); ArrayBase::from_data_ptr(data, ptr).with_strides_dim(strides, dim) - } + }} } diff --git a/src/impl_views/constructors.rs b/src/impl_views/constructors.rs index 29b7c13d7..b14847488 100644 --- a/src/impl_views/constructors.rs +++ b/src/impl_views/constructors.rs @@ -113,9 +113,9 @@ where D: Dimension #[inline] pub unsafe fn from_shape_ptr(shape: Sh, ptr: *const A) -> Self where Sh: Into> - { + { unsafe { RawArrayView::from_shape_ptr(shape, ptr).deref_into_view() - } + }} } /// Methods for read-write array views. @@ -216,9 +216,9 @@ where D: Dimension #[inline] pub unsafe fn from_shape_ptr(shape: Sh, ptr: *mut A) -> Self where Sh: Into> - { + { unsafe { RawArrayViewMut::from_shape_ptr(shape, ptr).deref_into_view_mut() - } + }} /// Convert the view into an `ArrayViewMut<'b, A, D>` where `'b` is a lifetime /// outlived by `'a'`. @@ -238,20 +238,20 @@ where D: Dimension /// Unsafe because: `ptr` must be valid for the given dimension and strides. #[inline(always)] pub(crate) unsafe fn new(ptr: NonNull, dim: D, strides: D) -> Self - { + { unsafe { if cfg!(debug_assertions) { assert!(is_aligned(ptr.as_ptr()), "The pointer must be aligned."); dimension::max_abs_offset_check_overflow::(&dim, &strides).unwrap(); } ArrayView::from_data_ptr(ViewRepr::new(), ptr).with_strides_dim(strides, dim) - } + }} /// Unsafe because: `ptr` must be valid for the given dimension and strides. #[inline] pub(crate) unsafe fn new_(ptr: *const A, dim: D, strides: D) -> Self - { + { unsafe { Self::new(nonnull_debug_checked_from_ptr(ptr as *mut A), dim, strides) - } + }} } impl ArrayViewMut<'_, A, D> @@ -262,20 +262,20 @@ where D: Dimension /// Unsafe because: `ptr` must be valid for the given dimension and strides. #[inline(always)] pub(crate) unsafe fn new(ptr: NonNull, dim: D, strides: D) -> Self - { + { unsafe { if cfg!(debug_assertions) { assert!(is_aligned(ptr.as_ptr()), "The pointer must be aligned."); dimension::max_abs_offset_check_overflow::(&dim, &strides).unwrap(); } ArrayViewMut::from_data_ptr(ViewRepr::new(), ptr).with_strides_dim(strides, dim) - } + }} /// Create a new `ArrayView` /// /// Unsafe because: `ptr` must be valid for the given dimension and strides. #[inline(always)] pub(crate) unsafe fn new_(ptr: *mut A, dim: D, strides: D) -> Self - { + { unsafe { Self::new(nonnull_debug_checked_from_ptr(ptr), dim, strides) - } + }} } diff --git a/src/impl_views/conversions.rs b/src/impl_views/conversions.rs index 5bc5f9ad6..78f4f1ffe 100644 --- a/src/impl_views/conversions.rs +++ b/src/impl_views/conversions.rs @@ -181,7 +181,7 @@ where D: Dimension /// original array that we borrow from in an inconsistent state. This is not allowed /// when using the resulting array view. pub(crate) unsafe fn into_maybe_uninit(self) -> ArrayViewMut<'a, MaybeUninit, D> - { + { unsafe { // Safe because: A and MaybeUninit have the same representation; // and we can go from initialized to (maybe) not unconditionally in terms of // representation. However, the user must be careful to not write uninit elements @@ -189,7 +189,7 @@ where D: Dimension self.into_raw_view_mut() .cast::>() .deref_into_view_mut() - } + }} } /// Private raw array view methods diff --git a/src/impl_views/indexing.rs b/src/impl_views/indexing.rs index 2879e7416..52c2b3915 100644 --- a/src/impl_views/indexing.rs +++ b/src/impl_views/indexing.rs @@ -143,10 +143,10 @@ where /// /// **Note:** only unchecked for non-debug builds of ndarray. unsafe fn uget(self, index: I) -> &'a A - { + { unsafe { debug_bounds_check!(self, index); &*self.as_ptr().offset(index.index_unchecked(&self.strides)) - } + }} } impl<'a, I, A, D> IndexLonger for ArrayViewMut<'a, A, D> @@ -209,10 +209,10 @@ where /// /// **Note:** only unchecked for non-debug builds of ndarray. unsafe fn uget(mut self, index: I) -> &'a mut A - { + { unsafe { debug_bounds_check!(self, index); &mut *self .as_mut_ptr() .offset(index.index_unchecked(&self.strides)) - } + }} } diff --git a/src/indexes.rs b/src/indexes.rs index 0fa2b50fb..a561293cf 100644 --- a/src/indexes.rs +++ b/src/indexes.rs @@ -317,7 +317,7 @@ mod tests fn test_indices_iter_c_fold() { macro_rules! run_test { - ($dim:expr) => { + ($dim:expr_2021) => { for num_consume in 0..3 { let mut it = indices($dim).into_iter(); for _ in 0..num_consume { diff --git a/src/iterators/macros.rs b/src/iterators/macros.rs index 78697ec25..e170ea459 100644 --- a/src/iterators/macros.rs +++ b/src/iterators/macros.rs @@ -53,7 +53,7 @@ macro_rules! impl_ndproducer { )* unsafe fn item(&$self_:ident, $ptr:pat) { - $refexpr:expr + $refexpr:expr_2021 } }) => { impl<$($typarm)*> NdProducer for $fulltype { @@ -79,13 +79,13 @@ impl<$($typarm)*> NdProducer for $fulltype { self.$base.contiguous_stride() } - unsafe fn as_ref(&$self_, $ptr: *mut A) -> Self::Item { + unsafe fn as_ref(&$self_, $ptr: *mut A) -> Self::Item { unsafe { $refexpr - } + }} - unsafe fn uget_ptr(&self, i: &Self::Dim) -> *mut A { + unsafe fn uget_ptr(&self, i: &Self::Dim) -> *mut A { unsafe { self.$base.uget_ptr(i) as *mut _ - } + }} fn stride_of(&self, axis: Axis) -> isize { self.$base.stride_of(axis) @@ -140,7 +140,7 @@ macro_rules! impl_iterator { type Item = $ity:ty; fn item(&mut $self_:ident, $elt:pat) { - $refexpr:expr + $refexpr:expr_2021 } }) => { expand_if!(@nonempty [$($cloneparm)*] diff --git a/src/iterators/mod.rs b/src/iterators/mod.rs index 55a9920a8..2eddf3f62 100644 --- a/src/iterators/mod.rs +++ b/src/iterators/mod.rs @@ -267,7 +267,7 @@ where D: Dimension } macro_rules! either { - ($value:expr, $inner:pat => $result:expr) => { + ($value:expr_2021, $inner:pat => $result:expr_2021) => { match $value { ElementsRepr::Slice($inner) => $result, ElementsRepr::Counted($inner) => $result, @@ -276,7 +276,7 @@ macro_rules! either { } macro_rules! either_mut { - ($value:expr, $inner:ident => $result:expr) => { + ($value:expr_2021, $inner:ident => $result:expr_2021) => { match $value { ElementsRepr::Slice(ref mut $inner) => $result, ElementsRepr::Counted(ref mut $inner) => $result, @@ -888,7 +888,7 @@ impl AxisIterCore #[inline] unsafe fn offset(&self, index: usize) -> *mut A - { + { unsafe { debug_assert!( index < self.end, "index={}, end={}, stride={}", @@ -897,7 +897,7 @@ impl AxisIterCore self.stride ); self.ptr.offset(index as isize * self.stride) - } + }} /// Splits the iterator at `index`, yielding two disjoint iterators. /// @@ -1221,14 +1221,14 @@ impl NdProducer for AxisIter<'_, A, D> } unsafe fn as_ref(&self, ptr: Self::Ptr) -> Self::Item - { + { unsafe { ArrayView::new_(ptr, self.iter.inner_dim.clone(), self.iter.inner_strides.clone()) - } + }} unsafe fn uget_ptr(&self, i: &Self::Dim) -> Self::Ptr - { + { unsafe { self.iter.offset(self.iter.index + i[0]) - } + }} fn stride_of(&self, _axis: Axis) -> isize { @@ -1280,14 +1280,14 @@ impl NdProducer for AxisIterMut<'_, A, D> } unsafe fn as_ref(&self, ptr: Self::Ptr) -> Self::Item - { + { unsafe { ArrayViewMut::new_(ptr, self.iter.inner_dim.clone(), self.iter.inner_strides.clone()) - } + }} unsafe fn uget_ptr(&self, i: &Self::Dim) -> Self::Ptr - { + { unsafe { self.iter.offset(self.iter.index + i[0]) - } + }} fn stride_of(&self, _axis: Axis) -> isize { diff --git a/src/iterators/windows.rs b/src/iterators/windows.rs index f3442c0af..40c4891db 100644 --- a/src/iterators/windows.rs +++ b/src/iterators/windows.rs @@ -192,16 +192,16 @@ impl<'a, A, D: Dimension> NdProducer for AxisWindows<'a, A, D> } unsafe fn as_ref(&self, ptr: *mut A) -> Self::Item - { + { unsafe { ArrayView::new_(ptr, self.window.clone(), self.strides.clone()) - } + }} unsafe fn uget_ptr(&self, i: &Self::Dim) -> *mut A - { + { unsafe { let mut d = D::zeros(self.base.ndim()); d[self.axis_idx] = i[0]; self.base.uget_ptr(&d) - } + }} fn stride_of(&self, axis: Axis) -> isize { diff --git a/src/itertools.rs b/src/itertools.rs index d3562e687..5d073679a 100644 --- a/src/itertools.rs +++ b/src/itertools.rs @@ -94,28 +94,28 @@ macro_rules! izip { // @closure creates a tuple-flattening closure for .map() call. usage: // @closure partial_pattern => partial_tuple , rest , of , iterators // eg. izip!( @closure ((a, b), c) => (a, b, c) , dd , ee ) - ( @closure $p:pat => $tup:expr ) => { + ( @closure $p:pat => $tup:expr_2021 ) => { |$p| $tup }; // The "b" identifier is a different identifier on each recursion level thanks to hygiene. - ( @closure $p:pat => ( $($tup:tt)* ) , $_iter:expr $( , $tail:expr )* ) => { + ( @closure $p:pat => ( $($tup:tt)* ) , $_iter:expr_2021 $( , $tail:expr_2021 )* ) => { izip!(@closure ($p, b) => ( $($tup)*, b ) $( , $tail )*) }; // unary - ($first:expr $(,)*) => { + ($first:expr_2021 $(,)*) => { IntoIterator::into_iter($first) }; // binary - ($first:expr, $second:expr $(,)*) => { + ($first:expr_2021, $second:expr_2021 $(,)*) => { izip!($first) .zip($second) }; // n-ary where n > 2 - ( $first:expr $( , $rest:expr )* $(,)* ) => { + ( $first:expr_2021 $( , $rest:expr_2021 )* $(,)* ) => { izip!($first) $( .zip($rest) diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 36853848e..9ca19ca7c 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -93,7 +93,7 @@ mod tests type M0 = Array0; macro_rules! assert_layouts { - ($mat:expr, $($layout:ident),*) => {{ + ($mat:expr_2021, $($layout:ident),*) => {{ let layout = $mat.view().layout(); $( assert!(layout.is(Layout::$layout), @@ -105,7 +105,7 @@ mod tests } macro_rules! assert_not_layouts { - ($mat:expr, $($layout:ident),*) => {{ + ($mat:expr_2021, $($layout:ident),*) => {{ let layout = $mat.view().layout(); $( assert!(!layout.is(Layout::$layout), diff --git a/src/linalg/impl_linalg.rs b/src/linalg/impl_linalg.rs index 0bbc0b026..338d10308 100644 --- a/src/linalg/impl_linalg.rs +++ b/src/linalg/impl_linalg.rs @@ -669,7 +669,7 @@ where A: LinalgScalar unsafe fn general_mat_vec_mul_impl( alpha: A, a: &ArrayRef2, x: &ArrayRef1, beta: A, y: RawArrayViewMut, ) where A: LinalgScalar -{ +{ unsafe { let ((m, k), k2) = (a.dim(), x.dim()); let m2 = y.dim(); if k != k2 || m != m2 { @@ -737,7 +737,7 @@ unsafe fn general_mat_vec_mul_impl( }); } } -} +}} /// Kronecker product of 2D matrices. /// diff --git a/src/macro_utils.rs b/src/macro_utils.rs index 75360de37..eb816f1f3 100644 --- a/src/macro_utils.rs +++ b/src/macro_utils.rs @@ -38,7 +38,7 @@ macro_rules! clone_bounds { /// debug assertions are enabled). #[cfg(debug_assertions)] macro_rules! ndassert { - ($e:expr, $($t:tt)*) => { assert!($e, $($t)*) }; + ($e:expr_2021, $($t:tt)*) => { assert!($e, $($t)*) }; } #[cfg(not(debug_assertions))] @@ -60,7 +60,7 @@ macro_rules! expand_if { // Macro to insert more informative out of bounds message in debug builds #[cfg(debug_assertions)] macro_rules! debug_bounds_check { - ($self_:ident, $index:expr) => { + ($self_:ident, $index:expr_2021) => { if $index.index_checked(&$self_.dim, &$self_.strides).is_none() { panic!( "ndarray: index {:?} is out of bounds for array of shape {:?}", diff --git a/src/slice.rs b/src/slice.rs index e2ce1e727..ec3f5e09a 100644 --- a/src/slice.rs +++ b/src/slice.rs @@ -587,7 +587,7 @@ where } macro_rules! impl_tryfrom_array_for_sliceinfo { - ($len:expr) => { + ($len:expr_2021) => { impl TryFrom<[SliceInfoElem; $len]> for SliceInfo<[SliceInfoElem; $len], Din, Dout> where @@ -809,7 +809,7 @@ impl_slicenextdim!((), NewAxis, Ix0, Ix1); #[macro_export] macro_rules! s( // convert a..b;c into @convert(a..b, c), final item - (@parse $in_dim:expr, $out_dim:expr, [$($stack:tt)*] $r:expr;$s:expr) => { + (@parse $in_dim:expr_2021, $out_dim:expr_2021, [$($stack:tt)*] $r:expr_2021;$s:expr_2021) => { match $r { r => { let in_dim = $crate::SliceNextDim::next_in_dim(&r, $in_dim); @@ -823,7 +823,7 @@ macro_rules! s( } }; // convert a..b into @convert(a..b), final item - (@parse $in_dim:expr, $out_dim:expr, [$($stack:tt)*] $r:expr) => { + (@parse $in_dim:expr_2021, $out_dim:expr_2021, [$($stack:tt)*] $r:expr_2021) => { match $r { r => { let in_dim = $crate::SliceNextDim::next_in_dim(&r, $in_dim); @@ -837,15 +837,15 @@ macro_rules! s( } }; // convert a..b;c into @convert(a..b, c), final item, trailing comma - (@parse $in_dim:expr, $out_dim:expr, [$($stack:tt)*] $r:expr;$s:expr ,) => { + (@parse $in_dim:expr_2021, $out_dim:expr_2021, [$($stack:tt)*] $r:expr_2021;$s:expr_2021 ,) => { $crate::s![@parse $in_dim, $out_dim, [$($stack)*] $r;$s] }; // convert a..b into @convert(a..b), final item, trailing comma - (@parse $in_dim:expr, $out_dim:expr, [$($stack:tt)*] $r:expr ,) => { + (@parse $in_dim:expr_2021, $out_dim:expr_2021, [$($stack:tt)*] $r:expr_2021 ,) => { $crate::s![@parse $in_dim, $out_dim, [$($stack)*] $r] }; // convert a..b;c into @convert(a..b, c) - (@parse $in_dim:expr, $out_dim:expr, [$($stack:tt)*] $r:expr;$s:expr, $($t:tt)*) => { + (@parse $in_dim:expr_2021, $out_dim:expr_2021, [$($stack:tt)*] $r:expr_2021;$s:expr_2021, $($t:tt)*) => { match $r { r => { $crate::s![@parse @@ -858,7 +858,7 @@ macro_rules! s( } }; // convert a..b into @convert(a..b) - (@parse $in_dim:expr, $out_dim:expr, [$($stack:tt)*] $r:expr, $($t:tt)*) => { + (@parse $in_dim:expr_2021, $out_dim:expr_2021, [$($stack:tt)*] $r:expr_2021, $($t:tt)*) => { match $r { r => { $crate::s![@parse @@ -881,11 +881,11 @@ macro_rules! s( // Catch-all clause for syntax errors (@parse $($t:tt)*) => { compile_error!("Invalid syntax in s![] call.") }; // convert range/index/new-axis into SliceInfoElem - (@convert $r:expr) => { + (@convert $r:expr_2021) => { <$crate::SliceInfoElem as ::core::convert::From<_>>::from($r) }; // convert range/index/new-axis and step into SliceInfoElem - (@convert $r:expr, $s:expr) => { + (@convert $r:expr_2021, $s:expr_2021) => { <$crate::SliceInfoElem as ::core::convert::From<_>>::from( <$crate::Slice as ::core::convert::From<_>>::from($r).step_by($s as isize) ) @@ -989,10 +989,10 @@ macro_rules! impl_multislice_tuple { private_impl! {} } }; - (@intersects_self $shape:expr, ($head:expr,)) => { + (@intersects_self $shape:expr_2021, ($head:expr_2021,)) => { false }; - (@intersects_self $shape:expr, ($head:expr, $($tail:expr,)*)) => { + (@intersects_self $shape:expr_2021, ($head:expr_2021, $($tail:expr_2021,)*)) => { $(slices_intersect($shape, $head, $tail)) ||* || impl_multislice_tuple!(@intersects_self $shape, ($($tail,)*)) }; diff --git a/src/stacking.rs b/src/stacking.rs index 8737d6f60..7aa2bddc4 100644 --- a/src/stacking.rs +++ b/src/stacking.rs @@ -177,10 +177,10 @@ where /// ``` #[macro_export] macro_rules! stack { - ($axis:expr, $( $array:expr ),+ ,) => { + ($axis:expr_2021, $( $array:expr_2021 ),+ ,) => { $crate::stack!($axis, $($array),+) }; - ($axis:expr, $( $array:expr ),+ ) => { + ($axis:expr_2021, $( $array:expr_2021 ),+ ) => { $crate::stack($axis, &[ $($crate::ArrayView::from(&$array) ),* ]).unwrap() }; } @@ -217,10 +217,10 @@ macro_rules! stack { /// ``` #[macro_export] macro_rules! concatenate { - ($axis:expr, $( $array:expr ),+ ,) => { + ($axis:expr_2021, $( $array:expr_2021 ),+ ,) => { $crate::concatenate!($axis, $($array),+) }; - ($axis:expr, $( $array:expr ),+ ) => { + ($axis:expr_2021, $( $array:expr_2021 ),+ ) => { $crate::concatenate($axis, &[ $($crate::ArrayView::from(&$array) ),* ]).unwrap() }; } diff --git a/src/zip/mod.rs b/src/zip/mod.rs index 640a74d1b..3a2334bc6 100644 --- a/src/zip/mod.rs +++ b/src/zip/mod.rs @@ -27,7 +27,7 @@ pub use self::ndproducer::{IntoNdProducer, NdProducer, Offset}; /// Return if the expression is a break value. macro_rules! fold_while { - ($e:expr) => { + ($e:expr_2021) => { match $e { FoldWhile::Continue(x) => x, x => return x, @@ -347,13 +347,15 @@ where D: Dimension F: FnMut(Acc, P::Item) -> FoldWhile, P: ZippableTuple, { - let mut i = 0; - while i < len { - let p = ptr.stride_offset(strides, i); - acc = fold_while!(function(acc, self.parts.as_ref(p))); - i += 1; + unsafe { + let mut i = 0; + while i < len { + let p = ptr.stride_offset(strides, i); + acc = fold_while!(function(acc, self.parts.as_ref(p))); + i += 1; + } + FoldWhile::Continue(acc) } - FoldWhile::Continue(acc) } fn for_each_core_strided(&mut self, acc: Acc, function: F) -> FoldWhile @@ -477,7 +479,7 @@ impl OffsetTuple for *mut T type Args = isize; unsafe fn stride_offset(self, stride: Self::Args, index: usize) -> Self { - self.offset(index as isize * stride) + unsafe { self.offset(index as isize * stride) } } } @@ -487,11 +489,11 @@ macro_rules! offset_impl { #[allow(non_snake_case)] impl<$($param: Offset),*> OffsetTuple for ($($param, )*) { type Args = ($($param::Stride,)*); - unsafe fn stride_offset(self, stride: Self::Args, index: usize) -> Self { + unsafe fn stride_offset(self, stride: Self::Args, index: usize) -> Self { unsafe { let ($($param, )*) = self; let ($($q, )*) = stride; ($(Offset::stride_offset($param, $q, index),)*) - } + }} } )+ }; @@ -530,16 +532,16 @@ macro_rules! zipt_impl { let ($(ref $p,)*) = *self; ($($p.as_ptr(), )*) } - unsafe fn as_ref(&self, ptr: Self::Ptr) -> Self::Item { + unsafe fn as_ref(&self, ptr: Self::Ptr) -> Self::Item { unsafe { let ($(ref $q ,)*) = *self; let ($($p,)*) = ptr; ($($q.as_ref($p),)*) - } + }} - unsafe fn uget_ptr(&self, i: &Self::Dim) -> Self::Ptr { + unsafe fn uget_ptr(&self, i: &Self::Dim) -> Self::Ptr { unsafe { let ($(ref $p,)*) = *self; ($($p.uget_ptr(i), )*) - } + }} fn split_at(self, axis: Axis, index: Ix) -> (Self, Self) { let ($($p,)*) = self; @@ -834,7 +836,7 @@ macro_rules! map_impl { /// before the array the raw view points to realizes its ownership. pub(crate) unsafe fn collect_with_partial(self, mut f: F) -> Partial where F: FnMut($($p::Item,)* ) -> R - { + { unsafe { // Get the last producer; and make a Partial that aliases its data pointer let (.., ref output) = &self.parts; @@ -863,7 +865,7 @@ macro_rules! map_impl { }); partial - } + }} } ); diff --git a/src/zip/ndproducer.rs b/src/zip/ndproducer.rs index 82f3f43a7..7e49a6953 100644 --- a/src/zip/ndproducer.rs +++ b/src/zip/ndproducer.rs @@ -109,9 +109,9 @@ impl Offset for *const T { type Stride = isize; unsafe fn stride_offset(self, s: Self::Stride, index: usize) -> Self - { + { unsafe { self.offset(s * (index as isize)) - } + }} private_impl! {} } @@ -119,9 +119,9 @@ impl Offset for *mut T { type Stride = isize; unsafe fn stride_offset(self, s: Self::Stride, index: usize) -> Self - { + { unsafe { self.offset(s * (index as isize)) - } + }} private_impl! {} } @@ -287,14 +287,14 @@ impl<'a, A, D: Dimension> NdProducer for ArrayView<'a, A, D> } unsafe fn as_ref(&self, ptr: *mut A) -> Self::Item - { + { unsafe { &*ptr - } + }} unsafe fn uget_ptr(&self, i: &Self::Dim) -> *mut A - { + { unsafe { self.ptr.as_ptr().offset(i.index_unchecked(&self.strides)) - } + }} fn stride_of(&self, axis: Axis) -> isize { @@ -343,14 +343,14 @@ impl<'a, A, D: Dimension> NdProducer for ArrayViewMut<'a, A, D> } unsafe fn as_ref(&self, ptr: *mut A) -> Self::Item - { + { unsafe { &mut *ptr - } + }} unsafe fn uget_ptr(&self, i: &Self::Dim) -> *mut A - { + { unsafe { self.ptr.as_ptr().offset(i.index_unchecked(&self.strides)) - } + }} fn stride_of(&self, axis: Axis) -> isize { @@ -404,12 +404,12 @@ impl NdProducer for RawArrayView } unsafe fn uget_ptr(&self, i: &Self::Dim) -> *const A - { + { unsafe { self.layout .ptr .as_ptr() .offset(i.index_unchecked(&self.layout.strides)) - } + }} fn stride_of(&self, axis: Axis) -> isize { @@ -463,12 +463,12 @@ impl NdProducer for RawArrayViewMut } unsafe fn uget_ptr(&self, i: &Self::Dim) -> *mut A - { + { unsafe { self.layout .ptr .as_ptr() .offset(i.index_unchecked(&self.layout.strides)) - } + }} fn stride_of(&self, axis: Axis) -> isize { diff --git a/src/zip/zipmacro.rs b/src/zip/zipmacro.rs index 0bbe956b3..696659a8a 100644 --- a/src/zip/zipmacro.rs +++ b/src/zip/zipmacro.rs @@ -98,28 +98,28 @@ macro_rules! azip { // Indexed with a single producer // we allow an optional trailing comma after the producers in each rule. - (@build $apply:ident (index $index:pat, $first_pat:pat in $first_prod:expr $(,)?) $body:expr) => { + (@build $apply:ident (index $index:pat, $first_pat:pat in $first_prod:expr_2021 $(,)?) $body:expr_2021) => { $crate::Zip::indexed($first_prod).$apply(|$index, $first_pat| $body) }; // Indexed with more than one producer - (@build $apply:ident (index $index:pat, $first_pat:pat in $first_prod:expr, $($pat:pat in $prod:expr),* $(,)?) $body:expr) => { + (@build $apply:ident (index $index:pat, $first_pat:pat in $first_prod:expr_2021, $($pat:pat in $prod:expr_2021),* $(,)?) $body:expr_2021) => { $crate::Zip::indexed($first_prod) $(.and($prod))* .$apply(|$index, $first_pat, $($pat),*| $body) }; // Unindexed with a single producer - (@build $apply:ident ($first_pat:pat in $first_prod:expr $(,)?) $body:expr) => { + (@build $apply:ident ($first_pat:pat in $first_prod:expr_2021 $(,)?) $body:expr_2021) => { $crate::Zip::from($first_prod).$apply(|$first_pat| $body) }; // Unindexed with more than one producer - (@build $apply:ident ($first_pat:pat in $first_prod:expr, $($pat:pat in $prod:expr),* $(,)?) $body:expr) => { + (@build $apply:ident ($first_pat:pat in $first_prod:expr_2021, $($pat:pat in $prod:expr_2021),* $(,)?) $body:expr_2021) => { $crate::Zip::from($first_prod) $(.and($prod))* .$apply(|$first_pat, $($pat),*| $body) }; // Unindexed with one or more producer, no loop body - (@build $apply:ident $first_prod:expr $(, $prod:expr)* $(,)?) => { + (@build $apply:ident $first_prod:expr_2021 $(, $prod:expr_2021)* $(,)?) => { $crate::Zip::from($first_prod) $(.and($prod))* }; diff --git a/tests/array.rs b/tests/array.rs index 3d6fa6715..6f3fa21d4 100644 --- a/tests/array.rs +++ b/tests/array.rs @@ -17,13 +17,13 @@ use num_complex::Complex; use std::convert::TryFrom; macro_rules! assert_panics { - ($body:expr) => { + ($body:expr_2021) => { if let Ok(v) = ::std::panic::catch_unwind(|| $body) { panic!("assertion failed: should_panic; \ non-panicking result: {:?}", v); } }; - ($body:expr, $($arg:tt)*) => { + ($body:expr_2021, $($arg:tt)*) => { if let Ok(_) = ::std::panic::catch_unwind(|| $body) { panic!($($arg)*); } @@ -412,7 +412,7 @@ fn test_slice_collapse_with_newaxis() fn test_multislice() { macro_rules! do_test { - ($arr:expr, $($s:expr),*) => { + ($arr:expr_2021, $($s:expr_2021),*) => { { let arr = $arr; let copy = arr.clone(); @@ -784,7 +784,7 @@ fn diag() fn merge_axes() { macro_rules! assert_merged { - ($arr:expr, $slice:expr, $take:expr, $into:expr) => { + ($arr:expr_2021, $slice:expr_2021, $take:expr_2021, $into:expr_2021) => { let mut v = $arr.slice($slice); let merged_len = v.len_of(Axis($take)) * v.len_of(Axis($into)); assert!(v.merge_axes(Axis($take), Axis($into))); @@ -793,7 +793,7 @@ fn merge_axes() }; } macro_rules! assert_not_merged { - ($arr:expr, $slice:expr, $take:expr, $into:expr) => { + ($arr:expr_2021, $slice:expr_2021, $take:expr_2021, $into:expr_2021) => { let mut v = $arr.slice($slice); let old_dim = v.raw_dim(); let old_strides = v.strides().to_owned(); @@ -1298,7 +1298,7 @@ fn owned_array_discontiguous_drop() } macro_rules! assert_matches { - ($value:expr, $pat:pat) => { + ($value:expr_2021, $pat:pat) => { match $value { $pat => {} ref err => panic!( diff --git a/tests/dimension.rs b/tests/dimension.rs index fe53d96b3..6beeb6dd1 100644 --- a/tests/dimension.rs +++ b/tests/dimension.rs @@ -263,13 +263,13 @@ fn test_hash() hasher.finish() } macro_rules! test_hash_eq { - ($arr:expr) => { + ($arr:expr_2021) => { assert_eq!(calc_hash(&Dim($arr)), calc_hash(&Dim($arr))); assert_eq!(calc_hash(&Dim($arr)), calc_hash(&IxDyn(&$arr))); }; } macro_rules! test_hash_ne { - ($arr1:expr, $arr2:expr) => { + ($arr1:expr_2021, $arr2:expr_2021) => { assert_ne!(calc_hash(&Dim($arr1)), calc_hash(&Dim($arr2))); assert_ne!(calc_hash(&Dim($arr1)), calc_hash(&IxDyn(&$arr2))); assert_ne!(calc_hash(&IxDyn(&$arr1)), calc_hash(&Dim($arr2))); @@ -330,7 +330,7 @@ fn test_all_ndindex() { use ndarray::IntoDimension; macro_rules! ndindex { - ($($i:expr),*) => { + ($($i:expr_2021),*) => { for &rev in &[false, true] { // rev is for C / F order let size = $($i *)* 1; diff --git a/tests/iterators.rs b/tests/iterators.rs index bdfd3ee50..d9e084b73 100644 --- a/tests/iterators.rs +++ b/tests/iterators.rs @@ -8,13 +8,13 @@ use itertools::enumerate; use std::cell::Cell; macro_rules! assert_panics { - ($body:expr) => { + ($body:expr_2021) => { if let Ok(v) = ::std::panic::catch_unwind(|| $body) { panic!("assertion failed: should_panic; \ non-panicking result: {:?}", v); } }; - ($body:expr, $($arg:tt)*) => { + ($body:expr_2021, $($arg:tt)*) => { if let Ok(_) = ::std::panic::catch_unwind(|| $body) { panic!($($arg)*); } @@ -1073,7 +1073,7 @@ fn test_impl_iter_compiles() let _ = slice_iter_non_empty_indices; // ndarray case - fn array_iter_non_empty_indices<'s, 'a>(array: &'a Array<&'s str, Ix1>) -> impl Iterator + 'a + fn array_iter_non_empty_indices<'s, 'a>(array: &'a Array<&'s str, Ix1>) -> impl Iterator + 'a + use<'a> { array .iter() From 8944edc8df9dc80bb047f0a05400e47accc25505 Mon Sep 17 00:00:00 2001 From: Adam Kern Date: Mon, 26 May 2025 13:43:00 -0400 Subject: [PATCH 4/8] No need for expr_2021 --- benches/bench1.rs | 2 +- src/array_approx.rs | 2 +- src/dimension/conversion.rs | 4 +-- src/dimension/dim.rs | 6 ++--- src/dimension/dimension_trait.rs | 6 ++--- src/dimension/macros.rs | 4 +-- src/dimension/ndindex.rs | 2 +- src/dimension/ops.rs | 6 ++--- src/dimension/remove_axis.rs | 2 +- src/dimension/reshape.rs | 4 +-- src/free_functions.rs | 16 +++++------ src/impl_constructors.rs | 46 ++++++++++++++++++-------------- src/impl_ops.rs | 10 +++---- src/indexes.rs | 2 +- src/iterators/macros.rs | 4 +-- src/iterators/mod.rs | 38 +++++++++++++------------- src/itertools.rs | 10 +++---- src/layout/mod.rs | 4 +-- src/macro_utils.rs | 4 +-- src/slice.rs | 22 +++++++-------- src/stacking.rs | 8 +++--- src/zip/mod.rs | 2 +- src/zip/zipmacro.rs | 10 +++---- tests/array.rs | 12 ++++----- tests/dimension.rs | 6 ++--- tests/iterators.rs | 8 +++--- 26 files changed, 125 insertions(+), 115 deletions(-) diff --git a/benches/bench1.rs b/benches/bench1.rs index 4ee86d7d8..c07b8e3d9 100644 --- a/benches/bench1.rs +++ b/benches/bench1.rs @@ -795,7 +795,7 @@ fn bench_col_iter(bench: &mut test::Bencher) } macro_rules! mat_mul { - ($modname:ident, $ty:ident, $(($name:ident, $m:expr_2021, $n:expr_2021, $k:expr_2021))+) => { + ($modname:ident, $ty:ident, $(($name:ident, $m:expr, $n:expr, $k:expr))+) => { mod $modname { use test::{black_box, Bencher}; use ndarray::Array; diff --git a/src/array_approx.rs b/src/array_approx.rs index d7aa575f0..958f6f6ba 100644 --- a/src/array_approx.rs +++ b/src/array_approx.rs @@ -29,7 +29,7 @@ mod approx_methods } macro_rules! impl_approx_traits { - ($approx:ident, $doc:expr_2021) => { + ($approx:ident, $doc:expr) => { mod $approx { use crate::imp_prelude::*; use crate::Zip; diff --git a/src/dimension/conversion.rs b/src/dimension/conversion.rs index 3982a58ae..0cf2e1296 100644 --- a/src/dimension/conversion.rs +++ b/src/dimension/conversion.rs @@ -106,13 +106,13 @@ macro_rules! tuple_type { } macro_rules! tuple_expr { - ([$self_:expr_2021] $($index:tt)*) => ( + ([$self_:expr] $($index:tt)*) => ( ( $($self_[$index], )* ) ); } macro_rules! array_expr { - ([$self_:expr_2021] $($index:tt)*) => ( + ([$self_:expr] $($index:tt)*) => ( [$($self_ . $index, )*] ); } diff --git a/src/dimension/dim.rs b/src/dimension/dim.rs index b001f8432..96e433bb3 100644 --- a/src/dimension/dim.rs +++ b/src/dimension/dim.rs @@ -169,17 +169,17 @@ macro_rules! impl_scalar_op { } macro_rules! add { - ($x:expr_2021, $y:expr_2021) => { + ($x:expr, $y:expr) => { $x += $y; }; } macro_rules! sub { - ($x:expr_2021, $y:expr_2021) => { + ($x:expr, $y:expr) => { $x -= $y; }; } macro_rules! mul { - ($x:expr_2021, $y:expr_2021) => { + ($x:expr, $y:expr) => { $x *= $y; }; } diff --git a/src/dimension/dimension_trait.rs b/src/dimension/dimension_trait.rs index 43cdb9eff..3544a7f3c 100644 --- a/src/dimension/dimension_trait.rs +++ b/src/dimension/dimension_trait.rs @@ -402,7 +402,7 @@ pub trait Dimension: // Dimension impls macro_rules! impl_insert_axis_array( - ($n:expr_2021) => ( + ($n:expr) => ( #[inline] fn insert_axis(&self, axis: Axis) -> Self::Larger { debug_assert!(axis.index() <= $n); @@ -878,7 +878,7 @@ impl Dimension for Dim<[Ix; 3]> let mut stride = *self; let mut order = Ix3(0, 1, 2); macro_rules! swap { - ($stride:expr_2021, $order:expr_2021, $x:expr_2021, $y:expr_2021) => { + ($stride:expr, $order:expr, $x:expr, $y:expr) => { if ($stride[$x] as isize).abs() > ($stride[$y] as isize).abs() { $stride.swap($x, $y); $order.ixm().swap($x, $y); @@ -904,7 +904,7 @@ impl Dimension for Dim<[Ix; 3]> } macro_rules! large_dim { - ($n:expr_2021, $name:ident, $pattern:ty, $larger:ty, { $($insert_axis:tt)* }) => ( + ($n:expr, $name:ident, $pattern:ty, $larger:ty, { $($insert_axis:tt)* }) => ( impl Dimension for Dim<[Ix; $n]> { const NDIM: Option = Some($n); type Pattern = $pattern; diff --git a/src/dimension/macros.rs b/src/dimension/macros.rs index 67c64e629..9a576e347 100644 --- a/src/dimension/macros.rs +++ b/src/dimension/macros.rs @@ -1,12 +1,12 @@ /// Indexing macro for Dim<[usize; N]> this /// gets the index at `$i` in the underlying array macro_rules! get { - ($dim:expr_2021, $i:expr_2021) => { + ($dim:expr, $i:expr) => { (*$dim.ix())[$i] }; } macro_rules! getm { - ($dim:expr_2021, $i:expr_2021) => { + ($dim:expr, $i:expr) => { (*$dim.ixm())[$i] }; } diff --git a/src/dimension/ndindex.rs b/src/dimension/ndindex.rs index dba3a23f0..ca2a3ea69 100644 --- a/src/dimension/ndindex.rs +++ b/src/dimension/ndindex.rs @@ -160,7 +160,7 @@ unsafe impl NdIndex for Ix } macro_rules! ndindex_with_array { - ($([$n:expr_2021, $ix_n:ident $($index:tt)*])+) => { + ($([$n:expr, $ix_n:ident $($index:tt)*])+) => { $( // implement NdIndex for [Ix; 2] and so on unsafe impl NdIndex<$ix_n> for [Ix; $n] { diff --git a/src/dimension/ops.rs b/src/dimension/ops.rs index 817c17253..1365ab488 100644 --- a/src/dimension/ops.rs +++ b/src/dimension/ops.rs @@ -8,7 +8,7 @@ pub trait DimAdd } macro_rules! impl_dimadd_const_out_const { - ($lhs:expr_2021, $rhs:expr_2021) => { + ($lhs:expr, $rhs:expr) => { impl DimAdd> for Dim<[usize; $lhs]> { type Output = Dim<[usize; $lhs + $rhs]>; } @@ -16,12 +16,12 @@ macro_rules! impl_dimadd_const_out_const { } macro_rules! impl_dimadd_const_out_dyn { - ($lhs:expr_2021, IxDyn) => { + ($lhs:expr, IxDyn) => { impl DimAdd for Dim<[usize; $lhs]> { type Output = IxDyn; } }; - ($lhs:expr_2021, $rhs:expr_2021) => { + ($lhs:expr, $rhs:expr) => { impl DimAdd> for Dim<[usize; $lhs]> { type Output = IxDyn; } diff --git a/src/dimension/remove_axis.rs b/src/dimension/remove_axis.rs index 10fed2bd1..cbb039fc5 100644 --- a/src/dimension/remove_axis.rs +++ b/src/dimension/remove_axis.rs @@ -43,7 +43,7 @@ impl RemoveAxis for Dim<[Ix; 2]> } macro_rules! impl_remove_axis_array( - ($($n:expr_2021),*) => ( + ($($n:expr),*) => ( $( impl RemoveAxis for Dim<[Ix; $n]> { diff --git a/src/dimension/reshape.rs b/src/dimension/reshape.rs index c209d3290..abcec4993 100644 --- a/src/dimension/reshape.rs +++ b/src/dimension/reshape.rs @@ -151,13 +151,13 @@ fn test_reshape() use crate::Dim; macro_rules! test_reshape { - (fail $order:ident from $from:expr_2021, $stride:expr_2021, to $to:expr_2021) => { + (fail $order:ident from $from:expr, $stride:expr, to $to:expr) => { let res = reshape_dim(&Dim($from), &Dim($stride), &Dim($to), Order::$order); println!("Reshape {:?} {:?} to {:?}, order {:?}\n => {:?}", $from, $stride, $to, Order::$order, res); let _res = res.expect_err("Expected failed reshape"); }; - (ok $order:ident from $from:expr_2021, $stride:expr_2021, to $to:expr_2021, $to_stride:expr_2021) => {{ + (ok $order:ident from $from:expr, $stride:expr, to $to:expr, $to_stride:expr) => {{ let res = reshape_dim(&Dim($from), &Dim($stride), &Dim($to), Order::$order); println!("Reshape {:?} {:?} to {:?}, order {:?}\n => {:?}", $from, $stride, $to, Order::$order, res); diff --git a/src/free_functions.rs b/src/free_functions.rs index 4b0676dd2..a2ad6137c 100644 --- a/src/free_functions.rs +++ b/src/free_functions.rs @@ -63,25 +63,25 @@ use crate::{imp_prelude::*, LayoutRef}; /// ``` #[macro_export] macro_rules! array { - ($([$([$([$([$([$([$($x:expr_2021),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ + ($([$([$([$([$([$([$($x:expr),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ compile_error!("Arrays of 7 dimensions or more (or ndarrays of Rust arrays) cannot be constructed with the array! macro."); }}; - ($([$([$([$([$([$($x:expr_2021),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ + ($([$([$([$([$([$($x:expr),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ $crate::Array6::from(vec![$([$([$([$([$([$($x,)*],)*],)*],)*],)*],)*]) }}; - ($([$([$([$([$($x:expr_2021),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ + ($([$([$([$([$($x:expr),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ $crate::Array5::from(vec![$([$([$([$([$($x,)*],)*],)*],)*],)*]) }}; - ($([$([$([$($x:expr_2021),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ + ($([$([$([$($x:expr),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ $crate::Array4::from(vec![$([$([$([$($x,)*],)*],)*],)*]) }}; - ($([$([$($x:expr_2021),* $(,)*]),+ $(,)*]),+ $(,)*) => {{ + ($([$([$($x:expr),* $(,)*]),+ $(,)*]),+ $(,)*) => {{ $crate::Array3::from(vec![$([$([$($x,)*],)*],)*]) }}; - ($([$($x:expr_2021),* $(,)*]),+ $(,)*) => {{ + ($([$($x:expr),* $(,)*]),+ $(,)*) => {{ $crate::Array2::from(vec![$([$($x,)*],)*]) }}; - ($($x:expr_2021),* $(,)*) => {{ + ($($x:expr),* $(,)*) => {{ $crate::Array::from(vec![$($x,)*]) }}; } @@ -421,7 +421,7 @@ mod meshgrid_impl } macro_rules! meshgrid_body { - ($count:literal, $indexing:expr_2021, $(($arr:expr_2021, $idx:literal)),+) => { + ($count:literal, $indexing:expr, $(($arr:expr, $idx:literal)),+) => { { let shape = construct_shape([$($arr),+], $indexing); ( diff --git a/src/impl_constructors.rs b/src/impl_constructors.rs index 781d74cc6..478006c75 100644 --- a/src/impl_constructors.rs +++ b/src/impl_constructors.rs @@ -271,7 +271,7 @@ macro_rules! size_of_shape_checked_unwrap { #[cfg(debug_assertions)] macro_rules! size_of_shape_checked_unwrap { - ($dim:expr_2021) => { + ($dim:expr) => { match dimension::size_of_shape_checked($dim) { Ok(sz) => sz, Err(_) => panic!( @@ -504,21 +504,25 @@ where /// indices. pub unsafe fn from_shape_vec_unchecked(shape: Sh, v: Vec) -> Self where Sh: Into> - { unsafe { - let shape = shape.into(); - let dim = shape.dim; - let strides = shape.strides.strides_for_dim(&dim); - Self::from_vec_dim_stride_unchecked(dim, strides, v) - }} + { + unsafe { + let shape = shape.into(); + let dim = shape.dim; + let strides = shape.strides.strides_for_dim(&dim); + Self::from_vec_dim_stride_unchecked(dim, strides, v) + } + } unsafe fn from_vec_dim_stride_unchecked(dim: D, strides: D, mut v: Vec) -> Self - { unsafe { - // debug check for issues that indicates wrong use of this constructor - debug_assert!(dimension::can_index_slice(&v, &dim, &strides, CanIndexCheckMode::OwnedMutable).is_ok()); + { + unsafe { + // debug check for issues that indicates wrong use of this constructor + debug_assert!(dimension::can_index_slice(&v, &dim, &strides, CanIndexCheckMode::OwnedMutable).is_ok()); - let ptr = nonnull_from_vec_data(&mut v).add(offset_from_low_addr_ptr_to_logical_ptr(&dim, &strides)); - ArrayBase::from_data_ptr(DataOwned::new(v), ptr).with_strides_dim(strides, dim) - }} + let ptr = nonnull_from_vec_data(&mut v).add(offset_from_low_addr_ptr_to_logical_ptr(&dim, &strides)); + ArrayBase::from_data_ptr(DataOwned::new(v), ptr).with_strides_dim(strides, dim) + } + } /// Creates an array from an iterator, mapped by `map` and interpret it according to the /// provided shape and strides. @@ -531,13 +535,15 @@ where Sh: Into>, I: TrustedIterator + ExactSizeIterator, F: FnMut(I::Item) -> A, - { unsafe { - let shape = shape.into(); - let dim = shape.dim; - let strides = shape.strides.strides_for_dim(&dim); - let v = to_vec_mapped(iter, map); - Self::from_vec_dim_stride_unchecked(dim, strides, v) - }} + { + unsafe { + let shape = shape.into(); + let dim = shape.dim; + let strides = shape.strides.strides_for_dim(&dim); + let v = to_vec_mapped(iter, map); + Self::from_vec_dim_stride_unchecked(dim, strides, v) + } + } /// Create an array with uninitialized elements, shape `shape`. /// diff --git a/src/impl_ops.rs b/src/impl_ops.rs index 01845f04e..53f49cc43 100644 --- a/src/impl_ops.rs +++ b/src/impl_ops.rs @@ -51,7 +51,7 @@ impl ScalarOperand for Complex {} impl ScalarOperand for Complex {} macro_rules! impl_binary_op( - ($trt:ident, $operator:tt, $mth:ident, $iop:tt, $doc:expr_2021) => ( + ($trt:ident, $operator:tt, $mth:ident, $iop:tt, $doc:expr) => ( /// Perform elementwise #[doc=$doc] /// between `self` and `rhs`, @@ -337,10 +337,10 @@ impl<'a, A, D, B> $trt for &'a ArrayRef // Pick the expression $a for commutative and $b for ordered binop macro_rules! if_commutative { - (Commute { $a:expr_2021 } or { $b:expr_2021 }) => { + (Commute { $a:expr } or { $b:expr }) => { $a }; - (Ordered { $a:expr_2021 } or { $b:expr_2021 }) => { + (Ordered { $a:expr } or { $b:expr }) => { $b }; } @@ -348,7 +348,7 @@ macro_rules! if_commutative { macro_rules! impl_scalar_lhs_op { // $commutative flag. Reuse the self + scalar impl if we can. // We can do this safely since these are the primitive numeric types - ($scalar:ty, $commutative:ident, $operator:tt, $trt:ident, $mth:ident, $doc:expr_2021) => ( + ($scalar:ty, $commutative:ident, $operator:tt, $trt:ident, $mth:ident, $doc:expr) => ( // these have no doc -- they are not visible in rustdoc // Perform elementwise // between the scalar `self` and array `rhs`, @@ -595,7 +595,7 @@ mod assign_ops use crate::imp_prelude::*; macro_rules! impl_assign_op { - ($trt:ident, $method:ident, $doc:expr_2021) => { + ($trt:ident, $method:ident, $doc:expr) => { use std::ops::$trt; #[doc=$doc] diff --git a/src/indexes.rs b/src/indexes.rs index a561293cf..0fa2b50fb 100644 --- a/src/indexes.rs +++ b/src/indexes.rs @@ -317,7 +317,7 @@ mod tests fn test_indices_iter_c_fold() { macro_rules! run_test { - ($dim:expr_2021) => { + ($dim:expr) => { for num_consume in 0..3 { let mut it = indices($dim).into_iter(); for _ in 0..num_consume { diff --git a/src/iterators/macros.rs b/src/iterators/macros.rs index e170ea459..2d1796b3e 100644 --- a/src/iterators/macros.rs +++ b/src/iterators/macros.rs @@ -53,7 +53,7 @@ macro_rules! impl_ndproducer { )* unsafe fn item(&$self_:ident, $ptr:pat) { - $refexpr:expr_2021 + $refexpr:expr } }) => { impl<$($typarm)*> NdProducer for $fulltype { @@ -140,7 +140,7 @@ macro_rules! impl_iterator { type Item = $ity:ty; fn item(&mut $self_:ident, $elt:pat) { - $refexpr:expr_2021 + $refexpr:expr } }) => { expand_if!(@nonempty [$($cloneparm)*] diff --git a/src/iterators/mod.rs b/src/iterators/mod.rs index 2eddf3f62..a1e4ee57f 100644 --- a/src/iterators/mod.rs +++ b/src/iterators/mod.rs @@ -267,7 +267,7 @@ where D: Dimension } macro_rules! either { - ($value:expr_2021, $inner:pat => $result:expr_2021) => { + ($value:expr, $inner:pat => $result:expr) => { match $value { ElementsRepr::Slice($inner) => $result, ElementsRepr::Counted($inner) => $result, @@ -276,7 +276,7 @@ macro_rules! either { } macro_rules! either_mut { - ($value:expr_2021, $inner:ident => $result:expr_2021) => { + ($value:expr, $inner:ident => $result:expr) => { match $value { ElementsRepr::Slice(ref mut $inner) => $result, ElementsRepr::Counted(ref mut $inner) => $result, @@ -888,16 +888,18 @@ impl AxisIterCore #[inline] unsafe fn offset(&self, index: usize) -> *mut A - { unsafe { - debug_assert!( + { + unsafe { + debug_assert!( index < self.end, "index={}, end={}, stride={}", index, self.end, self.stride ); - self.ptr.offset(index as isize * self.stride) - }} + self.ptr.offset(index as isize * self.stride) + } + } /// Splits the iterator at `index`, yielding two disjoint iterators. /// @@ -1221,14 +1223,14 @@ impl NdProducer for AxisIter<'_, A, D> } unsafe fn as_ref(&self, ptr: Self::Ptr) -> Self::Item - { unsafe { - ArrayView::new_(ptr, self.iter.inner_dim.clone(), self.iter.inner_strides.clone()) - }} + { + unsafe { ArrayView::new_(ptr, self.iter.inner_dim.clone(), self.iter.inner_strides.clone()) } + } unsafe fn uget_ptr(&self, i: &Self::Dim) -> Self::Ptr - { unsafe { - self.iter.offset(self.iter.index + i[0]) - }} + { + unsafe { self.iter.offset(self.iter.index + i[0]) } + } fn stride_of(&self, _axis: Axis) -> isize { @@ -1280,14 +1282,14 @@ impl NdProducer for AxisIterMut<'_, A, D> } unsafe fn as_ref(&self, ptr: Self::Ptr) -> Self::Item - { unsafe { - ArrayViewMut::new_(ptr, self.iter.inner_dim.clone(), self.iter.inner_strides.clone()) - }} + { + unsafe { ArrayViewMut::new_(ptr, self.iter.inner_dim.clone(), self.iter.inner_strides.clone()) } + } unsafe fn uget_ptr(&self, i: &Self::Dim) -> Self::Ptr - { unsafe { - self.iter.offset(self.iter.index + i[0]) - }} + { + unsafe { self.iter.offset(self.iter.index + i[0]) } + } fn stride_of(&self, _axis: Axis) -> isize { diff --git a/src/itertools.rs b/src/itertools.rs index 5d073679a..d3562e687 100644 --- a/src/itertools.rs +++ b/src/itertools.rs @@ -94,28 +94,28 @@ macro_rules! izip { // @closure creates a tuple-flattening closure for .map() call. usage: // @closure partial_pattern => partial_tuple , rest , of , iterators // eg. izip!( @closure ((a, b), c) => (a, b, c) , dd , ee ) - ( @closure $p:pat => $tup:expr_2021 ) => { + ( @closure $p:pat => $tup:expr ) => { |$p| $tup }; // The "b" identifier is a different identifier on each recursion level thanks to hygiene. - ( @closure $p:pat => ( $($tup:tt)* ) , $_iter:expr_2021 $( , $tail:expr_2021 )* ) => { + ( @closure $p:pat => ( $($tup:tt)* ) , $_iter:expr $( , $tail:expr )* ) => { izip!(@closure ($p, b) => ( $($tup)*, b ) $( , $tail )*) }; // unary - ($first:expr_2021 $(,)*) => { + ($first:expr $(,)*) => { IntoIterator::into_iter($first) }; // binary - ($first:expr_2021, $second:expr_2021 $(,)*) => { + ($first:expr, $second:expr $(,)*) => { izip!($first) .zip($second) }; // n-ary where n > 2 - ( $first:expr_2021 $( , $rest:expr_2021 )* $(,)* ) => { + ( $first:expr $( , $rest:expr )* $(,)* ) => { izip!($first) $( .zip($rest) diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 9ca19ca7c..36853848e 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -93,7 +93,7 @@ mod tests type M0 = Array0; macro_rules! assert_layouts { - ($mat:expr_2021, $($layout:ident),*) => {{ + ($mat:expr, $($layout:ident),*) => {{ let layout = $mat.view().layout(); $( assert!(layout.is(Layout::$layout), @@ -105,7 +105,7 @@ mod tests } macro_rules! assert_not_layouts { - ($mat:expr_2021, $($layout:ident),*) => {{ + ($mat:expr, $($layout:ident),*) => {{ let layout = $mat.view().layout(); $( assert!(!layout.is(Layout::$layout), diff --git a/src/macro_utils.rs b/src/macro_utils.rs index eb816f1f3..75360de37 100644 --- a/src/macro_utils.rs +++ b/src/macro_utils.rs @@ -38,7 +38,7 @@ macro_rules! clone_bounds { /// debug assertions are enabled). #[cfg(debug_assertions)] macro_rules! ndassert { - ($e:expr_2021, $($t:tt)*) => { assert!($e, $($t)*) }; + ($e:expr, $($t:tt)*) => { assert!($e, $($t)*) }; } #[cfg(not(debug_assertions))] @@ -60,7 +60,7 @@ macro_rules! expand_if { // Macro to insert more informative out of bounds message in debug builds #[cfg(debug_assertions)] macro_rules! debug_bounds_check { - ($self_:ident, $index:expr_2021) => { + ($self_:ident, $index:expr) => { if $index.index_checked(&$self_.dim, &$self_.strides).is_none() { panic!( "ndarray: index {:?} is out of bounds for array of shape {:?}", diff --git a/src/slice.rs b/src/slice.rs index ec3f5e09a..e2ce1e727 100644 --- a/src/slice.rs +++ b/src/slice.rs @@ -587,7 +587,7 @@ where } macro_rules! impl_tryfrom_array_for_sliceinfo { - ($len:expr_2021) => { + ($len:expr) => { impl TryFrom<[SliceInfoElem; $len]> for SliceInfo<[SliceInfoElem; $len], Din, Dout> where @@ -809,7 +809,7 @@ impl_slicenextdim!((), NewAxis, Ix0, Ix1); #[macro_export] macro_rules! s( // convert a..b;c into @convert(a..b, c), final item - (@parse $in_dim:expr_2021, $out_dim:expr_2021, [$($stack:tt)*] $r:expr_2021;$s:expr_2021) => { + (@parse $in_dim:expr, $out_dim:expr, [$($stack:tt)*] $r:expr;$s:expr) => { match $r { r => { let in_dim = $crate::SliceNextDim::next_in_dim(&r, $in_dim); @@ -823,7 +823,7 @@ macro_rules! s( } }; // convert a..b into @convert(a..b), final item - (@parse $in_dim:expr_2021, $out_dim:expr_2021, [$($stack:tt)*] $r:expr_2021) => { + (@parse $in_dim:expr, $out_dim:expr, [$($stack:tt)*] $r:expr) => { match $r { r => { let in_dim = $crate::SliceNextDim::next_in_dim(&r, $in_dim); @@ -837,15 +837,15 @@ macro_rules! s( } }; // convert a..b;c into @convert(a..b, c), final item, trailing comma - (@parse $in_dim:expr_2021, $out_dim:expr_2021, [$($stack:tt)*] $r:expr_2021;$s:expr_2021 ,) => { + (@parse $in_dim:expr, $out_dim:expr, [$($stack:tt)*] $r:expr;$s:expr ,) => { $crate::s![@parse $in_dim, $out_dim, [$($stack)*] $r;$s] }; // convert a..b into @convert(a..b), final item, trailing comma - (@parse $in_dim:expr_2021, $out_dim:expr_2021, [$($stack:tt)*] $r:expr_2021 ,) => { + (@parse $in_dim:expr, $out_dim:expr, [$($stack:tt)*] $r:expr ,) => { $crate::s![@parse $in_dim, $out_dim, [$($stack)*] $r] }; // convert a..b;c into @convert(a..b, c) - (@parse $in_dim:expr_2021, $out_dim:expr_2021, [$($stack:tt)*] $r:expr_2021;$s:expr_2021, $($t:tt)*) => { + (@parse $in_dim:expr, $out_dim:expr, [$($stack:tt)*] $r:expr;$s:expr, $($t:tt)*) => { match $r { r => { $crate::s![@parse @@ -858,7 +858,7 @@ macro_rules! s( } }; // convert a..b into @convert(a..b) - (@parse $in_dim:expr_2021, $out_dim:expr_2021, [$($stack:tt)*] $r:expr_2021, $($t:tt)*) => { + (@parse $in_dim:expr, $out_dim:expr, [$($stack:tt)*] $r:expr, $($t:tt)*) => { match $r { r => { $crate::s![@parse @@ -881,11 +881,11 @@ macro_rules! s( // Catch-all clause for syntax errors (@parse $($t:tt)*) => { compile_error!("Invalid syntax in s![] call.") }; // convert range/index/new-axis into SliceInfoElem - (@convert $r:expr_2021) => { + (@convert $r:expr) => { <$crate::SliceInfoElem as ::core::convert::From<_>>::from($r) }; // convert range/index/new-axis and step into SliceInfoElem - (@convert $r:expr_2021, $s:expr_2021) => { + (@convert $r:expr, $s:expr) => { <$crate::SliceInfoElem as ::core::convert::From<_>>::from( <$crate::Slice as ::core::convert::From<_>>::from($r).step_by($s as isize) ) @@ -989,10 +989,10 @@ macro_rules! impl_multislice_tuple { private_impl! {} } }; - (@intersects_self $shape:expr_2021, ($head:expr_2021,)) => { + (@intersects_self $shape:expr, ($head:expr,)) => { false }; - (@intersects_self $shape:expr_2021, ($head:expr_2021, $($tail:expr_2021,)*)) => { + (@intersects_self $shape:expr, ($head:expr, $($tail:expr,)*)) => { $(slices_intersect($shape, $head, $tail)) ||* || impl_multislice_tuple!(@intersects_self $shape, ($($tail,)*)) }; diff --git a/src/stacking.rs b/src/stacking.rs index 7aa2bddc4..8737d6f60 100644 --- a/src/stacking.rs +++ b/src/stacking.rs @@ -177,10 +177,10 @@ where /// ``` #[macro_export] macro_rules! stack { - ($axis:expr_2021, $( $array:expr_2021 ),+ ,) => { + ($axis:expr, $( $array:expr ),+ ,) => { $crate::stack!($axis, $($array),+) }; - ($axis:expr_2021, $( $array:expr_2021 ),+ ) => { + ($axis:expr, $( $array:expr ),+ ) => { $crate::stack($axis, &[ $($crate::ArrayView::from(&$array) ),* ]).unwrap() }; } @@ -217,10 +217,10 @@ macro_rules! stack { /// ``` #[macro_export] macro_rules! concatenate { - ($axis:expr_2021, $( $array:expr_2021 ),+ ,) => { + ($axis:expr, $( $array:expr ),+ ,) => { $crate::concatenate!($axis, $($array),+) }; - ($axis:expr_2021, $( $array:expr_2021 ),+ ) => { + ($axis:expr, $( $array:expr ),+ ) => { $crate::concatenate($axis, &[ $($crate::ArrayView::from(&$array) ),* ]).unwrap() }; } diff --git a/src/zip/mod.rs b/src/zip/mod.rs index 3a2334bc6..f1c5a0ed3 100644 --- a/src/zip/mod.rs +++ b/src/zip/mod.rs @@ -27,7 +27,7 @@ pub use self::ndproducer::{IntoNdProducer, NdProducer, Offset}; /// Return if the expression is a break value. macro_rules! fold_while { - ($e:expr_2021) => { + ($e:expr) => { match $e { FoldWhile::Continue(x) => x, x => return x, diff --git a/src/zip/zipmacro.rs b/src/zip/zipmacro.rs index 696659a8a..0bbe956b3 100644 --- a/src/zip/zipmacro.rs +++ b/src/zip/zipmacro.rs @@ -98,28 +98,28 @@ macro_rules! azip { // Indexed with a single producer // we allow an optional trailing comma after the producers in each rule. - (@build $apply:ident (index $index:pat, $first_pat:pat in $first_prod:expr_2021 $(,)?) $body:expr_2021) => { + (@build $apply:ident (index $index:pat, $first_pat:pat in $first_prod:expr $(,)?) $body:expr) => { $crate::Zip::indexed($first_prod).$apply(|$index, $first_pat| $body) }; // Indexed with more than one producer - (@build $apply:ident (index $index:pat, $first_pat:pat in $first_prod:expr_2021, $($pat:pat in $prod:expr_2021),* $(,)?) $body:expr_2021) => { + (@build $apply:ident (index $index:pat, $first_pat:pat in $first_prod:expr, $($pat:pat in $prod:expr),* $(,)?) $body:expr) => { $crate::Zip::indexed($first_prod) $(.and($prod))* .$apply(|$index, $first_pat, $($pat),*| $body) }; // Unindexed with a single producer - (@build $apply:ident ($first_pat:pat in $first_prod:expr_2021 $(,)?) $body:expr_2021) => { + (@build $apply:ident ($first_pat:pat in $first_prod:expr $(,)?) $body:expr) => { $crate::Zip::from($first_prod).$apply(|$first_pat| $body) }; // Unindexed with more than one producer - (@build $apply:ident ($first_pat:pat in $first_prod:expr_2021, $($pat:pat in $prod:expr_2021),* $(,)?) $body:expr_2021) => { + (@build $apply:ident ($first_pat:pat in $first_prod:expr, $($pat:pat in $prod:expr),* $(,)?) $body:expr) => { $crate::Zip::from($first_prod) $(.and($prod))* .$apply(|$first_pat, $($pat),*| $body) }; // Unindexed with one or more producer, no loop body - (@build $apply:ident $first_prod:expr_2021 $(, $prod:expr_2021)* $(,)?) => { + (@build $apply:ident $first_prod:expr $(, $prod:expr)* $(,)?) => { $crate::Zip::from($first_prod) $(.and($prod))* }; diff --git a/tests/array.rs b/tests/array.rs index 6f3fa21d4..3d6fa6715 100644 --- a/tests/array.rs +++ b/tests/array.rs @@ -17,13 +17,13 @@ use num_complex::Complex; use std::convert::TryFrom; macro_rules! assert_panics { - ($body:expr_2021) => { + ($body:expr) => { if let Ok(v) = ::std::panic::catch_unwind(|| $body) { panic!("assertion failed: should_panic; \ non-panicking result: {:?}", v); } }; - ($body:expr_2021, $($arg:tt)*) => { + ($body:expr, $($arg:tt)*) => { if let Ok(_) = ::std::panic::catch_unwind(|| $body) { panic!($($arg)*); } @@ -412,7 +412,7 @@ fn test_slice_collapse_with_newaxis() fn test_multislice() { macro_rules! do_test { - ($arr:expr_2021, $($s:expr_2021),*) => { + ($arr:expr, $($s:expr),*) => { { let arr = $arr; let copy = arr.clone(); @@ -784,7 +784,7 @@ fn diag() fn merge_axes() { macro_rules! assert_merged { - ($arr:expr_2021, $slice:expr_2021, $take:expr_2021, $into:expr_2021) => { + ($arr:expr, $slice:expr, $take:expr, $into:expr) => { let mut v = $arr.slice($slice); let merged_len = v.len_of(Axis($take)) * v.len_of(Axis($into)); assert!(v.merge_axes(Axis($take), Axis($into))); @@ -793,7 +793,7 @@ fn merge_axes() }; } macro_rules! assert_not_merged { - ($arr:expr_2021, $slice:expr_2021, $take:expr_2021, $into:expr_2021) => { + ($arr:expr, $slice:expr, $take:expr, $into:expr) => { let mut v = $arr.slice($slice); let old_dim = v.raw_dim(); let old_strides = v.strides().to_owned(); @@ -1298,7 +1298,7 @@ fn owned_array_discontiguous_drop() } macro_rules! assert_matches { - ($value:expr_2021, $pat:pat) => { + ($value:expr, $pat:pat) => { match $value { $pat => {} ref err => panic!( diff --git a/tests/dimension.rs b/tests/dimension.rs index 6beeb6dd1..fe53d96b3 100644 --- a/tests/dimension.rs +++ b/tests/dimension.rs @@ -263,13 +263,13 @@ fn test_hash() hasher.finish() } macro_rules! test_hash_eq { - ($arr:expr_2021) => { + ($arr:expr) => { assert_eq!(calc_hash(&Dim($arr)), calc_hash(&Dim($arr))); assert_eq!(calc_hash(&Dim($arr)), calc_hash(&IxDyn(&$arr))); }; } macro_rules! test_hash_ne { - ($arr1:expr_2021, $arr2:expr_2021) => { + ($arr1:expr, $arr2:expr) => { assert_ne!(calc_hash(&Dim($arr1)), calc_hash(&Dim($arr2))); assert_ne!(calc_hash(&Dim($arr1)), calc_hash(&IxDyn(&$arr2))); assert_ne!(calc_hash(&IxDyn(&$arr1)), calc_hash(&Dim($arr2))); @@ -330,7 +330,7 @@ fn test_all_ndindex() { use ndarray::IntoDimension; macro_rules! ndindex { - ($($i:expr_2021),*) => { + ($($i:expr),*) => { for &rev in &[false, true] { // rev is for C / F order let size = $($i *)* 1; diff --git a/tests/iterators.rs b/tests/iterators.rs index d9e084b73..3e6e98210 100644 --- a/tests/iterators.rs +++ b/tests/iterators.rs @@ -8,13 +8,13 @@ use itertools::enumerate; use std::cell::Cell; macro_rules! assert_panics { - ($body:expr_2021) => { + ($body:expr) => { if let Ok(v) = ::std::panic::catch_unwind(|| $body) { panic!("assertion failed: should_panic; \ non-panicking result: {:?}", v); } }; - ($body:expr_2021, $($arg:tt)*) => { + ($body:expr, $($arg:tt)*) => { if let Ok(_) = ::std::panic::catch_unwind(|| $body) { panic!($($arg)*); } @@ -1073,7 +1073,9 @@ fn test_impl_iter_compiles() let _ = slice_iter_non_empty_indices; // ndarray case - fn array_iter_non_empty_indices<'s, 'a>(array: &'a Array<&'s str, Ix1>) -> impl Iterator + 'a + use<'a> + fn array_iter_non_empty_indices<'s, 'a>( + array: &'a Array<&'s str, Ix1>, + ) -> impl Iterator + 'a + use<'a> { array .iter() From bc1d762f24eb7cfa64bc2c7370907685a39ce017 Mon Sep 17 00:00:00 2001 From: Adam Kern Date: Mon, 26 May 2025 14:03:47 -0400 Subject: [PATCH 5/8] If-let is ok but switch to use<_> --- src/array_serde.rs | 5 +-- src/impl_methods.rs | 76 +++++++++++++++++++++++++-------------------- tests/iterators.rs | 4 +-- 3 files changed, 44 insertions(+), 41 deletions(-) diff --git a/src/array_serde.rs b/src/array_serde.rs index 6c167b777..304d9bc23 100644 --- a/src/array_serde.rs +++ b/src/array_serde.rs @@ -237,10 +237,7 @@ where } }; - match ArrayBase::from_shape_vec(dim, data) { - Ok(array) => Ok(array), - _ => Err(de::Error::custom("data and dimension must match in size")), - } + ArrayBase::from_shape_vec(dim, data).map_err(|_| de::Error::custom("data and dimension must match in size")) } fn visit_map(self, mut visitor: V) -> Result, V::Error> diff --git a/src/impl_methods.rs b/src/impl_methods.rs index eb41cae7a..16141327b 100644 --- a/src/impl_methods.rs +++ b/src/impl_methods.rs @@ -895,11 +895,13 @@ impl ArrayRef #[inline] pub unsafe fn uget(&self, index: I) -> &A where I: NdIndex - { unsafe { - arraytraits::debug_bounds_check(self, &index); - let off = index.index_unchecked(&self.strides); - &*self.ptr.as_ptr().offset(off) - }} + { + unsafe { + arraytraits::debug_bounds_check(self, &index); + let off = index.index_unchecked(&self.strides); + &*self.ptr.as_ptr().offset(off) + } + } /// Perform *unchecked* array indexing. /// @@ -918,12 +920,14 @@ impl ArrayRef #[inline] pub unsafe fn uget_mut(&mut self, index: I) -> &mut A where I: NdIndex - { unsafe { - // debug_assert!(self.data.is_unique()); - arraytraits::debug_bounds_check(self, &index); - let off = index.index_unchecked(&self.strides); - &mut *self.ptr.as_ptr().offset(off) - }} + { + unsafe { + // debug_assert!(self.data.is_unique()); + arraytraits::debug_bounds_check(self, &index); + let off = index.index_unchecked(&self.strides); + &mut *self.ptr.as_ptr().offset(off) + } + } /// Swap elements at indices `index1` and `index2`. /// @@ -964,14 +968,16 @@ impl ArrayRef /// for `Array` and `ArrayViewMut`, but not for `ArcArray` or `CowArray`.) pub unsafe fn uswap(&mut self, index1: I, index2: I) where I: NdIndex - { unsafe { - // debug_assert!(self.data.is_unique()); - arraytraits::debug_bounds_check(self, &index1); - arraytraits::debug_bounds_check(self, &index2); - let off1 = index1.index_unchecked(&self.strides); - let off2 = index2.index_unchecked(&self.strides); - std::ptr::swap(self.ptr.as_ptr().offset(off1), self.ptr.as_ptr().offset(off2)); - }} + { + unsafe { + // debug_assert!(self.data.is_unique()); + arraytraits::debug_bounds_check(self, &index1); + arraytraits::debug_bounds_check(self, &index2); + let off1 = index1.index_unchecked(&self.strides); + let off2 = index2.index_unchecked(&self.strides); + std::ptr::swap(self.ptr.as_ptr().offset(off1), self.ptr.as_ptr().offset(off2)); + } + } // `get` for zero-dimensional arrays // panics if dimension is not zero. otherwise an element is always present. @@ -1760,9 +1766,9 @@ where #[inline] pub(crate) unsafe fn raw_view_mut_unchecked(&mut self) -> RawArrayViewMut where S: DataOwned - { unsafe { - RawArrayViewMut::new(self.ptr, self.dim.clone(), self.strides.clone()) - }} + { + unsafe { RawArrayViewMut::new(self.ptr, self.dim.clone(), self.strides.clone()) } + } /// Return the array’s data as a slice, if it is contiguous and in standard order. /// Return `None` otherwise. @@ -2442,21 +2448,21 @@ impl ArrayRef self.view() .into_dimensionality::<>::Output>() .unwrap() - } else { match self.broadcast(shape.clone()) { Some(view1) => { + } else if let Some(view1) = self.broadcast(shape.clone()) { view1 - } _ => { + } else { return Err(from_kind(ErrorKind::IncompatibleShape)); - }}}; + }; let view2 = if shape.slice() == other.dim.slice() { other .view() .into_dimensionality::<>::Output>() .unwrap() - } else { match other.broadcast(shape) { Some(view2) => { + } else if let Some(view2) = other.broadcast(shape.clone()) { view2 - } _ => { + } else { return Err(from_kind(ErrorKind::IncompatibleShape)); - }}}; + }; Ok((view1, view2)) } } @@ -3350,12 +3356,14 @@ impl ArrayRef #[track_caller] #[inline] unsafe fn unlimited_transmute(data: A) -> B -{ unsafe { - // safe when sizes are equal and caller guarantees that representations are equal - assert_eq!(size_of::(), size_of::()); - let old_data = ManuallyDrop::new(data); - (&*old_data as *const A as *const B).read() -}} +{ + unsafe { + // safe when sizes are equal and caller guarantees that representations are equal + assert_eq!(size_of::(), size_of::()); + let old_data = ManuallyDrop::new(data); + (&*old_data as *const A as *const B).read() + } +} type DimMaxOf = >::Output; diff --git a/tests/iterators.rs b/tests/iterators.rs index 3e6e98210..60c8ecbf7 100644 --- a/tests/iterators.rs +++ b/tests/iterators.rs @@ -1073,9 +1073,7 @@ fn test_impl_iter_compiles() let _ = slice_iter_non_empty_indices; // ndarray case - fn array_iter_non_empty_indices<'s, 'a>( - array: &'a Array<&'s str, Ix1>, - ) -> impl Iterator + 'a + use<'a> + fn array_iter_non_empty_indices<'s, 'a>(array: &'a Array<&'s str, Ix1>) -> impl Iterator + use<'a> { array .iter() From e44173397c30305faec204b999be69ccc3e95a46 Mon Sep 17 00:00:00 2001 From: Adam Kern Date: Mon, 26 May 2025 14:10:59 -0400 Subject: [PATCH 6/8] Revert "If-let is ok but switch to use<_>" This reverts commit bc1d762f24eb7cfa64bc2c7370907685a39ce017. --- src/array_serde.rs | 5 ++- src/impl_methods.rs | 76 ++++++++++++++++++++------------------------- tests/iterators.rs | 4 ++- 3 files changed, 41 insertions(+), 44 deletions(-) diff --git a/src/array_serde.rs b/src/array_serde.rs index 304d9bc23..6c167b777 100644 --- a/src/array_serde.rs +++ b/src/array_serde.rs @@ -237,7 +237,10 @@ where } }; - ArrayBase::from_shape_vec(dim, data).map_err(|_| de::Error::custom("data and dimension must match in size")) + match ArrayBase::from_shape_vec(dim, data) { + Ok(array) => Ok(array), + _ => Err(de::Error::custom("data and dimension must match in size")), + } } fn visit_map(self, mut visitor: V) -> Result, V::Error> diff --git a/src/impl_methods.rs b/src/impl_methods.rs index 16141327b..eb41cae7a 100644 --- a/src/impl_methods.rs +++ b/src/impl_methods.rs @@ -895,13 +895,11 @@ impl ArrayRef #[inline] pub unsafe fn uget(&self, index: I) -> &A where I: NdIndex - { - unsafe { - arraytraits::debug_bounds_check(self, &index); - let off = index.index_unchecked(&self.strides); - &*self.ptr.as_ptr().offset(off) - } - } + { unsafe { + arraytraits::debug_bounds_check(self, &index); + let off = index.index_unchecked(&self.strides); + &*self.ptr.as_ptr().offset(off) + }} /// Perform *unchecked* array indexing. /// @@ -920,14 +918,12 @@ impl ArrayRef #[inline] pub unsafe fn uget_mut(&mut self, index: I) -> &mut A where I: NdIndex - { - unsafe { - // debug_assert!(self.data.is_unique()); - arraytraits::debug_bounds_check(self, &index); - let off = index.index_unchecked(&self.strides); - &mut *self.ptr.as_ptr().offset(off) - } - } + { unsafe { + // debug_assert!(self.data.is_unique()); + arraytraits::debug_bounds_check(self, &index); + let off = index.index_unchecked(&self.strides); + &mut *self.ptr.as_ptr().offset(off) + }} /// Swap elements at indices `index1` and `index2`. /// @@ -968,16 +964,14 @@ impl ArrayRef /// for `Array` and `ArrayViewMut`, but not for `ArcArray` or `CowArray`.) pub unsafe fn uswap(&mut self, index1: I, index2: I) where I: NdIndex - { - unsafe { - // debug_assert!(self.data.is_unique()); - arraytraits::debug_bounds_check(self, &index1); - arraytraits::debug_bounds_check(self, &index2); - let off1 = index1.index_unchecked(&self.strides); - let off2 = index2.index_unchecked(&self.strides); - std::ptr::swap(self.ptr.as_ptr().offset(off1), self.ptr.as_ptr().offset(off2)); - } - } + { unsafe { + // debug_assert!(self.data.is_unique()); + arraytraits::debug_bounds_check(self, &index1); + arraytraits::debug_bounds_check(self, &index2); + let off1 = index1.index_unchecked(&self.strides); + let off2 = index2.index_unchecked(&self.strides); + std::ptr::swap(self.ptr.as_ptr().offset(off1), self.ptr.as_ptr().offset(off2)); + }} // `get` for zero-dimensional arrays // panics if dimension is not zero. otherwise an element is always present. @@ -1766,9 +1760,9 @@ where #[inline] pub(crate) unsafe fn raw_view_mut_unchecked(&mut self) -> RawArrayViewMut where S: DataOwned - { - unsafe { RawArrayViewMut::new(self.ptr, self.dim.clone(), self.strides.clone()) } - } + { unsafe { + RawArrayViewMut::new(self.ptr, self.dim.clone(), self.strides.clone()) + }} /// Return the array’s data as a slice, if it is contiguous and in standard order. /// Return `None` otherwise. @@ -2448,21 +2442,21 @@ impl ArrayRef self.view() .into_dimensionality::<>::Output>() .unwrap() - } else if let Some(view1) = self.broadcast(shape.clone()) { + } else { match self.broadcast(shape.clone()) { Some(view1) => { view1 - } else { + } _ => { return Err(from_kind(ErrorKind::IncompatibleShape)); - }; + }}}; let view2 = if shape.slice() == other.dim.slice() { other .view() .into_dimensionality::<>::Output>() .unwrap() - } else if let Some(view2) = other.broadcast(shape.clone()) { + } else { match other.broadcast(shape) { Some(view2) => { view2 - } else { + } _ => { return Err(from_kind(ErrorKind::IncompatibleShape)); - }; + }}}; Ok((view1, view2)) } } @@ -3356,14 +3350,12 @@ impl ArrayRef #[track_caller] #[inline] unsafe fn unlimited_transmute(data: A) -> B -{ - unsafe { - // safe when sizes are equal and caller guarantees that representations are equal - assert_eq!(size_of::(), size_of::()); - let old_data = ManuallyDrop::new(data); - (&*old_data as *const A as *const B).read() - } -} +{ unsafe { + // safe when sizes are equal and caller guarantees that representations are equal + assert_eq!(size_of::(), size_of::()); + let old_data = ManuallyDrop::new(data); + (&*old_data as *const A as *const B).read() +}} type DimMaxOf = >::Output; diff --git a/tests/iterators.rs b/tests/iterators.rs index 60c8ecbf7..3e6e98210 100644 --- a/tests/iterators.rs +++ b/tests/iterators.rs @@ -1073,7 +1073,9 @@ fn test_impl_iter_compiles() let _ = slice_iter_non_empty_indices; // ndarray case - fn array_iter_non_empty_indices<'s, 'a>(array: &'a Array<&'s str, Ix1>) -> impl Iterator + use<'a> + fn array_iter_non_empty_indices<'s, 'a>( + array: &'a Array<&'s str, Ix1>, + ) -> impl Iterator + 'a + use<'a> { array .iter() From c7cff9656295453ab9335a7455610767d1e14d6d Mon Sep 17 00:00:00 2001 From: Adam Kern Date: Mon, 26 May 2025 14:11:08 -0400 Subject: [PATCH 7/8] Revert "No need for expr_2021" This reverts commit 8944edc8df9dc80bb047f0a05400e47accc25505. --- benches/bench1.rs | 2 +- src/array_approx.rs | 2 +- src/dimension/conversion.rs | 4 +-- src/dimension/dim.rs | 6 ++--- src/dimension/dimension_trait.rs | 6 ++--- src/dimension/macros.rs | 4 +-- src/dimension/ndindex.rs | 2 +- src/dimension/ops.rs | 6 ++--- src/dimension/remove_axis.rs | 2 +- src/dimension/reshape.rs | 4 +-- src/free_functions.rs | 16 +++++------ src/impl_constructors.rs | 46 ++++++++++++++------------------ src/impl_ops.rs | 10 +++---- src/indexes.rs | 2 +- src/iterators/macros.rs | 4 +-- src/iterators/mod.rs | 38 +++++++++++++------------- src/itertools.rs | 10 +++---- src/layout/mod.rs | 4 +-- src/macro_utils.rs | 4 +-- src/slice.rs | 22 +++++++-------- src/stacking.rs | 8 +++--- src/zip/mod.rs | 2 +- src/zip/zipmacro.rs | 10 +++---- tests/array.rs | 12 ++++----- tests/dimension.rs | 6 ++--- tests/iterators.rs | 8 +++--- 26 files changed, 115 insertions(+), 125 deletions(-) diff --git a/benches/bench1.rs b/benches/bench1.rs index c07b8e3d9..4ee86d7d8 100644 --- a/benches/bench1.rs +++ b/benches/bench1.rs @@ -795,7 +795,7 @@ fn bench_col_iter(bench: &mut test::Bencher) } macro_rules! mat_mul { - ($modname:ident, $ty:ident, $(($name:ident, $m:expr, $n:expr, $k:expr))+) => { + ($modname:ident, $ty:ident, $(($name:ident, $m:expr_2021, $n:expr_2021, $k:expr_2021))+) => { mod $modname { use test::{black_box, Bencher}; use ndarray::Array; diff --git a/src/array_approx.rs b/src/array_approx.rs index 958f6f6ba..d7aa575f0 100644 --- a/src/array_approx.rs +++ b/src/array_approx.rs @@ -29,7 +29,7 @@ mod approx_methods } macro_rules! impl_approx_traits { - ($approx:ident, $doc:expr) => { + ($approx:ident, $doc:expr_2021) => { mod $approx { use crate::imp_prelude::*; use crate::Zip; diff --git a/src/dimension/conversion.rs b/src/dimension/conversion.rs index 0cf2e1296..3982a58ae 100644 --- a/src/dimension/conversion.rs +++ b/src/dimension/conversion.rs @@ -106,13 +106,13 @@ macro_rules! tuple_type { } macro_rules! tuple_expr { - ([$self_:expr] $($index:tt)*) => ( + ([$self_:expr_2021] $($index:tt)*) => ( ( $($self_[$index], )* ) ); } macro_rules! array_expr { - ([$self_:expr] $($index:tt)*) => ( + ([$self_:expr_2021] $($index:tt)*) => ( [$($self_ . $index, )*] ); } diff --git a/src/dimension/dim.rs b/src/dimension/dim.rs index 96e433bb3..b001f8432 100644 --- a/src/dimension/dim.rs +++ b/src/dimension/dim.rs @@ -169,17 +169,17 @@ macro_rules! impl_scalar_op { } macro_rules! add { - ($x:expr, $y:expr) => { + ($x:expr_2021, $y:expr_2021) => { $x += $y; }; } macro_rules! sub { - ($x:expr, $y:expr) => { + ($x:expr_2021, $y:expr_2021) => { $x -= $y; }; } macro_rules! mul { - ($x:expr, $y:expr) => { + ($x:expr_2021, $y:expr_2021) => { $x *= $y; }; } diff --git a/src/dimension/dimension_trait.rs b/src/dimension/dimension_trait.rs index 3544a7f3c..43cdb9eff 100644 --- a/src/dimension/dimension_trait.rs +++ b/src/dimension/dimension_trait.rs @@ -402,7 +402,7 @@ pub trait Dimension: // Dimension impls macro_rules! impl_insert_axis_array( - ($n:expr) => ( + ($n:expr_2021) => ( #[inline] fn insert_axis(&self, axis: Axis) -> Self::Larger { debug_assert!(axis.index() <= $n); @@ -878,7 +878,7 @@ impl Dimension for Dim<[Ix; 3]> let mut stride = *self; let mut order = Ix3(0, 1, 2); macro_rules! swap { - ($stride:expr, $order:expr, $x:expr, $y:expr) => { + ($stride:expr_2021, $order:expr_2021, $x:expr_2021, $y:expr_2021) => { if ($stride[$x] as isize).abs() > ($stride[$y] as isize).abs() { $stride.swap($x, $y); $order.ixm().swap($x, $y); @@ -904,7 +904,7 @@ impl Dimension for Dim<[Ix; 3]> } macro_rules! large_dim { - ($n:expr, $name:ident, $pattern:ty, $larger:ty, { $($insert_axis:tt)* }) => ( + ($n:expr_2021, $name:ident, $pattern:ty, $larger:ty, { $($insert_axis:tt)* }) => ( impl Dimension for Dim<[Ix; $n]> { const NDIM: Option = Some($n); type Pattern = $pattern; diff --git a/src/dimension/macros.rs b/src/dimension/macros.rs index 9a576e347..67c64e629 100644 --- a/src/dimension/macros.rs +++ b/src/dimension/macros.rs @@ -1,12 +1,12 @@ /// Indexing macro for Dim<[usize; N]> this /// gets the index at `$i` in the underlying array macro_rules! get { - ($dim:expr, $i:expr) => { + ($dim:expr_2021, $i:expr_2021) => { (*$dim.ix())[$i] }; } macro_rules! getm { - ($dim:expr, $i:expr) => { + ($dim:expr_2021, $i:expr_2021) => { (*$dim.ixm())[$i] }; } diff --git a/src/dimension/ndindex.rs b/src/dimension/ndindex.rs index ca2a3ea69..dba3a23f0 100644 --- a/src/dimension/ndindex.rs +++ b/src/dimension/ndindex.rs @@ -160,7 +160,7 @@ unsafe impl NdIndex for Ix } macro_rules! ndindex_with_array { - ($([$n:expr, $ix_n:ident $($index:tt)*])+) => { + ($([$n:expr_2021, $ix_n:ident $($index:tt)*])+) => { $( // implement NdIndex for [Ix; 2] and so on unsafe impl NdIndex<$ix_n> for [Ix; $n] { diff --git a/src/dimension/ops.rs b/src/dimension/ops.rs index 1365ab488..817c17253 100644 --- a/src/dimension/ops.rs +++ b/src/dimension/ops.rs @@ -8,7 +8,7 @@ pub trait DimAdd } macro_rules! impl_dimadd_const_out_const { - ($lhs:expr, $rhs:expr) => { + ($lhs:expr_2021, $rhs:expr_2021) => { impl DimAdd> for Dim<[usize; $lhs]> { type Output = Dim<[usize; $lhs + $rhs]>; } @@ -16,12 +16,12 @@ macro_rules! impl_dimadd_const_out_const { } macro_rules! impl_dimadd_const_out_dyn { - ($lhs:expr, IxDyn) => { + ($lhs:expr_2021, IxDyn) => { impl DimAdd for Dim<[usize; $lhs]> { type Output = IxDyn; } }; - ($lhs:expr, $rhs:expr) => { + ($lhs:expr_2021, $rhs:expr_2021) => { impl DimAdd> for Dim<[usize; $lhs]> { type Output = IxDyn; } diff --git a/src/dimension/remove_axis.rs b/src/dimension/remove_axis.rs index cbb039fc5..10fed2bd1 100644 --- a/src/dimension/remove_axis.rs +++ b/src/dimension/remove_axis.rs @@ -43,7 +43,7 @@ impl RemoveAxis for Dim<[Ix; 2]> } macro_rules! impl_remove_axis_array( - ($($n:expr),*) => ( + ($($n:expr_2021),*) => ( $( impl RemoveAxis for Dim<[Ix; $n]> { diff --git a/src/dimension/reshape.rs b/src/dimension/reshape.rs index abcec4993..c209d3290 100644 --- a/src/dimension/reshape.rs +++ b/src/dimension/reshape.rs @@ -151,13 +151,13 @@ fn test_reshape() use crate::Dim; macro_rules! test_reshape { - (fail $order:ident from $from:expr, $stride:expr, to $to:expr) => { + (fail $order:ident from $from:expr_2021, $stride:expr_2021, to $to:expr_2021) => { let res = reshape_dim(&Dim($from), &Dim($stride), &Dim($to), Order::$order); println!("Reshape {:?} {:?} to {:?}, order {:?}\n => {:?}", $from, $stride, $to, Order::$order, res); let _res = res.expect_err("Expected failed reshape"); }; - (ok $order:ident from $from:expr, $stride:expr, to $to:expr, $to_stride:expr) => {{ + (ok $order:ident from $from:expr_2021, $stride:expr_2021, to $to:expr_2021, $to_stride:expr_2021) => {{ let res = reshape_dim(&Dim($from), &Dim($stride), &Dim($to), Order::$order); println!("Reshape {:?} {:?} to {:?}, order {:?}\n => {:?}", $from, $stride, $to, Order::$order, res); diff --git a/src/free_functions.rs b/src/free_functions.rs index a2ad6137c..4b0676dd2 100644 --- a/src/free_functions.rs +++ b/src/free_functions.rs @@ -63,25 +63,25 @@ use crate::{imp_prelude::*, LayoutRef}; /// ``` #[macro_export] macro_rules! array { - ($([$([$([$([$([$([$($x:expr),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ + ($([$([$([$([$([$([$($x:expr_2021),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ compile_error!("Arrays of 7 dimensions or more (or ndarrays of Rust arrays) cannot be constructed with the array! macro."); }}; - ($([$([$([$([$([$($x:expr),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ + ($([$([$([$([$([$($x:expr_2021),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ $crate::Array6::from(vec![$([$([$([$([$([$($x,)*],)*],)*],)*],)*],)*]) }}; - ($([$([$([$([$($x:expr),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ + ($([$([$([$([$($x:expr_2021),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ $crate::Array5::from(vec![$([$([$([$([$($x,)*],)*],)*],)*],)*]) }}; - ($([$([$([$($x:expr),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ + ($([$([$([$($x:expr_2021),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ $crate::Array4::from(vec![$([$([$([$($x,)*],)*],)*],)*]) }}; - ($([$([$($x:expr),* $(,)*]),+ $(,)*]),+ $(,)*) => {{ + ($([$([$($x:expr_2021),* $(,)*]),+ $(,)*]),+ $(,)*) => {{ $crate::Array3::from(vec![$([$([$($x,)*],)*],)*]) }}; - ($([$($x:expr),* $(,)*]),+ $(,)*) => {{ + ($([$($x:expr_2021),* $(,)*]),+ $(,)*) => {{ $crate::Array2::from(vec![$([$($x,)*],)*]) }}; - ($($x:expr),* $(,)*) => {{ + ($($x:expr_2021),* $(,)*) => {{ $crate::Array::from(vec![$($x,)*]) }}; } @@ -421,7 +421,7 @@ mod meshgrid_impl } macro_rules! meshgrid_body { - ($count:literal, $indexing:expr, $(($arr:expr, $idx:literal)),+) => { + ($count:literal, $indexing:expr_2021, $(($arr:expr_2021, $idx:literal)),+) => { { let shape = construct_shape([$($arr),+], $indexing); ( diff --git a/src/impl_constructors.rs b/src/impl_constructors.rs index 478006c75..781d74cc6 100644 --- a/src/impl_constructors.rs +++ b/src/impl_constructors.rs @@ -271,7 +271,7 @@ macro_rules! size_of_shape_checked_unwrap { #[cfg(debug_assertions)] macro_rules! size_of_shape_checked_unwrap { - ($dim:expr) => { + ($dim:expr_2021) => { match dimension::size_of_shape_checked($dim) { Ok(sz) => sz, Err(_) => panic!( @@ -504,25 +504,21 @@ where /// indices. pub unsafe fn from_shape_vec_unchecked(shape: Sh, v: Vec) -> Self where Sh: Into> - { - unsafe { - let shape = shape.into(); - let dim = shape.dim; - let strides = shape.strides.strides_for_dim(&dim); - Self::from_vec_dim_stride_unchecked(dim, strides, v) - } - } + { unsafe { + let shape = shape.into(); + let dim = shape.dim; + let strides = shape.strides.strides_for_dim(&dim); + Self::from_vec_dim_stride_unchecked(dim, strides, v) + }} unsafe fn from_vec_dim_stride_unchecked(dim: D, strides: D, mut v: Vec) -> Self - { - unsafe { - // debug check for issues that indicates wrong use of this constructor - debug_assert!(dimension::can_index_slice(&v, &dim, &strides, CanIndexCheckMode::OwnedMutable).is_ok()); + { unsafe { + // debug check for issues that indicates wrong use of this constructor + debug_assert!(dimension::can_index_slice(&v, &dim, &strides, CanIndexCheckMode::OwnedMutable).is_ok()); - let ptr = nonnull_from_vec_data(&mut v).add(offset_from_low_addr_ptr_to_logical_ptr(&dim, &strides)); - ArrayBase::from_data_ptr(DataOwned::new(v), ptr).with_strides_dim(strides, dim) - } - } + let ptr = nonnull_from_vec_data(&mut v).add(offset_from_low_addr_ptr_to_logical_ptr(&dim, &strides)); + ArrayBase::from_data_ptr(DataOwned::new(v), ptr).with_strides_dim(strides, dim) + }} /// Creates an array from an iterator, mapped by `map` and interpret it according to the /// provided shape and strides. @@ -535,15 +531,13 @@ where Sh: Into>, I: TrustedIterator + ExactSizeIterator, F: FnMut(I::Item) -> A, - { - unsafe { - let shape = shape.into(); - let dim = shape.dim; - let strides = shape.strides.strides_for_dim(&dim); - let v = to_vec_mapped(iter, map); - Self::from_vec_dim_stride_unchecked(dim, strides, v) - } - } + { unsafe { + let shape = shape.into(); + let dim = shape.dim; + let strides = shape.strides.strides_for_dim(&dim); + let v = to_vec_mapped(iter, map); + Self::from_vec_dim_stride_unchecked(dim, strides, v) + }} /// Create an array with uninitialized elements, shape `shape`. /// diff --git a/src/impl_ops.rs b/src/impl_ops.rs index 53f49cc43..01845f04e 100644 --- a/src/impl_ops.rs +++ b/src/impl_ops.rs @@ -51,7 +51,7 @@ impl ScalarOperand for Complex {} impl ScalarOperand for Complex {} macro_rules! impl_binary_op( - ($trt:ident, $operator:tt, $mth:ident, $iop:tt, $doc:expr) => ( + ($trt:ident, $operator:tt, $mth:ident, $iop:tt, $doc:expr_2021) => ( /// Perform elementwise #[doc=$doc] /// between `self` and `rhs`, @@ -337,10 +337,10 @@ impl<'a, A, D, B> $trt for &'a ArrayRef // Pick the expression $a for commutative and $b for ordered binop macro_rules! if_commutative { - (Commute { $a:expr } or { $b:expr }) => { + (Commute { $a:expr_2021 } or { $b:expr_2021 }) => { $a }; - (Ordered { $a:expr } or { $b:expr }) => { + (Ordered { $a:expr_2021 } or { $b:expr_2021 }) => { $b }; } @@ -348,7 +348,7 @@ macro_rules! if_commutative { macro_rules! impl_scalar_lhs_op { // $commutative flag. Reuse the self + scalar impl if we can. // We can do this safely since these are the primitive numeric types - ($scalar:ty, $commutative:ident, $operator:tt, $trt:ident, $mth:ident, $doc:expr) => ( + ($scalar:ty, $commutative:ident, $operator:tt, $trt:ident, $mth:ident, $doc:expr_2021) => ( // these have no doc -- they are not visible in rustdoc // Perform elementwise // between the scalar `self` and array `rhs`, @@ -595,7 +595,7 @@ mod assign_ops use crate::imp_prelude::*; macro_rules! impl_assign_op { - ($trt:ident, $method:ident, $doc:expr) => { + ($trt:ident, $method:ident, $doc:expr_2021) => { use std::ops::$trt; #[doc=$doc] diff --git a/src/indexes.rs b/src/indexes.rs index 0fa2b50fb..a561293cf 100644 --- a/src/indexes.rs +++ b/src/indexes.rs @@ -317,7 +317,7 @@ mod tests fn test_indices_iter_c_fold() { macro_rules! run_test { - ($dim:expr) => { + ($dim:expr_2021) => { for num_consume in 0..3 { let mut it = indices($dim).into_iter(); for _ in 0..num_consume { diff --git a/src/iterators/macros.rs b/src/iterators/macros.rs index 2d1796b3e..e170ea459 100644 --- a/src/iterators/macros.rs +++ b/src/iterators/macros.rs @@ -53,7 +53,7 @@ macro_rules! impl_ndproducer { )* unsafe fn item(&$self_:ident, $ptr:pat) { - $refexpr:expr + $refexpr:expr_2021 } }) => { impl<$($typarm)*> NdProducer for $fulltype { @@ -140,7 +140,7 @@ macro_rules! impl_iterator { type Item = $ity:ty; fn item(&mut $self_:ident, $elt:pat) { - $refexpr:expr + $refexpr:expr_2021 } }) => { expand_if!(@nonempty [$($cloneparm)*] diff --git a/src/iterators/mod.rs b/src/iterators/mod.rs index a1e4ee57f..2eddf3f62 100644 --- a/src/iterators/mod.rs +++ b/src/iterators/mod.rs @@ -267,7 +267,7 @@ where D: Dimension } macro_rules! either { - ($value:expr, $inner:pat => $result:expr) => { + ($value:expr_2021, $inner:pat => $result:expr_2021) => { match $value { ElementsRepr::Slice($inner) => $result, ElementsRepr::Counted($inner) => $result, @@ -276,7 +276,7 @@ macro_rules! either { } macro_rules! either_mut { - ($value:expr, $inner:ident => $result:expr) => { + ($value:expr_2021, $inner:ident => $result:expr_2021) => { match $value { ElementsRepr::Slice(ref mut $inner) => $result, ElementsRepr::Counted(ref mut $inner) => $result, @@ -888,18 +888,16 @@ impl AxisIterCore #[inline] unsafe fn offset(&self, index: usize) -> *mut A - { - unsafe { - debug_assert!( + { unsafe { + debug_assert!( index < self.end, "index={}, end={}, stride={}", index, self.end, self.stride ); - self.ptr.offset(index as isize * self.stride) - } - } + self.ptr.offset(index as isize * self.stride) + }} /// Splits the iterator at `index`, yielding two disjoint iterators. /// @@ -1223,14 +1221,14 @@ impl NdProducer for AxisIter<'_, A, D> } unsafe fn as_ref(&self, ptr: Self::Ptr) -> Self::Item - { - unsafe { ArrayView::new_(ptr, self.iter.inner_dim.clone(), self.iter.inner_strides.clone()) } - } + { unsafe { + ArrayView::new_(ptr, self.iter.inner_dim.clone(), self.iter.inner_strides.clone()) + }} unsafe fn uget_ptr(&self, i: &Self::Dim) -> Self::Ptr - { - unsafe { self.iter.offset(self.iter.index + i[0]) } - } + { unsafe { + self.iter.offset(self.iter.index + i[0]) + }} fn stride_of(&self, _axis: Axis) -> isize { @@ -1282,14 +1280,14 @@ impl NdProducer for AxisIterMut<'_, A, D> } unsafe fn as_ref(&self, ptr: Self::Ptr) -> Self::Item - { - unsafe { ArrayViewMut::new_(ptr, self.iter.inner_dim.clone(), self.iter.inner_strides.clone()) } - } + { unsafe { + ArrayViewMut::new_(ptr, self.iter.inner_dim.clone(), self.iter.inner_strides.clone()) + }} unsafe fn uget_ptr(&self, i: &Self::Dim) -> Self::Ptr - { - unsafe { self.iter.offset(self.iter.index + i[0]) } - } + { unsafe { + self.iter.offset(self.iter.index + i[0]) + }} fn stride_of(&self, _axis: Axis) -> isize { diff --git a/src/itertools.rs b/src/itertools.rs index d3562e687..5d073679a 100644 --- a/src/itertools.rs +++ b/src/itertools.rs @@ -94,28 +94,28 @@ macro_rules! izip { // @closure creates a tuple-flattening closure for .map() call. usage: // @closure partial_pattern => partial_tuple , rest , of , iterators // eg. izip!( @closure ((a, b), c) => (a, b, c) , dd , ee ) - ( @closure $p:pat => $tup:expr ) => { + ( @closure $p:pat => $tup:expr_2021 ) => { |$p| $tup }; // The "b" identifier is a different identifier on each recursion level thanks to hygiene. - ( @closure $p:pat => ( $($tup:tt)* ) , $_iter:expr $( , $tail:expr )* ) => { + ( @closure $p:pat => ( $($tup:tt)* ) , $_iter:expr_2021 $( , $tail:expr_2021 )* ) => { izip!(@closure ($p, b) => ( $($tup)*, b ) $( , $tail )*) }; // unary - ($first:expr $(,)*) => { + ($first:expr_2021 $(,)*) => { IntoIterator::into_iter($first) }; // binary - ($first:expr, $second:expr $(,)*) => { + ($first:expr_2021, $second:expr_2021 $(,)*) => { izip!($first) .zip($second) }; // n-ary where n > 2 - ( $first:expr $( , $rest:expr )* $(,)* ) => { + ( $first:expr_2021 $( , $rest:expr_2021 )* $(,)* ) => { izip!($first) $( .zip($rest) diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 36853848e..9ca19ca7c 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -93,7 +93,7 @@ mod tests type M0 = Array0; macro_rules! assert_layouts { - ($mat:expr, $($layout:ident),*) => {{ + ($mat:expr_2021, $($layout:ident),*) => {{ let layout = $mat.view().layout(); $( assert!(layout.is(Layout::$layout), @@ -105,7 +105,7 @@ mod tests } macro_rules! assert_not_layouts { - ($mat:expr, $($layout:ident),*) => {{ + ($mat:expr_2021, $($layout:ident),*) => {{ let layout = $mat.view().layout(); $( assert!(!layout.is(Layout::$layout), diff --git a/src/macro_utils.rs b/src/macro_utils.rs index 75360de37..eb816f1f3 100644 --- a/src/macro_utils.rs +++ b/src/macro_utils.rs @@ -38,7 +38,7 @@ macro_rules! clone_bounds { /// debug assertions are enabled). #[cfg(debug_assertions)] macro_rules! ndassert { - ($e:expr, $($t:tt)*) => { assert!($e, $($t)*) }; + ($e:expr_2021, $($t:tt)*) => { assert!($e, $($t)*) }; } #[cfg(not(debug_assertions))] @@ -60,7 +60,7 @@ macro_rules! expand_if { // Macro to insert more informative out of bounds message in debug builds #[cfg(debug_assertions)] macro_rules! debug_bounds_check { - ($self_:ident, $index:expr) => { + ($self_:ident, $index:expr_2021) => { if $index.index_checked(&$self_.dim, &$self_.strides).is_none() { panic!( "ndarray: index {:?} is out of bounds for array of shape {:?}", diff --git a/src/slice.rs b/src/slice.rs index e2ce1e727..ec3f5e09a 100644 --- a/src/slice.rs +++ b/src/slice.rs @@ -587,7 +587,7 @@ where } macro_rules! impl_tryfrom_array_for_sliceinfo { - ($len:expr) => { + ($len:expr_2021) => { impl TryFrom<[SliceInfoElem; $len]> for SliceInfo<[SliceInfoElem; $len], Din, Dout> where @@ -809,7 +809,7 @@ impl_slicenextdim!((), NewAxis, Ix0, Ix1); #[macro_export] macro_rules! s( // convert a..b;c into @convert(a..b, c), final item - (@parse $in_dim:expr, $out_dim:expr, [$($stack:tt)*] $r:expr;$s:expr) => { + (@parse $in_dim:expr_2021, $out_dim:expr_2021, [$($stack:tt)*] $r:expr_2021;$s:expr_2021) => { match $r { r => { let in_dim = $crate::SliceNextDim::next_in_dim(&r, $in_dim); @@ -823,7 +823,7 @@ macro_rules! s( } }; // convert a..b into @convert(a..b), final item - (@parse $in_dim:expr, $out_dim:expr, [$($stack:tt)*] $r:expr) => { + (@parse $in_dim:expr_2021, $out_dim:expr_2021, [$($stack:tt)*] $r:expr_2021) => { match $r { r => { let in_dim = $crate::SliceNextDim::next_in_dim(&r, $in_dim); @@ -837,15 +837,15 @@ macro_rules! s( } }; // convert a..b;c into @convert(a..b, c), final item, trailing comma - (@parse $in_dim:expr, $out_dim:expr, [$($stack:tt)*] $r:expr;$s:expr ,) => { + (@parse $in_dim:expr_2021, $out_dim:expr_2021, [$($stack:tt)*] $r:expr_2021;$s:expr_2021 ,) => { $crate::s![@parse $in_dim, $out_dim, [$($stack)*] $r;$s] }; // convert a..b into @convert(a..b), final item, trailing comma - (@parse $in_dim:expr, $out_dim:expr, [$($stack:tt)*] $r:expr ,) => { + (@parse $in_dim:expr_2021, $out_dim:expr_2021, [$($stack:tt)*] $r:expr_2021 ,) => { $crate::s![@parse $in_dim, $out_dim, [$($stack)*] $r] }; // convert a..b;c into @convert(a..b, c) - (@parse $in_dim:expr, $out_dim:expr, [$($stack:tt)*] $r:expr;$s:expr, $($t:tt)*) => { + (@parse $in_dim:expr_2021, $out_dim:expr_2021, [$($stack:tt)*] $r:expr_2021;$s:expr_2021, $($t:tt)*) => { match $r { r => { $crate::s![@parse @@ -858,7 +858,7 @@ macro_rules! s( } }; // convert a..b into @convert(a..b) - (@parse $in_dim:expr, $out_dim:expr, [$($stack:tt)*] $r:expr, $($t:tt)*) => { + (@parse $in_dim:expr_2021, $out_dim:expr_2021, [$($stack:tt)*] $r:expr_2021, $($t:tt)*) => { match $r { r => { $crate::s![@parse @@ -881,11 +881,11 @@ macro_rules! s( // Catch-all clause for syntax errors (@parse $($t:tt)*) => { compile_error!("Invalid syntax in s![] call.") }; // convert range/index/new-axis into SliceInfoElem - (@convert $r:expr) => { + (@convert $r:expr_2021) => { <$crate::SliceInfoElem as ::core::convert::From<_>>::from($r) }; // convert range/index/new-axis and step into SliceInfoElem - (@convert $r:expr, $s:expr) => { + (@convert $r:expr_2021, $s:expr_2021) => { <$crate::SliceInfoElem as ::core::convert::From<_>>::from( <$crate::Slice as ::core::convert::From<_>>::from($r).step_by($s as isize) ) @@ -989,10 +989,10 @@ macro_rules! impl_multislice_tuple { private_impl! {} } }; - (@intersects_self $shape:expr, ($head:expr,)) => { + (@intersects_self $shape:expr_2021, ($head:expr_2021,)) => { false }; - (@intersects_self $shape:expr, ($head:expr, $($tail:expr,)*)) => { + (@intersects_self $shape:expr_2021, ($head:expr_2021, $($tail:expr_2021,)*)) => { $(slices_intersect($shape, $head, $tail)) ||* || impl_multislice_tuple!(@intersects_self $shape, ($($tail,)*)) }; diff --git a/src/stacking.rs b/src/stacking.rs index 8737d6f60..7aa2bddc4 100644 --- a/src/stacking.rs +++ b/src/stacking.rs @@ -177,10 +177,10 @@ where /// ``` #[macro_export] macro_rules! stack { - ($axis:expr, $( $array:expr ),+ ,) => { + ($axis:expr_2021, $( $array:expr_2021 ),+ ,) => { $crate::stack!($axis, $($array),+) }; - ($axis:expr, $( $array:expr ),+ ) => { + ($axis:expr_2021, $( $array:expr_2021 ),+ ) => { $crate::stack($axis, &[ $($crate::ArrayView::from(&$array) ),* ]).unwrap() }; } @@ -217,10 +217,10 @@ macro_rules! stack { /// ``` #[macro_export] macro_rules! concatenate { - ($axis:expr, $( $array:expr ),+ ,) => { + ($axis:expr_2021, $( $array:expr_2021 ),+ ,) => { $crate::concatenate!($axis, $($array),+) }; - ($axis:expr, $( $array:expr ),+ ) => { + ($axis:expr_2021, $( $array:expr_2021 ),+ ) => { $crate::concatenate($axis, &[ $($crate::ArrayView::from(&$array) ),* ]).unwrap() }; } diff --git a/src/zip/mod.rs b/src/zip/mod.rs index f1c5a0ed3..3a2334bc6 100644 --- a/src/zip/mod.rs +++ b/src/zip/mod.rs @@ -27,7 +27,7 @@ pub use self::ndproducer::{IntoNdProducer, NdProducer, Offset}; /// Return if the expression is a break value. macro_rules! fold_while { - ($e:expr) => { + ($e:expr_2021) => { match $e { FoldWhile::Continue(x) => x, x => return x, diff --git a/src/zip/zipmacro.rs b/src/zip/zipmacro.rs index 0bbe956b3..696659a8a 100644 --- a/src/zip/zipmacro.rs +++ b/src/zip/zipmacro.rs @@ -98,28 +98,28 @@ macro_rules! azip { // Indexed with a single producer // we allow an optional trailing comma after the producers in each rule. - (@build $apply:ident (index $index:pat, $first_pat:pat in $first_prod:expr $(,)?) $body:expr) => { + (@build $apply:ident (index $index:pat, $first_pat:pat in $first_prod:expr_2021 $(,)?) $body:expr_2021) => { $crate::Zip::indexed($first_prod).$apply(|$index, $first_pat| $body) }; // Indexed with more than one producer - (@build $apply:ident (index $index:pat, $first_pat:pat in $first_prod:expr, $($pat:pat in $prod:expr),* $(,)?) $body:expr) => { + (@build $apply:ident (index $index:pat, $first_pat:pat in $first_prod:expr_2021, $($pat:pat in $prod:expr_2021),* $(,)?) $body:expr_2021) => { $crate::Zip::indexed($first_prod) $(.and($prod))* .$apply(|$index, $first_pat, $($pat),*| $body) }; // Unindexed with a single producer - (@build $apply:ident ($first_pat:pat in $first_prod:expr $(,)?) $body:expr) => { + (@build $apply:ident ($first_pat:pat in $first_prod:expr_2021 $(,)?) $body:expr_2021) => { $crate::Zip::from($first_prod).$apply(|$first_pat| $body) }; // Unindexed with more than one producer - (@build $apply:ident ($first_pat:pat in $first_prod:expr, $($pat:pat in $prod:expr),* $(,)?) $body:expr) => { + (@build $apply:ident ($first_pat:pat in $first_prod:expr_2021, $($pat:pat in $prod:expr_2021),* $(,)?) $body:expr_2021) => { $crate::Zip::from($first_prod) $(.and($prod))* .$apply(|$first_pat, $($pat),*| $body) }; // Unindexed with one or more producer, no loop body - (@build $apply:ident $first_prod:expr $(, $prod:expr)* $(,)?) => { + (@build $apply:ident $first_prod:expr_2021 $(, $prod:expr_2021)* $(,)?) => { $crate::Zip::from($first_prod) $(.and($prod))* }; diff --git a/tests/array.rs b/tests/array.rs index 3d6fa6715..6f3fa21d4 100644 --- a/tests/array.rs +++ b/tests/array.rs @@ -17,13 +17,13 @@ use num_complex::Complex; use std::convert::TryFrom; macro_rules! assert_panics { - ($body:expr) => { + ($body:expr_2021) => { if let Ok(v) = ::std::panic::catch_unwind(|| $body) { panic!("assertion failed: should_panic; \ non-panicking result: {:?}", v); } }; - ($body:expr, $($arg:tt)*) => { + ($body:expr_2021, $($arg:tt)*) => { if let Ok(_) = ::std::panic::catch_unwind(|| $body) { panic!($($arg)*); } @@ -412,7 +412,7 @@ fn test_slice_collapse_with_newaxis() fn test_multislice() { macro_rules! do_test { - ($arr:expr, $($s:expr),*) => { + ($arr:expr_2021, $($s:expr_2021),*) => { { let arr = $arr; let copy = arr.clone(); @@ -784,7 +784,7 @@ fn diag() fn merge_axes() { macro_rules! assert_merged { - ($arr:expr, $slice:expr, $take:expr, $into:expr) => { + ($arr:expr_2021, $slice:expr_2021, $take:expr_2021, $into:expr_2021) => { let mut v = $arr.slice($slice); let merged_len = v.len_of(Axis($take)) * v.len_of(Axis($into)); assert!(v.merge_axes(Axis($take), Axis($into))); @@ -793,7 +793,7 @@ fn merge_axes() }; } macro_rules! assert_not_merged { - ($arr:expr, $slice:expr, $take:expr, $into:expr) => { + ($arr:expr_2021, $slice:expr_2021, $take:expr_2021, $into:expr_2021) => { let mut v = $arr.slice($slice); let old_dim = v.raw_dim(); let old_strides = v.strides().to_owned(); @@ -1298,7 +1298,7 @@ fn owned_array_discontiguous_drop() } macro_rules! assert_matches { - ($value:expr, $pat:pat) => { + ($value:expr_2021, $pat:pat) => { match $value { $pat => {} ref err => panic!( diff --git a/tests/dimension.rs b/tests/dimension.rs index fe53d96b3..6beeb6dd1 100644 --- a/tests/dimension.rs +++ b/tests/dimension.rs @@ -263,13 +263,13 @@ fn test_hash() hasher.finish() } macro_rules! test_hash_eq { - ($arr:expr) => { + ($arr:expr_2021) => { assert_eq!(calc_hash(&Dim($arr)), calc_hash(&Dim($arr))); assert_eq!(calc_hash(&Dim($arr)), calc_hash(&IxDyn(&$arr))); }; } macro_rules! test_hash_ne { - ($arr1:expr, $arr2:expr) => { + ($arr1:expr_2021, $arr2:expr_2021) => { assert_ne!(calc_hash(&Dim($arr1)), calc_hash(&Dim($arr2))); assert_ne!(calc_hash(&Dim($arr1)), calc_hash(&IxDyn(&$arr2))); assert_ne!(calc_hash(&IxDyn(&$arr1)), calc_hash(&Dim($arr2))); @@ -330,7 +330,7 @@ fn test_all_ndindex() { use ndarray::IntoDimension; macro_rules! ndindex { - ($($i:expr),*) => { + ($($i:expr_2021),*) => { for &rev in &[false, true] { // rev is for C / F order let size = $($i *)* 1; diff --git a/tests/iterators.rs b/tests/iterators.rs index 3e6e98210..d9e084b73 100644 --- a/tests/iterators.rs +++ b/tests/iterators.rs @@ -8,13 +8,13 @@ use itertools::enumerate; use std::cell::Cell; macro_rules! assert_panics { - ($body:expr) => { + ($body:expr_2021) => { if let Ok(v) = ::std::panic::catch_unwind(|| $body) { panic!("assertion failed: should_panic; \ non-panicking result: {:?}", v); } }; - ($body:expr, $($arg:tt)*) => { + ($body:expr_2021, $($arg:tt)*) => { if let Ok(_) = ::std::panic::catch_unwind(|| $body) { panic!($($arg)*); } @@ -1073,9 +1073,7 @@ fn test_impl_iter_compiles() let _ = slice_iter_non_empty_indices; // ndarray case - fn array_iter_non_empty_indices<'s, 'a>( - array: &'a Array<&'s str, Ix1>, - ) -> impl Iterator + 'a + use<'a> + fn array_iter_non_empty_indices<'s, 'a>(array: &'a Array<&'s str, Ix1>) -> impl Iterator + 'a + use<'a> { array .iter() From 32ebf614fab12ebb14373e3833b88d9801c261a1 Mon Sep 17 00:00:00 2001 From: Adam Kern Date: Mon, 26 May 2025 14:11:55 -0400 Subject: [PATCH 8/8] Revert "Initial output of cargo fix --edition to 2024" This reverts commit 5dc894e49e0e688751c478dc9d6709a08bdd776b. --- benches/bench1.rs | 2 +- examples/bounds_check_elim.rs | 14 ++++++------ src/array_approx.rs | 2 +- src/array_serde.rs | 13 +++++++---- src/data_traits.rs | 32 +++++++++++++-------------- src/dimension/conversion.rs | 4 ++-- src/dimension/dim.rs | 6 +++--- src/dimension/dimension_trait.rs | 6 +++--- src/dimension/macros.rs | 4 ++-- src/dimension/ndindex.rs | 2 +- src/dimension/ops.rs | 6 +++--- src/dimension/remove_axis.rs | 2 +- src/dimension/reshape.rs | 4 ++-- src/extension/nonnull.rs | 4 ++-- src/free_functions.rs | 16 +++++++------- src/impl_constructors.rs | 14 ++++++------ src/impl_methods.rs | 32 +++++++++++++-------------- src/impl_ops.rs | 10 ++++----- src/impl_owned_array.rs | 4 ++-- src/impl_raw_views.rs | 36 +++++++++++++++---------------- src/impl_special_element_types.rs | 4 ++-- src/impl_views/constructors.rs | 24 ++++++++++----------- src/impl_views/conversions.rs | 4 ++-- src/impl_views/indexing.rs | 8 +++---- src/indexes.rs | 2 +- src/iterators/macros.rs | 12 +++++------ src/iterators/mod.rs | 24 ++++++++++----------- src/iterators/windows.rs | 8 +++---- src/itertools.rs | 10 ++++----- src/layout/mod.rs | 4 ++-- src/linalg/impl_linalg.rs | 4 ++-- src/macro_utils.rs | 4 ++-- src/slice.rs | 22 +++++++++---------- src/stacking.rs | 8 +++---- src/zip/mod.rs | 34 ++++++++++++++--------------- src/zip/ndproducer.rs | 32 +++++++++++++-------------- src/zip/zipmacro.rs | 10 ++++----- tests/array.rs | 12 +++++------ tests/dimension.rs | 6 +++--- tests/iterators.rs | 6 +++--- 40 files changed, 227 insertions(+), 224 deletions(-) diff --git a/benches/bench1.rs b/benches/bench1.rs index 4ee86d7d8..c07b8e3d9 100644 --- a/benches/bench1.rs +++ b/benches/bench1.rs @@ -795,7 +795,7 @@ fn bench_col_iter(bench: &mut test::Bencher) } macro_rules! mat_mul { - ($modname:ident, $ty:ident, $(($name:ident, $m:expr_2021, $n:expr_2021, $k:expr_2021))+) => { + ($modname:ident, $ty:ident, $(($name:ident, $m:expr, $n:expr, $k:expr))+) => { mod $modname { use test::{black_box, Bencher}; use ndarray::Array; diff --git a/examples/bounds_check_elim.rs b/examples/bounds_check_elim.rs index e2bb94017..f1a91cca0 100644 --- a/examples/bounds_check_elim.rs +++ b/examples/bounds_check_elim.rs @@ -34,7 +34,7 @@ pub fn testvec_as_slice(a: &Vec) -> f64 { } */ -#[unsafe(no_mangle)] +#[no_mangle] pub fn test1d_single(a: &Array1, i: usize) -> f64 { if i < a.len() { @@ -44,7 +44,7 @@ pub fn test1d_single(a: &Array1, i: usize) -> f64 } } -#[unsafe(no_mangle)] +#[no_mangle] pub fn test1d_single_mut(a: &mut Array1, i: usize) -> f64 { if i < a.len() { @@ -54,7 +54,7 @@ pub fn test1d_single_mut(a: &mut Array1, i: usize) -> f64 } } -#[unsafe(no_mangle)] +#[no_mangle] pub fn test1d_len_of(a: &Array1) -> f64 { let a = a; @@ -65,7 +65,7 @@ pub fn test1d_len_of(a: &Array1) -> f64 sum } -#[unsafe(no_mangle)] +#[no_mangle] pub fn test1d_range(a: &Array1) -> f64 { let mut sum = 0.; @@ -75,7 +75,7 @@ pub fn test1d_range(a: &Array1) -> f64 sum } -#[unsafe(no_mangle)] +#[no_mangle] pub fn test1d_while(a: &Array1) -> f64 { let mut sum = 0.; @@ -87,7 +87,7 @@ pub fn test1d_while(a: &Array1) -> f64 sum } -#[unsafe(no_mangle)] +#[no_mangle] pub fn test2d_ranges(a: &Array2) -> f64 { let mut sum = 0.; @@ -99,7 +99,7 @@ pub fn test2d_ranges(a: &Array2) -> f64 sum } -#[unsafe(no_mangle)] +#[no_mangle] pub fn test2d_whiles(a: &Array2) -> f64 { let mut sum = 0.; diff --git a/src/array_approx.rs b/src/array_approx.rs index d7aa575f0..958f6f6ba 100644 --- a/src/array_approx.rs +++ b/src/array_approx.rs @@ -29,7 +29,7 @@ mod approx_methods } macro_rules! impl_approx_traits { - ($approx:ident, $doc:expr_2021) => { + ($approx:ident, $doc:expr) => { mod $approx { use crate::imp_prelude::*; use crate::Zip; diff --git a/src/array_serde.rs b/src/array_serde.rs index 6c167b777..5d51a8011 100644 --- a/src/array_serde.rs +++ b/src/array_serde.rs @@ -237,9 +237,10 @@ where } }; - match ArrayBase::from_shape_vec(dim, data) { - Ok(array) => Ok(array), - _ => Err(de::Error::custom("data and dimension must match in size")), + if let Ok(array) = ArrayBase::from_shape_vec(dim, data) { + Ok(array) + } else { + Err(de::Error::custom("data and dimension must match in size")) } } @@ -281,6 +282,10 @@ where None => return Err(de::Error::missing_field("dim")), }; - ArrayBase::from_shape_vec(dim, data).map_err(|_| de::Error::custom("data and dimension must match in size")) + if let Ok(array) = ArrayBase::from_shape_vec(dim, data) { + Ok(array) + } else { + Err(de::Error::custom("data and dimension must match in size")) + } } } diff --git a/src/data_traits.rs b/src/data_traits.rs index 7e2ec8010..4266e4017 100644 --- a/src/data_traits.rs +++ b/src/data_traits.rs @@ -89,11 +89,11 @@ pub unsafe trait RawDataClone: RawData #[doc(hidden)] unsafe fn clone_from_with_ptr(&mut self, other: &Self, ptr: NonNull) -> NonNull - { unsafe { + { let (data, ptr) = other.clone_with_ptr(ptr); *self = data; ptr - }} + } } /// Array representation trait. @@ -388,7 +388,7 @@ unsafe impl RawDataClone for OwnedRepr where A: Clone { unsafe fn clone_with_ptr(&self, ptr: NonNull) -> (Self, NonNull) - { unsafe { + { let mut u = self.clone(); let mut new_ptr = u.as_nonnull_mut(); if size_of::() != 0 { @@ -396,10 +396,10 @@ where A: Clone new_ptr = new_ptr.offset(our_off); } (u, new_ptr) - }} + } unsafe fn clone_from_with_ptr(&mut self, other: &Self, ptr: NonNull) -> NonNull - { unsafe { + { let our_off = if size_of::() != 0 { (ptr.as_ptr() as isize - other.as_ptr() as isize) / mem::size_of::() as isize } else { @@ -407,7 +407,7 @@ where A: Clone }; self.clone_from(other); self.as_nonnull_mut().offset(our_off) - }} + } } unsafe impl RawData for ViewRepr<&A> @@ -622,7 +622,7 @@ unsafe impl RawDataClone for CowRepr<'_, A> where A: Clone { unsafe fn clone_with_ptr(&self, ptr: NonNull) -> (Self, NonNull) - { unsafe { + { match self { CowRepr::View(view) => { let (new_view, ptr) = view.clone_with_ptr(ptr); @@ -633,10 +633,10 @@ where A: Clone (CowRepr::Owned(new_data), ptr) } } - }} + } unsafe fn clone_from_with_ptr(&mut self, other: &Self, ptr: NonNull) -> NonNull - { unsafe { + { match (&mut *self, other) { (CowRepr::View(self_), CowRepr::View(other)) => self_.clone_from_with_ptr(other, ptr), (CowRepr::Owned(self_), CowRepr::Owned(other)) => self_.clone_from_with_ptr(other, ptr), @@ -651,7 +651,7 @@ where A: Clone ptr } } - }} + } } unsafe impl<'a, A> Data for CowRepr<'a, A> @@ -731,9 +731,9 @@ impl RawDataSubst for OwnedRepr type Output = OwnedRepr; unsafe fn data_subst(self) -> Self::Output - { unsafe { + { self.data_subst() - }} + } } impl RawDataSubst for OwnedArcRepr @@ -741,9 +741,9 @@ impl RawDataSubst for OwnedArcRepr type Output = OwnedArcRepr; unsafe fn data_subst(self) -> Self::Output - { unsafe { + { OwnedArcRepr(Arc::from_raw(Arc::into_raw(self.0) as *const OwnedRepr)) - }} + } } impl RawDataSubst for RawViewRepr<*const A> @@ -791,10 +791,10 @@ impl<'a, A: 'a, B: 'a> RawDataSubst for CowRepr<'a, A> type Output = CowRepr<'a, B>; unsafe fn data_subst(self) -> Self::Output - { unsafe { + { match self { CowRepr::View(view) => CowRepr::View(view.data_subst()), CowRepr::Owned(owned) => CowRepr::Owned(owned.data_subst()), } - }} + } } diff --git a/src/dimension/conversion.rs b/src/dimension/conversion.rs index 3982a58ae..0cf2e1296 100644 --- a/src/dimension/conversion.rs +++ b/src/dimension/conversion.rs @@ -106,13 +106,13 @@ macro_rules! tuple_type { } macro_rules! tuple_expr { - ([$self_:expr_2021] $($index:tt)*) => ( + ([$self_:expr] $($index:tt)*) => ( ( $($self_[$index], )* ) ); } macro_rules! array_expr { - ([$self_:expr_2021] $($index:tt)*) => ( + ([$self_:expr] $($index:tt)*) => ( [$($self_ . $index, )*] ); } diff --git a/src/dimension/dim.rs b/src/dimension/dim.rs index b001f8432..96e433bb3 100644 --- a/src/dimension/dim.rs +++ b/src/dimension/dim.rs @@ -169,17 +169,17 @@ macro_rules! impl_scalar_op { } macro_rules! add { - ($x:expr_2021, $y:expr_2021) => { + ($x:expr, $y:expr) => { $x += $y; }; } macro_rules! sub { - ($x:expr_2021, $y:expr_2021) => { + ($x:expr, $y:expr) => { $x -= $y; }; } macro_rules! mul { - ($x:expr_2021, $y:expr_2021) => { + ($x:expr, $y:expr) => { $x *= $y; }; } diff --git a/src/dimension/dimension_trait.rs b/src/dimension/dimension_trait.rs index 43cdb9eff..3544a7f3c 100644 --- a/src/dimension/dimension_trait.rs +++ b/src/dimension/dimension_trait.rs @@ -402,7 +402,7 @@ pub trait Dimension: // Dimension impls macro_rules! impl_insert_axis_array( - ($n:expr_2021) => ( + ($n:expr) => ( #[inline] fn insert_axis(&self, axis: Axis) -> Self::Larger { debug_assert!(axis.index() <= $n); @@ -878,7 +878,7 @@ impl Dimension for Dim<[Ix; 3]> let mut stride = *self; let mut order = Ix3(0, 1, 2); macro_rules! swap { - ($stride:expr_2021, $order:expr_2021, $x:expr_2021, $y:expr_2021) => { + ($stride:expr, $order:expr, $x:expr, $y:expr) => { if ($stride[$x] as isize).abs() > ($stride[$y] as isize).abs() { $stride.swap($x, $y); $order.ixm().swap($x, $y); @@ -904,7 +904,7 @@ impl Dimension for Dim<[Ix; 3]> } macro_rules! large_dim { - ($n:expr_2021, $name:ident, $pattern:ty, $larger:ty, { $($insert_axis:tt)* }) => ( + ($n:expr, $name:ident, $pattern:ty, $larger:ty, { $($insert_axis:tt)* }) => ( impl Dimension for Dim<[Ix; $n]> { const NDIM: Option = Some($n); type Pattern = $pattern; diff --git a/src/dimension/macros.rs b/src/dimension/macros.rs index 67c64e629..9a576e347 100644 --- a/src/dimension/macros.rs +++ b/src/dimension/macros.rs @@ -1,12 +1,12 @@ /// Indexing macro for Dim<[usize; N]> this /// gets the index at `$i` in the underlying array macro_rules! get { - ($dim:expr_2021, $i:expr_2021) => { + ($dim:expr, $i:expr) => { (*$dim.ix())[$i] }; } macro_rules! getm { - ($dim:expr_2021, $i:expr_2021) => { + ($dim:expr, $i:expr) => { (*$dim.ixm())[$i] }; } diff --git a/src/dimension/ndindex.rs b/src/dimension/ndindex.rs index dba3a23f0..ca2a3ea69 100644 --- a/src/dimension/ndindex.rs +++ b/src/dimension/ndindex.rs @@ -160,7 +160,7 @@ unsafe impl NdIndex for Ix } macro_rules! ndindex_with_array { - ($([$n:expr_2021, $ix_n:ident $($index:tt)*])+) => { + ($([$n:expr, $ix_n:ident $($index:tt)*])+) => { $( // implement NdIndex for [Ix; 2] and so on unsafe impl NdIndex<$ix_n> for [Ix; $n] { diff --git a/src/dimension/ops.rs b/src/dimension/ops.rs index 817c17253..1365ab488 100644 --- a/src/dimension/ops.rs +++ b/src/dimension/ops.rs @@ -8,7 +8,7 @@ pub trait DimAdd } macro_rules! impl_dimadd_const_out_const { - ($lhs:expr_2021, $rhs:expr_2021) => { + ($lhs:expr, $rhs:expr) => { impl DimAdd> for Dim<[usize; $lhs]> { type Output = Dim<[usize; $lhs + $rhs]>; } @@ -16,12 +16,12 @@ macro_rules! impl_dimadd_const_out_const { } macro_rules! impl_dimadd_const_out_dyn { - ($lhs:expr_2021, IxDyn) => { + ($lhs:expr, IxDyn) => { impl DimAdd for Dim<[usize; $lhs]> { type Output = IxDyn; } }; - ($lhs:expr_2021, $rhs:expr_2021) => { + ($lhs:expr, $rhs:expr) => { impl DimAdd> for Dim<[usize; $lhs]> { type Output = IxDyn; } diff --git a/src/dimension/remove_axis.rs b/src/dimension/remove_axis.rs index 10fed2bd1..cbb039fc5 100644 --- a/src/dimension/remove_axis.rs +++ b/src/dimension/remove_axis.rs @@ -43,7 +43,7 @@ impl RemoveAxis for Dim<[Ix; 2]> } macro_rules! impl_remove_axis_array( - ($($n:expr_2021),*) => ( + ($($n:expr),*) => ( $( impl RemoveAxis for Dim<[Ix; $n]> { diff --git a/src/dimension/reshape.rs b/src/dimension/reshape.rs index c209d3290..abcec4993 100644 --- a/src/dimension/reshape.rs +++ b/src/dimension/reshape.rs @@ -151,13 +151,13 @@ fn test_reshape() use crate::Dim; macro_rules! test_reshape { - (fail $order:ident from $from:expr_2021, $stride:expr_2021, to $to:expr_2021) => { + (fail $order:ident from $from:expr, $stride:expr, to $to:expr) => { let res = reshape_dim(&Dim($from), &Dim($stride), &Dim($to), Order::$order); println!("Reshape {:?} {:?} to {:?}, order {:?}\n => {:?}", $from, $stride, $to, Order::$order, res); let _res = res.expect_err("Expected failed reshape"); }; - (ok $order:ident from $from:expr_2021, $stride:expr_2021, to $to:expr_2021, $to_stride:expr_2021) => {{ + (ok $order:ident from $from:expr, $stride:expr, to $to:expr, $to_stride:expr) => {{ let res = reshape_dim(&Dim($from), &Dim($stride), &Dim($to), Order::$order); println!("Reshape {:?} {:?} to {:?}, order {:?}\n => {:?}", $from, $stride, $to, Order::$order, res); diff --git a/src/extension/nonnull.rs b/src/extension/nonnull.rs index f3049cbc1..08f80927e 100644 --- a/src/extension/nonnull.rs +++ b/src/extension/nonnull.rs @@ -16,7 +16,7 @@ pub(crate) fn nonnull_from_vec_data(v: &mut Vec) -> NonNull /// but treat this as an unconditional conversion. #[inline] pub(crate) unsafe fn nonnull_debug_checked_from_ptr(ptr: *mut T) -> NonNull -{ unsafe { +{ debug_assert!(!ptr.is_null()); NonNull::new_unchecked(ptr) -}} +} diff --git a/src/free_functions.rs b/src/free_functions.rs index 4b0676dd2..a2ad6137c 100644 --- a/src/free_functions.rs +++ b/src/free_functions.rs @@ -63,25 +63,25 @@ use crate::{imp_prelude::*, LayoutRef}; /// ``` #[macro_export] macro_rules! array { - ($([$([$([$([$([$([$($x:expr_2021),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ + ($([$([$([$([$([$([$($x:expr),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ compile_error!("Arrays of 7 dimensions or more (or ndarrays of Rust arrays) cannot be constructed with the array! macro."); }}; - ($([$([$([$([$([$($x:expr_2021),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ + ($([$([$([$([$([$($x:expr),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ $crate::Array6::from(vec![$([$([$([$([$([$($x,)*],)*],)*],)*],)*],)*]) }}; - ($([$([$([$([$($x:expr_2021),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ + ($([$([$([$([$($x:expr),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ $crate::Array5::from(vec![$([$([$([$([$($x,)*],)*],)*],)*],)*]) }}; - ($([$([$([$($x:expr_2021),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ + ($([$([$([$($x:expr),* $(,)*]),+ $(,)*]),+ $(,)*]),+ $(,)*) => {{ $crate::Array4::from(vec![$([$([$([$($x,)*],)*],)*],)*]) }}; - ($([$([$($x:expr_2021),* $(,)*]),+ $(,)*]),+ $(,)*) => {{ + ($([$([$($x:expr),* $(,)*]),+ $(,)*]),+ $(,)*) => {{ $crate::Array3::from(vec![$([$([$($x,)*],)*],)*]) }}; - ($([$($x:expr_2021),* $(,)*]),+ $(,)*) => {{ + ($([$($x:expr),* $(,)*]),+ $(,)*) => {{ $crate::Array2::from(vec![$([$($x,)*],)*]) }}; - ($($x:expr_2021),* $(,)*) => {{ + ($($x:expr),* $(,)*) => {{ $crate::Array::from(vec![$($x,)*]) }}; } @@ -421,7 +421,7 @@ mod meshgrid_impl } macro_rules! meshgrid_body { - ($count:literal, $indexing:expr_2021, $(($arr:expr_2021, $idx:literal)),+) => { + ($count:literal, $indexing:expr, $(($arr:expr, $idx:literal)),+) => { { let shape = construct_shape([$($arr),+], $indexing); ( diff --git a/src/impl_constructors.rs b/src/impl_constructors.rs index 781d74cc6..c1e5b1b8b 100644 --- a/src/impl_constructors.rs +++ b/src/impl_constructors.rs @@ -271,7 +271,7 @@ macro_rules! size_of_shape_checked_unwrap { #[cfg(debug_assertions)] macro_rules! size_of_shape_checked_unwrap { - ($dim:expr_2021) => { + ($dim:expr) => { match dimension::size_of_shape_checked($dim) { Ok(sz) => sz, Err(_) => panic!( @@ -504,21 +504,21 @@ where /// indices. pub unsafe fn from_shape_vec_unchecked(shape: Sh, v: Vec) -> Self where Sh: Into> - { unsafe { + { let shape = shape.into(); let dim = shape.dim; let strides = shape.strides.strides_for_dim(&dim); Self::from_vec_dim_stride_unchecked(dim, strides, v) - }} + } unsafe fn from_vec_dim_stride_unchecked(dim: D, strides: D, mut v: Vec) -> Self - { unsafe { + { // debug check for issues that indicates wrong use of this constructor debug_assert!(dimension::can_index_slice(&v, &dim, &strides, CanIndexCheckMode::OwnedMutable).is_ok()); let ptr = nonnull_from_vec_data(&mut v).add(offset_from_low_addr_ptr_to_logical_ptr(&dim, &strides)); ArrayBase::from_data_ptr(DataOwned::new(v), ptr).with_strides_dim(strides, dim) - }} + } /// Creates an array from an iterator, mapped by `map` and interpret it according to the /// provided shape and strides. @@ -531,13 +531,13 @@ where Sh: Into>, I: TrustedIterator + ExactSizeIterator, F: FnMut(I::Item) -> A, - { unsafe { + { let shape = shape.into(); let dim = shape.dim; let strides = shape.strides.strides_for_dim(&dim); let v = to_vec_mapped(iter, map); Self::from_vec_dim_stride_unchecked(dim, strides, v) - }} + } /// Create an array with uninitialized elements, shape `shape`. /// diff --git a/src/impl_methods.rs b/src/impl_methods.rs index eb41cae7a..7291f07cb 100644 --- a/src/impl_methods.rs +++ b/src/impl_methods.rs @@ -895,11 +895,11 @@ impl ArrayRef #[inline] pub unsafe fn uget(&self, index: I) -> &A where I: NdIndex - { unsafe { + { arraytraits::debug_bounds_check(self, &index); let off = index.index_unchecked(&self.strides); &*self.ptr.as_ptr().offset(off) - }} + } /// Perform *unchecked* array indexing. /// @@ -918,12 +918,12 @@ impl ArrayRef #[inline] pub unsafe fn uget_mut(&mut self, index: I) -> &mut A where I: NdIndex - { unsafe { + { // debug_assert!(self.data.is_unique()); arraytraits::debug_bounds_check(self, &index); let off = index.index_unchecked(&self.strides); &mut *self.ptr.as_ptr().offset(off) - }} + } /// Swap elements at indices `index1` and `index2`. /// @@ -964,14 +964,14 @@ impl ArrayRef /// for `Array` and `ArrayViewMut`, but not for `ArcArray` or `CowArray`.) pub unsafe fn uswap(&mut self, index1: I, index2: I) where I: NdIndex - { unsafe { + { // debug_assert!(self.data.is_unique()); arraytraits::debug_bounds_check(self, &index1); arraytraits::debug_bounds_check(self, &index2); let off1 = index1.index_unchecked(&self.strides); let off2 = index2.index_unchecked(&self.strides); std::ptr::swap(self.ptr.as_ptr().offset(off1), self.ptr.as_ptr().offset(off2)); - }} + } // `get` for zero-dimensional arrays // panics if dimension is not zero. otherwise an element is always present. @@ -1760,9 +1760,9 @@ where #[inline] pub(crate) unsafe fn raw_view_mut_unchecked(&mut self) -> RawArrayViewMut where S: DataOwned - { unsafe { + { RawArrayViewMut::new(self.ptr, self.dim.clone(), self.strides.clone()) - }} + } /// Return the array’s data as a slice, if it is contiguous and in standard order. /// Return `None` otherwise. @@ -2442,21 +2442,21 @@ impl ArrayRef self.view() .into_dimensionality::<>::Output>() .unwrap() - } else { match self.broadcast(shape.clone()) { Some(view1) => { + } else if let Some(view1) = self.broadcast(shape.clone()) { view1 - } _ => { + } else { return Err(from_kind(ErrorKind::IncompatibleShape)); - }}}; + }; let view2 = if shape.slice() == other.dim.slice() { other .view() .into_dimensionality::<>::Output>() .unwrap() - } else { match other.broadcast(shape) { Some(view2) => { + } else if let Some(view2) = other.broadcast(shape) { view2 - } _ => { + } else { return Err(from_kind(ErrorKind::IncompatibleShape)); - }}}; + }; Ok((view1, view2)) } } @@ -3350,12 +3350,12 @@ impl ArrayRef #[track_caller] #[inline] unsafe fn unlimited_transmute(data: A) -> B -{ unsafe { +{ // safe when sizes are equal and caller guarantees that representations are equal assert_eq!(size_of::(), size_of::()); let old_data = ManuallyDrop::new(data); (&*old_data as *const A as *const B).read() -}} +} type DimMaxOf = >::Output; diff --git a/src/impl_ops.rs b/src/impl_ops.rs index 01845f04e..53f49cc43 100644 --- a/src/impl_ops.rs +++ b/src/impl_ops.rs @@ -51,7 +51,7 @@ impl ScalarOperand for Complex {} impl ScalarOperand for Complex {} macro_rules! impl_binary_op( - ($trt:ident, $operator:tt, $mth:ident, $iop:tt, $doc:expr_2021) => ( + ($trt:ident, $operator:tt, $mth:ident, $iop:tt, $doc:expr) => ( /// Perform elementwise #[doc=$doc] /// between `self` and `rhs`, @@ -337,10 +337,10 @@ impl<'a, A, D, B> $trt for &'a ArrayRef // Pick the expression $a for commutative and $b for ordered binop macro_rules! if_commutative { - (Commute { $a:expr_2021 } or { $b:expr_2021 }) => { + (Commute { $a:expr } or { $b:expr }) => { $a }; - (Ordered { $a:expr_2021 } or { $b:expr_2021 }) => { + (Ordered { $a:expr } or { $b:expr }) => { $b }; } @@ -348,7 +348,7 @@ macro_rules! if_commutative { macro_rules! impl_scalar_lhs_op { // $commutative flag. Reuse the self + scalar impl if we can. // We can do this safely since these are the primitive numeric types - ($scalar:ty, $commutative:ident, $operator:tt, $trt:ident, $mth:ident, $doc:expr_2021) => ( + ($scalar:ty, $commutative:ident, $operator:tt, $trt:ident, $mth:ident, $doc:expr) => ( // these have no doc -- they are not visible in rustdoc // Perform elementwise // between the scalar `self` and array `rhs`, @@ -595,7 +595,7 @@ mod assign_ops use crate::imp_prelude::*; macro_rules! impl_assign_op { - ($trt:ident, $method:ident, $doc:expr_2021) => { + ($trt:ident, $method:ident, $doc:expr) => { use std::ops::$trt; #[doc=$doc] diff --git a/src/impl_owned_array.rs b/src/impl_owned_array.rs index 3bfaae0e6..023e9ebb4 100644 --- a/src/impl_owned_array.rs +++ b/src/impl_owned_array.rs @@ -870,7 +870,7 @@ where D: Dimension pub(crate) unsafe fn drop_unreachable_raw( mut self_: RawArrayViewMut, data_ptr: NonNull, data_len: usize, ) where D: Dimension -{ unsafe { +{ let self_len = self_.len(); for i in 0..self_.ndim() { @@ -935,7 +935,7 @@ pub(crate) unsafe fn drop_unreachable_raw( assert_eq!(data_len, dropped_elements + self_len, "Internal error: inconsistency in move_into"); -}} +} /// Sort axes to standard order, i.e Axis(0) has biggest stride and Axis(n - 1) least stride /// diff --git a/src/impl_raw_views.rs b/src/impl_raw_views.rs index a51678761..5bb2a0e42 100644 --- a/src/impl_raw_views.rs +++ b/src/impl_raw_views.rs @@ -17,15 +17,15 @@ where D: Dimension /// meet all of the invariants of the `ArrayBase` type. #[inline] pub(crate) unsafe fn new(ptr: NonNull, dim: D, strides: D) -> Self - { unsafe { + { RawArrayView::from_data_ptr(RawViewRepr::new(), ptr).with_strides_dim(strides, dim) - }} + } #[inline] unsafe fn new_(ptr: *const A, dim: D, strides: D) -> Self - { unsafe { + { Self::new(nonnull_debug_checked_from_ptr(ptr as *mut A), dim, strides) - }} + } /// Create an `RawArrayView` from shape information and a raw pointer /// to the elements. @@ -70,7 +70,7 @@ where D: Dimension #[inline] pub unsafe fn from_shape_ptr(shape: Sh, ptr: *const A) -> Self where Sh: Into> - { unsafe { + { let shape = shape.into(); let dim = shape.dim; if cfg!(debug_assertions) { @@ -84,7 +84,7 @@ where D: Dimension } let strides = shape.strides.strides_for_dim(&dim); RawArrayView::new_(ptr, dim, strides) - }} + } /// Converts to a read-only view of the array. /// @@ -96,13 +96,13 @@ where D: Dimension /// correct lifetime. #[inline] pub unsafe fn deref_into_view<'a>(self) -> ArrayView<'a, A, D> - { unsafe { + { debug_assert!( is_aligned(self.layout.ptr.as_ptr()), "The pointer must be aligned." ); ArrayView::new(self.layout.ptr, self.layout.dim, self.layout.strides) - }} + } /// Split the array view along `axis` and return one array pointer strictly /// before the split and one array pointer after the split. @@ -233,15 +233,15 @@ where D: Dimension /// meet all of the invariants of the `ArrayBase` type. #[inline] pub(crate) unsafe fn new(ptr: NonNull, dim: D, strides: D) -> Self - { unsafe { + { RawArrayViewMut::from_data_ptr(RawViewRepr::new(), ptr).with_strides_dim(strides, dim) - }} + } #[inline] unsafe fn new_(ptr: *mut A, dim: D, strides: D) -> Self - { unsafe { + { Self::new(nonnull_debug_checked_from_ptr(ptr), dim, strides) - }} + } /// Create an `RawArrayViewMut` from shape information and a raw /// pointer to the elements. @@ -286,7 +286,7 @@ where D: Dimension #[inline] pub unsafe fn from_shape_ptr(shape: Sh, ptr: *mut A) -> Self where Sh: Into> - { unsafe { + { let shape = shape.into(); let dim = shape.dim; if cfg!(debug_assertions) { @@ -302,7 +302,7 @@ where D: Dimension } let strides = shape.strides.strides_for_dim(&dim); RawArrayViewMut::new_(ptr, dim, strides) - }} + } /// Converts to a non-mutable `RawArrayView`. #[inline] @@ -321,13 +321,13 @@ where D: Dimension /// correct lifetime. #[inline] pub unsafe fn deref_into_view<'a>(self) -> ArrayView<'a, A, D> - { unsafe { + { debug_assert!( is_aligned(self.layout.ptr.as_ptr()), "The pointer must be aligned." ); ArrayView::new(self.layout.ptr, self.layout.dim, self.layout.strides) - }} + } /// Converts to a mutable view of the array. /// @@ -339,13 +339,13 @@ where D: Dimension /// correct lifetime. #[inline] pub unsafe fn deref_into_view_mut<'a>(self) -> ArrayViewMut<'a, A, D> - { unsafe { + { debug_assert!( is_aligned(self.layout.ptr.as_ptr()), "The pointer must be aligned." ); ArrayViewMut::new(self.layout.ptr, self.layout.dim, self.layout.strides) - }} + } /// Split the array view along `axis` and return one array pointer strictly /// before the split and one array pointer after the split. diff --git a/src/impl_special_element_types.rs b/src/impl_special_element_types.rs index 3193888aa..42b524bc2 100644 --- a/src/impl_special_element_types.rs +++ b/src/impl_special_element_types.rs @@ -33,7 +33,7 @@ where /// array's storage; it is for example possible to slice these in place, but that must /// only be done after all elements have been initialized. pub unsafe fn assume_init(self) -> ArrayBase<>::Output, D> - { unsafe { + { let ArrayBase { data, layout: LayoutRef { ptr, dim, strides }, @@ -43,5 +43,5 @@ where let data = S::data_subst(data); let ptr = ptr.cast::(); ArrayBase::from_data_ptr(data, ptr).with_strides_dim(strides, dim) - }} + } } diff --git a/src/impl_views/constructors.rs b/src/impl_views/constructors.rs index b14847488..29b7c13d7 100644 --- a/src/impl_views/constructors.rs +++ b/src/impl_views/constructors.rs @@ -113,9 +113,9 @@ where D: Dimension #[inline] pub unsafe fn from_shape_ptr(shape: Sh, ptr: *const A) -> Self where Sh: Into> - { unsafe { + { RawArrayView::from_shape_ptr(shape, ptr).deref_into_view() - }} + } } /// Methods for read-write array views. @@ -216,9 +216,9 @@ where D: Dimension #[inline] pub unsafe fn from_shape_ptr(shape: Sh, ptr: *mut A) -> Self where Sh: Into> - { unsafe { + { RawArrayViewMut::from_shape_ptr(shape, ptr).deref_into_view_mut() - }} + } /// Convert the view into an `ArrayViewMut<'b, A, D>` where `'b` is a lifetime /// outlived by `'a'`. @@ -238,20 +238,20 @@ where D: Dimension /// Unsafe because: `ptr` must be valid for the given dimension and strides. #[inline(always)] pub(crate) unsafe fn new(ptr: NonNull, dim: D, strides: D) -> Self - { unsafe { + { if cfg!(debug_assertions) { assert!(is_aligned(ptr.as_ptr()), "The pointer must be aligned."); dimension::max_abs_offset_check_overflow::(&dim, &strides).unwrap(); } ArrayView::from_data_ptr(ViewRepr::new(), ptr).with_strides_dim(strides, dim) - }} + } /// Unsafe because: `ptr` must be valid for the given dimension and strides. #[inline] pub(crate) unsafe fn new_(ptr: *const A, dim: D, strides: D) -> Self - { unsafe { + { Self::new(nonnull_debug_checked_from_ptr(ptr as *mut A), dim, strides) - }} + } } impl ArrayViewMut<'_, A, D> @@ -262,20 +262,20 @@ where D: Dimension /// Unsafe because: `ptr` must be valid for the given dimension and strides. #[inline(always)] pub(crate) unsafe fn new(ptr: NonNull, dim: D, strides: D) -> Self - { unsafe { + { if cfg!(debug_assertions) { assert!(is_aligned(ptr.as_ptr()), "The pointer must be aligned."); dimension::max_abs_offset_check_overflow::(&dim, &strides).unwrap(); } ArrayViewMut::from_data_ptr(ViewRepr::new(), ptr).with_strides_dim(strides, dim) - }} + } /// Create a new `ArrayView` /// /// Unsafe because: `ptr` must be valid for the given dimension and strides. #[inline(always)] pub(crate) unsafe fn new_(ptr: *mut A, dim: D, strides: D) -> Self - { unsafe { + { Self::new(nonnull_debug_checked_from_ptr(ptr), dim, strides) - }} + } } diff --git a/src/impl_views/conversions.rs b/src/impl_views/conversions.rs index 78f4f1ffe..5bc5f9ad6 100644 --- a/src/impl_views/conversions.rs +++ b/src/impl_views/conversions.rs @@ -181,7 +181,7 @@ where D: Dimension /// original array that we borrow from in an inconsistent state. This is not allowed /// when using the resulting array view. pub(crate) unsafe fn into_maybe_uninit(self) -> ArrayViewMut<'a, MaybeUninit, D> - { unsafe { + { // Safe because: A and MaybeUninit have the same representation; // and we can go from initialized to (maybe) not unconditionally in terms of // representation. However, the user must be careful to not write uninit elements @@ -189,7 +189,7 @@ where D: Dimension self.into_raw_view_mut() .cast::>() .deref_into_view_mut() - }} + } } /// Private raw array view methods diff --git a/src/impl_views/indexing.rs b/src/impl_views/indexing.rs index 52c2b3915..2879e7416 100644 --- a/src/impl_views/indexing.rs +++ b/src/impl_views/indexing.rs @@ -143,10 +143,10 @@ where /// /// **Note:** only unchecked for non-debug builds of ndarray. unsafe fn uget(self, index: I) -> &'a A - { unsafe { + { debug_bounds_check!(self, index); &*self.as_ptr().offset(index.index_unchecked(&self.strides)) - }} + } } impl<'a, I, A, D> IndexLonger for ArrayViewMut<'a, A, D> @@ -209,10 +209,10 @@ where /// /// **Note:** only unchecked for non-debug builds of ndarray. unsafe fn uget(mut self, index: I) -> &'a mut A - { unsafe { + { debug_bounds_check!(self, index); &mut *self .as_mut_ptr() .offset(index.index_unchecked(&self.strides)) - }} + } } diff --git a/src/indexes.rs b/src/indexes.rs index a561293cf..0fa2b50fb 100644 --- a/src/indexes.rs +++ b/src/indexes.rs @@ -317,7 +317,7 @@ mod tests fn test_indices_iter_c_fold() { macro_rules! run_test { - ($dim:expr_2021) => { + ($dim:expr) => { for num_consume in 0..3 { let mut it = indices($dim).into_iter(); for _ in 0..num_consume { diff --git a/src/iterators/macros.rs b/src/iterators/macros.rs index e170ea459..78697ec25 100644 --- a/src/iterators/macros.rs +++ b/src/iterators/macros.rs @@ -53,7 +53,7 @@ macro_rules! impl_ndproducer { )* unsafe fn item(&$self_:ident, $ptr:pat) { - $refexpr:expr_2021 + $refexpr:expr } }) => { impl<$($typarm)*> NdProducer for $fulltype { @@ -79,13 +79,13 @@ impl<$($typarm)*> NdProducer for $fulltype { self.$base.contiguous_stride() } - unsafe fn as_ref(&$self_, $ptr: *mut A) -> Self::Item { unsafe { + unsafe fn as_ref(&$self_, $ptr: *mut A) -> Self::Item { $refexpr - }} + } - unsafe fn uget_ptr(&self, i: &Self::Dim) -> *mut A { unsafe { + unsafe fn uget_ptr(&self, i: &Self::Dim) -> *mut A { self.$base.uget_ptr(i) as *mut _ - }} + } fn stride_of(&self, axis: Axis) -> isize { self.$base.stride_of(axis) @@ -140,7 +140,7 @@ macro_rules! impl_iterator { type Item = $ity:ty; fn item(&mut $self_:ident, $elt:pat) { - $refexpr:expr_2021 + $refexpr:expr } }) => { expand_if!(@nonempty [$($cloneparm)*] diff --git a/src/iterators/mod.rs b/src/iterators/mod.rs index 2eddf3f62..55a9920a8 100644 --- a/src/iterators/mod.rs +++ b/src/iterators/mod.rs @@ -267,7 +267,7 @@ where D: Dimension } macro_rules! either { - ($value:expr_2021, $inner:pat => $result:expr_2021) => { + ($value:expr, $inner:pat => $result:expr) => { match $value { ElementsRepr::Slice($inner) => $result, ElementsRepr::Counted($inner) => $result, @@ -276,7 +276,7 @@ macro_rules! either { } macro_rules! either_mut { - ($value:expr_2021, $inner:ident => $result:expr_2021) => { + ($value:expr, $inner:ident => $result:expr) => { match $value { ElementsRepr::Slice(ref mut $inner) => $result, ElementsRepr::Counted(ref mut $inner) => $result, @@ -888,7 +888,7 @@ impl AxisIterCore #[inline] unsafe fn offset(&self, index: usize) -> *mut A - { unsafe { + { debug_assert!( index < self.end, "index={}, end={}, stride={}", @@ -897,7 +897,7 @@ impl AxisIterCore self.stride ); self.ptr.offset(index as isize * self.stride) - }} + } /// Splits the iterator at `index`, yielding two disjoint iterators. /// @@ -1221,14 +1221,14 @@ impl NdProducer for AxisIter<'_, A, D> } unsafe fn as_ref(&self, ptr: Self::Ptr) -> Self::Item - { unsafe { + { ArrayView::new_(ptr, self.iter.inner_dim.clone(), self.iter.inner_strides.clone()) - }} + } unsafe fn uget_ptr(&self, i: &Self::Dim) -> Self::Ptr - { unsafe { + { self.iter.offset(self.iter.index + i[0]) - }} + } fn stride_of(&self, _axis: Axis) -> isize { @@ -1280,14 +1280,14 @@ impl NdProducer for AxisIterMut<'_, A, D> } unsafe fn as_ref(&self, ptr: Self::Ptr) -> Self::Item - { unsafe { + { ArrayViewMut::new_(ptr, self.iter.inner_dim.clone(), self.iter.inner_strides.clone()) - }} + } unsafe fn uget_ptr(&self, i: &Self::Dim) -> Self::Ptr - { unsafe { + { self.iter.offset(self.iter.index + i[0]) - }} + } fn stride_of(&self, _axis: Axis) -> isize { diff --git a/src/iterators/windows.rs b/src/iterators/windows.rs index 40c4891db..f3442c0af 100644 --- a/src/iterators/windows.rs +++ b/src/iterators/windows.rs @@ -192,16 +192,16 @@ impl<'a, A, D: Dimension> NdProducer for AxisWindows<'a, A, D> } unsafe fn as_ref(&self, ptr: *mut A) -> Self::Item - { unsafe { + { ArrayView::new_(ptr, self.window.clone(), self.strides.clone()) - }} + } unsafe fn uget_ptr(&self, i: &Self::Dim) -> *mut A - { unsafe { + { let mut d = D::zeros(self.base.ndim()); d[self.axis_idx] = i[0]; self.base.uget_ptr(&d) - }} + } fn stride_of(&self, axis: Axis) -> isize { diff --git a/src/itertools.rs b/src/itertools.rs index 5d073679a..d3562e687 100644 --- a/src/itertools.rs +++ b/src/itertools.rs @@ -94,28 +94,28 @@ macro_rules! izip { // @closure creates a tuple-flattening closure for .map() call. usage: // @closure partial_pattern => partial_tuple , rest , of , iterators // eg. izip!( @closure ((a, b), c) => (a, b, c) , dd , ee ) - ( @closure $p:pat => $tup:expr_2021 ) => { + ( @closure $p:pat => $tup:expr ) => { |$p| $tup }; // The "b" identifier is a different identifier on each recursion level thanks to hygiene. - ( @closure $p:pat => ( $($tup:tt)* ) , $_iter:expr_2021 $( , $tail:expr_2021 )* ) => { + ( @closure $p:pat => ( $($tup:tt)* ) , $_iter:expr $( , $tail:expr )* ) => { izip!(@closure ($p, b) => ( $($tup)*, b ) $( , $tail )*) }; // unary - ($first:expr_2021 $(,)*) => { + ($first:expr $(,)*) => { IntoIterator::into_iter($first) }; // binary - ($first:expr_2021, $second:expr_2021 $(,)*) => { + ($first:expr, $second:expr $(,)*) => { izip!($first) .zip($second) }; // n-ary where n > 2 - ( $first:expr_2021 $( , $rest:expr_2021 )* $(,)* ) => { + ( $first:expr $( , $rest:expr )* $(,)* ) => { izip!($first) $( .zip($rest) diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 9ca19ca7c..36853848e 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -93,7 +93,7 @@ mod tests type M0 = Array0; macro_rules! assert_layouts { - ($mat:expr_2021, $($layout:ident),*) => {{ + ($mat:expr, $($layout:ident),*) => {{ let layout = $mat.view().layout(); $( assert!(layout.is(Layout::$layout), @@ -105,7 +105,7 @@ mod tests } macro_rules! assert_not_layouts { - ($mat:expr_2021, $($layout:ident),*) => {{ + ($mat:expr, $($layout:ident),*) => {{ let layout = $mat.view().layout(); $( assert!(!layout.is(Layout::$layout), diff --git a/src/linalg/impl_linalg.rs b/src/linalg/impl_linalg.rs index 338d10308..0bbc0b026 100644 --- a/src/linalg/impl_linalg.rs +++ b/src/linalg/impl_linalg.rs @@ -669,7 +669,7 @@ where A: LinalgScalar unsafe fn general_mat_vec_mul_impl( alpha: A, a: &ArrayRef2, x: &ArrayRef1, beta: A, y: RawArrayViewMut, ) where A: LinalgScalar -{ unsafe { +{ let ((m, k), k2) = (a.dim(), x.dim()); let m2 = y.dim(); if k != k2 || m != m2 { @@ -737,7 +737,7 @@ unsafe fn general_mat_vec_mul_impl( }); } } -}} +} /// Kronecker product of 2D matrices. /// diff --git a/src/macro_utils.rs b/src/macro_utils.rs index eb816f1f3..75360de37 100644 --- a/src/macro_utils.rs +++ b/src/macro_utils.rs @@ -38,7 +38,7 @@ macro_rules! clone_bounds { /// debug assertions are enabled). #[cfg(debug_assertions)] macro_rules! ndassert { - ($e:expr_2021, $($t:tt)*) => { assert!($e, $($t)*) }; + ($e:expr, $($t:tt)*) => { assert!($e, $($t)*) }; } #[cfg(not(debug_assertions))] @@ -60,7 +60,7 @@ macro_rules! expand_if { // Macro to insert more informative out of bounds message in debug builds #[cfg(debug_assertions)] macro_rules! debug_bounds_check { - ($self_:ident, $index:expr_2021) => { + ($self_:ident, $index:expr) => { if $index.index_checked(&$self_.dim, &$self_.strides).is_none() { panic!( "ndarray: index {:?} is out of bounds for array of shape {:?}", diff --git a/src/slice.rs b/src/slice.rs index ec3f5e09a..e2ce1e727 100644 --- a/src/slice.rs +++ b/src/slice.rs @@ -587,7 +587,7 @@ where } macro_rules! impl_tryfrom_array_for_sliceinfo { - ($len:expr_2021) => { + ($len:expr) => { impl TryFrom<[SliceInfoElem; $len]> for SliceInfo<[SliceInfoElem; $len], Din, Dout> where @@ -809,7 +809,7 @@ impl_slicenextdim!((), NewAxis, Ix0, Ix1); #[macro_export] macro_rules! s( // convert a..b;c into @convert(a..b, c), final item - (@parse $in_dim:expr_2021, $out_dim:expr_2021, [$($stack:tt)*] $r:expr_2021;$s:expr_2021) => { + (@parse $in_dim:expr, $out_dim:expr, [$($stack:tt)*] $r:expr;$s:expr) => { match $r { r => { let in_dim = $crate::SliceNextDim::next_in_dim(&r, $in_dim); @@ -823,7 +823,7 @@ macro_rules! s( } }; // convert a..b into @convert(a..b), final item - (@parse $in_dim:expr_2021, $out_dim:expr_2021, [$($stack:tt)*] $r:expr_2021) => { + (@parse $in_dim:expr, $out_dim:expr, [$($stack:tt)*] $r:expr) => { match $r { r => { let in_dim = $crate::SliceNextDim::next_in_dim(&r, $in_dim); @@ -837,15 +837,15 @@ macro_rules! s( } }; // convert a..b;c into @convert(a..b, c), final item, trailing comma - (@parse $in_dim:expr_2021, $out_dim:expr_2021, [$($stack:tt)*] $r:expr_2021;$s:expr_2021 ,) => { + (@parse $in_dim:expr, $out_dim:expr, [$($stack:tt)*] $r:expr;$s:expr ,) => { $crate::s![@parse $in_dim, $out_dim, [$($stack)*] $r;$s] }; // convert a..b into @convert(a..b), final item, trailing comma - (@parse $in_dim:expr_2021, $out_dim:expr_2021, [$($stack:tt)*] $r:expr_2021 ,) => { + (@parse $in_dim:expr, $out_dim:expr, [$($stack:tt)*] $r:expr ,) => { $crate::s![@parse $in_dim, $out_dim, [$($stack)*] $r] }; // convert a..b;c into @convert(a..b, c) - (@parse $in_dim:expr_2021, $out_dim:expr_2021, [$($stack:tt)*] $r:expr_2021;$s:expr_2021, $($t:tt)*) => { + (@parse $in_dim:expr, $out_dim:expr, [$($stack:tt)*] $r:expr;$s:expr, $($t:tt)*) => { match $r { r => { $crate::s![@parse @@ -858,7 +858,7 @@ macro_rules! s( } }; // convert a..b into @convert(a..b) - (@parse $in_dim:expr_2021, $out_dim:expr_2021, [$($stack:tt)*] $r:expr_2021, $($t:tt)*) => { + (@parse $in_dim:expr, $out_dim:expr, [$($stack:tt)*] $r:expr, $($t:tt)*) => { match $r { r => { $crate::s![@parse @@ -881,11 +881,11 @@ macro_rules! s( // Catch-all clause for syntax errors (@parse $($t:tt)*) => { compile_error!("Invalid syntax in s![] call.") }; // convert range/index/new-axis into SliceInfoElem - (@convert $r:expr_2021) => { + (@convert $r:expr) => { <$crate::SliceInfoElem as ::core::convert::From<_>>::from($r) }; // convert range/index/new-axis and step into SliceInfoElem - (@convert $r:expr_2021, $s:expr_2021) => { + (@convert $r:expr, $s:expr) => { <$crate::SliceInfoElem as ::core::convert::From<_>>::from( <$crate::Slice as ::core::convert::From<_>>::from($r).step_by($s as isize) ) @@ -989,10 +989,10 @@ macro_rules! impl_multislice_tuple { private_impl! {} } }; - (@intersects_self $shape:expr_2021, ($head:expr_2021,)) => { + (@intersects_self $shape:expr, ($head:expr,)) => { false }; - (@intersects_self $shape:expr_2021, ($head:expr_2021, $($tail:expr_2021,)*)) => { + (@intersects_self $shape:expr, ($head:expr, $($tail:expr,)*)) => { $(slices_intersect($shape, $head, $tail)) ||* || impl_multislice_tuple!(@intersects_self $shape, ($($tail,)*)) }; diff --git a/src/stacking.rs b/src/stacking.rs index 7aa2bddc4..8737d6f60 100644 --- a/src/stacking.rs +++ b/src/stacking.rs @@ -177,10 +177,10 @@ where /// ``` #[macro_export] macro_rules! stack { - ($axis:expr_2021, $( $array:expr_2021 ),+ ,) => { + ($axis:expr, $( $array:expr ),+ ,) => { $crate::stack!($axis, $($array),+) }; - ($axis:expr_2021, $( $array:expr_2021 ),+ ) => { + ($axis:expr, $( $array:expr ),+ ) => { $crate::stack($axis, &[ $($crate::ArrayView::from(&$array) ),* ]).unwrap() }; } @@ -217,10 +217,10 @@ macro_rules! stack { /// ``` #[macro_export] macro_rules! concatenate { - ($axis:expr_2021, $( $array:expr_2021 ),+ ,) => { + ($axis:expr, $( $array:expr ),+ ,) => { $crate::concatenate!($axis, $($array),+) }; - ($axis:expr_2021, $( $array:expr_2021 ),+ ) => { + ($axis:expr, $( $array:expr ),+ ) => { $crate::concatenate($axis, &[ $($crate::ArrayView::from(&$array) ),* ]).unwrap() }; } diff --git a/src/zip/mod.rs b/src/zip/mod.rs index 3a2334bc6..640a74d1b 100644 --- a/src/zip/mod.rs +++ b/src/zip/mod.rs @@ -27,7 +27,7 @@ pub use self::ndproducer::{IntoNdProducer, NdProducer, Offset}; /// Return if the expression is a break value. macro_rules! fold_while { - ($e:expr_2021) => { + ($e:expr) => { match $e { FoldWhile::Continue(x) => x, x => return x, @@ -347,15 +347,13 @@ where D: Dimension F: FnMut(Acc, P::Item) -> FoldWhile, P: ZippableTuple, { - unsafe { - let mut i = 0; - while i < len { - let p = ptr.stride_offset(strides, i); - acc = fold_while!(function(acc, self.parts.as_ref(p))); - i += 1; - } - FoldWhile::Continue(acc) + let mut i = 0; + while i < len { + let p = ptr.stride_offset(strides, i); + acc = fold_while!(function(acc, self.parts.as_ref(p))); + i += 1; } + FoldWhile::Continue(acc) } fn for_each_core_strided(&mut self, acc: Acc, function: F) -> FoldWhile @@ -479,7 +477,7 @@ impl OffsetTuple for *mut T type Args = isize; unsafe fn stride_offset(self, stride: Self::Args, index: usize) -> Self { - unsafe { self.offset(index as isize * stride) } + self.offset(index as isize * stride) } } @@ -489,11 +487,11 @@ macro_rules! offset_impl { #[allow(non_snake_case)] impl<$($param: Offset),*> OffsetTuple for ($($param, )*) { type Args = ($($param::Stride,)*); - unsafe fn stride_offset(self, stride: Self::Args, index: usize) -> Self { unsafe { + unsafe fn stride_offset(self, stride: Self::Args, index: usize) -> Self { let ($($param, )*) = self; let ($($q, )*) = stride; ($(Offset::stride_offset($param, $q, index),)*) - }} + } } )+ }; @@ -532,16 +530,16 @@ macro_rules! zipt_impl { let ($(ref $p,)*) = *self; ($($p.as_ptr(), )*) } - unsafe fn as_ref(&self, ptr: Self::Ptr) -> Self::Item { unsafe { + unsafe fn as_ref(&self, ptr: Self::Ptr) -> Self::Item { let ($(ref $q ,)*) = *self; let ($($p,)*) = ptr; ($($q.as_ref($p),)*) - }} + } - unsafe fn uget_ptr(&self, i: &Self::Dim) -> Self::Ptr { unsafe { + unsafe fn uget_ptr(&self, i: &Self::Dim) -> Self::Ptr { let ($(ref $p,)*) = *self; ($($p.uget_ptr(i), )*) - }} + } fn split_at(self, axis: Axis, index: Ix) -> (Self, Self) { let ($($p,)*) = self; @@ -836,7 +834,7 @@ macro_rules! map_impl { /// before the array the raw view points to realizes its ownership. pub(crate) unsafe fn collect_with_partial(self, mut f: F) -> Partial where F: FnMut($($p::Item,)* ) -> R - { unsafe { + { // Get the last producer; and make a Partial that aliases its data pointer let (.., ref output) = &self.parts; @@ -865,7 +863,7 @@ macro_rules! map_impl { }); partial - }} + } } ); diff --git a/src/zip/ndproducer.rs b/src/zip/ndproducer.rs index 7e49a6953..82f3f43a7 100644 --- a/src/zip/ndproducer.rs +++ b/src/zip/ndproducer.rs @@ -109,9 +109,9 @@ impl Offset for *const T { type Stride = isize; unsafe fn stride_offset(self, s: Self::Stride, index: usize) -> Self - { unsafe { + { self.offset(s * (index as isize)) - }} + } private_impl! {} } @@ -119,9 +119,9 @@ impl Offset for *mut T { type Stride = isize; unsafe fn stride_offset(self, s: Self::Stride, index: usize) -> Self - { unsafe { + { self.offset(s * (index as isize)) - }} + } private_impl! {} } @@ -287,14 +287,14 @@ impl<'a, A, D: Dimension> NdProducer for ArrayView<'a, A, D> } unsafe fn as_ref(&self, ptr: *mut A) -> Self::Item - { unsafe { + { &*ptr - }} + } unsafe fn uget_ptr(&self, i: &Self::Dim) -> *mut A - { unsafe { + { self.ptr.as_ptr().offset(i.index_unchecked(&self.strides)) - }} + } fn stride_of(&self, axis: Axis) -> isize { @@ -343,14 +343,14 @@ impl<'a, A, D: Dimension> NdProducer for ArrayViewMut<'a, A, D> } unsafe fn as_ref(&self, ptr: *mut A) -> Self::Item - { unsafe { + { &mut *ptr - }} + } unsafe fn uget_ptr(&self, i: &Self::Dim) -> *mut A - { unsafe { + { self.ptr.as_ptr().offset(i.index_unchecked(&self.strides)) - }} + } fn stride_of(&self, axis: Axis) -> isize { @@ -404,12 +404,12 @@ impl NdProducer for RawArrayView } unsafe fn uget_ptr(&self, i: &Self::Dim) -> *const A - { unsafe { + { self.layout .ptr .as_ptr() .offset(i.index_unchecked(&self.layout.strides)) - }} + } fn stride_of(&self, axis: Axis) -> isize { @@ -463,12 +463,12 @@ impl NdProducer for RawArrayViewMut } unsafe fn uget_ptr(&self, i: &Self::Dim) -> *mut A - { unsafe { + { self.layout .ptr .as_ptr() .offset(i.index_unchecked(&self.layout.strides)) - }} + } fn stride_of(&self, axis: Axis) -> isize { diff --git a/src/zip/zipmacro.rs b/src/zip/zipmacro.rs index 696659a8a..0bbe956b3 100644 --- a/src/zip/zipmacro.rs +++ b/src/zip/zipmacro.rs @@ -98,28 +98,28 @@ macro_rules! azip { // Indexed with a single producer // we allow an optional trailing comma after the producers in each rule. - (@build $apply:ident (index $index:pat, $first_pat:pat in $first_prod:expr_2021 $(,)?) $body:expr_2021) => { + (@build $apply:ident (index $index:pat, $first_pat:pat in $first_prod:expr $(,)?) $body:expr) => { $crate::Zip::indexed($first_prod).$apply(|$index, $first_pat| $body) }; // Indexed with more than one producer - (@build $apply:ident (index $index:pat, $first_pat:pat in $first_prod:expr_2021, $($pat:pat in $prod:expr_2021),* $(,)?) $body:expr_2021) => { + (@build $apply:ident (index $index:pat, $first_pat:pat in $first_prod:expr, $($pat:pat in $prod:expr),* $(,)?) $body:expr) => { $crate::Zip::indexed($first_prod) $(.and($prod))* .$apply(|$index, $first_pat, $($pat),*| $body) }; // Unindexed with a single producer - (@build $apply:ident ($first_pat:pat in $first_prod:expr_2021 $(,)?) $body:expr_2021) => { + (@build $apply:ident ($first_pat:pat in $first_prod:expr $(,)?) $body:expr) => { $crate::Zip::from($first_prod).$apply(|$first_pat| $body) }; // Unindexed with more than one producer - (@build $apply:ident ($first_pat:pat in $first_prod:expr_2021, $($pat:pat in $prod:expr_2021),* $(,)?) $body:expr_2021) => { + (@build $apply:ident ($first_pat:pat in $first_prod:expr, $($pat:pat in $prod:expr),* $(,)?) $body:expr) => { $crate::Zip::from($first_prod) $(.and($prod))* .$apply(|$first_pat, $($pat),*| $body) }; // Unindexed with one or more producer, no loop body - (@build $apply:ident $first_prod:expr_2021 $(, $prod:expr_2021)* $(,)?) => { + (@build $apply:ident $first_prod:expr $(, $prod:expr)* $(,)?) => { $crate::Zip::from($first_prod) $(.and($prod))* }; diff --git a/tests/array.rs b/tests/array.rs index 6f3fa21d4..3d6fa6715 100644 --- a/tests/array.rs +++ b/tests/array.rs @@ -17,13 +17,13 @@ use num_complex::Complex; use std::convert::TryFrom; macro_rules! assert_panics { - ($body:expr_2021) => { + ($body:expr) => { if let Ok(v) = ::std::panic::catch_unwind(|| $body) { panic!("assertion failed: should_panic; \ non-panicking result: {:?}", v); } }; - ($body:expr_2021, $($arg:tt)*) => { + ($body:expr, $($arg:tt)*) => { if let Ok(_) = ::std::panic::catch_unwind(|| $body) { panic!($($arg)*); } @@ -412,7 +412,7 @@ fn test_slice_collapse_with_newaxis() fn test_multislice() { macro_rules! do_test { - ($arr:expr_2021, $($s:expr_2021),*) => { + ($arr:expr, $($s:expr),*) => { { let arr = $arr; let copy = arr.clone(); @@ -784,7 +784,7 @@ fn diag() fn merge_axes() { macro_rules! assert_merged { - ($arr:expr_2021, $slice:expr_2021, $take:expr_2021, $into:expr_2021) => { + ($arr:expr, $slice:expr, $take:expr, $into:expr) => { let mut v = $arr.slice($slice); let merged_len = v.len_of(Axis($take)) * v.len_of(Axis($into)); assert!(v.merge_axes(Axis($take), Axis($into))); @@ -793,7 +793,7 @@ fn merge_axes() }; } macro_rules! assert_not_merged { - ($arr:expr_2021, $slice:expr_2021, $take:expr_2021, $into:expr_2021) => { + ($arr:expr, $slice:expr, $take:expr, $into:expr) => { let mut v = $arr.slice($slice); let old_dim = v.raw_dim(); let old_strides = v.strides().to_owned(); @@ -1298,7 +1298,7 @@ fn owned_array_discontiguous_drop() } macro_rules! assert_matches { - ($value:expr_2021, $pat:pat) => { + ($value:expr, $pat:pat) => { match $value { $pat => {} ref err => panic!( diff --git a/tests/dimension.rs b/tests/dimension.rs index 6beeb6dd1..fe53d96b3 100644 --- a/tests/dimension.rs +++ b/tests/dimension.rs @@ -263,13 +263,13 @@ fn test_hash() hasher.finish() } macro_rules! test_hash_eq { - ($arr:expr_2021) => { + ($arr:expr) => { assert_eq!(calc_hash(&Dim($arr)), calc_hash(&Dim($arr))); assert_eq!(calc_hash(&Dim($arr)), calc_hash(&IxDyn(&$arr))); }; } macro_rules! test_hash_ne { - ($arr1:expr_2021, $arr2:expr_2021) => { + ($arr1:expr, $arr2:expr) => { assert_ne!(calc_hash(&Dim($arr1)), calc_hash(&Dim($arr2))); assert_ne!(calc_hash(&Dim($arr1)), calc_hash(&IxDyn(&$arr2))); assert_ne!(calc_hash(&IxDyn(&$arr1)), calc_hash(&Dim($arr2))); @@ -330,7 +330,7 @@ fn test_all_ndindex() { use ndarray::IntoDimension; macro_rules! ndindex { - ($($i:expr_2021),*) => { + ($($i:expr),*) => { for &rev in &[false, true] { // rev is for C / F order let size = $($i *)* 1; diff --git a/tests/iterators.rs b/tests/iterators.rs index d9e084b73..bdfd3ee50 100644 --- a/tests/iterators.rs +++ b/tests/iterators.rs @@ -8,13 +8,13 @@ use itertools::enumerate; use std::cell::Cell; macro_rules! assert_panics { - ($body:expr_2021) => { + ($body:expr) => { if let Ok(v) = ::std::panic::catch_unwind(|| $body) { panic!("assertion failed: should_panic; \ non-panicking result: {:?}", v); } }; - ($body:expr_2021, $($arg:tt)*) => { + ($body:expr, $($arg:tt)*) => { if let Ok(_) = ::std::panic::catch_unwind(|| $body) { panic!($($arg)*); } @@ -1073,7 +1073,7 @@ fn test_impl_iter_compiles() let _ = slice_iter_non_empty_indices; // ndarray case - fn array_iter_non_empty_indices<'s, 'a>(array: &'a Array<&'s str, Ix1>) -> impl Iterator + 'a + use<'a> + fn array_iter_non_empty_indices<'s, 'a>(array: &'a Array<&'s str, Ix1>) -> impl Iterator + 'a { array .iter()