@@ -67,6 +67,7 @@ declare_lint_pass! {
67
67
MISSING_FRAGMENT_SPECIFIER ,
68
68
MUST_NOT_SUSPEND ,
69
69
NAMED_ARGUMENTS_USED_POSITIONALLY ,
70
+ NON_CONTIGUOUS_RANGE_ENDPOINTS ,
70
71
NON_EXHAUSTIVE_OMITTED_PATTERNS ,
71
72
ORDER_DEPENDENT_TRAIT_OBJECTS ,
72
73
OVERLAPPING_RANGE_ENDPOINTS ,
@@ -812,6 +813,36 @@ declare_lint! {
812
813
"detects range patterns with overlapping endpoints"
813
814
}
814
815
816
+ declare_lint ! {
817
+ /// The `non_contiguous_range_endpoints` lint detects likely off-by-one errors when using
818
+ /// exclusive [range patterns].
819
+ ///
820
+ /// [range patterns]: https://doc.rust-lang.org/nightly/reference/patterns.html#range-patterns
821
+ ///
822
+ /// ### Example
823
+ ///
824
+ /// ```rust
825
+ /// # #![feature(exclusive_range_pattern)]
826
+ /// let x = 123u32;
827
+ /// match x {
828
+ /// 0..100 => { println!("small"); }
829
+ /// 101..1000 => { println!("large"); }
830
+ /// _ => { println!("larger"); }
831
+ /// }
832
+ /// ```
833
+ ///
834
+ /// {{produces}}
835
+ ///
836
+ /// ### Explanation
837
+ ///
838
+ /// It is likely a mistake to have range patterns in a match expression that miss out a single
839
+ /// number. Check that the beginning and end values are what you expect, and keep in mind that
840
+ /// with `..=` the right bound is inclusive, and with `..` it is exclusive.
841
+ pub NON_CONTIGUOUS_RANGE_ENDPOINTS ,
842
+ Warn ,
843
+ "detects off-by-one errors with exclusive range patterns"
844
+ }
845
+
815
846
declare_lint ! {
816
847
/// The `bindings_with_variant_name` lint detects pattern bindings with
817
848
/// the same name as one of the matched variants.
0 commit comments