Skip to content

Commit 1d7d4e9

Browse files
committed
1 parent 43ac941 commit 1d7d4e9

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

clippy_lints/src/matches.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -713,16 +713,18 @@ fn all_ranges<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arms: &'tcx [Arm<'_>]) -> Ve
713713
} = *arm
714714
{
715715
if let PatKind::Range(ref lhs, ref rhs, ref range_end) = pat.kind {
716-
let lhs = constant(cx, cx.tables, lhs)?.0;
717-
let rhs = constant(cx, cx.tables, rhs)?.0;
718-
let rhs = match *range_end {
719-
RangeEnd::Included => Bound::Included(rhs),
720-
RangeEnd::Excluded => Bound::Excluded(rhs),
721-
};
722-
return Some(SpannedRange {
723-
span: pat.span,
724-
node: (lhs, rhs),
725-
});
716+
if let (Some(l), Some(r)) = (lhs, rhs) {
717+
let lhs = constant(cx, cx.tables, l)?.0;
718+
let rhs = constant(cx, cx.tables, r)?.0;
719+
let rhs = match *range_end {
720+
RangeEnd::Included => Bound::Included(rhs),
721+
RangeEnd::Excluded => Bound::Excluded(rhs),
722+
};
723+
return Some(SpannedRange {
724+
span: pat.span,
725+
node: (lhs, rhs),
726+
});
727+
}
726728
}
727729

728730
if let PatKind::Lit(ref value) = pat.kind {

clippy_lints/src/utils/author.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -617,9 +617,13 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
617617
start_pat, end_pat, end_kind, current
618618
);
619619
self.current = start_pat;
620-
self.visit_expr(start);
620+
if let Some(expr) = start {
621+
self.visit_expr(expr);
622+
}
621623
self.current = end_pat;
622-
self.visit_expr(end);
624+
if let Some(expr) = end {
625+
self.visit_expr(expr);
626+
}
623627
},
624628
PatKind::Slice(ref start, ref middle, ref end) => {
625629
let start_pat = self.next("start");

clippy_lints/src/utils/hir_utils.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,10 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
195195
ls == rs && over(l, r, |l, r| self.eq_pat(l, r))
196196
},
197197
(&PatKind::Range(ref ls, ref le, ref li), &PatKind::Range(ref rs, ref re, ref ri)) => {
198-
self.eq_expr(ls, rs) && self.eq_expr(le, re) && (*li == *ri)
198+
if let (Some(ls), Some(rs), Some(le), Some(re)) = (ls, rs, le, re) {
199+
return self.eq_expr(ls, rs) && self.eq_expr(le, re) && (*li == *ri);
200+
}
201+
false
199202
},
200203
(&PatKind::Ref(ref le, ref lm), &PatKind::Ref(ref re, ref rm)) => lm == rm && self.eq_pat(le, re),
201204
(&PatKind::Slice(ref ls, ref li, ref le), &PatKind::Slice(ref rs, ref ri, ref re)) => {

clippy_lints/src/utils/inspector.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,12 @@ fn print_pat(cx: &LateContext<'_, '_>, pat: &hir::Pat<'_>, indent: usize) {
483483
},
484484
hir::PatKind::Range(ref l, ref r, ref range_end) => {
485485
println!("{}Range", ind);
486-
print_expr(cx, l, indent + 1);
487-
print_expr(cx, r, indent + 1);
486+
if let Some(expr) = l {
487+
print_expr(cx, expr, indent + 1);
488+
}
489+
if let Some(expr) = r {
490+
print_expr(cx, expr, indent + 1);
491+
}
488492
match *range_end {
489493
hir::RangeEnd::Included => println!("{} end included", ind),
490494
hir::RangeEnd::Excluded => println!("{} end excluded", ind),

0 commit comments

Comments
 (0)