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

Fix ICE on undocumented_unsafe_blocks #7988

Merged

Conversation

giraffate
Copy link
Contributor

fix #7979

changelog: Fix ICE on undocumented_unsafe_blocks

@rust-highfive
Copy link

r? @camsteffen

(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 Nov 17, 2021
@flip1995
Copy link
Member

@bors r+

Thanks! And another one from this lint...

@bors
Copy link
Contributor

bors commented Nov 17, 2021

📌 Commit 3f3d7c2 has been approved by flip1995

@bors
Copy link
Contributor

bors commented Nov 17, 2021

⌛ Testing commit 3f3d7c2 with merge d550e5f...

} else {
self.macro_expansion = false;
enclosing_scope_span.to(block_span)
enclosing_scope_span.to(block_span).source_callsite()
Copy link
Contributor

Choose a reason for hiding this comment

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

This fixes the case in question but I think there are more cases unaccounted for. In general I think two spans should be ensured to have the same span.ctxt() before combining them with to, with_hi, etc, otherwise the operation is unpredictable. There can be any combination of contexts between the two spans.

A general fix might be...

if enclosing_scope_span.ctxt() != block_span.ctxt() {
    // get the span of the macro call
    // mac! { unsafe {} }
    enclosing_scope_span = hygiene::walk_chain(enclosing_scope_span, block_span.ctxt());
    if enclosing_scope_span.ctxt() != block_span.ctxt() {
        // if the contexts are still not equal after walk_chain,
        // the unsafe block span context is a descendant of the enclosing scope span context
        // { macro_with_unsafe!() }
        // return since I don't know what span to use
        return;
    }
}

But then I don't know if this lint is designed to work with the span of a macro call, where there can be an arbitrary amount of code between the start of the macro call and the unsafe block.

Copy link
Contributor

Choose a reason for hiding this comment

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

@bors
Copy link
Contributor

bors commented Nov 17, 2021

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

@bors bors merged commit d550e5f into rust-lang:master Nov 17, 2021
@giraffate giraffate deleted the fix_ice_on_undocumented_unsafe_blocks branch November 17, 2021 23:48
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.

ICE on undocumented_unsafe_blocks lint
5 participants