check_rust_version¶
rhiza_hooks.check_rust_version
¶
Check that the Rust version is consistent across project files.
A Rust project states its version in up to three places:
rust-toolchain.toml—[toolchain] channel, the toolchain rustup installs for this checkout;rust-toolchain— the legacy form of the same file, either TOML or a bare channel name on a single line;Cargo.toml—rust-versionunder[package]and/or[workspace.package], the crate's minimum supported Rust version (MSRV).
The hook enforces that the two toolchain files agree with each other, that the
two MSRV declarations agree with each other, and that the pinned toolchain is
not older than the declared MSRV (a pin below the MSRV cannot build the crate).
Named channels (stable, beta, nightly-2024-01-01) carry no version
number, so they are accepted without comparison.
check_version_consistency(repo_root)
¶
Check Rust version consistency across project files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_root
|
Path
|
Root directory of the repository. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of error messages (empty if consistent, or if the repository |
list[str]
|
declares no Rust versions at all). |
Source code in rhiza_hooks/check_rust_version.py
get_cargo_rust_versions(repo_root)
¶
Collect the MSRVs declared in Cargo.toml.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_root
|
Path
|
Root directory of the repository. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Mapping of table label ( |
dict[str, str]
|
|
Source code in rhiza_hooks/check_rust_version.py
get_toolchain_channels(repo_root)
¶
Collect the pinned toolchain channels declared in the repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_root
|
Path
|
Root directory of the repository. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Mapping of filename to channel string, containing only the files that |
dict[str, str]
|
exist and actually declare a channel. |
Source code in rhiza_hooks/check_rust_version.py
main(argv=None)
¶
Main entry point for the hook.
Source code in rhiza_hooks/check_rust_version.py
read_legacy_toolchain(path)
¶
Read the channel from a legacy rust-toolchain file.
rustup accepts either the modern TOML form or a bare channel name, so TOML is tried first and plain text is the fallback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The channel string, or None if the file is missing, unreadable, or |
str | None
|
declares no channel. |