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
clippy: Fix some warnings in components/script/timers.rs
#31878
Conversation
Hello @mrobinson, I hope you are well. |
@@ -418,6 +418,12 @@ enum InternalTimerCallback { | |||
), | |||
} | |||
|
|||
impl Default for JsTimers { |
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.
Please don't add dead code. I think you can replace all calls JSTimers::new()
with JSTimers::default()
everywhere and move the contents of new()
into default()
.
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.
Thank you @mrobinson
Indeed the implementation of JsTimers::default
behavior is unused.
However won't the change and replacement of new()
with default()
have effects on the use of JsTimers::new()
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, every usage of JSTimers::new()
should be replaced with JSTimers::default()
.
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.
Thank you @mrobinson Indeed the implementation of
JsTimers::default
behavior is unused. However won't the change and replacement ofnew()
withdefault()
have effects on the use ofJsTimers::new()
Apologies @mrobinson
I have reread your review and it does make sense.
components/script
components/script
components/script/timers.rs
I have update the PR @mrobinson |
components/script/timers.rs
Outdated
@@ -419,7 +419,7 @@ enum InternalTimerCallback { | |||
} | |||
|
|||
impl JsTimers { | |||
pub fn new() -> JsTimers { | |||
pub fn default() -> JsTimers { |
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.
This method should also be the implementation of the Default
trait. Here's an example of this from the rust documentation: https://doc.rust-lang.org/std/default/trait.Default.html#how-can-i-implement-default
components/script/timers.rs
Outdated
@@ -419,7 +419,7 @@ enum InternalTimerCallback { | |||
} | |||
|
|||
impl JsTimers { | |||
pub fn new() -> JsTimers { | |||
pub fn default() -> JsTimers { |
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.
This method should also be the implementation of the Default
trait. Here's an example of this from the rust documentation: https://doc.rust-lang.org/std/default/trait.Default.html#how-can-i-implement-default
Hello @mrobinson. I have update the PR, please review and revert. |
@@ -418,8 +418,8 @@ enum InternalTimerCallback { | |||
), | |||
} | |||
|
|||
impl JsTimers { | |||
pub fn default() -> JsTimers { | |||
impl Default for JsTimers { |
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.
You'll need to have the default()
method inside a block like this:
impl Default for JsTimers {
...
}
but the rest of the methods will need to be inside a block that looks like this:
impl JsTimers {
...
}
@jahielkomu I left a comment above. The build is failing because you have surrounded all JsTimer structure functions with the |
e482c6d
to
cf13963
Compare
Yes @mrobinson I have updated the PR and have separated the
then
Instead of
Please review and revert. |
* Fixed some clippy warnings in components/script/timers.rs * Formatted changes in components/script/timers.rs * Updated changes in components/script/timers.rs * Updated Default implementation of JsTimers in components/script/timers.rs * UPDATED DEFAULT METHOD IMPLEMENTATION OF JsTimers in components/script/timers.rs
* Fixed some clippy warnings in components/script/timers.rs * Formatted changes in components/script/timers.rs * Updated changes in components/script/timers.rs * Updated Default implementation of JsTimers in components/script/timers.rs * UPDATED DEFAULT METHOD IMPLEMENTATION OF JsTimers in components/script/timers.rs
Fixed clippy warnings in components/script/timers.rs
./mach build -d
does not report any errors./mach test-tidy
does not report any errors