Skip to content

fix(error): use core::error::Error and core::fmt in error module - #498

Merged
Mec-iS merged 1 commit into
smartcorelib:mainfrom
ShryukGrandhi:fix/issue-414-no-std-step-1-swap-std-error-error-and-s
Oct 22, 2026
Merged

Mec-iS merged 1 commit into
smartcorelib:mainfrom
ShryukGrandhi:fix/issue-414-no-std-step-1-swap-std-error-error-and-s

Conversation

@ShryukGrandhi

Copy link
Copy Markdown
Contributor

Fixes #414

Checklist

  • My branch is up-to-date with main branch.
  • Everything works and tested on latest stable Rust.
  • Coverage and Linting have been applied

Current behaviour

src/error/mod.rs imports std::error::Error and std::fmt for the Failed and FailedError types. This ties the error module to std and blocks the no-std work in #413.

New expected behaviour

The module imports core::error::Error and core::fmt. core::error::Error is stable since Rust 1.81, so it is in the MSRV (1.85). The behaviour does not change, because std::error::Error and std::fmt are re-exports of the core items. The use std::error::Error in the test module stays as it is, as the issue says.

A new unit test, failed_implements_core_error, uses Failed as a &dyn core::error::Error and checks the Display output and source().

Tested with:

  • cargo fmt --all -- --check
  • cargo clippy --all-features -- -Drust-2018-idioms -Drust-2024-compatibility -Dwarnings
  • cargo test --all-features (all pass)
  • cargo +1.85.0 build --all-features (MSRV)

Change logs

Changed

  • src/error/mod.rs: use core::error::Error and core::fmt instead of the std:: paths.

Signed-off-by: ShryukGrandhi <85529990+ShryukGrandhi@users.noreply.github.com>
@ShryukGrandhi
ShryukGrandhi requested a review from Mec-iS as a code owner October 22, 2026 07:10
@codecov

codecov Bot commented Oct 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.58%. Comparing base (9eaae9e) to head (35cabff).
⚠️ Report is 203 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #498       +/-   ##
===========================================
+ Coverage   43.97%   85.58%   +41.60%     
===========================================
  Files          85       96       +11     
  Lines        7281     9373     +2092     
===========================================
+ Hits         3202     8022     +4820     
+ Misses       4079     1351     -2728     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Mec-iS

Mec-iS commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the PR, @ShryukGrandhi. This is a good, minimal first step for #414/#413.

What I checked

  • core::error::Error is stable since Rust 1.81, so it is fine with the 1.85 MSRV.
  • std::error::Error and std::fmt re-export the core items, so there is no behaviour change. impl Error for Failed {} and both fmt::Display impls compile unchanged.
  • The diff touches only src/error/mod.rs. Codecov reports all modified lines covered.

Suggestions (non-blocking)

  1. failed_implements_core_error largely duplicates failed_implements_error_with_no_source, which already checks source().is_none() and the trait-object cast. The new part is the Display assertion on Failed::predict. You could fold that assertion into the existing test, or keep the new test but reword the comment. Its name suggests it proves the module is std-free, which it doesn't, because the test module still uses std.
  2. This change doesn't make the module no-std yet. Failed still uses String and msg.to_string(), which come from the std prelude. Under #![no_std] they will need extern crate alloc; and use alloc::string::{String, ToString};. It would help to note in the PR description that this is step 1 and that the alloc imports are left for the follow-up in feat: no-std feature flag for embedded/edge targets #413, so the issue isn't closed prematurely. Fixes #414 is fine only if no-std Step 1: swap std::error::Error and std::fmt to core:: in error/mod.rs #414 is scoped to this swap.
  3. The serde derives on Failed and FailedError need serde built with default-features = false plus alloc for no-std. That is worth tracking in the feat: no-std feature flag for embedded/edge targets #413 checklist.
  4. Consider adding a CI job that builds with --no-default-features, or later a thumbv7em-none-eabihf target, so regressions are caught once the no-std work lands.

Codecov's base commit is 203 commits behind head, so please rebase on main to refresh CI before merge. Otherwise LGTM for this step. @Mec-iS, over to you.

@Mec-iS
Mec-iS merged commit 6ab90e2 into smartcorelib:main Oct 22, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

no-std Step 1: swap std::error::Error and std::fmt to core:: in error/mod.rs

2 participants