Skip to content

Consider operator's span when computing binop expr span #144711

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

Merged
merged 1 commit into from
Jul 31, 2025

Conversation

compiler-errors
Copy link
Member

When computing the span of a binop consisting of lhs and rhs, we previously just took the spans of lhs.span.to(rhs.span). In the case that both lhs and rhs are both arguments to a macro, this can produce a wildly incorrect span.

To fix this, first compute the span between lhs and the binary operator, which will cause lhs to possibly be adjusted to a relevant macro metavar, and then compute that span extended to rhs, which will cause it to also be adjusted to a relevant macro metavar.

This coincidentally fixes a FIXME in tests/ui/lint/wide_pointer_comparisons.rs and suppresses a nonsense suggestion.

@rustbot
Copy link
Collaborator

rustbot commented Jul 31, 2025

r? @petrochenkov

rustbot has assigned @petrochenkov.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 31, 2025
@petrochenkov
Copy link
Contributor

Nice, this is a part of #126763.

@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Collaborator

bors commented Jul 31, 2025

📌 Commit 51cd9b5 has been approved by petrochenkov

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 31, 2025
bors added a commit that referenced this pull request Jul 31, 2025
Rollup of 6 pull requests

Successful merges:

 - #144688 (Uniform `enter_trace_span!` and add documentation)
 - #144702 (stall `ConstArgHasType` in `compute_goal_fast_path`)
 - #144711 (Consider operator's span when computing binop expr span)
 - #144712 (Deduplicate `IntTy`/`UintTy`/`FloatTy`.)
 - #144726 (merge rustc_attr_data_structures into rustc_hir)
 - #144733 (fix: Match width of ascii and unicode secondary file start)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit edd2574 into rust-lang:master Jul 31, 2025
10 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jul 31, 2025
rust-timer added a commit that referenced this pull request Jul 31, 2025
Rollup merge of #144711 - compiler-errors:op-span, r=petrochenkov

Consider operator's span when computing binop expr span

When computing the span of a binop consisting of `lhs` and `rhs`, we previously just took the spans of `lhs.span.to(rhs.span)`. In the case that both `lhs` and `rhs` are both arguments to a macro, this can produce a wildly incorrect span.

To fix this, first compute the span between `lhs` and the binary operator, which will cause `lhs` to possibly be adjusted to a relevant macro metavar, and then compute that span extended to `rhs`, which will cause it to also be adjusted to a relevant macro metavar.

This coincidentally fixes a FIXME in `tests/ui/lint/wide_pointer_comparisons.rs` and suppresses a nonsense suggestion.
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Aug 1, 2025
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#144688 (Uniform `enter_trace_span!` and add documentation)
 - rust-lang/rust#144702 (stall `ConstArgHasType` in `compute_goal_fast_path`)
 - rust-lang/rust#144711 (Consider operator's span when computing binop expr span)
 - rust-lang/rust#144712 (Deduplicate `IntTy`/`UintTy`/`FloatTy`.)
 - rust-lang/rust#144726 (merge rustc_attr_data_structures into rustc_hir)
 - rust-lang/rust#144733 (fix: Match width of ascii and unicode secondary file start)

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants