about summary refs log tree commit diff
path: root/compiler/rustc_lint
diff options
context:
space:
mode:
authorOli Scherer <github333195615777966@oli-obk.de>2025-02-05 15:22:10 +0000
committerOli Scherer <github333195615777966@oli-obk.de>2025-03-06 10:03:11 +0000
commit0e7b2835735fc7fee08505fa6c14670bc7ee7601 (patch)
tree66e56105fd9b954d4217c828bf865929b6b8f0c2 /compiler/rustc_lint
parent4f2b108816e782f68d5964bec74448c04bd36ac5 (diff)
downloadrust-0e7b2835735fc7fee08505fa6c14670bc7ee7601.tar.gz
rust-0e7b2835735fc7fee08505fa6c14670bc7ee7601.zip
Avoid having to handle an `Option` in the type system
Diffstat (limited to 'compiler/rustc_lint')
-rw-r--r--compiler/rustc_lint/src/types.rs24
1 files changed, 8 insertions, 16 deletions
diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs
index 8304d533c26..d873d9fca64 100644
--- a/compiler/rustc_lint/src/types.rs
+++ b/compiler/rustc_lint/src/types.rs
@@ -883,22 +883,14 @@ fn ty_is_known_nonnull<'tcx>(
                     try {
                         match **pat {
                             ty::PatternKind::Range { start, end, include_end } => {
-                                match (start, end) {
-                                    (Some(start), None) => {
-                                        start.try_to_value()?.try_to_bits(tcx, typing_env)? > 0
-                                    }
-                                    (Some(start), Some(end)) => {
-                                        let start =
-                                            start.try_to_value()?.try_to_bits(tcx, typing_env)?;
-                                        let end =
-                                            end.try_to_value()?.try_to_bits(tcx, typing_env)?;
-
-                                        match include_end {
-                                            RangeEnd::Included => start > 0 && end >= start,
-                                            RangeEnd::Excluded => start > 0 && end > start,
-                                        }
-                                    }
-                                    _ => false,
+                                let start = start.try_to_value()?.try_to_bits(tcx, typing_env)?;
+                                let end = end.try_to_value()?.try_to_bits(tcx, typing_env)?;
+
+                                match include_end {
+                                    // This also works for negative numbers, as we just need
+                                    // to ensure we aren't wrapping over zero.
+                                    RangeEnd::Included => start > 0 && end >= start,
+                                    RangeEnd::Excluded => start > 0 && end > start,
                                 }
                             }
                         }