Open CharlyCst opened 2 weeks ago
Pretty straightforward! I'll work on it. It'll be my first PR.
This is actually more complicated than I assumed.
The offending code is operating on the HIR where parens have already been elided into the token tree heirarchy.
The suggested replacement of &raw const
or &raw mut
is dropped into the span err_span.with_hi(ex.span.lo())
from here.
The cleanest way to solve it would be to narrow the referenced span when lowering from the AST to the HIR so that the 'hir::Expr' node's Span
doesn't point to or include the parens - only the contents of them - since the HIR isn't supposed to know about parens anyways.
I doubt that this would change the correctness of other lints and errors operating on the HIR, but it almost certainly breaks a lot of the ui compiletests which would then have different spans highlighted in their stderr contents.
Are there other lints/errors that have run into similar issues to reference?
For reference, I commented out this line which replaces the HIR Span
with the AST Paren Span
to get a sense for how significant of an effect it would have:
It is definitely not the solution on its own.
(a.unwrap)()
(|| {})(|| { let b = 1; })
(a as [Foo; 3]).0
=> (a as [Foo; 3][0]
instead of (a as [Foo; 3])[0]
Code
Current output
Desired output
Rationale and extra context
The suggestion removes the left parenthesis, but keeps the right parenthesis. Of course the proposed change does not compile. Original code:
(&TEST)
suggestion:&raw const TEST)
Other cases
No response
Rust Version
rustc 1.84.0-nightly (da935398d 2024-10-19) binary: rustc commit-hash: da935398d582344c5b7689bd6632d8ec01b0c988 commit-date: 2024-10-19 host: aarch64-apple-darwin release: 1.84.0-nightly LLVM version: 19.1.1
Anything else?
Link to rust playground