Skip to content

collapsible_span_lint_calls mangles macro invocations #15880

@ada4a

Description

@ada4a

Summary

The suggestion contains the expansion of format!

Reproducer

I tried this code:

fn foo(cx: &LateContext<'_>, expr: &Expr<'_>, lint: &'static Lint, too_generic_to_ty: Ty) { span_lint_and_then( cx, lint, expr.span, format!("casting from `{cast_from}` to a possibly more-strictly-aligned pointer (`{cast_to}`)"), |diag| { diag.note(format!("the alignment of the target pointer isn't known because the alignment of `{too_generic_to_ty}` can vary")); }, ); }

I expected to see this happen:

help: collapse into | 57 ~ span_lint_and_note(cx, lint, expr.span, format!("casting from `{cast_from}` to a possibly more-strictly-aligned pointer (`{cast_to}`)"), None, format!("the alignment of the target pointer isn't known because the alignment of `{too_generic_to_ty}` can vary")); 

Instead, this happened:

help: collapse into | 57 ~ span_lint_and_note(cx, lint, expr.span, $crate::__export::must_use({ 58 + $crate::fmt::format($crate::__export::format_args!($($arg)*)) 59 + }), None, $crate::__export::must_use({ 60 + $crate::fmt::format($crate::__export::format_args!($($arg)*)) 61 ~ })); 

Version

rustc 1.92.0-nightly (839222065 2025-10-05) binary: rustc commit-hash: 839222065a44ac21c15df68ed2f2f3c0127b0b8e commit-date: 2025-10-05 host: x86_64-unknown-linux-gnu release: 1.92.0-nightly LLVM version: 21.1.2 

Additional Labels

@rustbot claim

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions