Conversation
|
Some changes occurred in compiler/rustc_attr_parsing cc @jdonszelmann, @JonathanBrouwer Some changes occurred in compiler/rustc_passes/src/check_attr.rs cc @jdonszelmann, @JonathanBrouwer Some changes occurred in compiler/rustc_hir/src/attrs |
|
|
This comment has been minimized.
This comment has been minimized.
ed6f9af to
952c5ba
Compare
|
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
|
|
||
| /// Represents the trace attribute of `#[cfg_attr]` | ||
| CfgAttrTrace, | ||
| CfgAttrTrace(Span), |
There was a problem hiding this comment.
How does this behave with multiple cfg_attr attributes? Since this attribute can exist multiple times, ideally we should have a ThinVec<Span> here?
| @@ -0,0 +1,5 @@ | |||
| fn main() { | |||
| let _x = 30; | |||
| #[cfg_attr(, (cc))] //~ ERROR expected a literal (`1u8`, `1.0f32`, `"string"`, etc.) here, found `,` | |||
There was a problem hiding this comment.
This issue is not specific to cfg_attr, this will ICE with all attributes.
For example, this also ICES:
fn main() {
let _x = 30;
#[inline]
_x
}I think @jdonszelmann had an idea involving MultiSpans at some point to properly fix this
There was a problem hiding this comment.
I updated the code.
The reason is that Attribute::Parsed(AttributeKind::...) does not seem to have a uniform “source span” model, a lot of them don't have span.
The current callers of has_span_without_desugaring_kind only need the narrower diagnostics question: whether an attribute should make suggestion rendering treat the expression like a prefixed form. I think a proper name is is_prefix_attr_for_suggestions: the goal is to reflect that this is not really a generic span-recovery API.
The new fix's behavior is intentionally conservative. We still filter out desugaring-generated lint attributes precisely where we can identify them, but otherwise prefer treating parsed expression attributes as affecting suggestion precedence.
a more concrete way is maybe add a API such as get_span_from_attr(attr_kind) -> Vec<Span> and then check desugaring_kind of spans, I'm hesitant whether it's necessary.
952c5ba to
46e2396
Compare
Fixes #154801
r? @JonathanBrouwer
The root cause is we recovery from parsing attribute error here:
rust/compiler/rustc_attr_parsing/src/parser.rs
Line 550 in ed6f9af
while the later suggestion code from type checking try to inspect the attr span of the
exprin the second error, keep the span seems reasonable.