Open workingjubilee opened 7 months ago
honestly the main reason this issue was opened is because it seems like the only reason that this would vary so much is a serious bug in the linting framework.
wait, am I supposed to be writing Span::call_site().located_at(source_span)
to point the error at the source while making the span aware it is a "macro-tainted" span? doing that seems to cause the lints to stop firing...
honestly the main reason this issue was opened is because it seems like the only reason that this would vary so much is a serious bug in the linting framework.
IIRC, many lints don't try to handle macro-generated code (or code with mixed soures) because it's a lot of complexity. The lints typically use Span::from_expansion
to check if a span is macro-generated, and assumes that spans generated from proc macros properly account for hygiene. In this case, I think you need Span::mixed_site().located_at(user_span)
in order for the span to be marked as "generated from macros" (from your proc macro) so lints can avoid firing on macro-generated spans.
for note, just using Span::call_site
, without redirecting the span to its source in some way, can result in the span just touching a single character in an obviously-illogical way, which can be quite vexing. I think this is a consequence mostly of nested proc macro expansions? -Zmacro-backtrace
doesn't really illuminate this much, as far as I've noticed.
I was trying to apply this diff:
Code
Current output
Desired output
None?
Rationale and extra context
This takes in an enum's name, so of course it formats out to using
__pgrx_internals_enum_SomeEnum
or whatever. Butformat_ident
is basically just constructing an Ident but with theSpan
of the original ident it is based on. Apparently the expanded code triggers lints only if it has that span, butSpan::call_site
does not! It seems odd/annoying for the lint to ignore irrational spans like this but punish me for trying to forward the correct span so that errors get reported more clearly from the macro.This is slightly different from https://github.com/rust-lang/rust/issues/24580 because it's about the lint firing being inconsistent but I don't mind if it's closed for technically duplication I guess.
Other cases
No response
Rust Version
Anything else?
No response