]> git.lizzy.rs Git - rust.git/blobdiff - src/tools/clippy/clippy_lints/src/methods/mod.rs
introduce PredicateAtom
[rust.git] / src / tools / clippy / clippy_lints / src / methods / mod.rs
index 4877556a49e37daaf59173ede295f148af2d4895..2c70183d87666d7aa0ac5ea93fc94d4406c7579d 100644 (file)
@@ -1558,13 +1558,10 @@ fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::Impl
             // if return type is impl trait, check the associated types
             if let ty::Opaque(def_id, _) = ret_ty.kind {
                 // one of the associated types must be Self
-                for predicate in cx.tcx.predicates_of(def_id).predicates {
-                    if let ty::PredicateKind::Projection(poly_projection_predicate) = predicate.0.kind() {
-                        let binder = poly_projection_predicate.ty();
-                        let associated_type = binder.skip_binder();
-
+                for &(predicate, _span) in cx.tcx.predicates_of(def_id).predicates {
+                    if let ty::PredicateAtom::Projection(projection_predicate) = predicate.skip_binders() {
                         // walk the associated type and check for Self
-                        if contains_self_ty(associated_type) {
+                        if contains_self_ty(projection_predicate.ty) {
                             return;
                         }
                     }
@@ -2354,8 +2351,8 @@ fn lint_iter_nth_zero<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, nth_ar
                 cx,
                 ITER_NTH_ZERO,
                 expr.span,
-                "called `.nth(0)` on a `std::iter::Iterator`",
-                "try calling",
+                "called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent",
+                "try calling `.next()` instead of `.nth(0)`",
                 format!("{}.next()", snippet_with_applicability(cx, nth_args[0].span, "..", &mut applicability)),
                 applicability,
             );
@@ -3290,7 +3287,12 @@ fn lint_option_as_ref_deref<'tcx>(
                         if let hir::ExprKind::Path(qpath) = &args[0].kind;
                         if let hir::def::Res::Local(local_id) = cx.qpath_res(qpath, args[0].hir_id);
                         if closure_body.params[0].pat.hir_id == local_id;
-                        let adj = cx.typeck_results().expr_adjustments(&args[0]).iter().map(|x| &x.kind).collect::<Box<[_]>>();
+                        let adj = cx
+                            .typeck_results()
+                            .expr_adjustments(&args[0])
+                            .iter()
+                            .map(|x| &x.kind)
+                            .collect::<Box<[_]>>();
                         if let [ty::adjustment::Adjust::Deref(None), ty::adjustment::Adjust::Borrow(_)] = *adj;
                         then {
                             let method_did = cx.typeck_results().type_dependent_def_id(closure_expr.hir_id).unwrap();