@@ -79,7 +79,10 @@ impl<'tcx> Visitor<'tcx> for MatchVisitor<'_, '_, 'tcx> {
7979 intravisit:: walk_local ( self , loc) ;
8080 let els = loc. els ;
8181 if let Some ( init) = loc. init && els. is_some ( ) {
82- self . check_let ( & loc. pat , init, loc. span ) ;
82+ // Build a span without the else { ... } as we don't want to underline
83+ // the entire else block in the IDE setting.
84+ let span = loc. span . with_hi ( init. span . hi ( ) ) ;
85+ self . check_let ( & loc. pat , init, span) ;
8386 }
8487
8588 let ( msg, sp) = match loc. source {
@@ -630,11 +633,6 @@ fn irrefutable_let_patterns(
630633 count : usize ,
631634 span : Span ,
632635) {
633- let span = match source {
634- LetSource :: LetElse ( span) => span,
635- _ => span,
636- } ;
637-
638636 macro_rules! emit_diag {
639637 (
640638 $lint: expr,
@@ -680,7 +678,7 @@ fn irrefutable_let_patterns(
680678 "removing the guard and adding a `let` inside the match arm"
681679 ) ;
682680 }
683- LetSource :: LetElse ( .. ) => {
681+ LetSource :: LetElse => {
684682 emit_diag ! (
685683 lint,
686684 "`let...else`" ,
@@ -1127,7 +1125,7 @@ pub enum LetSource {
11271125 GenericLet ,
11281126 IfLet ,
11291127 IfLetGuard ,
1130- LetElse ( Span ) ,
1128+ LetElse ,
11311129 WhileLet ,
11321130}
11331131
@@ -1156,8 +1154,8 @@ fn let_source_parent(tcx: TyCtxt<'_>, parent: HirId, pat_id: Option<HirId>) -> L
11561154 let parent_parent = hir. get_parent_node ( parent) ;
11571155 let parent_parent_node = hir. get ( parent_parent) ;
11581156 match parent_parent_node {
1159- hir:: Node :: Stmt ( hir:: Stmt { kind : hir:: StmtKind :: Local ( _) , span , .. } ) => {
1160- return LetSource :: LetElse ( * span ) ;
1157+ hir:: Node :: Stmt ( hir:: Stmt { kind : hir:: StmtKind :: Local ( _) , .. } ) => {
1158+ return LetSource :: LetElse ;
11611159 }
11621160 hir:: Node :: Arm ( hir:: Arm { guard : Some ( hir:: Guard :: If ( _) ) , .. } ) => {
11631161 return LetSource :: IfLetGuard ;
0 commit comments