Skip to content
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

Merged
merged 5 commits into from Mar 27, 2024

Conversation

jahielkomu
Copy link
Contributor

@jahielkomu jahielkomu commented Mar 26, 2024

Fixed clippy warnings in components/script/timers.rs

  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes are part of Fix as many clippy problems as possible #31500
  • These changes do not require tests because it doesn't change functionality

@jahielkomu
Copy link
Contributor Author

jahielkomu commented Mar 26, 2024

Hello @mrobinson, I hope you are well.
This is komuhangi, an outreachy applicant.
Please kindly review.

@@ -418,6 +418,12 @@ enum InternalTimerCallback {
),
}

impl Default for JsTimers {
Copy link
Member

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().

Copy link
Contributor Author

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()

Copy link
Member

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().

Copy link
Contributor Author

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()

Apologies @mrobinson
I have reread your review and it does make sense.

@mrobinson mrobinson changed the title Contribution/6 clippy: Fix some warnings in components/script Mar 26, 2024
@mrobinson mrobinson changed the title clippy: Fix some warnings in components/script clippy: Fix some warnings in components/script/timers.rs Mar 26, 2024
@jahielkomu
Copy link
Contributor Author

I have update the PR @mrobinson
Please kindly review.

@@ -419,7 +419,7 @@ enum InternalTimerCallback {
}

impl JsTimers {
pub fn new() -> JsTimers {
pub fn default() -> JsTimers {
Copy link
Member

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

@@ -419,7 +419,7 @@ enum InternalTimerCallback {
}

impl JsTimers {
pub fn new() -> JsTimers {
pub fn default() -> JsTimers {
Copy link
Member

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

@jahielkomu
Copy link
Contributor Author

Hello @mrobinson.

I have update the PR, please review and revert.
I did not think that it was necessary to change the visibility of the default associated function to default it to the surrounding visibility.

@@ -418,8 +418,8 @@ enum InternalTimerCallback {
),
}

impl JsTimers {
pub fn default() -> JsTimers {
impl Default for JsTimers {
Copy link
Member

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 {
 ...
}

@mrobinson
Copy link
Member

I have update the PR, please review and revert. I did not think that it was necessary to change the visibility of the default associated function to default it to the surrounding visibility.

@jahielkomu I left a comment above. The build is failing because you have surrounded all JsTimer structure functions with the Default implementation block. The thing is that you need only put this kind of block around the functions necessary to implement the Default trait.

@jahielkomu
Copy link
Contributor Author

I have update the PR, please review and revert. I did not think that it was necessary to change the visibility of the default associated function to default it to the surrounding visibility.

@jahielkomu I left a comment above. The build is failing because you have surrounded all JsTimer structure functions with the Default implementation block. The thing is that you need only put this kind of block around the functions necessary to implement the Default trait.

Yes @mrobinson
I realized I confused myself from the beginning.

I have updated the PR and have separated the Default implementation from the rest of the methods as in

impl Default for JsTimers {
...
}

then

impl JsTimers {
...
}

Instead of

impl JsTimers {
impl Default for JsTimers {
...
} 
...
}

Please review and revert.
Thank you.

@mrobinson mrobinson added this pull request to the merge queue Mar 27, 2024
Merged via the queue into servo:main with commit 29f796a Mar 27, 2024
9 checks passed
ektuu pushed a commit to ektuu/servo that referenced this pull request Mar 28, 2024
* 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
MunishMummadi pushed a commit to MunishMummadi/servo that referenced this pull request Mar 29, 2024
* 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
@jahielkomu jahielkomu deleted the contribution/6 branch April 2, 2024 09:34
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.

None yet

2 participants