This commit is contained in:
Bastian Kauschke 2020-06-19 10:22:25 +02:00
parent d164ab65f7
commit dfa1af2059
4 changed files with 22 additions and 22 deletions

View File

@ -3,7 +3,7 @@ use rustc_hir::intravisit::FnKind;
use rustc_hir::{Body, FnDecl, HirId}; use rustc_hir::{Body, FnDecl, HirId};
use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::{Opaque, PredicateKind::Trait, ToPolyTraitRef}; use rustc_middle::ty::{Opaque, PredicateKind::Trait};
use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::{sym, Span}; use rustc_span::{sym, Span};
use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt; use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt;
@ -91,12 +91,11 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
cx.tcx.infer_ctxt().enter(|infcx| { cx.tcx.infer_ctxt().enter(|infcx| {
for FulfillmentError { obligation, .. } in send_errors { for FulfillmentError { obligation, .. } in send_errors {
infcx.maybe_note_obligation_cause_for_async_await(db, &obligation); infcx.maybe_note_obligation_cause_for_async_await(db, &obligation);
if let Trait(trait_pred, _) = obligation.predicate.kind() { if let Trait(trait_pred, _) = obligation.predicate.ignore_qualifiers().skip_binder().kind() {
let trait_ref = trait_pred.to_poly_trait_ref(); db.note(&format!(
db.note(&*format!(
"`{}` doesn't implement `{}`", "`{}` doesn't implement `{}`",
trait_ref.skip_binder().self_ty(), trait_pred.self_ty(),
trait_ref.print_only_trait_path(), trait_pred.trait_ref.print_only_trait_path(),
)); ));
} }
} }

View File

@ -1558,13 +1558,10 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
// if return type is impl trait, check the associated types // if return type is impl trait, check the associated types
if let ty::Opaque(def_id, _) = ret_ty.kind { if let ty::Opaque(def_id, _) = ret_ty.kind {
// one of the associated types must be Self // one of the associated types must be Self
for predicate in cx.tcx.predicates_of(def_id).predicates { for &(predicate, _span) in cx.tcx.predicates_of(def_id).predicates {
if let ty::PredicateKind::Projection(poly_projection_predicate) = predicate.0.kind() { if let ty::PredicateKind::Projection(projection_predicate) = predicate.ignore_qualifiers().skip_binder().kind() {
let binder = poly_projection_predicate.ty();
let associated_type = binder.skip_binder();
// walk the associated type and check for Self // walk the associated type and check for Self
if contains_self_ty(associated_type) { if contains_self_ty(projection_predicate.ty) {
return; return;
} }
} }

View File

@ -114,12 +114,12 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds().iter()) let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds().iter())
.filter(|p| !p.is_global()) .filter(|p| !p.is_global())
.filter_map(|obligation| { .filter_map(|obligation| {
if let ty::PredicateKind::Trait(poly_trait_ref, _) = obligation.predicate.kind() { // Note that we do not want to deal with qualified predicates here.
if poly_trait_ref.def_id() == sized_trait || poly_trait_ref.skip_binder().has_escaping_bound_vars() if let ty::PredicateKind::Trait(pred, _) = obligation.predicate.kind() {
{ if pred.def_id() == sized_trait {
return None; return None;
} }
Some(poly_trait_ref) Some(pred)
} else { } else {
None None
} }
@ -159,14 +159,13 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
} }
} }
//
// * Exclude a type that is specifically bounded by `Borrow`. // * Exclude a type that is specifically bounded by `Borrow`.
// * Exclude a type whose reference also fulfills its bound. (e.g., `std::convert::AsRef`, // * Exclude a type whose reference also fulfills its bound. (e.g., `std::convert::AsRef`,
// `serde::Serialize`) // `serde::Serialize`)
let (implements_borrow_trait, all_borrowable_trait) = { let (implements_borrow_trait, all_borrowable_trait) = {
let preds = preds let preds = preds
.iter() .iter()
.filter(|t| t.skip_binder().self_ty() == ty) .filter(|t| t.self_ty() == ty)
.collect::<Vec<_>>(); .collect::<Vec<_>>();
( (
@ -174,8 +173,13 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
!preds.is_empty() && { !preds.is_empty() && {
let ty_empty_region = cx.tcx.mk_imm_ref(cx.tcx.lifetimes.re_root_empty, ty); let ty_empty_region = cx.tcx.mk_imm_ref(cx.tcx.lifetimes.re_root_empty, ty);
preds.iter().all(|t| { preds.iter().all(|t| {
let ty_params = &t.skip_binder().trait_ref.substs.iter().skip(1).collect::<Vec<_>>(); let ty_params = t
implements_trait(cx, ty_empty_region, t.def_id(), ty_params) .trait_ref
.substs
.iter()
.skip(1)
.collect::<Vec<_>>();
implements_trait(cx, ty_empty_region, t.def_id(), &ty_params)
}) })
}, },
) )

View File

@ -1263,8 +1263,8 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
ty::Tuple(ref substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)), ty::Tuple(ref substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)),
ty::Opaque(ref def_id, _) => { ty::Opaque(ref def_id, _) => {
for (predicate, _) in cx.tcx.predicates_of(*def_id).predicates { for (predicate, _) in cx.tcx.predicates_of(*def_id).predicates {
if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) = predicate.kind() { if let ty::PredicateKind::Trait(trait_predicate, _) = predicate.ignore_qualifiers().skip_binder().kind() {
if must_use_attr(&cx.tcx.get_attrs(poly_trait_predicate.skip_binder().trait_ref.def_id)).is_some() { if must_use_attr(&cx.tcx.get_attrs(trait_predicate.trait_ref.def_id)).is_some() {
return true; return true;
} }
} }