@@ -3901,21 +3901,24 @@ fn lint_from_iter(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<
3901
3901
let ty = cx. typeck_results ( ) . expr_ty ( expr) ;
3902
3902
let arg_ty = cx. typeck_results ( ) . expr_ty ( & args[ 0 ] ) ;
3903
3903
3904
- let from_iter_id = get_trait_def_id ( cx, & paths:: FROM_ITERATOR ) . unwrap ( ) ;
3905
- let iter_id = get_trait_def_id ( cx, & paths:: ITERATOR ) . unwrap ( ) ;
3904
+ if_chain ! {
3905
+ if let Some ( from_iter_id) = get_trait_def_id( cx, & paths:: FROM_ITERATOR ) ;
3906
+ if let Some ( iter_id) = get_trait_def_id( cx, & paths:: ITERATOR ) ;
3906
3907
3907
- if implements_trait ( cx, ty, from_iter_id, & [ ] ) && implements_trait ( cx, arg_ty, iter_id, & [ ] ) {
3908
- // `expr` implements `FromIterator` trait
3909
- let iter_expr = snippet ( cx, args[ 0 ] . span , ".." ) ;
3910
- span_lint_and_sugg (
3911
- cx,
3912
- FROM_ITER_INSTEAD_OF_COLLECT ,
3913
- expr. span ,
3914
- "usage of `FromIterator::from_iter`" ,
3915
- "use `.collect()` instead of `::from_iter()`" ,
3916
- format ! ( "{}.collect()" , iter_expr) ,
3917
- Applicability :: MaybeIncorrect ,
3918
- ) ;
3908
+ if implements_trait( cx, ty, from_iter_id, & [ ] ) && implements_trait( cx, arg_ty, iter_id, & [ ] ) ;
3909
+ then {
3910
+ // `expr` implements `FromIterator` trait
3911
+ let iter_expr = snippet( cx, args[ 0 ] . span, ".." ) ;
3912
+ span_lint_and_sugg(
3913
+ cx,
3914
+ FROM_ITER_INSTEAD_OF_COLLECT ,
3915
+ expr. span,
3916
+ "usage of `FromIterator::from_iter`" ,
3917
+ "use `.collect()` instead of `::from_iter()`" ,
3918
+ format!( "{}.collect()" , iter_expr) ,
3919
+ Applicability :: MaybeIncorrect ,
3920
+ ) ;
3921
+ }
3919
3922
}
3920
3923
}
3921
3924
0 commit comments