From: binggh Date: Tue, 3 May 2022 09:51:23 +0000 (+0800) Subject: Easier readability for needless_late_init X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=f505cc9f7265eee332984f30516852e24d6e8385;p=rust.git Easier readability for needless_late_init --- diff --git a/clippy_lints/src/needless_late_init.rs b/clippy_lints/src/needless_late_init.rs index a863a7990ca..b70871b38be 100644 --- a/clippy_lints/src/needless_late_init.rs +++ b/clippy_lints/src/needless_late_init.rs @@ -3,7 +3,7 @@ use clippy_utils::source::snippet_opt; use clippy_utils::ty::needs_ordered_drop; use clippy_utils::visitors::{expr_visitor, expr_visitor_no_bodies, is_local_used}; -use rustc_errors::Applicability; +use rustc_errors::{Applicability, MultiSpan}; use rustc_hir::intravisit::Visitor; use rustc_hir::{ BindingAnnotation, Block, Expr, ExprKind, HirId, Local, LocalSource, MatchSource, Node, Pat, PatKind, Stmt, @@ -267,11 +267,14 @@ fn check<'tcx>( match usage.expr.kind { ExprKind::Assign(..) => { let assign = LocalAssign::new(cx, usage.expr, binding_id)?; + let mut msg_span = MultiSpan::from_spans(vec![local_stmt.span, assign.span]); + msg_span.push_span_label(local_stmt.span, "created here"); + msg_span.push_span_label(assign.span, "initialised here"); span_lint_and_then( cx, NEEDLESS_LATE_INIT, - local_stmt.span, + msg_span, "unneeded late initialization", |diag| { diag.tool_only_span_suggestion( @@ -365,7 +368,6 @@ fn check<'tcx>( impl<'tcx> LateLintPass<'tcx> for NeedlessLateInit { fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) { let mut parents = cx.tcx.hir().parent_iter(local.hir_id); - if_chain! { if let Local { init: None,