@@ -879,26 +879,34 @@ fn ty_is_known_nonnull<'tcx>(
879
879
}
880
880
ty:: Pat ( base, pat) => {
881
881
ty_is_known_nonnull ( tcx, typing_env, * base, mode)
882
- || Option :: unwrap_or_default (
883
- try {
884
- match * * pat {
885
- ty:: PatternKind :: Range { start, end } => {
886
- let start = start. try_to_value ( ) ?. try_to_bits ( tcx, typing_env) ?;
887
- let end = end. try_to_value ( ) ?. try_to_bits ( tcx, typing_env) ?;
888
-
889
- // This also works for negative numbers, as we just need
890
- // to ensure we aren't wrapping over zero.
891
- start > 0 && end >= start
892
- }
893
- ty:: PatternKind :: NotNull => true ,
894
- }
895
- } ,
896
- )
882
+ || pat_ty_is_known_nonnull ( tcx, typing_env, * pat)
897
883
}
898
884
_ => false ,
899
885
}
900
886
}
901
887
888
+ fn pat_ty_is_known_nonnull < ' tcx > (
889
+ tcx : TyCtxt < ' tcx > ,
890
+ typing_env : ty:: TypingEnv < ' tcx > ,
891
+ pat : ty:: Pattern < ' tcx > ,
892
+ ) -> bool {
893
+ Option :: unwrap_or_default (
894
+ try {
895
+ match * pat {
896
+ ty:: PatternKind :: Range { start, end } => {
897
+ let start = start. try_to_value ( ) ?. try_to_bits ( tcx, typing_env) ?;
898
+ let end = end. try_to_value ( ) ?. try_to_bits ( tcx, typing_env) ?;
899
+
900
+ // This also works for negative numbers, as we just need
901
+ // to ensure we aren't wrapping over zero.
902
+ start > 0 && end >= start
903
+ }
904
+ ty:: PatternKind :: NotNull => true ,
905
+ }
906
+ } ,
907
+ )
908
+ }
909
+
902
910
/// Given a non-null scalar (or transparent) type `ty`, return the nullable version of that type.
903
911
/// If the type passed in was not scalar, returns None.
904
912
fn get_nullable_type < ' tcx > (
@@ -1040,15 +1048,24 @@ pub(crate) fn repr_nullable_ptr<'tcx>(
1040
1048
}
1041
1049
None
1042
1050
}
1043
- ty:: Pat ( base, pat) => match * * pat {
1044
- ty:: PatternKind :: NotNull | ty:: PatternKind :: Range { .. } => {
1045
- get_nullable_type ( tcx, typing_env, * base)
1046
- }
1047
- } ,
1051
+ & ty:: Pat ( base, pat) => get_nullable_type_from_pat ( tcx, typing_env, base, pat) ,
1048
1052
_ => None ,
1049
1053
}
1050
1054
}
1051
1055
1056
+ fn get_nullable_type_from_pat < ' tcx > (
1057
+ tcx : TyCtxt < ' tcx > ,
1058
+ typing_env : ty:: TypingEnv < ' tcx > ,
1059
+ base : Ty < ' tcx > ,
1060
+ pat : ty:: Pattern < ' tcx > ,
1061
+ ) -> Option < Ty < ' tcx > > {
1062
+ match * pat {
1063
+ ty:: PatternKind :: NotNull | ty:: PatternKind :: Range { .. } => {
1064
+ get_nullable_type ( tcx, typing_env, base)
1065
+ }
1066
+ }
1067
+ }
1068
+
1052
1069
impl < ' a , ' tcx > ImproperCTypesVisitor < ' a , ' tcx > {
1053
1070
/// Check if the type is array and emit an unsafe type lint.
1054
1071
fn check_for_array_ty ( & mut self , sp : Span , ty : Ty < ' tcx > ) -> bool {
0 commit comments