Skip to content

Suppress garbled suggestions from strict provenance lints in macros#156861

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Dnreikronos:fix/strict-provenance-macro-suggestions
May 25, 2026
Merged

Suppress garbled suggestions from strict provenance lints in macros#156861
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Dnreikronos:fix/strict-provenance-macro-suggestions

Conversation

@Dnreikronos

@Dnreikronos Dnreikronos commented May 23, 2026

Copy link
Copy Markdown
Contributor

The strict provenance lints (lossy_provenance_casts, fuzzy_provenance_casts) build suggestions using span arithmetic (shrink_to_lo(), shrink_to_hi(), .to()). When the cast sits inside a macro, those span operations produce broken output like $e as ).addr() because the spans don't map cleanly back to source text.

The fix wraps suggestion fields in Option and checks can_be_used_for_suggestions() before constructing them. The lint itself still fires, you just don't get the garbled suggestion. Same approach already used in op.rs and static_mut_refs.rs in this crate.

What changed

  • errors.rs: sugg fields in LossyProvenanceInt2Ptr and LossyProvenancePtr2Int are now Option<...>
  • cast.rs: suggestion construction in both lossy_provenance_ptr2int_lint and fuzzy_provenance_int2ptr_lint is guarded behind can_be_used_for_suggestions()
  • New regression test confirms both lints fire on casts inside macros, with no suggestion block in output

Fixes #156850

@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 May 23, 2026
@rustbot

rustbot commented May 23, 2026

Copy link
Copy Markdown
Collaborator

r? @TaKO8Ki

rustbot has assigned @TaKO8Ki.
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 73 candidates
  • Random selection from 18 candidates

@rustbot

This comment has been minimized.

@P8L1

This comment has been minimized.

@Dnreikronos Dnreikronos force-pushed the fix/strict-provenance-macro-suggestions branch from 46ace1f to 2afd8d3 Compare May 23, 2026 20:00

@mu001999 mu001999 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment thread compiler/rustc_hir_typeck/src/cast.rs Outdated
Comment thread compiler/rustc_hir_typeck/src/cast.rs Outdated
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 24, 2026
@rustbot

rustbot commented May 24, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot rustbot assigned mu001999 and unassigned TaKO8Ki May 24, 2026
@Dnreikronos Dnreikronos force-pushed the fix/strict-provenance-macro-suggestions branch 2 times, most recently from 0e706a1 to 13fae85 Compare May 24, 2026 15:01
Comment thread tests/ui/lint/lint-strict-provenance-macro-casts.rs
@Dnreikronos Dnreikronos force-pushed the fix/strict-provenance-macro-suggestions branch from 13fae85 to ccac0d9 Compare May 24, 2026 15:58
@Dnreikronos Dnreikronos requested a review from mu001999 May 24, 2026 16:03
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 24, 2026
@Dnreikronos

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@mu001999 mu001999 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@rust-bors

rust-bors Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor

📌 Commit ccac0d9 has been approved by mu001999

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 May 25, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request May 25, 2026
…stions, r=mu001999

Suppress garbled suggestions from strict provenance lints in macros

The strict provenance lints (`lossy_provenance_casts`, `fuzzy_provenance_casts`) build suggestions using span arithmetic (`shrink_to_lo()`, `shrink_to_hi()`, `.to()`). When the cast sits inside a macro, those span operations produce broken output like `$e as ).addr()` because the spans don't map cleanly back to source text.

The fix wraps suggestion fields in `Option` and checks `can_be_used_for_suggestions()` before constructing them. The lint itself still fires, you just don't get the garbled suggestion. Same approach already used in `op.rs` and `static_mut_refs.rs` in this crate.

### What changed

- `errors.rs`: `sugg` fields in `LossyProvenanceInt2Ptr` and `LossyProvenancePtr2Int` are now `Option<...>`
- `cast.rs`: suggestion construction in both `lossy_provenance_ptr2int_lint` and `fuzzy_provenance_int2ptr_lint` is guarded behind `can_be_used_for_suggestions()`
- New regression test confirms both lints fire on casts inside macros, with no suggestion block in output

Fixes #156850
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
...............................F.................. (50/143)
.................................................. (100/143)
...........................................        (143/143)

======== tests/rustdoc-gui/go-to-collapsed-elem.goml ========

[ERROR] line 25
    at `tests/rustdoc-gui/go-to-collapsed-elem.goml` line 21: request failed: [GET file:///checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc-gui/doc/trait.impl/lib2/scroll_traits/trait.Iterator.js]: net::ERR_FILE_NOT_FOUND


<= doc-ui tests done: 142 succeeded, 1 failed, 0 filtered out

Error: ()

@rust-bors rust-bors Bot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 25, 2026
@rust-bors rust-bors Bot removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label May 25, 2026
@rust-bors

rust-bors Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor

💔 Test for 04f346b failed: CI. Failed job:

@mu001999

Copy link
Copy Markdown
Member

@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 May 25, 2026
@rust-bors

This comment has been minimized.

@rust-bors rust-bors Bot added merged-by-bors This PR was explicitly merged by bors. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 25, 2026
@rust-bors

rust-bors Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor

☀️ Test successful - CI
Approved by: mu001999
Duration: 3h 12m 33s
Pushing 783eb8c to main...

@rust-bors rust-bors Bot merged commit 783eb8c into rust-lang:main May 25, 2026
12 checks passed
@rustbot rustbot added this to the 1.98.0 milestone May 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor
What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 5b686bc (parent) -> 783eb8c (this PR)

Test differences

Show 4 test diffs

Stage 1

  • [ui] tests/ui/lint/lint-strict-provenance-macro-casts.rs: [missing] -> pass (J1)

Stage 2

  • [ui] tests/ui/lint/lint-strict-provenance-macro-casts.rs: [missing] -> pass (J0)

Additionally, 2 doctest diffs were found. These are ignored, as they are noisy.

Job group index

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 783eb8c8682ddde0807c60ed8293670ef523794f --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. dist-i686-mingw: 2h 32m -> 1h 32m (-39.1%)
  2. i686-gnu-1: 1h 40m -> 2h 12m (+31.4%)
  3. x86_64-msvc-ext1: 1h 45m -> 2h 18m (+31.0%)
  4. dist-aarch64-linux: 2h 35m -> 1h 55m (-26.0%)
  5. x86_64-mingw-1: 2h 51m -> 2h 11m (-23.3%)
  6. dist-powerpc-linux: 1h 36m -> 1h 14m (-22.4%)
  7. dist-aarch64-apple: 1h 39m -> 2h (+21.2%)
  8. x86_64-gnu-aux: 2h 14m -> 1h 46m (-20.9%)
  9. x86_64-mingw-2: 2h 38m -> 2h 5m (-20.7%)
  10. dist-x86_64-mingw: 2h 32m -> 2h 2m (-19.8%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (783eb8c): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This perf run didn't have relevant results for this metric.

Max RSS (memory usage)

Results (primary -4.4%, secondary -7.3%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-4.4% [-4.4%, -4.4%] 1
Improvements ✅
(secondary)
-7.3% [-7.3%, -7.3%] 1
All ❌✅ (primary) -4.4% [-4.4%, -4.4%] 1

Cycles

Results (primary -1.8%, secondary 3.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.1% [2.9%, 3.4%] 2
Improvements ✅
(primary)
-1.8% [-1.8%, -1.8%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -1.8% [-1.8%, -1.8%] 1

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 509.684s -> 511.327s (0.32%)
Artifact size: 400.68 MiB -> 400.66 MiB (-0.00%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. 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.

Invalid suggestions from strict provenance lint with macros

7 participants