Skip to content

Conversation

@CosmicHorrorDev
Copy link
Contributor

@CosmicHorrorDev CosmicHorrorDev commented Sep 18, 2025

thiserror largely wasn't getting much use in pest, and it's a rather heavy dependency for an otherwise lightweight crate. The only other crate in the workspace that uses thiserror is debugger which doesn't seem worth trying to remove

Summary by CodeRabbit

  • New Features

    • None
  • Refactor

    • Reworked error handling to use explicit standard error trait implementations and clarify integrations between core and optional adapters.
  • Chores

    • Removed an external error dependency and simplified feature flags to reduce configuration complexity.
  • Performance

    • Potentially faster builds and smaller dependency footprint due to dependency and feature cleanup.

@CosmicHorrorDev CosmicHorrorDev requested a review from a team as a code owner September 18, 2025 02:57
@CosmicHorrorDev CosmicHorrorDev requested review from tomtau and removed request for a team September 18, 2025 02:57
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 18, 2025

Walkthrough

The PR removes the thiserror dependency and replaces derives with explicit core::error::Error / std::error::Error and fmt::Display implementations gated by the std feature. Cargo features std and miette-error are updated to drop dep:thiserror. The miette adapter gets an explicit Display and Error impl.

Changes

Cohort / File(s) Summary of Changes
Cargo features and dependencies
pest/Cargo.toml
Removed thiserror from [dependencies]. Updated std feature to ["ucd-trie/std"]. Updated miette-error feature to ["std", "pretty-print", "dep:miette"].
Error types and miette adapter
pest/src/error.rs
Removed #[cfg_attr(feature = "std", derive(thiserror::Error))] from Error<R> and ErrorVariant<R>. Added impl<R: RuleType> core::error::Error for Error<R> and impl<R: RuleType> std::error::Error for ErrorVariant<R> (both cfg(feature = "std")). In miette_adapter: replaced derive(thiserror::Error, Debug) with derive(Debug), added use core::fmt;, updated help signature to Box<dyn fmt::Display + 'a>, and added explicit fmt::Display and std::error::Error impls for MietteAdapter<R>.

Sequence Diagram(s)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • tomtau
  • NoahTheDuke

Poem

I nibble lines and patch the seam,
No derive to haunt my dream—
With Display stitched and Error sewn,
The crate hops tidy, newly grown. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "deps: drop thiserror for a manual impl" is a concise, single-sentence summary that accurately describes the primary change (removing the thiserror dependency and replacing it with manual implementations) reflected in the Cargo.toml and pest/src/error.rs edits, and it is specific enough for a teammate scanning history to understand the main intent.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment on lines +45 to +46
#[cfg(feature = "std")]
impl<R: RuleType> core::error::Error for Error<R> {}
Copy link
Contributor Author

@CosmicHorrorDev CosmicHorrorDev Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh awkward mix of std and core here, but worth asking. Would you be fine bumping the MSRV up to 1.81.0 for core::error::Error? It's only one version up and I believe debian's latest release is 1.84

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pest/src/error.rs (1)

752-754: Remove leftover thiserror derive from MietteAdapter and fix other thiserror usages.

Leftover #[derive(thiserror::Error)] will break the build if the thiserror dependency is removed.

  • Apply to pest/src/error.rs (lines ~752-754):
-    #[derive(thiserror::Error, Debug)]
+    #[derive(Debug)]
     pub(crate) struct MietteAdapter<R: RuleType>(pub(crate) Error<R>);
  • Also address other occurrences: debugger/src/lib.rs:82 has #[derive(Debug, thiserror::Error)] — remove the thiserror derive or keep the thiserror dependency (debugger/Cargo.toml:30:thiserror = "2") so the workspace stays buildable.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3da954b and 161f21e.

