1 use crate::consts::{constant, Constant};
2 use crate::utils::paths;
3 use crate::utils::sugg::Sugg;
5 expr_block, is_allowed, is_expn_of, match_qpath, match_type, multispan_sugg, remove_blocks, snippet,
6 snippet_with_applicability, span_lint_and_sugg, span_lint_and_then, span_note_and_lint, walk_ptrs_ty,
8 use if_chain::if_chain;
9 use rustc::declare_lint_pass;
10 use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass};
11 use rustc::ty::{self, Ty};
12 use rustc_errors::Applicability;
13 use rustc_hir::def::CtorKind;
15 use rustc_session::declare_tool_lint;
16 use rustc_span::source_map::Span;
17 use std::cmp::Ordering;
18 use std::collections::Bound;
19 use syntax::ast::LitKind;
21 declare_clippy_lint! {
22 /// **What it does:** Checks for matches with a single arm where an `if let`
23 /// will usually suffice.
25 /// **Why is this bad?** Just readability – `if let` nests less than a `match`.
27 /// **Known problems:** None.
31 /// # fn bar(stool: &str) {}
32 /// # let x = Some("abc");
34 /// Some(ref foo) => bar(foo),
40 "a `match` statement with a single nontrivial arm (i.e., where the other arm is `_ => {}`) instead of `if let`"
43 declare_clippy_lint! {
44 /// **What it does:** Checks for matches with two arms where an `if let else` will
47 /// **Why is this bad?** Just readability – `if let` nests less than a `match`.
49 /// **Known problems:** Personal style preferences may differ.
56 /// # fn bar(foo: &usize) {}
57 /// # let other_ref: usize = 1;
58 /// # let x: Option<&usize> = Some(&1);
60 /// Some(ref foo) => bar(foo),
61 /// _ => bar(&other_ref),
65 /// Using `if let` with `else`:
68 /// # fn bar(foo: &usize) {}
69 /// # let other_ref: usize = 1;
70 /// # let x: Option<&usize> = Some(&1);
71 /// if let Some(ref foo) = x {
77 pub SINGLE_MATCH_ELSE,
79 "a `match` statement with two arms where the second arm's pattern is a placeholder instead of a specific match pattern"
82 declare_clippy_lint! {
83 /// **What it does:** Checks for matches where all arms match a reference,
84 /// suggesting to remove the reference and deref the matched expression
85 /// instead. It also checks for `if let &foo = bar` blocks.
87 /// **Why is this bad?** It just makes the code less readable. That reference
88 /// destructuring adds nothing to the code.
90 /// **Known problems:** None.
95 /// &A(ref y) => foo(y),
102 "a `match` or `if let` with all arms prefixed with `&` instead of deref-ing the match expression"
105 declare_clippy_lint! {
106 /// **What it does:** Checks for matches where match expression is a `bool`. It
107 /// suggests to replace the expression with an `if...else` block.
109 /// **Why is this bad?** It makes the code less readable.
111 /// **Known problems:** None.
117 /// let condition: bool = true;
118 /// match condition {
123 /// Use if/else instead:
127 /// let condition: bool = true;
136 "a `match` on a boolean expression instead of an `if..else` block"
139 declare_clippy_lint! {
140 /// **What it does:** Checks for overlapping match arms.
142 /// **Why is this bad?** It is likely to be an error and if not, makes the code
145 /// **Known problems:** None.
151 /// 1...10 => println!("1 ... 10"),
152 /// 5...15 => println!("5 ... 15"),
156 pub MATCH_OVERLAPPING_ARM,
158 "a `match` with overlapping arms"
161 declare_clippy_lint! {
162 /// **What it does:** Checks for arm which matches all errors with `Err(_)`
163 /// and take drastic actions like `panic!`.
165 /// **Why is this bad?** It is generally a bad practice, just like
166 /// catching all exceptions in java with `catch(Exception)`
168 /// **Known problems:** None.
172 /// let x: Result<i32, &str> = Ok(3);
174 /// Ok(_) => println!("ok"),
175 /// Err(_) => panic!("err"),
178 pub MATCH_WILD_ERR_ARM,
180 "a `match` with `Err(_)` arm and take drastic actions"
183 declare_clippy_lint! {
184 /// **What it does:** Checks for match which is used to add a reference to an
187 /// **Why is this bad?** Using `as_ref()` or `as_mut()` instead is shorter.
189 /// **Known problems:** None.
193 /// let x: Option<()> = None;
194 /// let r: Option<&()> = match x {
196 /// Some(ref v) => Some(v),
201 "a `match` on an Option value instead of using `as_ref()` or `as_mut`"
204 declare_clippy_lint! {
205 /// **What it does:** Checks for wildcard enum matches using `_`.
207 /// **Why is this bad?** New enum variants added by library updates can be missed.
209 /// **Known problems:** Suggested replacements may be incorrect if guards exhaustively cover some
210 /// variants, and also may not use correct path to enum if it's not present in the current scope.
214 /// # enum Foo { A(usize), B(usize) }
215 /// # let x = Foo::B(1);
221 pub WILDCARD_ENUM_MATCH_ARM,
223 "a wildcard enum match arm using `_`"
226 declare_clippy_lint! {
227 /// **What it does:** Checks for wildcard pattern used with others patterns in same match arm.
229 /// **Why is this bad?** Wildcard pattern already covers any other pattern as it will match anyway.
230 /// It makes the code less readable, especially to spot wildcard pattern use in match arm.
232 /// **Known problems:** None.
241 pub PATS_WITH_WILD_MATCH_ARM,
243 "a wildcard pattern used with others patterns in same match arm"
246 declare_lint_pass!(Matches => [
251 MATCH_OVERLAPPING_ARM,
254 WILDCARD_ENUM_MATCH_ARM,
255 PATS_WITH_WILD_MATCH_ARM
258 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Matches {
259 fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
260 if in_external_macro(cx.sess(), expr.span) {
263 if let ExprKind::Match(ref ex, ref arms, MatchSource::Normal) = expr.kind {
264 check_single_match(cx, ex, arms, expr);
265 check_match_bool(cx, ex, arms, expr);
266 check_overlapping_arms(cx, ex, arms);
267 check_wild_err_arm(cx, ex, arms);
268 check_wild_enum_match(cx, ex, arms);
269 check_match_as_ref(cx, ex, arms, expr);
270 check_pats_wild_match(cx, ex, arms);
272 if let ExprKind::Match(ref ex, ref arms, _) = expr.kind {
273 check_match_ref_pats(cx, ex, arms, expr);
279 fn check_single_match(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) {
280 if arms.len() == 2 && arms[0].guard.is_none() && arms[1].guard.is_none() {
281 if let PatKind::Or(..) = arms[0].pat.kind {
282 // don't lint for or patterns for now, this makes
283 // the lint noisy in unnecessary situations
286 let els = remove_blocks(&arms[1].body);
287 let els = if is_unit_expr(els) {
289 } else if let ExprKind::Block(_, _) = els.kind {
290 // matches with blocks that contain statements are prettier as `if let + else`
293 // allow match arms with just expressions
296 let ty = cx.tables.expr_ty(ex);
297 if ty.kind != ty::Bool || is_allowed(cx, MATCH_BOOL, ex.hir_id) {
298 check_single_match_single_pattern(cx, ex, arms, expr, els);
299 check_single_match_opt_like(cx, ex, arms, expr, ty, els);
304 fn check_single_match_single_pattern(
305 cx: &LateContext<'_, '_>,
309 els: Option<&Expr<'_>>,
311 if is_wild(&arms[1].pat) {
312 report_single_match_single_pattern(cx, ex, arms, expr, els);
316 fn report_single_match_single_pattern(
317 cx: &LateContext<'_, '_>,
321 els: Option<&Expr<'_>>,
323 let lint = if els.is_some() { SINGLE_MATCH_ELSE } else { SINGLE_MATCH };
324 let els_str = els.map_or(String::new(), |els| {
325 format!(" else {}", expr_block(cx, els, None, ".."))
331 "you seem to be trying to use match for destructuring a single pattern. Consider using `if \
335 "if let {} = {} {}{}",
336 snippet(cx, arms[0].pat.span, ".."),
337 snippet(cx, ex.span, ".."),
338 expr_block(cx, &arms[0].body, None, ".."),
341 Applicability::HasPlaceholders,
345 fn check_single_match_opt_like(
346 cx: &LateContext<'_, '_>,
351 els: Option<&Expr<'_>>,
353 // list of candidate `Enum`s we know will never get any more members
355 (&paths::COW, "Borrowed"),
356 (&paths::COW, "Cow::Borrowed"),
357 (&paths::COW, "Cow::Owned"),
358 (&paths::COW, "Owned"),
359 (&paths::OPTION, "None"),
360 (&paths::RESULT, "Err"),
361 (&paths::RESULT, "Ok"),
364 let path = match arms[1].pat.kind {
365 PatKind::TupleStruct(ref path, ref inner, _) => {
366 // Contains any non wildcard patterns (e.g., `Err(err)`)?
367 if !inner.iter().all(is_wild) {
370 print::to_string(print::NO_ANN, |s| s.print_qpath(path, false))
372 PatKind::Binding(BindingAnnotation::Unannotated, .., ident, None) => ident.to_string(),
373 PatKind::Path(ref path) => print::to_string(print::NO_ANN, |s| s.print_qpath(path, false)),
377 for &(ty_path, pat_path) in candidates {
378 if path == *pat_path && match_type(cx, ty, ty_path) {
379 report_single_match_single_pattern(cx, ex, arms, expr, els);
384 fn check_match_bool(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) {
385 // Type of expression is `bool`.
386 if cx.tables.expr_ty(ex).kind == ty::Bool {
391 "you seem to be trying to match on a boolean expression",
395 let exprs = if let PatKind::Lit(ref arm_bool) = arms[0].pat.kind {
396 if let ExprKind::Lit(ref lit) = arm_bool.kind {
398 LitKind::Bool(true) => Some((&*arms[0].body, &*arms[1].body)),
399 LitKind::Bool(false) => Some((&*arms[1].body, &*arms[0].body)),
409 if let Some((true_expr, false_expr)) = exprs {
410 let sugg = match (is_unit_expr(true_expr), is_unit_expr(false_expr)) {
411 (false, false) => Some(format!(
413 snippet(cx, ex.span, "b"),
414 expr_block(cx, true_expr, None, ".."),
415 expr_block(cx, false_expr, None, "..")
417 (false, true) => Some(format!(
419 snippet(cx, ex.span, "b"),
420 expr_block(cx, true_expr, None, "..")
423 let test = Sugg::hir(cx, ex, "..");
424 Some(format!("if {} {}", !test, expr_block(cx, false_expr, None, "..")))
426 (true, true) => None,
429 if let Some(sugg) = sugg {
432 "consider using an `if`/`else` expression",
434 Applicability::HasPlaceholders,
444 fn check_overlapping_arms<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ex: &'tcx Expr<'_>, arms: &'tcx [Arm<'_>]) {
445 if arms.len() >= 2 && cx.tables.expr_ty(ex).is_integral() {
446 let ranges = all_ranges(cx, arms);
447 let type_ranges = type_ranges(&ranges);
448 if !type_ranges.is_empty() {
449 if let Some((start, end)) = overlapping(&type_ranges) {
452 MATCH_OVERLAPPING_ARM,
454 "some ranges overlap",
456 "overlaps with this",
463 fn is_wild<'tcx>(pat: &impl std::ops::Deref<Target = Pat<'tcx>>) -> bool {
465 PatKind::Wild => true,
470 fn check_wild_err_arm(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>]) {
471 let ex_ty = walk_ptrs_ty(cx.tables.expr_ty(ex));
472 if match_type(cx, ex_ty, &paths::RESULT) {
474 if let PatKind::TupleStruct(ref path, ref inner, _) = arm.pat.kind {
475 let path_str = print::to_string(print::NO_ANN, |s| s.print_qpath(path, false));
477 if path_str == "Err";
478 if inner.iter().any(is_wild);
479 if let ExprKind::Block(ref block, _) = arm.body.kind;
480 if is_panic_block(block);
482 // `Err(_)` arm with `panic!` found
483 span_note_and_lint(cx,
486 "`Err(_)` will match all errors, maybe not a good idea",
488 "to remove this warning, match each error separately \
489 or use `unreachable!` macro");
497 fn check_wild_enum_match(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>]) {
498 let ty = cx.tables.expr_ty(ex);
500 // If there isn't a nice closed set of possible values that can be conveniently enumerated,
501 // don't complain about not enumerating the mall.
505 // First pass - check for violation, but don't do much book-keeping because this is hopefully
506 // the uncommon case, and the book-keeping is slightly expensive.
507 let mut wildcard_span = None;
508 let mut wildcard_ident = None;
510 if let PatKind::Wild = arm.pat.kind {
511 wildcard_span = Some(arm.pat.span);
512 } else if let PatKind::Binding(_, _, ident, None) = arm.pat.kind {
513 wildcard_span = Some(arm.pat.span);
514 wildcard_ident = Some(ident);
518 if let Some(wildcard_span) = wildcard_span {
519 // Accumulate the variants which should be put in place of the wildcard because they're not
522 let mut missing_variants = vec![];
523 if let ty::Adt(def, _) = ty.kind {
524 for variant in &def.variants {
525 missing_variants.push(variant);
530 if arm.guard.is_some() {
531 // Guards mean that this case probably isn't exhaustively covered. Technically
532 // this is incorrect, as we should really check whether each variant is exhaustively
533 // covered by the set of guards that cover it, but that's really hard to do.
536 if let PatKind::Path(ref path) = arm.pat.kind {
537 if let QPath::Resolved(_, p) = path {
538 missing_variants.retain(|e| e.ctor_def_id != Some(p.res.def_id()));
540 } else if let PatKind::TupleStruct(ref path, ..) = arm.pat.kind {
541 if let QPath::Resolved(_, p) = path {
542 missing_variants.retain(|e| e.ctor_def_id != Some(p.res.def_id()));
547 let mut suggestion: Vec<String> = missing_variants
550 let suffix = match v.ctor_kind {
551 CtorKind::Fn => "(..)",
552 CtorKind::Const | CtorKind::Fictive => "",
554 let ident_str = if let Some(ident) = wildcard_ident {
555 format!("{} @ ", ident.name)
559 // This path assumes that the enum type is imported into scope.
560 format!("{}{}{}", ident_str, cx.tcx.def_path_str(v.def_id), suffix)
564 if suggestion.is_empty() {
568 let mut message = "wildcard match will miss any future added variants";
570 if let ty::Adt(def, _) = ty.kind {
571 if def.is_variant_list_non_exhaustive() {
572 message = "match on non-exhaustive enum doesn't explicitly match all known variants";
573 suggestion.push(String::from("_"));
579 WILDCARD_ENUM_MATCH_ARM,
583 suggestion.join(" | "),
584 Applicability::MachineApplicable,
589 // If the block contains only a `panic!` macro (as expression or statement)
590 fn is_panic_block(block: &Block<'_>) -> bool {
591 match (&block.expr, block.stmts.len(), block.stmts.first()) {
592 (&Some(ref exp), 0, _) => {
593 is_expn_of(exp.span, "panic").is_some() && is_expn_of(exp.span, "unreachable").is_none()
595 (&None, 1, Some(stmt)) => {
596 is_expn_of(stmt.span, "panic").is_some() && is_expn_of(stmt.span, "unreachable").is_none()
602 fn check_match_ref_pats(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) {
603 if has_only_ref_pats(arms) {
604 let mut suggs = Vec::new();
605 let (title, msg) = if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, ref inner) = ex.kind {
606 let span = ex.span.source_callsite();
607 suggs.push((span, Sugg::hir_with_macro_callsite(cx, inner, "..").to_string()));
609 "you don't need to add `&` to both the expression and the patterns",
613 let span = ex.span.source_callsite();
614 suggs.push((span, Sugg::hir_with_macro_callsite(cx, ex, "..").deref().to_string()));
616 "you don't need to add `&` to all patterns",
617 "instead of prefixing all patterns with `&`, you can dereference the expression",
621 suggs.extend(arms.iter().filter_map(|a| {
622 if let PatKind::Ref(ref refp, _) = a.pat.kind {
623 Some((a.pat.span, snippet(cx, refp.span, "..").to_string()))
629 span_lint_and_then(cx, MATCH_REF_PATS, expr.span, title, |db| {
630 if !expr.span.from_expansion() {
631 multispan_sugg(db, msg.to_owned(), suggs);
637 fn check_match_as_ref(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) {
638 if arms.len() == 2 && arms[0].guard.is_none() && arms[1].guard.is_none() {
639 let arm_ref: Option<BindingAnnotation> = if is_none_arm(&arms[0]) {
640 is_ref_some_arm(&arms[1])
641 } else if is_none_arm(&arms[1]) {
642 is_ref_some_arm(&arms[0])
646 if let Some(rb) = arm_ref {
647 let suggestion = if rb == BindingAnnotation::Ref {
653 let output_ty = cx.tables.expr_ty(expr);
654 let input_ty = cx.tables.expr_ty(ex);
656 let cast = if_chain! {
657 if let ty::Adt(_, substs) = input_ty.kind;
658 let input_ty = substs.type_at(0);
659 if let ty::Adt(_, substs) = output_ty.kind;
660 let output_ty = substs.type_at(0);
661 if let ty::Ref(_, output_ty, _) = output_ty.kind;
662 if input_ty != output_ty;
670 let mut applicability = Applicability::MachineApplicable;
675 &format!("use `{}()` instead", suggestion),
679 snippet_with_applicability(cx, ex.span, "_", &mut applicability),
689 fn check_pats_wild_match(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>]) {
690 let mut is_non_exhaustive_enum = false;
691 let ty = cx.tables.expr_ty(ex);
693 if let ty::Adt(def, _) = ty.kind {
694 if def.is_variant_list_non_exhaustive() {
695 is_non_exhaustive_enum = true;
701 if let PatKind::Or(ref fields) = arm.pat.kind {
702 // look for multiple fields in this arm that contains at least one Wild pattern
703 if fields.len() > 1 && fields.iter().any(is_wild) {
706 PATS_WITH_WILD_MATCH_ARM,
708 "wildcard pattern covers any other pattern as it will match anyway.",
710 // handle case where a non exhaustive enum is being used
711 if is_non_exhaustive_enum {
714 "consider handling `_` separately.",
715 "_ => ...".to_string(),
716 Applicability::MaybeIncorrect,
721 "consider replacing with wildcard pattern only",
723 Applicability::MachineApplicable,
733 /// Gets all arms that are unbounded `PatRange`s.
734 fn all_ranges<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arms: &'tcx [Arm<'_>]) -> Vec<SpannedRange<Constant>> {
738 ref pat, guard: None, ..
741 if let PatKind::Range(ref lhs, ref rhs, ref range_end) = pat.kind {
742 let lhs = constant(cx, cx.tables, lhs)?.0;
743 let rhs = constant(cx, cx.tables, rhs)?.0;
744 let rhs = match *range_end {
745 RangeEnd::Included => Bound::Included(rhs),
746 RangeEnd::Excluded => Bound::Excluded(rhs),
748 return Some(SpannedRange {
754 if let PatKind::Lit(ref value) = pat.kind {
755 let value = constant(cx, cx.tables, value)?.0;
756 return Some(SpannedRange {
758 node: (value.clone(), Bound::Included(value)),
767 #[derive(Debug, Eq, PartialEq)]
768 pub struct SpannedRange<T> {
770 pub node: (T, Bound<T>),
773 type TypedRanges = Vec<SpannedRange<u128>>;
775 /// Gets all `Int` ranges or all `Uint` ranges. Mixed types are an error anyway
776 /// and other types than
777 /// `Uint` and `Int` probably don't make sense.
778 fn type_ranges(ranges: &[SpannedRange<Constant>]) -> TypedRanges {
781 .filter_map(|range| match range.node {
782 (Constant::Int(start), Bound::Included(Constant::Int(end))) => Some(SpannedRange {
784 node: (start, Bound::Included(end)),
786 (Constant::Int(start), Bound::Excluded(Constant::Int(end))) => Some(SpannedRange {
788 node: (start, Bound::Excluded(end)),
790 (Constant::Int(start), Bound::Unbounded) => Some(SpannedRange {
792 node: (start, Bound::Unbounded),
799 fn is_unit_expr(expr: &Expr<'_>) -> bool {
801 ExprKind::Tup(ref v) if v.is_empty() => true,
802 ExprKind::Block(ref b, _) if b.stmts.is_empty() && b.expr.is_none() => true,
807 // Checks if arm has the form `None => None`
808 fn is_none_arm(arm: &Arm<'_>) -> bool {
810 PatKind::Path(ref path) if match_qpath(path, &paths::OPTION_NONE) => true,
815 // Checks if arm has the form `Some(ref v) => Some(v)` (checks for `ref` and `ref mut`)
816 fn is_ref_some_arm(arm: &Arm<'_>) -> Option<BindingAnnotation> {
818 if let PatKind::TupleStruct(ref path, ref pats, _) = arm.pat.kind;
819 if pats.len() == 1 && match_qpath(path, &paths::OPTION_SOME);
820 if let PatKind::Binding(rb, .., ident, _) = pats[0].kind;
821 if rb == BindingAnnotation::Ref || rb == BindingAnnotation::RefMut;
822 if let ExprKind::Call(ref e, ref args) = remove_blocks(&arm.body).kind;
823 if let ExprKind::Path(ref some_path) = e.kind;
824 if match_qpath(some_path, &paths::OPTION_SOME) && args.len() == 1;
825 if let ExprKind::Path(ref qpath) = args[0].kind;
826 if let &QPath::Resolved(_, ref path2) = qpath;
827 if path2.segments.len() == 1 && ident.name == path2.segments[0].ident.name;
835 fn has_only_ref_pats(arms: &[Arm<'_>]) -> bool {
840 PatKind::Ref(..) => Some(true), // &-patterns
841 PatKind::Wild => Some(false), // an "anything" wildcard is also fine
842 _ => None, // any other pattern is not fine
845 .collect::<Option<Vec<bool>>>();
846 // look for Some(v) where there's at least one true element
847 mapped.map_or(false, |v| v.iter().any(|el| *el))
850 pub fn overlapping<T>(ranges: &[SpannedRange<T>]) -> Option<(&SpannedRange<T>, &SpannedRange<T>)>
854 #[derive(Copy, Clone, Debug, Eq, PartialEq)]
856 Start(T, &'a SpannedRange<T>),
857 End(Bound<T>, &'a SpannedRange<T>),
860 impl<'a, T: Copy> Kind<'a, T> {
861 fn range(&self) -> &'a SpannedRange<T> {
863 Kind::Start(_, r) | Kind::End(_, r) => r,
867 fn value(self) -> Bound<T> {
869 Kind::Start(t, _) => Bound::Included(t),
870 Kind::End(t, _) => t,
875 impl<'a, T: Copy + Ord> PartialOrd for Kind<'a, T> {
876 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
877 Some(self.cmp(other))
881 impl<'a, T: Copy + Ord> Ord for Kind<'a, T> {
882 fn cmp(&self, other: &Self) -> Ordering {
883 match (self.value(), other.value()) {
884 (Bound::Included(a), Bound::Included(b)) | (Bound::Excluded(a), Bound::Excluded(b)) => a.cmp(&b),
885 // Range patterns cannot be unbounded (yet)
886 (Bound::Unbounded, _) | (_, Bound::Unbounded) => unimplemented!(),
887 (Bound::Included(a), Bound::Excluded(b)) => match a.cmp(&b) {
888 Ordering::Equal => Ordering::Greater,
891 (Bound::Excluded(a), Bound::Included(b)) => match a.cmp(&b) {
892 Ordering::Equal => Ordering::Less,
899 let mut values = Vec::with_capacity(2 * ranges.len());
902 values.push(Kind::Start(r.node.0, r));
903 values.push(Kind::End(r.node.1, r));
908 for (a, b) in values.iter().zip(values.iter().skip(1)) {
910 (&Kind::Start(_, ra), &Kind::End(_, rb)) => {
911 if ra.node != rb.node {
912 return Some((ra, rb));
915 (&Kind::End(a, _), &Kind::Start(b, _)) if a != Bound::Included(b) => (),
916 _ => return Some((a.range(), b.range())),