Skip to content

Commit

Permalink
Disallow build warnings for Rust (#4703)
Browse files Browse the repository at this point in the history
# Motivation

Build warnings are distracting and confusing.

There is one type of build warning that can start appearing without any
changes in the code: future incompatibility.
When there is a breaking change in a future version of a dependency,
this will start causing build warnings without changes in the
repository. We need to disable these warning in order to safely disallow
any build warnings in Rust and prevent the introduction of new warnings.

# Changes

1. Add `RUSTFLAGS="-D warnings"` in front of `cargo test` in CI to
disallow build warning.
2. Disable the "future incompatibility" warning by adding a
`config.toml` file.
3. Fix a warning by removing unused `use candid::types::number;` from
`rs/backend/src/accounts_store/schema/proxy/tests.rs`.
4. Fix a warning by removing unused `schema_label` from
`rs/backend/src/state/partitions.rs`

# Tests

CI passes

# Todos

- [x] Add entry to changelog (if necessary).
  • Loading branch information
dskloetd authored Apr 22, 2024
1 parent 5c19941 commit 3f00741
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[future-incompat-report]
frequency = "never"
2 changes: 1 addition & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
- name: Run Unit Tests
shell: bash
run: |
cargo test --lib --bins --benches --examples --all-features
RUSTFLAGS="-D warnings" cargo test --lib --bins --benches --examples --all-features
env:
RUST_BACKTRACE: 1
- name: Lint rustdoc
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG-Nns-Dapp-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ proposal is successful, the changes it released will be moved from this file to

#### Changed

* Disallow build warnings for Rust.

#### Deprecated

#### Removed
Expand Down
1 change: 0 additions & 1 deletion rs/backend/src/accounts_store/schema/proxy/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use candid::types::number;
use ic_stable_structures::memory_manager;
use pretty_assertions::assert_eq;
use proptest::proptest;
Expand Down
9 changes: 0 additions & 9 deletions rs/backend/src/state/partitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,6 @@ pub enum PartitionsMaybe {
}

impl PartitionsMaybe {
/// Gets the schema label.
#[cfg(test)]
pub fn schema_label(&self) -> SchemaLabel {
match self {
#[cfg(test)]
PartitionsMaybe::Partitions(partitions) => partitions.schema_label(),
PartitionsMaybe::None(_) => SchemaLabel::Map,
}
}
/// Gets or creates partitions.
///
/// WARNING: Partitioning overwrites the memory. Please be sure that you have extracted all useful data from raw memory before calling this.
Expand Down

0 comments on commit 3f00741

Please sign in to comment.