Rename trait_of_item -> trait_of_assoc
This commit is contained in:
parent
0d7abc8df0
commit
172af038a7
37 changed files with 47 additions and 47 deletions
|
|
@ -2384,7 +2384,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
if let Some(body_expr) = finder.body_expr
|
||||
&& let Some(loop_span) = finder.loop_span
|
||||
&& let Some(def_id) = typeck_results.type_dependent_def_id(body_expr.hir_id)
|
||||
&& let Some(trait_did) = tcx.trait_of_item(def_id)
|
||||
&& let Some(trait_did) = tcx.trait_of_assoc(def_id)
|
||||
&& tcx.is_diagnostic_item(sym::Iterator, trait_did)
|
||||
{
|
||||
if let Some(loop_bind) = finder.loop_bind {
|
||||
|
|
|
|||
|
|
@ -938,7 +938,7 @@ impl<'tcx> BorrowedContentSource<'tcx> {
|
|||
fn from_call(func: Ty<'tcx>, tcx: TyCtxt<'tcx>) -> Option<Self> {
|
||||
match *func.kind() {
|
||||
ty::FnDef(def_id, args) => {
|
||||
let trait_id = tcx.trait_of_item(def_id)?;
|
||||
let trait_id = tcx.trait_of_assoc(def_id)?;
|
||||
|
||||
if tcx.is_lang_item(trait_id, LangItem::Deref)
|
||||
|| tcx.is_lang_item(trait_id, LangItem::DerefMut)
|
||||
|
|
|
|||
|
|
@ -784,7 +784,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
|
|||
self.revalidate_conditional_constness(callee, fn_args, *fn_span);
|
||||
|
||||
// Attempting to call a trait method?
|
||||
if let Some(trait_did) = tcx.trait_of_item(callee) {
|
||||
if let Some(trait_did) = tcx.trait_of_assoc(callee) {
|
||||
// We can't determine the actual callee here, so we have to do different checks
|
||||
// than usual.
|
||||
|
||||
|
|
|
|||
|
|
@ -369,7 +369,7 @@ where
|
|||
assert!(promoted.is_none() || Q::ALLOW_PROMOTED);
|
||||
|
||||
// Don't peek inside trait associated constants.
|
||||
if promoted.is_none() && cx.tcx.trait_of_item(def).is_none() {
|
||||
if promoted.is_none() && cx.tcx.trait_of_assoc(def).is_none() {
|
||||
let qualifs = cx.tcx.at(constant.span).mir_const_qualif(def);
|
||||
|
||||
if !Q::in_qualifs(&qualifs) {
|
||||
|
|
|
|||
|
|
@ -725,7 +725,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||
) {
|
||||
let tcx = *self.tcx;
|
||||
|
||||
let trait_def_id = tcx.trait_of_item(def_id).unwrap();
|
||||
let trait_def_id = tcx.trait_of_assoc(def_id).unwrap();
|
||||
let virtual_trait_ref = ty::TraitRef::from_method(tcx, trait_def_id, virtual_instance.args);
|
||||
let existential_trait_ref = ty::ExistentialTraitRef::erase_self_ty(tcx, virtual_trait_ref);
|
||||
let concrete_trait_ref = existential_trait_ref.with_self_ty(tcx, dyn_ty);
|
||||
|
|
|
|||
|
|
@ -759,7 +759,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
|||
&self,
|
||||
err: &mut Diag<'_, impl EmissionGuarantee>,
|
||||
) {
|
||||
let trait_ = match self.tcx.trait_of_item(self.def_id) {
|
||||
let trait_ = match self.tcx.trait_of_assoc(self.def_id) {
|
||||
Some(def_id) => def_id,
|
||||
None => return,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -694,7 +694,7 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
|
|||
// i.e. changing `Default::default()` to `<() as Default>::default()`.
|
||||
if let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = expr.kind
|
||||
&& let Res::Def(DefKind::AssocFn, def_id) = path.res
|
||||
&& self.fcx.tcx.trait_of_item(def_id).is_some()
|
||||
&& self.fcx.tcx.trait_of_assoc(def_id).is_some()
|
||||
&& let Some(args) = self.fcx.typeck_results.borrow().node_args_opt(expr.hir_id)
|
||||
&& let self_ty = args.type_at(0)
|
||||
&& let Some(vid) = self.fcx.root_vid(self_ty)
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall {
|
|||
return;
|
||||
};
|
||||
|
||||
let Some(trait_id) = cx.tcx.trait_of_item(did) else { return };
|
||||
let Some(trait_id) = cx.tcx.trait_of_assoc(did) else { return };
|
||||
|
||||
let Some(trait_) = cx.tcx.get_diagnostic_name(trait_id) else { return };
|
||||
|
||||
|
|
|
|||
|
|
@ -1996,7 +1996,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
/// If the given `DefId` describes an item belonging to a trait,
|
||||
/// returns the `DefId` of the trait that the trait item belongs to;
|
||||
/// otherwise, returns `None`.
|
||||
pub fn trait_of_item(self, def_id: DefId) -> Option<DefId> {
|
||||
pub fn trait_of_assoc(self, def_id: DefId) -> Option<DefId> {
|
||||
self.assoc_parent(def_id).filter(|id| self.def_kind(id) == DefKind::Trait)
|
||||
}
|
||||
|
||||
|
|
@ -2174,7 +2174,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
|
||||
#[inline]
|
||||
pub fn is_const_default_method(self, def_id: DefId) -> bool {
|
||||
matches!(self.trait_of_item(def_id), Some(trait_id) if self.is_const_trait(trait_id))
|
||||
matches!(self.trait_of_assoc(def_id), Some(trait_id) if self.is_const_trait(trait_id))
|
||||
}
|
||||
|
||||
pub fn impl_method_has_trait_impl_trait_tys(self, def_id: DefId) -> bool {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ impl<'tcx> MirLint<'tcx> for CheckCallRecursion {
|
|||
|
||||
if let DefKind::Fn | DefKind::AssocFn = tcx.def_kind(def_id) {
|
||||
// If this is trait/impl method, extract the trait's args.
|
||||
let trait_args = match tcx.trait_of_item(def_id.to_def_id()) {
|
||||
let trait_args = match tcx.trait_of_assoc(def_id.to_def_id()) {
|
||||
Some(trait_def_id) => {
|
||||
let trait_args_count = tcx.generics_of(trait_def_id).count();
|
||||
&GenericArgs::identity_for_item(tcx, def_id)[..trait_args_count]
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceKind<'tcx>) -> Body<
|
|||
build_call_shim(tcx, instance, Some(adjustment), CallKind::Direct(def_id))
|
||||
}
|
||||
ty::InstanceKind::FnPtrShim(def_id, ty) => {
|
||||
let trait_ = tcx.trait_of_item(def_id).unwrap();
|
||||
let trait_ = tcx.trait_of_assoc(def_id).unwrap();
|
||||
// Supports `Fn` or `async Fn` traits.
|
||||
let adjustment = match tcx
|
||||
.fn_trait_kind_from_def_id(trait_)
|
||||
|
|
|
|||
|
|
@ -650,7 +650,7 @@ fn characteristic_def_id_of_mono_item<'tcx>(
|
|||
// its self-type. If the self-type does not provide a characteristic
|
||||
// DefId, we use the location of the impl after all.
|
||||
|
||||
if tcx.trait_of_item(def_id).is_some() {
|
||||
if tcx.trait_of_assoc(def_id).is_some() {
|
||||
let self_ty = instance.args.type_at(0);
|
||||
// This is a default implementation of a trait method.
|
||||
return characteristic_def_id_of_type(self_ty).or(Some(def_id));
|
||||
|
|
|
|||
|
|
@ -429,7 +429,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
|
|||
Node::TraitItem(trait_item) => {
|
||||
// mark the trait live
|
||||
let trait_item_id = trait_item.owner_id.to_def_id();
|
||||
if let Some(trait_id) = self.tcx.trait_of_item(trait_item_id) {
|
||||
if let Some(trait_id) = self.tcx.trait_of_assoc(trait_item_id) {
|
||||
self.check_def_id(trait_id);
|
||||
}
|
||||
intravisit::walk_trait_item(self, trait_item);
|
||||
|
|
|
|||
|
|
@ -339,7 +339,7 @@ pub(crate) fn transform_instance<'tcx>(
|
|||
} else if let ty::InstanceKind::Virtual(def_id, _) = instance.def {
|
||||
// Transform self into a trait object of the trait that defines the method for virtual
|
||||
// functions to match the type erasure done below.
|
||||
let upcast_ty = match tcx.trait_of_item(def_id) {
|
||||
let upcast_ty = match tcx.trait_of_assoc(def_id) {
|
||||
Some(trait_id) => trait_object_ty(
|
||||
tcx,
|
||||
ty::Binder::dummy(ty::TraitRef::from_method(tcx, trait_id, instance.args)),
|
||||
|
|
@ -364,7 +364,7 @@ pub(crate) fn transform_instance<'tcx>(
|
|||
};
|
||||
instance.args = tcx.mk_args_trait(self_ty, instance.args.into_iter().skip(1));
|
||||
} else if let ty::InstanceKind::VTableShim(def_id) = instance.def
|
||||
&& let Some(trait_id) = tcx.trait_of_item(def_id)
|
||||
&& let Some(trait_id) = tcx.trait_of_assoc(def_id)
|
||||
{
|
||||
// Adjust the type ids of VTableShims to the type id expected in the call sites for the
|
||||
// entry in the vtable (i.e., by using the signature of the closure passed as an argument
|
||||
|
|
@ -480,7 +480,7 @@ fn implemented_method<'tcx>(
|
|||
// Provided method in a `trait` block
|
||||
trait_method = trait_method_bound;
|
||||
method_id = instance.def_id();
|
||||
trait_id = tcx.trait_of_item(method_id)?;
|
||||
trait_id = tcx.trait_of_assoc(method_id)?;
|
||||
trait_ref = ty::EarlyBinder::bind(TraitRef::from_method(tcx, trait_id, instance.args));
|
||||
trait_id
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1303,7 +1303,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
|
|||
&& let Some(args) = self.node_args_opt(expr.hir_id)
|
||||
&& args.iter().any(|arg| self.generic_arg_contains_target(arg))
|
||||
&& let Some(def_id) = self.typeck_results.type_dependent_def_id(expr.hir_id)
|
||||
&& self.tecx.tcx.trait_of_item(def_id).is_some()
|
||||
&& self.tecx.tcx.trait_of_assoc(def_id).is_some()
|
||||
&& !has_impl_trait(def_id)
|
||||
// FIXME(fn_delegation): In delegation item argument spans are equal to last path
|
||||
// segment. This leads to ICE's when emitting `multipart_suggestion`.
|
||||
|
|
|
|||
|
|
@ -360,7 +360,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
},
|
||||
] = path.segments
|
||||
&& data.trait_ref.def_id == *trait_id
|
||||
&& self.tcx.trait_of_item(*item_id) == Some(*trait_id)
|
||||
&& self.tcx.trait_of_assoc(*item_id) == Some(*trait_id)
|
||||
&& let None = self.tainted_by_errors()
|
||||
{
|
||||
let assoc_item = self.tcx.associated_item(item_id);
|
||||
|
|
|
|||
|
|
@ -987,7 +987,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
else {
|
||||
return false;
|
||||
};
|
||||
if self.tcx.trait_of_item(did) != Some(clone_trait) {
|
||||
if self.tcx.trait_of_assoc(did) != Some(clone_trait) {
|
||||
return false;
|
||||
}
|
||||
Some(ident.span)
|
||||
|
|
|
|||
|
|
@ -759,7 +759,7 @@ fn instantiate_and_check_impossible_predicates<'tcx>(
|
|||
|
||||
// Specifically check trait fulfillment to avoid an error when trying to resolve
|
||||
// associated items.
|
||||
if let Some(trait_def_id) = tcx.trait_of_item(key.0) {
|
||||
if let Some(trait_def_id) = tcx.trait_of_assoc(key.0) {
|
||||
let trait_ref = ty::TraitRef::from_method(tcx, trait_def_id, key.1);
|
||||
predicates.push(trait_ref.upcast(tcx));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1507,7 +1507,7 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
|
|||
let tcx = selcx.tcx();
|
||||
let self_ty = obligation.predicate.self_ty();
|
||||
let item_def_id = obligation.predicate.def_id;
|
||||
let trait_def_id = tcx.trait_of_item(item_def_id).unwrap();
|
||||
let trait_def_id = tcx.trait_of_assoc(item_def_id).unwrap();
|
||||
let args = tcx.mk_args(&[self_ty.into()]);
|
||||
let (term, obligations) = if tcx.is_lang_item(trait_def_id, LangItem::DiscriminantKind) {
|
||||
let discriminant_def_id =
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ fn resolve_instance_raw<'tcx>(
|
|||
) -> Result<Option<Instance<'tcx>>, ErrorGuaranteed> {
|
||||
let PseudoCanonicalInput { typing_env, value: (def_id, args) } = key;
|
||||
|
||||
let result = if let Some(trait_def_id) = tcx.trait_of_item(def_id) {
|
||||
let result = if let Some(trait_def_id) = tcx.trait_of_assoc(def_id) {
|
||||
debug!(" => associated item, attempting to find impl in typing_env {:#?}", typing_env);
|
||||
resolve_associated_item(
|
||||
tcx,
|
||||
|
|
|
|||
|
|
@ -364,7 +364,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
|
|||
// * `&self` methods on `&T` can have auto-borrow, but `&self` methods on `T` will take
|
||||
// priority.
|
||||
if let Some(fn_id) = typeck.type_dependent_def_id(hir_id)
|
||||
&& let Some(trait_id) = cx.tcx.trait_of_item(fn_id)
|
||||
&& let Some(trait_id) = cx.tcx.trait_of_assoc(fn_id)
|
||||
&& let arg_ty = cx.tcx.erase_regions(adjusted_ty)
|
||||
&& let ty::Ref(_, sub_ty, _) = *arg_ty.kind()
|
||||
&& let args =
|
||||
|
|
|
|||
|
|
@ -317,7 +317,7 @@ impl<'tcx> Visitor<'tcx> for VarVisitor<'_, 'tcx> {
|
|||
.cx
|
||||
.typeck_results()
|
||||
.type_dependent_def_id(expr.hir_id)
|
||||
.and_then(|def_id| self.cx.tcx.trait_of_item(def_id))
|
||||
.and_then(|def_id| self.cx.tcx.trait_of_assoc(def_id))
|
||||
&& ((meth.ident.name == sym::index && self.cx.tcx.lang_items().index_trait() == Some(trait_id))
|
||||
|| (meth.ident.name == sym::index_mut && self.cx.tcx.lang_items().index_mut_trait() == Some(trait_id)))
|
||||
&& !self.check(args_1, args_0, expr)
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ pub(super) fn check(
|
|||
if cx
|
||||
.typeck_results()
|
||||
.type_dependent_def_id(expr.hir_id)
|
||||
.and_then(|id| cx.tcx.trait_of_item(id))
|
||||
.and_then(|id| cx.tcx.trait_of_assoc(id))
|
||||
.zip(cx.tcx.lang_items().clone_trait())
|
||||
.is_none_or(|(x, y)| x != y)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -44,9 +44,9 @@ pub(super) fn check<'tcx>(
|
|||
let typeck = cx.typeck_results();
|
||||
if let Some(iter_id) = cx.tcx.get_diagnostic_item(sym::Iterator)
|
||||
&& let Some(method_id) = typeck.type_dependent_def_id(expr.hir_id)
|
||||
&& cx.tcx.trait_of_item(method_id) == Some(iter_id)
|
||||
&& cx.tcx.trait_of_assoc(method_id) == Some(iter_id)
|
||||
&& let Some(method_id) = typeck.type_dependent_def_id(cloned_call.hir_id)
|
||||
&& cx.tcx.trait_of_item(method_id) == Some(iter_id)
|
||||
&& cx.tcx.trait_of_assoc(method_id) == Some(iter_id)
|
||||
&& let cloned_recv_ty = typeck.expr_ty_adjusted(cloned_recv)
|
||||
&& let Some(iter_assoc_ty) = cx.get_associated_type(cloned_recv_ty, iter_id, sym::Item)
|
||||
&& matches!(*iter_assoc_ty.kind(), ty::Ref(_, ty, _) if !is_copy(cx, ty))
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ pub(super) fn check(
|
|||
&& is_type_lang_item(cx, cx.typeck_results().expr_ty(collect_expr), LangItem::String)
|
||||
&& let Some(take_id) = cx.typeck_results().type_dependent_def_id(take_expr.hir_id)
|
||||
&& let Some(iter_trait_id) = cx.tcx.get_diagnostic_item(sym::Iterator)
|
||||
&& cx.tcx.trait_of_item(take_id) == Some(iter_trait_id)
|
||||
&& cx.tcx.trait_of_assoc(take_id) == Some(iter_trait_id)
|
||||
&& let Some(repeat_kind) = parse_repeat_arg(cx, repeat_arg)
|
||||
&& let ctxt = collect_expr.span.ctxt()
|
||||
&& ctxt == take_expr.span.ctxt()
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ pub(super) fn check(cx: &LateContext<'_>, e: &hir::Expr<'_>, recv: &hir::Expr<'_
|
|||
hir::ExprKind::MethodCall(method, obj, [], _) => {
|
||||
if ident_eq(name, obj) && method.ident.name == sym::clone
|
||||
&& let Some(fn_id) = cx.typeck_results().type_dependent_def_id(closure_expr.hir_id)
|
||||
&& let Some(trait_id) = cx.tcx.trait_of_item(fn_id)
|
||||
&& let Some(trait_id) = cx.tcx.trait_of_assoc(fn_id)
|
||||
&& cx.tcx.lang_items().clone_trait() == Some(trait_id)
|
||||
// no autoderefs
|
||||
&& !cx.typeck_results().expr_adjustments(obj).iter()
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ fn get_open_options(
|
|||
// This might be a user defined extension trait with a method like `truncate_write`
|
||||
// which would be a false positive
|
||||
if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(argument.hir_id)
|
||||
&& cx.tcx.trait_of_item(method_def_id).is_some()
|
||||
&& cx.tcx.trait_of_assoc(method_def_id).is_some()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -286,7 +286,7 @@ fn parse_iter_usage<'tcx>(
|
|||
let iter_id = cx.tcx.get_diagnostic_item(sym::Iterator)?;
|
||||
|
||||
match (name.ident.name, args) {
|
||||
(sym::next, []) if cx.tcx.trait_of_item(did) == Some(iter_id) => (IterUsageKind::Nth(0), e.span),
|
||||
(sym::next, []) if cx.tcx.trait_of_assoc(did) == Some(iter_id) => (IterUsageKind::Nth(0), e.span),
|
||||
(sym::next_tuple, []) => {
|
||||
return if paths::ITERTOOLS_NEXT_TUPLE.matches(cx, did)
|
||||
&& let ty::Adt(adt_def, subs) = cx.typeck_results().expr_ty(e).kind()
|
||||
|
|
@ -303,7 +303,7 @@ fn parse_iter_usage<'tcx>(
|
|||
None
|
||||
};
|
||||
},
|
||||
(sym::nth | sym::skip, [idx_expr]) if cx.tcx.trait_of_item(did) == Some(iter_id) => {
|
||||
(sym::nth | sym::skip, [idx_expr]) if cx.tcx.trait_of_assoc(did) == Some(iter_id) => {
|
||||
if let Some(Constant::Int(idx)) = ConstEvalCtxt::new(cx).eval(idx_expr) {
|
||||
let span = if name.ident.as_str() == "nth" {
|
||||
e.span
|
||||
|
|
@ -312,7 +312,7 @@ fn parse_iter_usage<'tcx>(
|
|||
&& next_name.ident.name == sym::next
|
||||
&& next_expr.span.ctxt() == ctxt
|
||||
&& let Some(next_id) = cx.typeck_results().type_dependent_def_id(next_expr.hir_id)
|
||||
&& cx.tcx.trait_of_item(next_id) == Some(iter_id)
|
||||
&& cx.tcx.trait_of_assoc(next_id) == Some(iter_id)
|
||||
{
|
||||
next_expr.span
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ pub(super) fn check_method(cx: &LateContext<'_>, expr: &Expr<'_>) {
|
|||
pub(super) fn check_function(cx: &LateContext<'_>, expr: &Expr<'_>, callee: &Expr<'_>) {
|
||||
if let ExprKind::Path(ref qpath) = callee.kind
|
||||
&& let Some(item_def_id) = cx.qpath_res(qpath, callee.hir_id).opt_def_id()
|
||||
&& let Some(trait_def_id) = cx.tcx.trait_of_item(item_def_id)
|
||||
&& let Some(trait_def_id) = cx.tcx.trait_of_assoc(item_def_id)
|
||||
{
|
||||
let qpath_spans = match qpath {
|
||||
QPath::Resolved(_, path) => {
|
||||
|
|
|
|||
|
|
@ -734,7 +734,7 @@ fn check_if_applicable_to_argument<'tcx>(cx: &LateContext<'tcx>, arg: &Expr<'tcx
|
|||
fn check_borrow_predicate<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) {
|
||||
if let ExprKind::MethodCall(_, caller, &[arg], _) = expr.kind
|
||||
&& let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
|
||||
&& cx.tcx.trait_of_item(method_def_id).is_none()
|
||||
&& cx.tcx.trait_of_assoc(method_def_id).is_none()
|
||||
&& let Some(borrow_id) = cx.tcx.get_diagnostic_item(sym::Borrow)
|
||||
&& cx.tcx.predicates_of(method_def_id).predicates.iter().any(|(pred, _)| {
|
||||
if let ClauseKind::Trait(trait_pred) = pred.kind().skip_binder()
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ fn is_calling_clone(cx: &LateContext<'_>, arg: &hir::Expr<'_>) -> bool {
|
|||
hir::ExprKind::MethodCall(method, obj, [], _) => {
|
||||
if method.ident.name == sym::clone
|
||||
&& let Some(fn_id) = cx.typeck_results().type_dependent_def_id(closure_expr.hir_id)
|
||||
&& let Some(trait_id) = cx.tcx.trait_of_item(fn_id)
|
||||
&& let Some(trait_id) = cx.tcx.trait_of_assoc(fn_id)
|
||||
// We check it's the `Clone` trait.
|
||||
&& cx.tcx.lang_items().clone_trait().is_some_and(|id| id == trait_id)
|
||||
// no autoderefs
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ fn check_op(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left: bool)
|
|||
ExprKind::MethodCall(_, arg, [], _)
|
||||
if typeck
|
||||
.type_dependent_def_id(expr.hir_id)
|
||||
.and_then(|id| cx.tcx.trait_of_item(id))
|
||||
.and_then(|id| cx.tcx.trait_of_assoc(id))
|
||||
.is_some_and(|id| matches!(cx.tcx.get_diagnostic_name(id), Some(sym::ToString | sym::ToOwned))) =>
|
||||
{
|
||||
(arg, arg.span)
|
||||
|
|
|
|||
|
|
@ -380,7 +380,7 @@ fn can_switch_ranges<'tcx>(
|
|||
if let ExprKind::MethodCall(_, receiver, _, _) = parent_expr.kind
|
||||
&& receiver.hir_id == use_ctxt.child_id
|
||||
&& let Some(method_did) = cx.typeck_results().type_dependent_def_id(parent_expr.hir_id)
|
||||
&& let Some(trait_did) = cx.tcx.trait_of_item(method_did)
|
||||
&& let Some(trait_did) = cx.tcx.trait_of_assoc(method_did)
|
||||
&& matches!(
|
||||
cx.tcx.get_diagnostic_name(trait_did),
|
||||
Some(sym::Iterator | sym::IntoIterator | sym::RangeBounds)
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ fn check_partial_eq(cx: &LateContext<'_>, method_span: Span, method_def_id: Loca
|
|||
let arg_ty = cx.typeck_results().expr_ty_adjusted(arg);
|
||||
|
||||
if let Some(fn_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
|
||||
&& let Some(trait_id) = cx.tcx.trait_of_item(fn_id)
|
||||
&& let Some(trait_id) = cx.tcx.trait_of_assoc(fn_id)
|
||||
&& trait_id == trait_def_id
|
||||
&& matches_ty(receiver_ty, arg_ty, self_arg, other_arg)
|
||||
{
|
||||
|
|
@ -250,7 +250,7 @@ fn check_to_string(cx: &LateContext<'_>, method_span: Span, method_def_id: Local
|
|||
let is_bad = match expr.kind {
|
||||
ExprKind::MethodCall(segment, _receiver, &[_arg], _) if segment.ident.name == name.name => {
|
||||
if let Some(fn_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
|
||||
&& let Some(trait_id) = cx.tcx.trait_of_item(fn_id)
|
||||
&& let Some(trait_id) = cx.tcx.trait_of_assoc(fn_id)
|
||||
&& trait_id == trait_def_id
|
||||
{
|
||||
true
|
||||
|
|
@ -318,7 +318,7 @@ where
|
|||
&& let ExprKind::Path(qpath) = f.kind
|
||||
&& is_default_method_on_current_ty(self.cx.tcx, qpath, self.implemented_ty_id)
|
||||
&& let Some(method_def_id) = path_def_id(self.cx, f)
|
||||
&& let Some(trait_def_id) = self.cx.tcx.trait_of_item(method_def_id)
|
||||
&& let Some(trait_def_id) = self.cx.tcx.trait_of_assoc(method_def_id)
|
||||
&& self.cx.tcx.is_diagnostic_item(sym::Default, trait_def_id)
|
||||
{
|
||||
span_error(self.cx, self.method_span, expr);
|
||||
|
|
@ -426,7 +426,7 @@ fn check_from(cx: &LateContext<'_>, method_span: Span, method_def_id: LocalDefId
|
|||
if let Some((fn_def_id, node_args)) = fn_def_id_with_node_args(cx, expr)
|
||||
&& let [s1, s2] = **node_args
|
||||
&& let (Some(s1), Some(s2)) = (s1.as_type(), s2.as_type())
|
||||
&& let Some(trait_def_id) = cx.tcx.trait_of_item(fn_def_id)
|
||||
&& let Some(trait_def_id) = cx.tcx.trait_of_assoc(fn_def_id)
|
||||
&& cx.tcx.is_diagnostic_item(sym::Into, trait_def_id)
|
||||
&& get_impl_trait_def_id(cx, method_def_id) == cx.tcx.get_diagnostic_item(sym::From)
|
||||
&& s1 == sig.inputs()[0]
|
||||
|
|
|
|||
|
|
@ -300,7 +300,7 @@ fn check_io_mode(cx: &LateContext<'_>, call: &hir::Expr<'_>) -> Option<IoOp> {
|
|||
};
|
||||
|
||||
if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(call.hir_id)
|
||||
&& let Some(trait_def_id) = cx.tcx.trait_of_item(method_def_id)
|
||||
&& let Some(trait_def_id) = cx.tcx.trait_of_assoc(method_def_id)
|
||||
{
|
||||
if let Some(diag_name) = cx.tcx.get_diagnostic_name(trait_def_id) {
|
||||
match diag_name {
|
||||
|
|
|
|||
|
|
@ -349,7 +349,7 @@ pub fn is_ty_alias(qpath: &QPath<'_>) -> bool {
|
|||
/// Checks if the given method call expression calls an inherent method.
|
||||
pub fn is_inherent_method_call(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||
if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) {
|
||||
cx.tcx.trait_of_item(method_id).is_none()
|
||||
cx.tcx.trait_of_assoc(method_id).is_none()
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
|
@ -367,7 +367,7 @@ pub fn is_diag_item_method(cx: &LateContext<'_>, def_id: DefId, diag_item: Symbo
|
|||
|
||||
/// Checks if a method is in a diagnostic item trait
|
||||
pub fn is_diag_trait_item(cx: &LateContext<'_>, def_id: DefId, diag_item: Symbol) -> bool {
|
||||
if let Some(trait_did) = cx.tcx.trait_of_item(def_id) {
|
||||
if let Some(trait_did) = cx.tcx.trait_of_assoc(def_id) {
|
||||
return cx.tcx.is_diagnostic_item(diag_item, trait_did);
|
||||
}
|
||||
false
|
||||
|
|
|
|||
|
|
@ -420,7 +420,7 @@ pub fn is_stable_const_fn(cx: &LateContext<'_>, def_id: DefId, msrv: Msrv) -> bo
|
|||
.lookup_const_stability(def_id)
|
||||
.or_else(|| {
|
||||
cx.tcx
|
||||
.trait_of_item(def_id)
|
||||
.trait_of_assoc(def_id)
|
||||
.and_then(|trait_def_id| cx.tcx.lookup_const_stability(trait_def_id))
|
||||
})
|
||||
.is_none_or(|const_stab| {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue