// 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;
}
}
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,
);
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();