Skip to content

Avoid a bogus THIR span for let x = offset_of!(..)#152284

Merged
rust-bors[bot] merged 2 commits intorust-lang:mainfrom
Zalathar:bogus-thir-let
Feb 8, 2026
Merged

Avoid a bogus THIR span for let x = offset_of!(..)#152284
rust-bors[bot] merged 2 commits intorust-lang:mainfrom
Zalathar:bogus-thir-let

Conversation

@Zalathar
Copy link
Member

@Zalathar Zalathar commented Feb 7, 2026

The code that creates spans for THIR let statements was doing span endpoint manipulation without checking for inclusion/context, resulting in bogus spans observed in #151693.

The incorrect spans are easiest to observe with -Zunpretty=thir-tree, but they also cause strange user-facing diagnostics for irrefutable let-else.

@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 Feb 7, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 7, 2026

r? @nnethercote

rustbot has assigned @nnethercote.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 21 candidates
  • Random selection from 12 candidates

@Zalathar
Copy link
Member Author

Zalathar commented Feb 7, 2026

cc @jyn514 as this should resolve #151693

@Zalathar
Copy link
Member Author

Zalathar commented Feb 7, 2026

I could also imagine making MatchVisitor::check_let more sophisticated about how it uses spans for diagnostics, avoiding the need for any span adjustment at this site, but that would be a deeper and trickier change.

@nnethercote
Copy link
Contributor

@bors r+ rollup

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 8, 2026

📌 Commit cc3fdc6 has been approved by nnethercote

It is now in the queue for this repository.

@rust-bors rust-bors bot 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 Feb 8, 2026
@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Feb 8, 2026
Avoid a bogus THIR span for `let x = offset_of!(..)`

The code that creates spans for THIR `let` statements was doing span endpoint manipulation without checking for inclusion/context, resulting in bogus spans observed in #151693.

The incorrect spans are easiest to observe with `-Zunpretty=thir-tree`, but they also cause strange user-facing diagnostics for irrefutable let-else.
@rust-bors rust-bors bot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 8, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 8, 2026

💔 Test for ff65aad failed: CI. Failed job:

@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
REPOSITORY                                   TAG       IMAGE ID       CREATED      SIZE
ghcr.io/dependabot/dependabot-updater-core   latest    b72a662c47e3   8 days ago   790MB
=> Removing docker images...
Deleted Images:
untagged: ghcr.io/dependabot/dependabot-updater-core:latest
untagged: ghcr.io/dependabot/dependabot-updater-core@sha256:57ef9cc45f72cc4258ee1baa8243bc3cd55c0a0e570b6768c37346247be35f0d
deleted: sha256:b72a662c47e31df2e7bf59368b2b83be239f02a1baa721393717711a1a719df9
deleted: sha256:3e13ccd80f19769f39008cfc6549938e1ea4905f47b028c1df2dd6085191386c
deleted: sha256:842807995a512b2c5a9b241a3aecdbe79af6b0642d96fa5460cfcf0c9d8be295
deleted: sha256:0f9074b9f46f4570eb7cb4b65fcb3c3d909f9b1d14ca66b30508117b6deda303
deleted: sha256:2ca99cb9251d19157c56b5d91c8961bb4b35196a5ca9b4ffdccbf24abbfe2a5f

@Zalathar
Copy link
Member Author

Zalathar commented Feb 8, 2026

Failure looks Docker-related, so probably bogus.

@bors retry

@rust-bors rust-bors bot 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 Feb 8, 2026
rust-bors bot pushed a commit that referenced this pull request Feb 8, 2026
Rollup of 2 pull requests

Successful merges:

 - #152310 (Remove `rustdoc` adhoc group)
 - #152284 (Avoid a bogus THIR span for `let x = offset_of!(..)`)
init.span.find_ancestor_inside_same_ctxt(local.span) =>
{
local.span.with_hi(init_span.hi())
}
Copy link
Contributor

@cjgillot cjgillot Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just init.span.to(local.span)?

Copy link
Member Author

@Zalathar Zalathar Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partly because I didn't remember that until existed, but also I think it's doing something subtly different?

This code caps local.span.hi to init_span.hi, but Span::until would cap it to init_span.lo.

Oh I think I misread your suggestion; let me think about it again.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand it, local.span is the span of the entire let-statement, and init.span is the span of the RHS:

let x = offset_of!(Foo, field) else { return; }
        ^^^^^^^^^^^^^^^^^^^^^^ init.span
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ local.span
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ (what the old+new code is trying to get)

I don't think using Span::until with local.span can ever get the desired result.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Honestly local is kind of a bad name for the let statement; I assume it was overlooked by the rename from StmtKind::Local to StmtKind::Let in #122487.)

@rust-bors rust-bors bot merged commit 1992e71 into rust-lang:main Feb 8, 2026
11 of 12 checks passed
rust-timer added a commit that referenced this pull request Feb 8, 2026
Rollup merge of #152284 - Zalathar:bogus-thir-let, r=nnethercote

Avoid a bogus THIR span for `let x = offset_of!(..)`

The code that creates spans for THIR `let` statements was doing span endpoint manipulation without checking for inclusion/context, resulting in bogus spans observed in #151693.

The incorrect spans are easiest to observe with `-Zunpretty=thir-tree`, but they also cause strange user-facing diagnostics for irrefutable let-else.
@rustbot rustbot added this to the 1.95.0 milestone Feb 8, 2026
@Zalathar Zalathar deleted the bogus-thir-let branch February 8, 2026 05:50
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.

5 participants

Comments