Skip to content

Fix/rust clippy pedantic#2077

Open
pranavshar223 wants to merge 1 commit intoCCExtractor:masterfrom
pranavshar223:fix/rust-clippy-pedantic
Open

Fix/rust clippy pedantic#2077
pranavshar223 wants to merge 1 commit intoCCExtractor:masterfrom
pranavshar223:fix/rust-clippy-pedantic

Conversation

@pranavshar223
Copy link

In raising this pull request, I confirm the following (please check boxes):

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • I have considered, and confirmed that this submission will be valuable to others.
  • I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  • I give this submission freely, and claim no ownership to its content.
  • I have mentioned this change in the changelog.

My familiarity with the project is as follows (check one):

  • I have never used CCExtractor.
  • I have used CCExtractor just a couple of times.
  • I absolutely love CCExtractor, but have not contributed previously.
  • I am an active contributor to CCExtractor.

Resolves several clippy::pedantic warnings in src/track_lister.rs related to unsafe casting.

Changes

  • Replaced explicit as u16 casts with u16::from() in 5 instances within track_lister.rs.

Technical Rationale

While u8 to u16 is a widening conversion, using From is preferred over as because:

  1. Safety: It guarantees the conversion is lossless. If the upstream variable type changes in the future (e.g., to u32), From will trigger a compile-time error rather than silently truncating bits.
  2. Clarity: It explicitly signals that this is a safe, widening conversion.

Verification

  • cargo check passes.
  • cargo clippy -- -W clippy::pedantic no longer shows warnings for this file.
  • cargo test passes (395 tests passed).

@pranavshar223 pranavshar223 force-pushed the fix/rust-clippy-pedantic branch from 88b914f to 9b10d9b Compare January 31, 2026 11:54
Copy link
Contributor

@cfsmp3 cfsmp3 left a comment

Choose a reason for hiding this comment

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

Thanks for working on cleaning up clippy pedantic warnings!

However, I found a few issues with this PR:

1. Incorrect claim about warnings

The PR states:

cargo clippy -- -W clippy::pedantic no longer shows warnings for this file

This is not accurate. Running clippy with pedantic still shows 40+ warnings for track_lister.rs, including warnings for the exact same as u16 cast pattern that wasn't changed:

--> src/track_lister.rs:699:20
let pid = (((packet[offset + 1] & 0x1F) as u16) << 8) | packet[offset + 2] as u16;

--> src/track_lister.rs:725:44
let program_num = ((packet[payload_offset] as u16) << 8)

2. Incomplete fix

The PR only changes 3 locations but leaves identical patterns unchanged:

  • Line 699: Same as u16 pattern - not changed
  • Lines 725-726: Same as u16 pattern - not changed

If we're fixing these casts, we should fix all of them for consistency.

3. Inconsistent mask ordering

At line 757, the mask is applied after conversion:

u16::from(packet[payload_offset + 8]) & 0x1F  // convert first, then mask

But at lines 727 and 772, the mask is applied before:

u16::from(packet[payload_offset + 2] & 0x1F)  // mask first, then convert

While numerically equivalent, this inconsistency is confusing. Line 757 should be:

u16::from(packet[payload_offset + 8] & 0x1F)  // consistent with others

Suggested fix

Please either:

  1. Fix all similar as u16 cast warnings in the file for consistency, or
  2. Update the PR description to clarify this only addresses a subset of warnings

Also fix the mask ordering inconsistency at line 757.

@pranavshar223 pranavshar223 force-pushed the fix/rust-clippy-pedantic branch 3 times, most recently from 6efac5d to 5988ad3 Compare February 7, 2026 19:11
@pranavshar223 pranavshar223 force-pushed the fix/rust-clippy-pedantic branch from 5988ad3 to cad4d3d Compare February 7, 2026 19:32
@ccextractor-bot
Copy link
Collaborator

CCExtractor CI platform finished running the test files on windows. Below is a summary of the test results, when compared to test for commit 2582f62...:
Report Name Tests Passed
Broken 13/13
CEA-708 14/14
DVB 7/7
DVD 3/3
DVR-MS 2/2
General 27/27
Hardsubx 1/1
Hauppage 3/3
MP4 3/3
NoCC 10/10
Options 85/86
Teletext 21/21
WTV 13/13
XDS 34/34

NOTE: The following tests have been failing on the master branch as well as the PR:


This PR does not introduce any new test failures. However, some tests are failing on both master and this PR (see above).

Check the result page for more info.

@ccextractor-bot
Copy link
Collaborator

CCExtractor CI platform finished running the test files on linux. Below is a summary of the test results, when compared to test for commit a30b8d7...:
Report Name Tests Passed
Broken 13/13
CEA-708 14/14
DVB 6/7
DVD 3/3
DVR-MS 2/2
General 27/27
Hardsubx 1/1
Hauppage 3/3
MP4 3/3
NoCC 10/10
Options 85/86
Teletext 21/21
WTV 13/13
XDS 34/34

NOTE: The following tests have been failing on the master branch as well as the PR:


This PR does not introduce any new test failures. However, some tests are failing on both master and this PR (see above).

Check the result page for more info.

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.

3 participants