Skip to content

Conversation

decathorpe
Copy link
Contributor

The str::from_utf8 method on the str type was only stabilized in Rust 1.87. It looks like the method is used via this path accidentally in some places, because it is used via std::str::from_utf8 in most other places (which has been available since Rust 1.0).

This should fix compiling (and running tests) with a Rust toolchain less recent than 1.87 :)

// All possible characters encoded in 2 bytes in UTF-8 which first byte is 0xC2 (0b11000010)
// Second byte follows the pattern 10xxxxxx
let first = str::from_utf8(&[0b11000010, 0b10000000])
let first = std::str::from_utf8(&[0b11000010, 0b10000000])
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think, it would be better to import std::str::from_utf8 in the test module

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I understand what you mean - I don't think the changes I made are wrong, are they?

Or did you mean, instead of using the fully qualified path in multiple places, to add use std::str::from_utf8; and then refer to it as just from_utf8(...)? I've seen both usages across the code base, but AFAICT usage via the fully qualified path was much more frequent, so I went with that style for my PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, I try to avoid using fully qualified paths, except there are only few places (1-3) to use and it is under cfg or inside of a macro.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Searching the source code with rg "std::str::from_utf8" shows me ~45 usages of the fully qualified path (not counting five use statements), and only ~10 usages of from_utf8 (where imported by use std::str::from_utf8). So clearly there are much more places where std::str::from_utf8 is referred to by the fully qualified path than there are places where the item imported and then referred to as just from_utf8.

So I'm not sure what you mean when you say "I try to avoid using fully qualified paths", as reality doesn't seem to confirm this :D

Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay, convinced

@codecov-commenter
Copy link

codecov-commenter commented Aug 6, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.23%. Comparing base (38b44d4) to head (5df8ad7).
⚠️ Report is 11 commits behind head on master.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #891      +/-   ##
==========================================
+ Coverage   55.52%   58.23%   +2.70%     
==========================================
  Files          42       42              
  Lines       15511    15206     -305     
==========================================
+ Hits         8613     8855     +242     
+ Misses       6898     6351     -547     
Flag Coverage Δ
unittests 58.23% <100.00%> (+2.70%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.

The `str::from_utf8` method on the `str` type was only stabilized in
Rust 1.87.

It looks like the method is used via this path accidentally in some
places, because it is used via `std::str::from_utf8` in most other
places (which has been available since Rust 1.0).
@Mingun Mingun merged commit ea34144 into tafia:master Aug 8, 2025
7 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.

3 participants