-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Bad span in suggestion for unsafe_attr_outside_unsafe in macro expansion with cfg_attr #132908
Comments
I'm pretty sure this is related to this line:
This is assuming that the span is around I'm looking at this in relation to #132906, as I would like to figure out a way to prevent the lint from firing on macro_rules generated from a proc-macro. However, I haven't cracked that problem. Thought I would note that I see where the problem here is. EDIT: Correction: This only happens from a macro, so I'm not sure why it is different between the two. |
Posted a fix in #133270. |
Fix span of unsafe attribute diagnostic This fixes the span of the `unsafe_attr_outside_unsafe` diagnostic when the attribute uses `cfg_attr` and comes from a macro. Previously the span it was pointing to was in the wrong place (offset by 2 bytes in the start, and 1 byte in the end), causing a corrupt suggestion. The problem is that the lint was trying to do manual byte manipulation of the `Attribute` span to get within the `#[` and `]` tokens. However, when the attribute comes from `cfg_attr`, that span starts from the attribute path (like `no_mangle`), not the `#[` of the `cfg_attr`. The solution here is to store the span of the `AttrItem` while parsing, so that we know for sure that it covers the correct range (the path and all args). We could not use `AttrItem::span()` (which is removed in this PR), because that function did not correctly account for the path and arguments coming from separate expansion contexts. For example, in the macro expansion of `#[$p = $a]`, the span would be `$p = ` because you are not allowed to generate a span across expansion contexts. Fixes rust-lang#132908
Properly record metavar spans for other expansions other than TT This properly records metavar spans for nonterminals other than tokentree. This means that we operations like `span.to(other_span)` work correctly for macros. As you can see, other diagnostics involving metavars have improved as a result. Fixes rust-lang#132908 Alternative to rust-lang#133270 cc `@ehuss` cc `@petrochenkov`
Properly record metavar spans for other expansions other than TT This properly records metavar spans for nonterminals other than tokentree. This means that we operations like `span.to(other_span)` work correctly for macros. As you can see, other diagnostics involving metavars have improved as a result. Fixes rust-lang#132908 Alternative to rust-lang#133270 cc `@ehuss` cc `@petrochenkov`
Properly record metavar spans for other expansions other than TT This properly records metavar spans for nonterminals other than tokentree. This means that we operations like `span.to(other_span)` work correctly for macros. As you can see, other diagnostics involving metavars have improved as a result. Fixes rust-lang#132908 Alternative to rust-lang#133270 cc `@ehuss` cc `@petrochenkov`
Properly record metavar spans for other expansions other than TT This properly records metavar spans for nonterminals other than tokentree. This means that we operations like `span.to(other_span)` work correctly for macros. As you can see, other diagnostics involving metavars have improved as a result. Fixes rust-lang#132908 Alternative to rust-lang#133270 cc `@ehuss` cc `@petrochenkov`
Properly record metavar spans for other expansions other than TT This properly records metavar spans for nonterminals other than tokentree. This means that we operations like `span.to(other_span)` work correctly for macros. As you can see, other diagnostics involving metavars have improved as a result. Fixes rust-lang#132908 Alternative to rust-lang#133270 cc `@ehuss` cc `@petrochenkov`
Properly record metavar spans for other expansions other than TT This properly records metavar spans for nonterminals other than tokentree. This means that we operations like `span.to(other_span)` work correctly for macros. As you can see, other diagnostics involving metavars have improved as a result. Fixes rust-lang#132908 Alternative to rust-lang#133270 cc `@ehuss` cc `@petrochenkov`
The following code:
generates a suggestion which when applied looks like:
#[cfg_attr(all(), liunsafe(nk_section = ".text.startup)")]
Somehow the span is off by two bytes on both the start and end.
This doesn't happen outside of a macro expansion, and it seems to also require the cfg_attr.
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: