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

The scope of the unsafe block can be appropriately reduced #4700

Closed
wants to merge 0 commits into from

Conversation

peamaeq
Copy link

@peamaeq peamaeq commented May 18, 2022

Motivation

Solution

@netlify
Copy link

netlify bot commented May 18, 2022

Deploy Preview for tokio-rs ready!

Name Link
🔨 Latest commit c13bd07
🔍 Latest deploy log https://app.netlify.com/sites/tokio-rs/deploys/6284949cca1e700009447aec
😎 Deploy Preview https://deploy-preview-4700--tokio-rs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions github-actions bot added the R-loom Run loom tests on this PR label May 18, 2022
@Darksonn Darksonn added the A-tokio Area: The main tokio crate label May 18, 2022
Comment on lines 110 to 112
self.num_initialized = parts.initialized;
unsafe {
self.num_initialized = parts.initialized;
vec.set_len(parts.len);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not so sure that this makes the code easier to read. The assignment to num_initialized is important for the safety of the set_len call too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this assignment is important for its safety, I think the unsafe block should try to include only those places that are really unsafe, so that you can clearly focus on certain parameters of the unsafe function.

Comment on lines 153 to 163
impl Drop for Waiting {
fn drop(&mut self) {
unsafe {
let rc = UnregisterWaitEx(self.wait_object, INVALID_HANDLE_VALUE);

let rc = unsafe { UnregisterWaitEx(self.wait_object, INVALID_HANDLE_VALUE) };
if rc == 0 {
panic!("failed to unregister: {}", io::Error::last_os_error());
}
drop(Box::from_raw(self.tx));
}
drop(unsafe { Box::from_raw(self.tx) });

}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs some rustfmt.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@Darksonn
Copy link
Contributor

There are some more things that need rustfmt. You can fix them with the following command:

# Mac or Linux
rustfmt --edition 2018 $(git ls-files '*.rs')

# Powershell
Get-ChildItem . -Filter "*.rs" -Recurse | foreach { rustfmt --edition 2018 $_.FullName }

@peamaeq
Copy link
Author

peamaeq commented May 23, 2022

There are some more things that need rustfmt. You can fix them with the following command:

# Mac or Linux
rustfmt --edition 2018 $(git ls-files '*.rs')

# Powershell
Get-ChildItem . -Filter "*.rs" -Recurse | foreach { rustfmt --edition 2018 $_.FullName }

Thank you for your suggestion

@Darksonn
Copy link
Contributor

You will need to merge in master to fix the CI failures.

@Darksonn
Copy link
Contributor

I'm not really sure why CI failed here.

@taiki-e
Copy link
Member

taiki-e commented Jun 28, 2022

I'm not really sure why CI failed here.

I believe it's cross-rs/cross#724, removing the cache should fix it.

@Darksonn Darksonn closed this Jun 29, 2022
@github-actions github-actions bot removed the R-loom Run loom tests on this PR label Jun 29, 2022
@Darksonn
Copy link
Contributor

Uhh, what. I tried merging in master to fix the CI failures, but it closed the PR instead, and it wont let me reopen it.

@peamaeq Can you please reopen this PR, of if unable, open a new one? You will need the newest changes from Tokio master for CI to pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants