@@ -575,7 +575,7 @@ declare_clippy_lint! {
575
575
/// temporary placeholder for dealing with the `Option` type, then this does
576
576
/// not mitigate the need for error handling. If there is a chance that `.get()`
577
577
/// will be `None` in your program, then it is advisable that the `None` case
578
- /// is handled in a future refactor instead of using `.unwrap()` or the Index
578
+ /// is handled in a future refactor instead of using `.unwrap()` or the Index
579
579
/// trait.
580
580
///
581
581
/// **Example:**
@@ -2135,22 +2135,6 @@ fn lint_asref(cx: &LateContext<'_, '_>, expr: &hir::Expr, call_name: &str, as_re
2135
2135
}
2136
2136
2137
2137
fn ty_has_iter_method ( cx : & LateContext < ' _ , ' _ > , self_ref_ty : ty:: Ty < ' _ > ) -> Option < ( & ' static Lint , & ' static str , & ' static str ) > {
2138
- let ( self_ty, mutbl) = match self_ref_ty. sty {
2139
- ty:: TyKind :: Ref ( _, self_ty, mutbl) => ( self_ty, mutbl) ,
2140
- _ => unreachable ! ( ) ,
2141
- } ;
2142
- let method_name = match mutbl {
2143
- hir:: MutImmutable => "iter" ,
2144
- hir:: MutMutable => "iter_mut" ,
2145
- } ;
2146
-
2147
- let def_id = match self_ty. sty {
2148
- ty:: TyKind :: Array ( ..) => return Some ( ( INTO_ITER_ON_ARRAY , "array" , method_name) ) ,
2149
- ty:: TyKind :: Slice ( ..) => return Some ( ( INTO_ITER_ON_REF , "slice" , method_name) ) ,
2150
- ty:: Adt ( adt, _) => adt. did ,
2151
- _ => return None ,
2152
- } ;
2153
-
2154
2138
// FIXME: instead of this hard-coded list, we should check if `<adt>::iter`
2155
2139
// exists and has the desired signature. Unfortunately FnCtxt is not exported
2156
2140
// so we can't use its `lookup_method` method.
@@ -2170,6 +2154,22 @@ fn ty_has_iter_method(cx: &LateContext<'_, '_>, self_ref_ty: ty::Ty<'_>) -> Opti
2170
2154
( INTO_ITER_ON_REF , & [ "std" , "sync" , "mpsc" , "Receiver" ] ) ,
2171
2155
] ;
2172
2156
2157
+ let ( self_ty, mutbl) = match self_ref_ty. sty {
2158
+ ty:: TyKind :: Ref ( _, self_ty, mutbl) => ( self_ty, mutbl) ,
2159
+ _ => unreachable ! ( ) ,
2160
+ } ;
2161
+ let method_name = match mutbl {
2162
+ hir:: MutImmutable => "iter" ,
2163
+ hir:: MutMutable => "iter_mut" ,
2164
+ } ;
2165
+
2166
+ let def_id = match self_ty. sty {
2167
+ ty:: TyKind :: Array ( ..) => return Some ( ( INTO_ITER_ON_ARRAY , "array" , method_name) ) ,
2168
+ ty:: TyKind :: Slice ( ..) => return Some ( ( INTO_ITER_ON_REF , "slice" , method_name) ) ,
2169
+ ty:: Adt ( adt, _) => adt. did ,
2170
+ _ => return None ,
2171
+ } ;
2172
+
2173
2173
for ( lint, path) in & INTO_ITER_COLLECTIONS {
2174
2174
if match_def_path ( cx. tcx , def_id, path) {
2175
2175
return Some ( ( lint, path. last ( ) . unwrap ( ) , method_name) )
0 commit comments