@@ -575,7 +575,7 @@ declare_clippy_lint! {
575575/// temporary placeholder for dealing with the `Option` type, then this does
576576/// not mitigate the need for error handling. If there is a chance that `.get()`
577577/// 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
579579/// trait.
580580///
581581/// **Example:**
@@ -2135,22 +2135,6 @@ fn lint_asref(cx: &LateContext<'_, '_>, expr: &hir::Expr, call_name: &str, as_re
21352135}
21362136
21372137fn 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-
21542138 // FIXME: instead of this hard-coded list, we should check if `<adt>::iter`
21552139 // exists and has the desired signature. Unfortunately FnCtxt is not exported
21562140 // 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
21702154 ( INTO_ITER_ON_REF , & [ "std" , "sync" , "mpsc" , "Receiver" ] ) ,
21712155 ] ;
21722156
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+
21732173 for ( lint, path) in & INTO_ITER_COLLECTIONS {
21742174 if match_def_path ( cx. tcx , def_id, path) {
21752175 return Some ( ( lint, path. last ( ) . unwrap ( ) , method_name) )
0 commit comments