Skip to content

fix undocumented-unsafe-blocks false positive #9648

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

Merged
merged 1 commit into from
Oct 29, 2022

Conversation

llogiq
Copy link
Contributor

@llogiq llogiq commented Oct 14, 2022

This fixes #9142 by iterating over the parent nodes as long as within a block, expression, statement, local, const or static.


changelog: none

@rust-highfive
Copy link

r? @giraffate

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Oct 14, 2022
@llogiq llogiq force-pushed the fix-undocumented-unsafe-blocks branch from ad8055f to 6754ed8 Compare October 15, 2022 13:57
@llogiq
Copy link
Contributor Author

llogiq commented Oct 16, 2022

I now no longer look at blocks.

This would of course still allow e.g. foo(bar(Baz(unsafe { .. }))) including possible newlines in between and accept the safety comment before foo.

@llogiq llogiq force-pushed the fix-undocumented-unsafe-blocks branch from 6754ed8 to f955e9c Compare October 18, 2022 21:38
@llogiq
Copy link
Contributor Author

llogiq commented Oct 23, 2022

Ping @giraffate

Or @Jarcho do you want to take over the review?

@Jarcho
Copy link
Contributor

Jarcho commented Oct 24, 2022

I guess I can take over.

I'm still not sure about walking up expressions in general. Method and let chains can result in some pretty crazy expressions. Clippy in particular is pretty bad about having 40-50 line let chains, although I assume that's unusual in other projects.

I think the best plan here would be to fix the current regression by only walking up a single level if the parent is a let statement (and in the same SyntaxContext) and checking there. We can then figure out what forms should be allowed by the lint and deal with that in a different PR.

@llogiq llogiq force-pushed the fix-undocumented-unsafe-blocks branch from f955e9c to 7cf0059 Compare October 26, 2022 22:23
@llogiq
Copy link
Contributor Author

llogiq commented Oct 26, 2022

@Jarcho Ok, this now only looks one parent upwards. r?

@rustbot
Copy link
Collaborator

rustbot commented Oct 26, 2022

Error: Parsing assign command in comment failed: ...'' | error: specify user to assign to at >| ''...

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #t-infra on Zulip.

@llogiq
Copy link
Contributor Author

llogiq commented Oct 27, 2022

That comment was meant for Jarcho, not Rustbot. But nice error 😉.

@@ -490,4 +490,20 @@ unsafe impl CrateRoot for () {}
// SAFETY: ok
unsafe impl CrateRoot for (i32) {}

fn issue_9142() {
// SAFETY: ok
let _ = unsafe {};
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you change this to be on two lines. e.g.

// SAFETY: ok
let _ =
    unsafe {}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, rustfmt pulled this together.

@llogiq llogiq force-pushed the fix-undocumented-unsafe-blocks branch from 7cf0059 to e19fe89 Compare October 28, 2022 20:09
@Jarcho
Copy link
Contributor

Jarcho commented Oct 29, 2022

All looks good now. Thank you.

@bors r+

@bors
Copy link
Contributor

bors commented Oct 29, 2022

📌 Commit e19fe89 has been approved by Jarcho

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Oct 29, 2022

⌛ Testing commit e19fe89 with merge fdaa425...

@bors
Copy link
Contributor

bors commented Oct 29, 2022

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: Jarcho
Pushing fdaa425 to master...

@bors bors merged commit fdaa425 into rust-lang:master Oct 29, 2022
@llogiq llogiq deleted the fix-undocumented-unsafe-blocks branch October 29, 2022 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False positive in undocumented_unsafe_blocks (stable-to-stable regression)
6 participants