Skip to content

Commit f505cc9

Browse files
author
binggh
committed
Easier readability for needless_late_init
1 parent 0ceacbe commit f505cc9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

clippy_lints/src/needless_late_init.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clippy_utils::path_to_local;
33
use clippy_utils::source::snippet_opt;
44
use clippy_utils::ty::needs_ordered_drop;
55
use clippy_utils::visitors::{expr_visitor, expr_visitor_no_bodies, is_local_used};
6-
use rustc_errors::Applicability;
6+
use rustc_errors::{Applicability, MultiSpan};
77
use rustc_hir::intravisit::Visitor;
88
use rustc_hir::{
99
BindingAnnotation, Block, Expr, ExprKind, HirId, Local, LocalSource, MatchSource, Node, Pat, PatKind, Stmt,
@@ -267,11 +267,14 @@ fn check<'tcx>(
267267
match usage.expr.kind {
268268
ExprKind::Assign(..) => {
269269
let assign = LocalAssign::new(cx, usage.expr, binding_id)?;
270+
let mut msg_span = MultiSpan::from_spans(vec![local_stmt.span, assign.span]);
271+
msg_span.push_span_label(local_stmt.span, "created here");
272+
msg_span.push_span_label(assign.span, "initialised here");
270273

271274
span_lint_and_then(
272275
cx,
273276
NEEDLESS_LATE_INIT,
274-
local_stmt.span,
277+
msg_span,
275278
"unneeded late initialization",
276279
|diag| {
277280
diag.tool_only_span_suggestion(
@@ -365,7 +368,6 @@ fn check<'tcx>(
365368
impl<'tcx> LateLintPass<'tcx> for NeedlessLateInit {
366369
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) {
367370
let mut parents = cx.tcx.hir().parent_iter(local.hir_id);
368-
369371
if_chain! {
370372
if let Local {
371373
init: None,

0 commit comments

Comments
 (0)