Skip to content

feat: Migrate to Rust 2024 edition with clippy improvements#180

Closed
inureyes wants to merge 2 commits into
mainfrom
feat/migrate-to-2024-edition
Closed

feat: Migrate to Rust 2024 edition with clippy improvements#180
inureyes wants to merge 2 commits into
mainfrom
feat/migrate-to-2024-edition

Conversation

@inureyes
Copy link
Copy Markdown
Member

Summary

Migrate bssh codebase to Rust 2024 edition and apply clippy improvements.

  • 2024 Edition Migration: Updated both main Cargo.toml and crates/bssh-russh/Cargo.toml to edition 2024
  • Pattern Matching Improvements: Removed explicit ref/ref mut bindings in favor of implicit borrowing (2024 feature)
  • Clippy Refinements: Applied 38 collapsible-if improvements converting nested if-let statements to guard clause syntax using 2024's && syntax
  • Bytes Dependency: Pinned bytes to 1.11.1 for compatibility

Note on Unsafe Functions

Rust 2024 marks std::env::set_var and std::env::remove_var as unsafe due to race conditions in multi-threaded environments. ~102 test usages remain unwrapped pending implementation of EnvGuard RAII wrapper (issue #179).

Testing

Follow-up

Issue #179 created for comprehensive solution using RAII wrapper pattern.

- Update edition from 2021 to 2024 in both Cargo.toml files
  - Cargo.toml (bssh main package)
  - crates/bssh-russh/Cargo.toml (SSH library fork)

- Fix pattern matching for 2024 edition:
  - Remove explicit 'ref' and 'ref mut' bindings in if-let patterns
  - 2024 edition uses implicit borrowing in patterns
  - Updated session_info to mutable variable where needed
  - src/server/handler.rs (4 pattern changes)
  - src/server/shell.rs (1 pattern change)

- Code changes summary:
  - 119 files reformatted by rustfmt
  - No breaking API changes
  - All unsafe code, macros, async/await remain compatible
  - All dependencies support 2024 edition

- Compilation status:
  - cargo build --release: ✅ SUCCESS
  - All binaries (bssh, bssh-server, bssh-keygen) compile correctly

2024 edition improvements applied:
- Implicit pattern borrowing eliminates need for 'ref'/'ref mut'
- Support for guard clauses (if let X = Y && condition)
- Better error messages and compile-time checks
- Collapse nested if-let statements using 2024 edition guard clause syntax
- Convert 38 instances from nested if-let to single if-let with && conditions
- Improves code readability and embraces 2024 edition improvements

Files modified:
- crates/bssh-russh/src/client/mod.rs (7 fixes)
- crates/bssh-russh/src/server/session.rs (12 fixes)
- crates/bssh-russh/src/client/session.rs (9 fixes)
- crates/bssh-russh/src/server/mod.rs (2 fixes)
- crates/bssh-russh/src/client/encrypted.rs (3 fixes)
- crates/bssh-russh/src/server/encrypted.rs (2 fixes)
- crates/bssh-russh/src/ssh_read.rs (1 fix)
- crates/bssh-russh/src/keys/known_hosts.rs (1 fix)
- crates/bssh-russh/src/kex/dh/mod.rs (1 fix)

Example transformation:
  // Before
  if let Some(x) = y {
      if condition {
          // ...
      }
  }

  // After (2024 edition)
  if let Some(x) = y && condition {
      // ...
  }
@inureyes inureyes added the type:enhancement New feature or request label Apr 14, 2026
@inureyes inureyes self-assigned this Apr 14, 2026
@inureyes inureyes closed this Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant