From 05d3d17248d63314e9c1bef1c6380b53e2f141ea Mon Sep 17 00:00:00 2001 From: Urgau Date: Wed, 25 Jun 2025 23:03:18 +0200 Subject: Fix suggestion spans inside macros for the `unused_must_use` lint --- compiler/rustc_lint/src/unused.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'compiler/rustc_lint/src') diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index a868c887493..a206f71e153 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -183,6 +183,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults { let mut op_warned = false; if let Some(must_use_op) = must_use_op { + let span = expr.span.find_oldest_ancestor_in_same_ctxt(); cx.emit_span_lint( UNUSED_MUST_USE, expr.span, @@ -191,11 +192,11 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults { label: expr.span, suggestion: if expr_is_from_block { UnusedOpSuggestion::BlockTailExpr { - before_span: expr.span.shrink_to_lo(), - after_span: expr.span.shrink_to_hi(), + before_span: span.shrink_to_lo(), + after_span: span.shrink_to_hi(), } } else { - UnusedOpSuggestion::NormalExpr { span: expr.span.shrink_to_lo() } + UnusedOpSuggestion::NormalExpr { span: span.shrink_to_lo() } }, }, ); @@ -508,9 +509,10 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults { ); } MustUsePath::Def(span, def_id, reason) => { + let span = span.find_oldest_ancestor_in_same_ctxt(); cx.emit_span_lint( UNUSED_MUST_USE, - *span, + span, UnusedDef { pre: descr_pre, post: descr_post, -- cgit 1.4.1-3-g733a5