]> git.lizzy.rs Git - rust.git/commitdiff
Easier readability for needless_late_init
authorbinggh <binggh@proton.me>
Tue, 3 May 2022 09:51:23 +0000 (17:51 +0800)
committerbinggh <binggh@proton.me>
Tue, 3 May 2022 09:51:23 +0000 (17:51 +0800)
clippy_lints/src/needless_late_init.rs

index a863a7990ca8cd2afb834d9ab6e413101c70cc00..b70871b38beab178f63735330657ab8388e2f355 100644 (file)
@@ -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,