feat: initial support for safe_kw in extern blocks#18350
Conversation
|
This PR provides basic support to prevent r-a emitting syntax errors, and ensures that hovering does not display incorrect signatures. I create this PR first so that it can be merged before Monday. Additional support such as completions and assists will be added in next few PRs. |
|
Please add a test that unsafe diagnostics is not triggered for |
|
Tests for |
|
Thanks! @bors r+ |
|
☀️ Test successful - checks-actions |
| pub mutable: bool, | ||
| pub is_extern: bool, | ||
| pub has_safe_kw: bool, | ||
| pub has_unsafe_kw: bool, |
There was a problem hiding this comment.
4 bools is becoming noticeable. Can you check whether that increases the size (hover tells the size)? If then it's probably better to turn it into a bitflags (not necessary to do now though).
Also, why is has_unsafe_kw needed, given it defaults to unsafe?
There was a problem hiding this comment.
Also, why is has_unsafe_kw needed, given it defaults to unsafe?
It seems to be used for pretty-printing?
There was a problem hiding this comment.
I don't think we promise pretty-printing will recover exactly the original code, at least if we do there are bunch of cases this promise is broken.
There was a problem hiding this comment.
And I'd argue it's better to always write unsafe in pretty printing since it may not be clear that the function is unsafe because it is extern (if we even show that it is extern, I don't remember now).
There was a problem hiding this comment.
I kept both has_xxx_kw here in case we need them later, and it is similar to FnFlags. I also left a comment here: https://github.com/roife/rust-analyzer/blob/002f6ad6f1ca6aa59e1ebccc8478930101f8150f/crates/hir-def/src/item_tree.rs#L826-L829 that we may use bitflags in the future.
There was a problem hiding this comment.
This one shouldn't have changed the size, but the next one (5th bool) might given alignment of 8 and other 4 byte fields in this struct.
I do think we should just swap all of these kinds of flags (this struct and others) to use bitflags, its more uniform that way and generally packs nicer.
There was a problem hiding this comment.
I do agree we don't really need to preserve the explicit unsafe in our IRs here though, as in this case its not meaningful. But it doesn't really matter much either
This PR adds initial support for
safekeywords in external blocks.Changes
safekw andunsafekw, as well as functions withsafekw in extern_blocksHAS_SAFE_KWtoFnFlagssafekw inis_fn_unsafe_to_callquery