Port improved unused_unsafe check to -Zthir_unsafeck#99379
Port improved unused_unsafe check to -Zthir_unsafeck#99379LeSeulArtichaut wants to merge 1 commit intorust-lang:masterfrom
-Zthir_unsafeck#99379Conversation
|
I’ll take a look through the further changes made to the MIR-version that came up during review after I had created dc1056a and see if any of those apply to this code as-well. I can probably start looking into this tomorrow or Tuesday. Haven’t looked at the diffs so far or tried the rebase myself; I assume this is at the moment just a rebase and there weren’t any hard to solve merge conflicts? |
Thanks a lot, that'd be great if you still have the squashed commits. I've tried to resolve the differences I could spot but that's nowhere near a guarantee.
Exactly, just enough for the code to compile and for the tests to pass. |
They’re on GitHub, too. Just look for the “force-pushed” messages in the PR to get the relevant commit hashes to look at (I’d assume that Footnotes
|
10d0898 to
8809979
Compare
|
Okay, so I believe we're looking at 59e19357dfc54744980f256a4105e701f7dd99b1...99a1aa904aceb120220a46954c5d270290d4b471.
|
|
Can’t currently dedicate the significant amount of attention to reviewing this. Reassigning, but might be able to come back to this later if this doesn’t get reviewed by the time autumn rolls around. r? rust-lang/compiler |
|
Not really my ballpark, sorry. r? rust-lang/compiler |
|
r? rust-lang/compiler |
|
☔ The latest upstream changes (presumably #100740) made this pull request unmergeable. Please resolve the merge conflicts. |
cjgillot
left a comment
There was a problem hiding this comment.
I left some questions. Mainly: why do you need to design this as a second pass over the HIR, and not report this straight while visiting THIR?
| used_unsafe_blocks: visitor.used_unsafe_blocks, | ||
| context: if body_unsafety.is_unsafe() { Context::UnsafeFn(hir_id) } else { Context::Safe }, | ||
| }; | ||
| intravisit::Visitor::visit_body(&mut visitor2, tcx.hir().body(tcx.hir().body_owned_by(hir_id))); |
There was a problem hiding this comment.
Why does this traversal happen on HIR and not THIR?
| } | ||
| (Context::UnsafeBlock(hir_id), Some(_)) => UnusedUnsafe::InUnsafeBlock(hir_id), | ||
| }; | ||
| report_unused_unsafe(self.tcx, block.hir_id, unused_unsafe); |
There was a problem hiding this comment.
Why don't we report this at the end of UnsafetyVisitor::in_safety_context?
| }; | ||
| closure_visitor.visit_expr(&closure_thir[expr]); | ||
| // Unsafe blocks can be used in closures, make sure to take it into account | ||
| self.safety_context = closure_visitor.safety_context; |
There was a problem hiding this comment.
safety_context has a stack-like behaviour. Should this be an assert_eq?
| | ------ ^^^^^^ unnecessary `unsafe` block | ||
| | | | ||
| | because it's nested under this `unsafe` block |
There was a problem hiding this comment.
It's a shame we have this output regression here
| error: unnecessary `unsafe` block | ||
| --> $DIR/lint-unused-unsafe.rs:1054:29 | ||
| | | ||
| LL | let _ = async { unsafe { | ||
| | ^^^^^^ unnecessary `unsafe` block | ||
| | |
There was a problem hiding this comment.
This isn't pointing at the reason, the async fn in 1051. Or is it because there's another unsafe block within it before calling the unsafe fn? Either way, we should be pointing at the reason this is unnecessary, otherwise people will have to either already know what the problem is or start changing things at random.
| error: unnecessary `unsafe` block | ||
| --> $DIR/lint-unused-unsafe.rs:1068:29 | ||
| | | ||
| LL | let _ = async { unsafe { | ||
| | ^^^^^^ unnecessary `unsafe` block |
There was a problem hiding this comment.
Another case, it should point at the enclosing async fn
| error: unnecessary `unsafe` block | ||
| --> $DIR/lint-unused-unsafe.rs:1069:33 | ||
| | | ||
| LL | async unsafe fn async_blocks() { | ||
| | ------------------------------ because it's nested under this `unsafe` fn | ||
| ... | ||
| LL | let _ = async { unsafe { let _ = async { unsf() }; }}; | ||
| | ^^^^^^ unnecessary `unsafe` block |
There was a problem hiding this comment.
Interestingly, this points at the async fn, even though it is nested inside of another unsafe block.
| error: unnecessary `unsafe` block | ||
| --> $DIR/lint-unused-unsafe.rs:21:13 | ||
| | | ||
| LL | fn bad1() { unsafe {} } | ||
| | ^^^^^^ unnecessary `unsafe` block |
There was a problem hiding this comment.
This should mention that within the unsafe block there are no unsafe operations, so the block is unnecessary.
|
Thanks a lot for the reviews! Unfortunately I won't have time to continue working on this, sorry... |
Rebase of dc1056a as proposed in #93678 (comment), cc @steffahn.
r? @nagisa, do you want to review this as a followup of #93678?