-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
tokio: remove wildcard in match pattern #5970
Conversation
That would trigger a warning because TypeC is not snake case, which would fail our build. |
Yes, the CI is useful for it. But if we do this, we can avoid such error before CI, and it may have better code smell. |
tokio-macros/src/entry.rs
Outdated
let worker_threads = match (flavor, self.worker_threads) { | ||
(CurrentThread, Some((_, worker_threads_span))) => { | ||
(RuntimeFlavor::CurrentThread, Some((_, worker_threads_span))) => { |
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 don't mind dropping the import for this case, but I don't want to drop it for Poll
, Result
, Ok
, or Ordering
. That's too much noise.
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 don't mind dropping the import for this case, but I don't want to drop it for
Poll
,Result
,Ok
, orOrdering
. That's too much noise.
Some kinds of enum of them, such as Result
, Ordering
might not be changed in the future, unless the std of rust make some broken changes. I reserve my opinion on these enums. But I believe some enums which is defiend in internal code of tokio might change in the future.
We can use use MyEnum as E
to reduce the noise.
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 have made some changes, allowing the wildcard in Result and Ordering for reduce the noise. And keep the other changes.
tokio/src/runtime/handle.rs
Outdated
use TryCurrentErrorKind::*; | ||
use TryCurrentErrorKind as E; | ||
match self { | ||
NoContext => f.write_str("NoContext"), | ||
ThreadLocalDestroyed => f.write_str("ThreadLocalDestroyed"), | ||
E::NoContext => f.write_str("NoContext"), | ||
E::ThreadLocalDestroyed => f.write_str("ThreadLocalDestroyed"), |
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.
Why E? Should this not be a K for kind?
I'm also okay with TryCurrentErrorKind::
here.
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.
E means Error, and I may have been influenced by golang :). I believe in Rust the error have a kind, which can refer to: https://doc.rust-lang.org/std/io/enum.ErrorKind.html, and the use of TryCurrentErrorKind ::
here is not tedious, so let us just use TryCurrentErrorKind ::
.
269b100
to
58fb956
Compare
The CI has passed, it looked like the last CI gone wrong. |
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.
Thanks.
When we use wildcard
*
in match pattern, it can lead to potential errors.If we delete
TypeC
,add addTypeD
The Rust compiler takes
TypeC
as a named variables, not a variant of the enum, and the unexpected error occurs.So we should never use such as
use MyEnum::*;
wildcard in Rust code.