Skip to content

Commit 2b0affb

Browse files
TimTheBigsebcrozet
andauthored
Move to rust 2024 edition (#1523)
* Move to rust 2024 edition * chore: cargo fmt * chore: use less _ matches * chore: clippy fixes * chore: fix MSRV to 1.84 (for edition 2024) * chore: more 2024 idioms fixes * fix compilation of nalgebra-sparse --------- Co-authored-by: Sébastien Crozet <sebcrozet@dimforge.com>
1 parent 72d6e0a commit 2b0affb

171 files changed

Lines changed: 1334 additions & 1196 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/nalgebra-ci-build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
- name: Select rustc version
6161
uses: actions-rs/toolchain@v1
6262
with:
63-
toolchain: 1.79.0
63+
toolchain: 1.85.0
6464
override: true
6565
- uses: actions/checkout@v4
6666
- name: check
@@ -77,7 +77,7 @@ jobs:
7777
- name: Select rustc version
7878
uses: actions-rs/toolchain@v1
7979
with:
80-
toolchain: 1.81.0
80+
toolchain: 1.85.0
8181
override: true
8282
- uses: actions/checkout@v4
8383
- name: test

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ This project adheres to [Semantic Versioning](https://semver.org/).
1111

1212
- Add the `convert-glam030` feature to enable conversion from/to types from `glam` v0.30.
1313

14+
### Changed
15+
16+
- Moved to Rust 2024 edition.
17+
1418
## [0.33.2] (29 October 2024)
1519

1620
### Added

Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ readme = "README.md"
1111
categories = ["science", "mathematics", "wasm", "no-std"]
1212
keywords = ["linear", "algebra", "matrix", "vector", "math"]
1313
license = "Apache-2.0"
14-
edition = "2018"
14+
edition = "2024"
15+
rust-version = "1.85.0"
1516
exclude = ["/ci/*", "/.travis.yml", "/Makefile"]
1617

1718
[badges]
@@ -103,6 +104,7 @@ matrixmultiply = { version = "0.3", optional = true }
103104
serde = { version = "1.0", default-features = false, features = [
104105
"derive",
105106
], optional = true }
107+
# TODO: once rkyv is updated to 0.8, we could consider removing the `allow(unsafe_op_in_unsafe_fn)`.
106108
rkyv = { version = "0.7.41", default-features = false, optional = true }
107109
mint = { version = "0.5", optional = true }
108110
quickcheck = { version = "1", optional = true }
@@ -134,7 +136,7 @@ rayon = { version = "1.6", optional = true }
134136
[dev-dependencies]
135137
serde_json = "1.0"
136138
rand_xorshift = "0.4"
137-
rand_isaac = "0.3"
139+
rand_isaac = "0.4"
138140
criterion = { version = "0.4", features = ["html_reports"] }
139141
nalgebra = { path = ".", features = ["debug", "compare", "rand", "macros"] }
140142

benches/common/macros.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ macro_rules! bench_binop(
55
fn $name(bh: &mut criterion::Criterion) {
66
use rand::SeedableRng;
77
let mut rng = IsaacRng::seed_from_u64(0);
8-
let a = rng.gen::<$t1>();
9-
let b = rng.gen::<$t2>();
8+
let a = rng.random::<$t1>();
9+
let b = rng.random::<$t2>();
1010

1111
bh.bench_function(stringify!($name), move |bh| bh.iter(|| {
1212
a.$binop(b)
@@ -20,8 +20,8 @@ macro_rules! bench_binop_ref(
2020
fn $name(bh: &mut criterion::Criterion) {
2121
use rand::SeedableRng;
2222
let mut rng = IsaacRng::seed_from_u64(0);
23-
let a = rng.gen::<$t1>();
24-
let b = rng.gen::<$t2>();
23+
let a = rng.random::<$t1>();
24+
let b = rng.random::<$t2>();
2525

2626
bh.bench_function(stringify!($name), move |bh| bh.iter(|| {
2727
a.$binop(&b)
@@ -35,8 +35,8 @@ macro_rules! bench_binop_fn(
3535
fn $name(bh: &mut criterion::Criterion) {
3636
use rand::SeedableRng;
3737
let mut rng = IsaacRng::seed_from_u64(0);
38-
let a = rng.gen::<$t1>();
39-
let b = rng.gen::<$t2>();
38+
let a = rng.random::<$t1>();
39+
let b = rng.random::<$t2>();
4040

4141
bh.bench_function(stringify!($name), move |bh| bh.iter(|| {
4242
$binop(&a, &b)
@@ -53,7 +53,7 @@ macro_rules! bench_unop_na(
5353
use rand::SeedableRng;
5454
let mut rng = IsaacRng::seed_from_u64(0);
5555

56-
let elems: Vec<$t> = (0usize .. LEN).map(|_| rng.gen::<$t>()).collect();
56+
let elems: Vec<$t> = (0usize .. LEN).map(|_| rng.random::<$t>()).collect();
5757
let mut i = 0;
5858

5959
bh.bench_function(stringify!($name), move |bh| bh.iter(|| {
@@ -75,7 +75,7 @@ macro_rules! bench_unop(
7575
use rand::SeedableRng;
7676
let mut rng = IsaacRng::seed_from_u64(0);
7777

78-
let mut elems: Vec<$t> = (0usize .. LEN).map(|_| rng.gen::<$t>()).collect();
78+
let mut elems: Vec<$t> = (0usize .. LEN).map(|_| rng.random::<$t>()).collect();
7979
let mut i = 0;
8080

8181
bh.bench_function(stringify!($name), move |bh| bh.iter(|| {
@@ -97,7 +97,7 @@ macro_rules! bench_construction(
9797
use rand::SeedableRng;
9898
let mut rng = IsaacRng::seed_from_u64(0);
9999

100-
$(let $args: Vec<$types> = (0usize .. LEN).map(|_| rng.gen::<$types>()).collect();)*
100+
$(let $args: Vec<$types> = (0usize .. LEN).map(|_| rng.random::<$types>()).collect();)*
101101
let mut i = 0;
102102

103103
bh.bench_function(stringify!($name), move |bh| bh.iter(|| {

benches/core/matrix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use na::{DMatrix, DVector, Matrix2, Matrix3, Matrix4, OMatrix, Vector2, Vector3, Vector4, U10};
1+
use na::{DMatrix, DVector, Matrix2, Matrix3, Matrix4, OMatrix, U10, Vector2, Vector3, Vector4};
22
use rand::Rng;
33
use rand_isaac::IsaacRng;
44
use std::ops::{Add, Div, Mul, Sub};

benches/core/vector.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn vec10000_axpy_f64(bh: &mut criterion::Criterion) {
5252
let mut rng = IsaacRng::seed_from_u64(0);
5353
let mut a = DVector::new_random(10000);
5454
let b = DVector::new_random(10000);
55-
let n = rng.gen::<f64>();
55+
let n = rng.random::<f64>();
5656

5757
bh.bench_function("vec10000_axpy_f64", move |bh| {
5858
bh.iter(|| a.axpy(n, &b, 1.0))
@@ -64,8 +64,8 @@ fn vec10000_axpy_beta_f64(bh: &mut criterion::Criterion) {
6464
let mut rng = IsaacRng::seed_from_u64(0);
6565
let mut a = DVector::new_random(10000);
6666
let b = DVector::new_random(10000);
67-
let n = rng.gen::<f64>();
68-
let beta = rng.gen::<f64>();
67+
let n = rng.random::<f64>();
68+
let beta = rng.random::<f64>();
6969

7070
bh.bench_function("vec10000_axpy_beta_f64", move |bh| {
7171
bh.iter(|| a.axpy(n, &b, beta))
@@ -77,7 +77,7 @@ fn vec10000_axpy_f64_slice(bh: &mut criterion::Criterion) {
7777
let mut rng = IsaacRng::seed_from_u64(0);
7878
let mut a = DVector::new_random(10000);
7979
let b = DVector::new_random(10000);
80-
let n = rng.gen::<f64>();
80+
let n = rng.random::<f64>();
8181

8282
bh.bench_function("vec10000_axpy_f64_slice", move |bh| {
8383
bh.iter(|| {
@@ -94,7 +94,7 @@ fn vec10000_axpy_f64_static(bh: &mut criterion::Criterion) {
9494
let mut rng = IsaacRng::seed_from_u64(0);
9595
let mut a = SVector::<f64, 10000>::new_random();
9696
let b = SVector::<f64, 10000>::new_random();
97-
let n = rng.gen::<f64>();
97+
let n = rng.random::<f64>();
9898

9999
// NOTE: for some reasons, it is much faster if the argument are boxed (Box::new(OVector...)).
100100
bh.bench_function("vec10000_axpy_f64_static", move |bh| {
@@ -107,7 +107,7 @@ fn vec10000_axpy_f32(bh: &mut criterion::Criterion) {
107107
let mut rng = IsaacRng::seed_from_u64(0);
108108
let mut a = DVector::new_random(10000);
109109
let b = DVector::new_random(10000);
110-
let n = rng.gen::<f32>();
110+
let n = rng.random::<f32>();
111111

112112
bh.bench_function("vec10000_axpy_f32", move |bh| {
113113
bh.iter(|| a.axpy(n, &b, 1.0))
@@ -119,8 +119,8 @@ fn vec10000_axpy_beta_f32(bh: &mut criterion::Criterion) {
119119
let mut rng = IsaacRng::seed_from_u64(0);
120120
let mut a = DVector::new_random(10000);
121121
let b = DVector::new_random(10000);
122-
let n = rng.gen::<f32>();
123-
let beta = rng.gen::<f32>();
122+
let n = rng.random::<f32>();
123+
let beta = rng.random::<f32>();
124124

125125
bh.bench_function("vec10000_axpy_beta_f32", move |bh| {
126126
bh.iter(|| a.axpy(n, &b, beta))

benches/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub mod linalg;
1717
fn reproducible_dmatrix(nrows: usize, ncols: usize) -> DMatrix<f64> {
1818
use rand::SeedableRng;
1919
let mut rng = IsaacRng::seed_from_u64(0);
20-
DMatrix::<f64>::from_fn(nrows, ncols, |_, _| rng.gen())
20+
DMatrix::<f64>::from_fn(nrows, ncols, |_, _| rng.random())
2121
}
2222

2323
criterion_main!(

nalgebra-glm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ readme = "../README.md"
1111
categories = ["science", "mathematics", "wasm", "no standard library"]
1212
keywords = ["linear", "algebra", "matrix", "vector", "math"]
1313
license = "Apache-2.0"
14-
edition = "2018"
14+
edition = "2024"
1515

1616
[badges]
1717
maintenance = { status = "actively-developed" }

nalgebra-glm/src/common.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use core::mem;
22

3+
use crate::RealNumber;
34
use crate::aliases::{TMat, TVec};
45
use crate::traits::Number;
5-
use crate::RealNumber;
66

77
/// For each matrix or vector component `x` if `x >= 0`; otherwise, it returns `-x`.
88
///
@@ -515,11 +515,7 @@ pub fn smoothstep<T: RealNumber>(edge0: T, edge1: T, x: T) -> T {
515515

516516
/// Returns 0.0 if `x < edge`, otherwise it returns 1.0.
517517
pub fn step_scalar<T: Number>(edge: T, x: T) -> T {
518-
if edge > x {
519-
T::zero()
520-
} else {
521-
T::one()
522-
}
518+
if edge > x { T::zero() } else { T::one() }
523519
}
524520

525521
/// Returns 0.0 if `x[i] < edge`, otherwise it returns 1.0.

nalgebra-glm/src/constructors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
use crate::RealNumber;
12
use crate::aliases::{
23
Qua, TMat, TMat2, TMat2x3, TMat2x4, TMat3, TMat3x2, TMat3x4, TMat4, TMat4x2, TMat4x3, TVec1,
34
TVec2, TVec3, TVec4,
45
};
5-
use crate::RealNumber;
66
use na::Scalar;
77

88
/// Creates a new 1D vector.

0 commit comments

Comments
 (0)