514: chore: Apply some suggestions by -Dclippy::pedantic#66
514: chore: Apply some suggestions by -Dclippy::pedantic#66martin-augment wants to merge 1 commit intomainfrom
Conversation
`-Dclippy::pedantic` is not added to test-lang-rust-clippy.yml because not all sugestions could be applied at the moment. Added `-Dclippy::cargo` to CI. `multiple_crate_versions` is needed because at the moment there are two versions of `heck` and `hashbrown` coming as transitive dependencies
WalkthroughThis pull request encompasses refactoring and enhancement across multiple components. The Rust CI workflow is modified to add workspace-scoped Clippy checks with specific lint configurations. Multiple files in ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on applying a series of code quality and style improvements, primarily driven by suggestions from Highlights
Ignored Files
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
PR Review: Apply clippy::pedantic suggestionsOverall this is a solid, mechanical improvement PR that makes the codebase more idiomatic Rust. Most changes are straightforward clippy pedantic fixes. A few items worth discussing: Bug: Unclosed doc comment code block in
|
🤖 Augment PR SummarySummary: This PR applies a batch of Changes:
Technical Notes: Most changes are behavior-preserving and aim to satisfy stricter lint settings while reducing unnecessary moves/clones. 🤖 Was this summary useful? React with 👍 or 👎 |
| /// recently logged message. | ||
| /// | ||
| /// # Example | ||
| /// ```ignore |
There was a problem hiding this comment.
There was a problem hiding this comment.
value:useful; category:bug; feedback: The Augment AI reviewer is correct! The code snippet in the docstring is not closed and this breaks the doc tests. Prevents CI failures.
| } | ||
|
|
||
| /// A custom error type for tests. | ||
| #[non_exhaustive] |
There was a problem hiding this comment.
Adding #[non_exhaustive] to the public TestError changes its public API (e.g., external users can no longer construct it), which can be a breaking change if avro_test_helper is consumed outside this workspace.
Severity: medium
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
There was a problem hiding this comment.
value:good-but-wont-fix; category:bug; feedback: The Augment AI reviewer is correct! The external users are not supposed to construct this error. It is a helper error that just unifies any other kind of errors, so that they could be used with TestResult in avro-rs' unit/IT tests.
There was a problem hiding this comment.
Code Review
This pull request applies a number of stylistic and idiomatic improvements suggested by clippy::pedantic. The changes are generally good, improving code clarity and following Rust best practices. I've found one area in the test helper logging utilities where the documentation is ambiguous and could lead to confusion in tests, and I've provided a suggestion to clarify it.
| /// - If the message is found, it is removed from the log messages and the function | ||
| /// completes successfully. |
There was a problem hiding this comment.
The documentation states that if the message is found, 'it is removed from the log messages'. This is ambiguous when the same message is logged multiple times. The current implementation uses retain, which removes all occurrences of the message. This can lead to unexpected behavior in tests.
For example, if a test does this:
log("some message");
log("some message");
assert_logged("some message"); // This will pass, but removes BOTH "message" logs.
assert_logged("some message"); // This will now FAIL, which is likely not the intended behavior.A more correct implementation for a test helper like this would be to remove only the first occurrence of the message. This would allow for asserting multiple identical logs.
Consider changing the implementation to something like this:
let mut deleted = false;
LOG_MESSAGES.with(|msgs| {
if let Some(pos) = msgs.borrow().iter().position(|msg| msg == expected_message) {
msgs.borrow_mut().remove(pos);
deleted = true;
}
});Alternatively, if removing all occurrences is the desired behavior, the documentation should be updated to reflect that, for example: 'all occurrences of the message are removed'.
There was a problem hiding this comment.
value:useful; category:bug; feedback: The Gemini AI reviewer is correct! The assert_logged() test helper method should delete only one matching message, not all of them. The helper method should be called the same number of times as the message has been logged to remove all of them.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
avro_test_helper/src/logger.rs (1)
71-105:⚠️ Potential issue | 🟠 Major
assert_not_loggedonly checks the last message, which may cause false negatives.The function uses
msgs.borrow().last()to check only the most recently logged message. Based on the existing test pattern inavro/src/types.rs(lines 1370-1450),assert_not_loggedis called after multiple validation failures that each log a message. If an earlier message in the sequence matchesunexpected_messagebut the last message is different, this assertion will incorrectly pass.Consider checking all messages instead:
🐛 Proposed fix to check all messages
#[track_caller] pub fn assert_not_logged(unexpected_message: &str) { - LOG_MESSAGES.with(|msgs| match msgs.borrow().last() { - Some(last_log) if last_log == unexpected_message => { + LOG_MESSAGES.with(|msgs| { + if msgs.borrow().iter().any(|msg| msg == unexpected_message) { panic!("The following log message should not have been logged: '{unexpected_message}'") } - _ => (), }); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@avro_test_helper/src/logger.rs` around lines 71 - 105, The assert_not_logged function only compares unexpected_message to the most recent entry via LOG_MESSAGES.with(|msgs| msgs.borrow().last()), which misses earlier matching logs; update assert_not_logged to iterate over all stored messages in LOG_MESSAGES (e.g., use msgs.borrow().iter().any(...) or equivalent) and panic if any entry equals unexpected_message so it correctly detects matches anywhere in the captured logs (refer to LOG_MESSAGES and assert_not_logged to locate the change).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@avro_test_helper/src/logger.rs`:
- Around line 71-105: The assert_not_logged function only compares
unexpected_message to the most recent entry via LOG_MESSAGES.with(|msgs|
msgs.borrow().last()), which misses earlier matching logs; update
assert_not_logged to iterate over all stored messages in LOG_MESSAGES (e.g., use
msgs.borrow().iter().any(...) or equivalent) and panic if any entry equals
unexpected_message so it correctly detects matches anywhere in the captured logs
(refer to LOG_MESSAGES and assert_not_logged to locate the change).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: cd07b9f5-c3b2-4b7d-b762-6443409c3140
📒 Files selected for processing (13)
.github/workflows/test-lang-rust-clippy.ymlavro/src/serde/ser_schema/mod.rsavro/tests/append_to_existing.rsavro_derive/build.rsavro_derive/src/attributes/avro.rsavro_derive/src/attributes/mod.rsavro_derive/src/case.rsavro_derive/src/enums/mod.rsavro_derive/src/enums/plain.rsavro_derive/src/lib.rsavro_test_helper/src/data.rsavro_test_helper/src/lib.rsavro_test_helper/src/logger.rs
value:useful; category:bug; feedback: The Claude AI reviewer is correct! The code snippet in the docstring is not closed and this breaks the doc tests. Prevents CI failures. |
value:valid-but-wont-fix; category:bug; feedback: The Claude AI reviewer is not correct! Usually this is a good suggestion but in this particular case this is not possible because |
value:useful; category:bug; feedback: The CodeRabbit AI reviewer is correct! The |
514: To review by AI