From 176c49c78d85a3b12b767ef4911f1eba0cc95c09 Mon Sep 17 00:00:00 2001 From: Kumpelinus Date: Sat, 13 Sep 2025 20:20:02 +0200 Subject: [PATCH] chore: upgrade Rust toolchain to 1.89 and modernize code with let-chains --- .devcontainer/Dockerfile | 2 +- .github/workflows/Dockerfile.dev | 2 +- .github/workflows/docker-build-static.yml | 16 +++++++++++--- .github/workflows/rust.yml | 4 ++-- Cargo.toml | 1 + app/Cargo.toml | 1 + app/src/components/form/file_input.rs | 26 +++++++++++------------ app/src/infra/attributes.rs | 8 +++---- app/src/lib.rs | 1 + crates/access-control/Cargo.toml | 1 + crates/auth/Cargo.toml | 1 + crates/domain-handlers/Cargo.toml | 1 + crates/domain-model/Cargo.toml | 1 + crates/domain/Cargo.toml | 1 + crates/frontend-options/Cargo.toml | 1 + crates/graphql-server/Cargo.toml | 3 ++- crates/ldap/Cargo.toml | 3 ++- crates/ldap/src/search.rs | 12 +++++------ crates/opaque-handler/Cargo.toml | 1 + crates/sql-backend-handler/Cargo.toml | 1 + crates/test-utils/Cargo.toml | 1 + crates/validation/Cargo.toml | 1 + migration-tool/Cargo.toml | 1 + rust-toolchain.toml | 2 ++ server/Cargo.toml | 1 + server/tests/common/graphql.rs | 1 + set-password/Cargo.toml | 1 + 27 files changed, 62 insertions(+), 33 deletions(-) create mode 100644 rust-toolchain.toml diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 5fdf404..2e96738 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,4 +1,4 @@ -FROM rust:1.85 +FROM rust:1.89 ARG USERNAME=lldapdev # We need to keep the user as 1001 to match the GitHub runner's UID. diff --git a/.github/workflows/Dockerfile.dev b/.github/workflows/Dockerfile.dev index 2e969d2..9b9d6a5 100644 --- a/.github/workflows/Dockerfile.dev +++ b/.github/workflows/Dockerfile.dev @@ -1,5 +1,5 @@ # Keep tracking base image -FROM rust:1.85-slim-bookworm +FROM rust:1.89-slim-bookworm # Set needed env path ENV PATH="/opt/armv7l-linux-musleabihf-cross/:/opt/armv7l-linux-musleabihf-cross/bin/:/opt/aarch64-linux-musl-cross/:/opt/aarch64-linux-musl-cross/bin/:/opt/x86_64-linux-musl-cross/:/opt/x86_64-linux-musl-cross/bin/:$PATH" diff --git a/.github/workflows/docker-build-static.yml b/.github/workflows/docker-build-static.yml index 0a537b5..e62df65 100644 --- a/.github/workflows/docker-build-static.yml +++ b/.github/workflows/docker-build-static.yml @@ -24,7 +24,7 @@ on: env: CARGO_TERM_COLOR: always - + MSRV: "1.89" ### CI Docs @@ -88,6 +88,12 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v5.0.0 + - name: Install Rust + id: toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: "${{ env.MSRV }}" + targets: "wasm32-unknown-unknown" - uses: actions/cache@v4 with: path: | @@ -99,8 +105,6 @@ jobs: key: lldap-ui-${{ hashFiles('**/Cargo.lock') }} restore-keys: | lldap-ui- - - name: Add wasm target (rust) - run: rustup target add wasm32-unknown-unknown - name: Install wasm-pack with cargo run: cargo install wasm-pack || true env: @@ -133,6 +137,12 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v5.0.0 + - name: Install Rust + id: toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: "${{ env.MSRV }}" + targets: "${{ matrix.target }}" - uses: actions/cache@v4 with: path: | diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index fe7e732..a7ad83f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -8,7 +8,7 @@ on: env: CARGO_TERM_COLOR: always - MSRV: 1.85.0 + MSRV: "1.89" jobs: pre_job: @@ -42,7 +42,7 @@ jobs: toolchain: "${{ env.MSRV }}" - uses: Swatinem/rust-cache@v2 - name: Build - run: cargo build --verbose --workspace + run: cargo +${{steps.toolchain.outputs.name}} build --verbose --workspace - name: Run tests run: cargo +${{steps.toolchain.outputs.name}} test --verbose --workspace - name: Generate GraphQL schema diff --git a/Cargo.toml b/Cargo.toml index 436ab71..f202bbd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ edition = "2024" homepage = "https://github.com/lldap/lldap" license = "GPL-3.0-only" repository = "https://github.com/lldap/lldap" +rust-version = "1.89" [profile.release] lto = true diff --git a/app/Cargo.toml b/app/Cargo.toml index 7c8b3c6..0d73792 100644 --- a/app/Cargo.toml +++ b/app/Cargo.toml @@ -8,6 +8,7 @@ authors.workspace = true homepage.workspace = true license.workspace = true repository.workspace = true +rust-version.workspace = true [dependencies] anyhow = "1" diff --git a/app/src/components/form/file_input.rs b/app/src/components/form/file_input.rs index 529c40f..96cc0aa 100644 --- a/app/src/components/form/file_input.rs +++ b/app/src/components/form/file_input.rs @@ -147,20 +147,18 @@ impl Component for JpegFileInput { true } Msg::FileLoaded(file_name, data) => { - if let Some(avatar) = &mut self.avatar { - if let Some(file) = &avatar.file { - if file.name() == file_name { - if let Result::Ok(data) = data { - if !is_valid_jpeg(data.as_slice()) { - // Clear the selection. - self.avatar = Some(JsFile::default()); - // TODO: bail!("Chosen image is not a valid JPEG"); - } else { - avatar.contents = Some(data); - return true; - } - } - } + if let Some(avatar) = &mut self.avatar + && let Some(file) = &avatar.file + && file.name() == file_name + && let Result::Ok(data) = data + { + if !is_valid_jpeg(data.as_slice()) { + // Clear the selection. + self.avatar = Some(JsFile::default()); + // TODO: bail!("Chosen image is not a valid JPEG"); + } else { + avatar.contents = Some(data); + return true; } } self.reader = None; diff --git a/app/src/infra/attributes.rs b/app/src/infra/attributes.rs index 866fe93..87175fd 100644 --- a/app/src/infra/attributes.rs +++ b/app/src/infra/attributes.rs @@ -8,7 +8,7 @@ pub mod group { use super::AttributeDescription; - pub fn resolve_group_attribute_description(name: &str) -> Option { + pub fn resolve_group_attribute_description(name: &str) -> Option> { match name { "creation_date" => Some(AttributeDescription { attribute_identifier: name, @@ -39,7 +39,7 @@ pub mod group { } } - pub fn resolve_group_attribute_description_or_default(name: &str) -> AttributeDescription { + pub fn resolve_group_attribute_description_or_default(name: &str) -> AttributeDescription<'_> { match resolve_group_attribute_description(name) { Some(d) => d, None => AttributeDescription { @@ -55,7 +55,7 @@ pub mod user { use super::AttributeDescription; - pub fn resolve_user_attribute_description(name: &str) -> Option { + pub fn resolve_user_attribute_description(name: &str) -> Option> { match name { "avatar" => Some(AttributeDescription { attribute_identifier: name, @@ -111,7 +111,7 @@ pub mod user { } } - pub fn resolve_user_attribute_description_or_default(name: &str) -> AttributeDescription { + pub fn resolve_user_attribute_description_or_default(name: &str) -> AttributeDescription<'_> { match resolve_user_attribute_description(name) { Some(d) => d, None => AttributeDescription { diff --git a/app/src/lib.rs b/app/src/lib.rs index 09ef487..8c40952 100644 --- a/app/src/lib.rs +++ b/app/src/lib.rs @@ -2,6 +2,7 @@ #![forbid(non_ascii_idents)] #![allow(clippy::uninlined_format_args)] #![allow(clippy::let_unit_value)] +#![allow(clippy::unnecessary_operation)] // Doesn't work well with the html macro. pub mod components; pub mod infra; diff --git a/crates/access-control/Cargo.toml b/crates/access-control/Cargo.toml index 5fd80f7..1d271eb 100644 --- a/crates/access-control/Cargo.toml +++ b/crates/access-control/Cargo.toml @@ -7,6 +7,7 @@ edition.workspace = true homepage.workspace = true license.workspace = true repository.workspace = true +rust-version.workspace = true [dependencies] tracing = "*" diff --git a/crates/auth/Cargo.toml b/crates/auth/Cargo.toml index dc4c05c..b12a364 100644 --- a/crates/auth/Cargo.toml +++ b/crates/auth/Cargo.toml @@ -7,6 +7,7 @@ authors.workspace = true homepage.workspace = true license.workspace = true repository.workspace = true +rust-version.workspace = true [features] default = ["opaque_server", "opaque_client"] diff --git a/crates/domain-handlers/Cargo.toml b/crates/domain-handlers/Cargo.toml index 3a07ff0..871a4fd 100644 --- a/crates/domain-handlers/Cargo.toml +++ b/crates/domain-handlers/Cargo.toml @@ -6,6 +6,7 @@ authors.workspace = true homepage.workspace = true license.workspace = true repository.workspace = true +rust-version.workspace = true [features] test = [] diff --git a/crates/domain-model/Cargo.toml b/crates/domain-model/Cargo.toml index 3644245..128f951 100644 --- a/crates/domain-model/Cargo.toml +++ b/crates/domain-model/Cargo.toml @@ -6,6 +6,7 @@ authors.workspace = true homepage.workspace = true license.workspace = true repository.workspace = true +rust-version.workspace = true [features] test = [] diff --git a/crates/domain/Cargo.toml b/crates/domain/Cargo.toml index 8000899..16bed0f 100644 --- a/crates/domain/Cargo.toml +++ b/crates/domain/Cargo.toml @@ -9,6 +9,7 @@ edition.workspace = true homepage.workspace = true license.workspace = true repository.workspace = true +rust-version.workspace = true [features] test = [] diff --git a/crates/frontend-options/Cargo.toml b/crates/frontend-options/Cargo.toml index 6b39d77..16761ff 100644 --- a/crates/frontend-options/Cargo.toml +++ b/crates/frontend-options/Cargo.toml @@ -7,6 +7,7 @@ edition.workspace = true homepage.workspace = true license.workspace = true repository.workspace = true +rust-version.workspace = true [dependencies.serde] workspace = true diff --git a/crates/graphql-server/Cargo.toml b/crates/graphql-server/Cargo.toml index e08bf42..10bb9b6 100644 --- a/crates/graphql-server/Cargo.toml +++ b/crates/graphql-server/Cargo.toml @@ -7,6 +7,7 @@ authors.workspace = true homepage.workspace = true license.workspace = true repository.workspace = true +rust-version.workspace = true [dependencies] anyhow = "*" @@ -72,4 +73,4 @@ path = "../test-utils" [dev-dependencies.tokio] features = ["full"] -version = "1.25" \ No newline at end of file +version = "1.25" diff --git a/crates/ldap/Cargo.toml b/crates/ldap/Cargo.toml index 2c5d94e..58d7ee7 100644 --- a/crates/ldap/Cargo.toml +++ b/crates/ldap/Cargo.toml @@ -7,6 +7,7 @@ edition.workspace = true homepage.workspace = true license.workspace = true repository.workspace = true +rust-version.workspace = true [dependencies] anyhow = "*" @@ -63,4 +64,4 @@ version = "1.25" [dev-dependencies.lldap_domain] path = "../domain" -features = ["test"] \ No newline at end of file +features = ["test"] diff --git a/crates/ldap/src/search.rs b/crates/ldap/src/search.rs index 7af83e1..2f4b7e6 100644 --- a/crates/ldap/src/search.rs +++ b/crates/ldap/src/search.rs @@ -291,12 +291,12 @@ pub fn make_ldap_subschema_entry(schema: PublicSchema) -> LdapOp { } pub(crate) fn is_root_dse_request(request: &LdapSearchRequest) -> bool { - if request.base.is_empty() && request.scope == LdapSearchScope::Base { - if let LdapFilter::Present(attribute) = &request.filter { - if attribute.eq_ignore_ascii_case("objectclass") { - return true; - } - } + if request.base.is_empty() + && request.scope == LdapSearchScope::Base + && let LdapFilter::Present(attribute) = &request.filter + && attribute.eq_ignore_ascii_case("objectclass") + { + return true; } false } diff --git a/crates/opaque-handler/Cargo.toml b/crates/opaque-handler/Cargo.toml index 774a358..2824c68 100644 --- a/crates/opaque-handler/Cargo.toml +++ b/crates/opaque-handler/Cargo.toml @@ -7,6 +7,7 @@ edition.workspace = true homepage.workspace = true license.workspace = true repository.workspace = true +rust-version.workspace = true [features] test = [] diff --git a/crates/sql-backend-handler/Cargo.toml b/crates/sql-backend-handler/Cargo.toml index c9558bc..9f0fadf 100644 --- a/crates/sql-backend-handler/Cargo.toml +++ b/crates/sql-backend-handler/Cargo.toml @@ -7,6 +7,7 @@ edition.workspace = true homepage.workspace = true license.workspace = true repository.workspace = true +rust-version.workspace = true [features] test = [] diff --git a/crates/test-utils/Cargo.toml b/crates/test-utils/Cargo.toml index 0d354c9..682ca96 100644 --- a/crates/test-utils/Cargo.toml +++ b/crates/test-utils/Cargo.toml @@ -6,6 +6,7 @@ edition.workspace = true homepage.workspace = true license.workspace = true repository.workspace = true +rust-version.workspace = true [dependencies] async-trait = "0.1" diff --git a/crates/validation/Cargo.toml b/crates/validation/Cargo.toml index 6aca79d..d2857ef 100644 --- a/crates/validation/Cargo.toml +++ b/crates/validation/Cargo.toml @@ -7,3 +7,4 @@ edition.workspace = true homepage.workspace = true license.workspace = true repository.workspace = true +rust-version.workspace = true diff --git a/migration-tool/Cargo.toml b/migration-tool/Cargo.toml index 3417f36..be4e763 100644 --- a/migration-tool/Cargo.toml +++ b/migration-tool/Cargo.toml @@ -7,6 +7,7 @@ authors.workspace = true homepage.workspace = true license.workspace = true repository.workspace = true +rust-version.workspace = true [dependencies] anyhow = "*" diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..4f3e8c5 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "1.89" diff --git a/server/Cargo.toml b/server/Cargo.toml index 9fb832e..9bce462 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -9,6 +9,7 @@ authors.workspace = true homepage.workspace = true license.workspace = true repository.workspace = true +rust-version.workspace = true [dependencies] actix = "0.13" diff --git a/server/tests/common/graphql.rs b/server/tests/common/graphql.rs index 81cc594..b619f73 100644 --- a/server/tests/common/graphql.rs +++ b/server/tests/common/graphql.rs @@ -1,3 +1,4 @@ +#![allow(dead_code)] use crate::common::env; use anyhow::{Context, Result, anyhow}; use graphql_client::GraphQLQuery; diff --git a/set-password/Cargo.toml b/set-password/Cargo.toml index fbe2141..b1dbae8 100644 --- a/set-password/Cargo.toml +++ b/set-password/Cargo.toml @@ -7,6 +7,7 @@ authors.workspace = true homepage.workspace = true license.workspace = true repository.workspace = true +rust-version.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html