Use std::str::from_utf8 consistently to fix compiling with Rust < 1.87#891
Use std::str::from_utf8 consistently to fix compiling with Rust < 1.87#891Mingun merged 1 commit intotafia:masterfrom decathorpe:master
Conversation
| // 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]) |
There was a problem hiding this comment.
I think, it would be better to import std::str::from_utf8 in the test module
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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).
The
str::from_utf8method on thestrtype 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 viastd::str::from_utf8in 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 :)