mirror of
https://github.com/rust-lang/rust.git
synced 2026-06-01 14:10:03 +03:00
783eb8c868
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 rust-lang/rust#156850