The scope of the unsafe block can be appropriately reduced#126
Open
peamaeq wants to merge 1 commit intoconsole-rs:mainfrom
Open
The scope of the unsafe block can be appropriately reduced#126peamaeq wants to merge 1 commit intoconsole-rs:mainfrom
peamaeq wants to merge 1 commit intoconsole-rs:mainfrom
Conversation
benesch
pushed a commit
to benesch/console
that referenced
this pull request
Dec 4, 2022
…onsole-rs#126) I was working on a lost waker lint, and noticed that the "coma" task wasn't being linted, because it never sends another stats update. This fixes it to lint tasks when we first get them, too.
benesch
pushed a commit
to benesch/console
that referenced
this pull request
Dec 4, 2022
This lint will warn when a task that isn't completed has no more wakers, implying the task will never wake up again. Note that this depends on console-rs#126 in most cases. 
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In this function you use the unsafe keyword for almost the entrie function body. However, I found that only 5 functions are real unsafe operations (see the list below).
We need to mark unsafe operations more precisely using unsafe keyword. Keeping unsafe blocks small can bring many benefits. For example, when mistakes happen, we can locate any errors related to memory safety within an unsafe block. This is the balance between Safe and Unsafe Rust. The separation is designed to make using Safe Rust as ergonomic as possible, but requires extra effort and care when writing Unsafe Rust.
Real unsafe operation list:
SetConsoleCursorInfo() function(these are unsafe functions)
Hope this PR can help you.
Best regards.
References
https://doc.rust-lang.org/nomicon/safe-unsafe-meaning.html
https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html