-
Notifications
You must be signed in to change notification settings - Fork 265
Use std::str::from_utf8 consistently to fix compiling with Rust < 1.87 #891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, convinced
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_utf8
method on thestr
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 viastd::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 :)