mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-30 16:39:26 +00:00
change usages of impl_trait_ref to bound_impl_trait_ref
This commit is contained in:
parent
efb631a09c
commit
a160ce3a48
11 changed files with 18 additions and 18 deletions
|
@ -247,11 +247,11 @@ fn check_hash_peq<'tcx>(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let trait_ref = cx.tcx.impl_trait_ref(impl_id).expect("must be a trait implementation");
|
let trait_ref = cx.tcx.bound_impl_trait_ref(impl_id).expect("must be a trait implementation");
|
||||||
|
|
||||||
// Only care about `impl PartialEq<Foo> for Foo`
|
// Only care about `impl PartialEq<Foo> for Foo`
|
||||||
// For `impl PartialEq<B> for A, input_types is [A, B]
|
// For `impl PartialEq<B> for A, input_types is [A, B]
|
||||||
if trait_ref.substs.type_at(1) == ty {
|
if trait_ref.subst_identity().substs.type_at(1) == ty {
|
||||||
span_lint_and_then(
|
span_lint_and_then(
|
||||||
cx,
|
cx,
|
||||||
DERIVED_HASH_WITH_MANUAL_EQ,
|
DERIVED_HASH_WITH_MANUAL_EQ,
|
||||||
|
@ -295,11 +295,11 @@ fn check_ord_partial_ord<'tcx>(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let trait_ref = cx.tcx.impl_trait_ref(impl_id).expect("must be a trait implementation");
|
let trait_ref = cx.tcx.bound_impl_trait_ref(impl_id).expect("must be a trait implementation");
|
||||||
|
|
||||||
// Only care about `impl PartialOrd<Foo> for Foo`
|
// Only care about `impl PartialOrd<Foo> for Foo`
|
||||||
// For `impl PartialOrd<B> for A, input_types is [A, B]
|
// For `impl PartialOrd<B> for A, input_types is [A, B]
|
||||||
if trait_ref.substs.type_at(1) == ty {
|
if trait_ref.subst_identity().substs.type_at(1) == ty {
|
||||||
let mess = if partial_ord_is_automatically_derived {
|
let mess = if partial_ord_is_automatically_derived {
|
||||||
"you are implementing `Ord` explicitly but have derived `PartialOrd`"
|
"you are implementing `Ord` explicitly but have derived `PartialOrd`"
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -55,8 +55,8 @@ impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom {
|
||||||
// check for `impl From<???> for ..`
|
// check for `impl From<???> for ..`
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let hir::ItemKind::Impl(impl_) = &item.kind;
|
if let hir::ItemKind::Impl(impl_) = &item.kind;
|
||||||
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id);
|
if let Some(impl_trait_ref) = cx.tcx.bound_impl_trait_ref(item.owner_id.to_def_id());
|
||||||
if cx.tcx.is_diagnostic_item(sym::From, impl_trait_ref.def_id);
|
if cx.tcx.is_diagnostic_item(sym::From, impl_trait_ref.skip_binder().def_id);
|
||||||
then {
|
then {
|
||||||
lint_impl_body(cx, item.span, impl_.items);
|
lint_impl_body(cx, item.span, impl_.items);
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto {
|
||||||
&& let Some(into_trait_seg) = hir_trait_ref.path.segments.last()
|
&& let Some(into_trait_seg) = hir_trait_ref.path.segments.last()
|
||||||
// `impl Into<target_ty> for self_ty`
|
// `impl Into<target_ty> for self_ty`
|
||||||
&& let Some(GenericArgs { args: [GenericArg::Type(target_ty)], .. }) = into_trait_seg.args
|
&& let Some(GenericArgs { args: [GenericArg::Type(target_ty)], .. }) = into_trait_seg.args
|
||||||
&& let Some(middle_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id)
|
&& let Some(middle_trait_ref) = cx.tcx.bound_impl_trait_ref(item.owner_id.to_def_id()).map(ty::EarlyBinder::subst_identity)
|
||||||
&& cx.tcx.is_diagnostic_item(sym::Into, middle_trait_ref.def_id)
|
&& cx.tcx.is_diagnostic_item(sym::Into, middle_trait_ref.def_id)
|
||||||
&& !matches!(middle_trait_ref.substs.type_at(1).kind(), ty::Alias(ty::Opaque, _))
|
&& !matches!(middle_trait_ref.substs.type_at(1).kind(), ty::Alias(ty::Opaque, _))
|
||||||
{
|
{
|
||||||
|
|
|
@ -101,7 +101,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
|
||||||
if name.ident.as_str() == "MIN";
|
if name.ident.as_str() == "MIN";
|
||||||
if let Some(const_id) = cx.typeck_results().type_dependent_def_id(cond_num_val.hir_id);
|
if let Some(const_id) = cx.typeck_results().type_dependent_def_id(cond_num_val.hir_id);
|
||||||
if let Some(impl_id) = cx.tcx.impl_of_method(const_id);
|
if let Some(impl_id) = cx.tcx.impl_of_method(const_id);
|
||||||
if let None = cx.tcx.impl_trait_ref(impl_id); // An inherent impl
|
if let None = cx.tcx.bound_impl_trait_ref(impl_id); // An inherent impl
|
||||||
if cx.tcx.type_of(impl_id).is_integral();
|
if cx.tcx.type_of(impl_id).is_integral();
|
||||||
then {
|
then {
|
||||||
print_lint_and_sugg(cx, var_name, expr)
|
print_lint_and_sugg(cx, var_name, expr)
|
||||||
|
@ -114,7 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
|
||||||
if name.ident.as_str() == "min_value";
|
if name.ident.as_str() == "min_value";
|
||||||
if let Some(func_id) = cx.typeck_results().type_dependent_def_id(func.hir_id);
|
if let Some(func_id) = cx.typeck_results().type_dependent_def_id(func.hir_id);
|
||||||
if let Some(impl_id) = cx.tcx.impl_of_method(func_id);
|
if let Some(impl_id) = cx.tcx.impl_of_method(func_id);
|
||||||
if let None = cx.tcx.impl_trait_ref(impl_id); // An inherent impl
|
if let None = cx.tcx.bound_impl_trait_ref(impl_id); // An inherent impl
|
||||||
if cx.tcx.type_of(impl_id).is_integral();
|
if cx.tcx.type_of(impl_id).is_integral();
|
||||||
then {
|
then {
|
||||||
print_lint_and_sugg(cx, var_name, expr)
|
print_lint_and_sugg(cx, var_name, expr)
|
||||||
|
|
|
@ -53,7 +53,7 @@ pub fn is_clone_like(cx: &LateContext<'_>, method_name: &str, method_def_id: hir
|
||||||
"to_vec" => cx
|
"to_vec" => cx
|
||||||
.tcx
|
.tcx
|
||||||
.impl_of_method(method_def_id)
|
.impl_of_method(method_def_id)
|
||||||
.filter(|&impl_did| cx.tcx.type_of(impl_did).is_slice() && cx.tcx.impl_trait_ref(impl_did).is_none())
|
.filter(|&impl_did| cx.tcx.type_of(impl_did).is_slice() && cx.tcx.bound_impl_trait_ref(impl_did).is_none())
|
||||||
.is_some(),
|
.is_some(),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ pub(super) fn check(cx: &LateContext<'_>, method_name: &str, expr: &Expr<'_>, se
|
||||||
if count <= 1;
|
if count <= 1;
|
||||||
if let Some(call_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
|
if let Some(call_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
|
||||||
if let Some(impl_id) = cx.tcx.impl_of_method(call_id);
|
if let Some(impl_id) = cx.tcx.impl_of_method(call_id);
|
||||||
if cx.tcx.impl_trait_ref(impl_id).is_none();
|
if cx.tcx.bound_impl_trait_ref(impl_id).is_none();
|
||||||
let self_ty = cx.tcx.type_of(impl_id);
|
let self_ty = cx.tcx.type_of(impl_id);
|
||||||
if self_ty.is_slice() || self_ty.is_str();
|
if self_ty.is_slice() || self_ty.is_str();
|
||||||
then {
|
then {
|
||||||
|
|
|
@ -175,7 +175,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
|
||||||
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) {
|
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) {
|
||||||
// If the method is an impl for a trait, don't doc.
|
// If the method is an impl for a trait, don't doc.
|
||||||
if let Some(cid) = cx.tcx.associated_item(impl_item.owner_id).impl_container(cx.tcx) {
|
if let Some(cid) = cx.tcx.associated_item(impl_item.owner_id).impl_container(cx.tcx) {
|
||||||
if cx.tcx.impl_trait_ref(cid).is_some() {
|
if cx.tcx.bound_impl_trait_ref(cid).is_some() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -155,7 +155,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
|
||||||
let container_id = assoc_item.container_id(cx.tcx);
|
let container_id = assoc_item.container_id(cx.tcx);
|
||||||
let trait_def_id = match assoc_item.container {
|
let trait_def_id = match assoc_item.container {
|
||||||
TraitContainer => Some(container_id),
|
TraitContainer => Some(container_id),
|
||||||
ImplContainer => cx.tcx.impl_trait_ref(container_id).map(|t| t.def_id),
|
ImplContainer => cx.tcx.bound_impl_trait_ref(container_id).map(|t| t.skip_binder().def_id),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(trait_def_id) = trait_def_id {
|
if let Some(trait_def_id) = trait_def_id {
|
||||||
|
|
|
@ -89,8 +89,8 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy {
|
||||||
if let Some(trait_id) = trait_ref.trait_def_id();
|
if let Some(trait_id) = trait_ref.trait_def_id();
|
||||||
if send_trait == trait_id;
|
if send_trait == trait_id;
|
||||||
if hir_impl.polarity == ImplPolarity::Positive;
|
if hir_impl.polarity == ImplPolarity::Positive;
|
||||||
if let Some(ty_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id);
|
if let Some(ty_trait_ref) = cx.tcx.bound_impl_trait_ref(item.owner_id.to_def_id());
|
||||||
if let self_ty = ty_trait_ref.self_ty();
|
if let self_ty = ty_trait_ref.subst_identity().self_ty();
|
||||||
if let ty::Adt(adt_def, impl_trait_substs) = self_ty.kind();
|
if let ty::Adt(adt_def, impl_trait_substs) = self_ty.kind();
|
||||||
then {
|
then {
|
||||||
let mut non_send_fields = Vec::new();
|
let mut non_send_fields = Vec::new();
|
||||||
|
|
|
@ -244,7 +244,7 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion {
|
||||||
})) => {
|
})) => {
|
||||||
#[allow(trivial_casts)]
|
#[allow(trivial_casts)]
|
||||||
if let Some(Node::Item(item)) = get_parent_node(cx.tcx, owner_id.into())
|
if let Some(Node::Item(item)) = get_parent_node(cx.tcx, owner_id.into())
|
||||||
&& let Some(trait_ref) = cx.tcx.impl_trait_ref(item.owner_id)
|
&& let Some(trait_ref) = cx.tcx.bound_impl_trait_ref(item.owner_id.to_def_id()).map(|t| t.subst_identity())
|
||||||
&& let Some(trait_item_id) = cx.tcx.associated_item(owner_id).trait_item_def_id
|
&& let Some(trait_item_id) = cx.tcx.associated_item(owner_id).trait_item_def_id
|
||||||
{
|
{
|
||||||
(
|
(
|
||||||
|
|
|
@ -133,11 +133,11 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
|
||||||
ref mut types_to_skip,
|
ref mut types_to_skip,
|
||||||
..
|
..
|
||||||
}) = self.stack.last_mut();
|
}) = self.stack.last_mut();
|
||||||
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_id);
|
if let Some(impl_trait_ref) = cx.tcx.bound_impl_trait_ref(impl_id.to_def_id());
|
||||||
then {
|
then {
|
||||||
// `self_ty` is the semantic self type of `impl <trait> for <type>`. This cannot be
|
// `self_ty` is the semantic self type of `impl <trait> for <type>`. This cannot be
|
||||||
// `Self`.
|
// `Self`.
|
||||||
let self_ty = impl_trait_ref.self_ty();
|
let self_ty = impl_trait_ref.subst_identity().self_ty();
|
||||||
|
|
||||||
// `trait_method_sig` is the signature of the function, how it is declared in the
|
// `trait_method_sig` is the signature of the function, how it is declared in the
|
||||||
// trait, not in the impl of the trait.
|
// trait, not in the impl of the trait.
|
||||||
|
|
Loading…
Reference in a new issue