📒 Files selected for processing (2)
  • pest/Cargo.toml (1 hunks)
  • pest/src/error.rs (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
pest/src/error.rs (2)
pest/src/iterators/pair.rs (1)
  • line_col (290-293)
pest/src/position.rs (2)
  • line_col (129-170)
  • line_col (503-518)
🪛 GitHub Actions: pest Continuous Integration
pest/src/error.rs

[error] 752-752: cargo check failed: failed to resolve: use of undeclared crate or module thiserror (pest/src/error.rs:752).


[error] 780-780: cargo check failed: failed to resolve: use of undeclared crate or module fmt (pest/src/error.rs:780).

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Fuzzing
🔇 Additional comments (2)
pest/Cargo.toml (1)

25-25: miette-error feature: removal of thiserror dep is correct.

pest/src/error.rs (1)

65-67: LGTM: ErrorVariant implements std::error::Error under std.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
pest/src/error.rs (1)

45-46: Use std::error::Error instead of core::error::Error for compatibility with MSRV.

The current implementation uses core::error::Error which wasn't stabilized until Rust 1.81.0. Based on the existing comment thread, the maintainer hasn't confirmed whether they want to bump the MSRV. Until that decision is made, you should use std::error::Error to maintain compatibility with the current MSRV.

Apply this diff to maintain MSRV compatibility:

 #[cfg(feature = "std")]
-impl<R: RuleType> core::error::Error for Error<R> {}
+impl<R: RuleType> std::error::Error for Error<R> {}
🧹 Nitpick comments (1)
pest/src/error.rs (1)

743-743: Remove redundant use core::fmt; import.

There's already a use core::fmt; statement at line 23 in the parent module scope. This import is redundant and can be removed.

Apply this diff to remove the redundant import:

 mod miette_adapter {
-    use core::fmt;
     use alloc::string::ToString;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 161f21e and 34f62c1.

📒 Files selected for processing (2)
  • pest/Cargo.toml (1 hunks)
  • pest/src/error.rs (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pest/Cargo.toml
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: Test Coverage
  • GitHub Check: check for no_std compatibility
  • GitHub Check: Minimal Versions Testing
  • GitHub Check: cargo hack check --feature-powerset
  • GitHub Check: check for semver compatibility
  • GitHub Check: Documentation check
  • GitHub Check: Unit, Style, and Lint Testing
  • GitHub Check: Fuzzing
🔇 Additional comments (5)
pest/src/error.rs (5)

65-66: LGTM! Correct use of std::error::Error for ErrorVariant.

The implementation correctly uses std::error::Error and is properly gated with the std feature flag.


776-778: LGTM! Correct return type for help method.

The signature correctly returns Box<dyn fmt::Display + 'a> which aligns with the miette::Diagnostic trait requirements.


781-785: LGTM! Proper manual Display implementation.

The manual implementation correctly formats the error message and properly uses the fully qualified core::fmt types.


787-789: LGTM! Correct manual Error implementation with proper trait bounds.

The implementation correctly requires both Debug and Display traits as bounds, matching what thiserror would have generated. The use of std::error::Error is appropriate since this is within a std feature-gated module.


753-754: LGTM! Clean removal of thiserror derive macros.

The struct now only derives Debug, which is correct. The previous thiserror::Error derive and its #[error] attribute have been properly replaced with manual implementations.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (2)
pest/src/error.rs (2)

744-744: fmt import fix looks good.


45-47: MSRV: implement std::error::Error (not core::error::Error).

Rust 1.80 doesn’t have core::error::Error. Keep the existing std feature‑gate but switch to std::error::Error.

-#[cfg(feature = "std")]
-impl<R: RuleType> core::error::Error for Error<R> {}
+#[cfg(feature = "std")]
+impl<R: RuleType> std::error::Error for Error<R> {}
🧹 Nitpick comments (1)
pest/src/error.rs (1)

65-67: Do we really want Error for ErrorVariant?

Implementing std::error::Error for the variant enum expands the public trait surface and can surprise downstream users. If not required, consider dropping it to avoid unnecessary API commitments.

-#[cfg(feature = "std")]
-impl<R: RuleType> std::error::Error for ErrorVariant<R> {}
+// (consider removing this impl unless there is a concrete use case)

Would you confirm if any downstream code relies on ErrorVariant: Error? If not, I recommend removing this impl.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 34f62c1 and d0e4230.

📒 Files selected for processing (2)
  • pest/Cargo.toml (1 hunks)
  • pest/src/error.rs (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pest/Cargo.toml
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: cargo hack check --feature-powerset
  • GitHub Check: Unit, Style, and Lint Testing
  • GitHub Check: Fuzzing
🔇 Additional comments (3)
pest/src/error.rs (3)

776-779: help() return type is correct and lifetime-safe.


781-785: Display message for MietteAdapter is clear and matches test expectations.


741-742: Resolved — miette adapter already gated on std via feature

Verified pest/Cargo.toml (and vm/Cargo.toml) declare miette-error = ["std", "pretty-print", "dep:miette"], so the module's use of Box and std::error::Error is safe and no cfg change is required.

Copy link
Contributor

@tomtau tomtau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm; I think it's ok to bump MSRV to 1.81 -- maybe in a separate PR?

@tomtau tomtau merged commit a2889a0 into pest-parser:master Sep 18, 2025
9 checks passed
@CosmicHorrorDev CosmicHorrorDev deleted the drop-thiserror branch September 18, 2025 06:24
@CosmicHorrorDev
Copy link
Contributor Author

I can handle that in another PR tomorrow 👍

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.

2 participants