Skip to content

Suppress garbled suggestions from strict provenance lints in macros#156861

Open
Dnreikronos wants to merge 1 commit into
rust-lang:mainfrom
Dnreikronos:fix/strict-provenance-macro-suggestions
Open

Suppress garbled suggestions from strict provenance lints in macros#156861
Dnreikronos wants to merge 1 commit into
rust-lang:mainfrom
Dnreikronos:fix/strict-provenance-macro-suggestions

Conversation

@Dnreikronos
Copy link
Copy Markdown

@Dnreikronos Dnreikronos commented May 23, 2026

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
Copy link
Copy Markdown
Collaborator

rustbot commented May 23, 2026

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
Copy link
Copy Markdown
Member

@mu001999 mu001999 left a comment

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
Copy link
Copy Markdown
Collaborator

rustbot commented May 24, 2026

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
Author

@rustbot ready

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

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid suggestions from strict provenance lint with macros

5 participants