Rename impl_of_method -> impl_of_assoc
This commit is contained in:
parent
172af038a7
commit
b43164cef6
41 changed files with 45 additions and 45 deletions
|
|
@ -682,7 +682,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
}
|
||||
let my_def = self.body.source.def_id();
|
||||
let Some(td) =
|
||||
self.infcx.tcx.impl_of_method(my_def).and_then(|x| self.infcx.tcx.trait_id_of_impl(x))
|
||||
self.infcx.tcx.impl_of_assoc(my_def).and_then(|x| self.infcx.tcx.trait_id_of_impl(x))
|
||||
else {
|
||||
return (false, false, None);
|
||||
};
|
||||
|
|
@ -880,7 +880,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
let opt_suggestions = tcx
|
||||
.typeck(path_segment.hir_id.owner.def_id)
|
||||
.type_dependent_def_id(expr.hir_id)
|
||||
.and_then(|def_id| tcx.impl_of_method(def_id))
|
||||
.and_then(|def_id| tcx.impl_of_assoc(def_id))
|
||||
.map(|def_id| tcx.associated_items(def_id))
|
||||
.map(|assoc_items| {
|
||||
assoc_items
|
||||
|
|
@ -1056,7 +1056,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
.tcx
|
||||
.typeck(path_segment.hir_id.owner.def_id)
|
||||
.type_dependent_def_id(cur_expr.hir_id)
|
||||
.and_then(|def_id| self.infcx.tcx.impl_of_method(def_id))
|
||||
.and_then(|def_id| self.infcx.tcx.impl_of_assoc(def_id))
|
||||
.map(|def_id| self.infcx.tcx.associated_items(def_id))
|
||||
.map(|assoc_items| {
|
||||
assoc_items.filter_by_name_unhygienic(sym::iter_mut).peekable()
|
||||
|
|
|
|||
|
|
@ -1761,7 +1761,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
|
|||
);
|
||||
|
||||
assert!(!matches!(
|
||||
tcx.impl_of_method(def_id).map(|imp| tcx.def_kind(imp)),
|
||||
tcx.impl_of_assoc(def_id).map(|imp| tcx.def_kind(imp)),
|
||||
Some(DefKind::Impl { of_trait: true })
|
||||
));
|
||||
self.prove_predicates(
|
||||
|
|
|
|||
|
|
@ -533,7 +533,7 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
|
|||
// First, let's see if this is a method within an inherent impl. Because
|
||||
// if yes, we want to make the result subroutine DIE a child of the
|
||||
// subroutine's self-type.
|
||||
if let Some(impl_def_id) = cx.tcx.impl_of_method(instance.def_id()) {
|
||||
if let Some(impl_def_id) = cx.tcx.impl_of_assoc(instance.def_id()) {
|
||||
// If the method does *not* belong to a trait, proceed
|
||||
if cx.tcx.trait_id_of_impl(impl_def_id).is_none() {
|
||||
let impl_self_ty = cx.tcx.instantiate_and_normalize_erasing_regions(
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
|
|||
// Only consider nodes that actually have exported symbols.
|
||||
match tcx.def_kind(def_id) {
|
||||
DefKind::Fn | DefKind::Static { .. } => {}
|
||||
DefKind::AssocFn if tcx.impl_of_method(def_id.to_def_id()).is_some() => {}
|
||||
DefKind::AssocFn if tcx.impl_of_assoc(def_id.to_def_id()).is_some() => {}
|
||||
_ => return None,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -755,7 +755,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||
let limit = if candidates.len() == 5 { 5 } else { 4 };
|
||||
|
||||
for (index, &item) in candidates.iter().take(limit).enumerate() {
|
||||
let impl_ = tcx.impl_of_method(item).unwrap();
|
||||
let impl_ = tcx.impl_of_assoc(item).unwrap();
|
||||
|
||||
let note_span = if item.is_local() {
|
||||
Some(tcx.def_span(item))
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for MapUnitFn {
|
|||
|
||||
fn is_impl_slice(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||
if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_method(method_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_assoc(method_id)
|
||||
{
|
||||
return cx.tcx.type_of(impl_id).skip_binder().is_slice();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByValue {
|
|||
fn check_ty(&mut self, cx: &LateContext<'_>, ty: &'tcx hir::Ty<'tcx, AmbigArg>) {
|
||||
match &ty.kind {
|
||||
TyKind::Ref(_, hir::MutTy { ty: inner_ty, mutbl: hir::Mutability::Not }) => {
|
||||
if let Some(impl_did) = cx.tcx.impl_of_method(ty.hir_id.owner.to_def_id()) {
|
||||
if let Some(impl_did) = cx.tcx.impl_of_assoc(ty.hir_id.owner.to_def_id()) {
|
||||
if cx.tcx.impl_trait_ref(impl_did).is_some() {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1904,7 +1904,7 @@ impl InvalidAtomicOrdering {
|
|||
if let ExprKind::MethodCall(method_path, _, args, _) = &expr.kind
|
||||
&& recognized_names.contains(&method_path.ident.name)
|
||||
&& let Some(m_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
|
||||
&& let Some(impl_did) = cx.tcx.impl_of_method(m_def_id)
|
||||
&& let Some(impl_did) = cx.tcx.impl_of_assoc(m_def_id)
|
||||
&& let Some(adt) = cx.tcx.type_of(impl_did).instantiate_identity().ty_adt_def()
|
||||
// skip extension traits, only lint functions from the standard library
|
||||
&& cx.tcx.trait_id_of_impl(impl_did).is_none()
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ impl EffectiveVisibilities {
|
|||
// don't check this condition for them.
|
||||
let is_impl = matches!(tcx.def_kind(def_id), DefKind::Impl { .. });
|
||||
let is_associated_item_in_trait_impl = tcx
|
||||
.impl_of_method(def_id.to_def_id())
|
||||
.impl_of_assoc(def_id.to_def_id())
|
||||
.and_then(|impl_id| tcx.trait_id_of_impl(impl_id))
|
||||
.is_some();
|
||||
if !is_impl && !is_associated_item_in_trait_impl {
|
||||
|
|
|
|||
|
|
@ -2002,7 +2002,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
|
||||
/// If the given `DefId` describes a method belonging to an impl, returns the
|
||||
/// `DefId` of the impl that the method belongs to; otherwise, returns `None`.
|
||||
pub fn impl_of_method(self, def_id: DefId) -> Option<DefId> {
|
||||
pub fn impl_of_assoc(self, def_id: DefId) -> Option<DefId> {
|
||||
self.assoc_parent(def_id).filter(|id| matches!(self.def_kind(id), DefKind::Impl { .. }))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ impl<'tcx> MirLint<'tcx> for CheckDropRecursion {
|
|||
// First check if `body` is an `fn drop()` of `Drop`
|
||||
if let DefKind::AssocFn = tcx.def_kind(def_id)
|
||||
&& let Some(trait_ref) =
|
||||
tcx.impl_of_method(def_id.to_def_id()).and_then(|def_id| tcx.impl_trait_ref(def_id))
|
||||
tcx.impl_of_assoc(def_id.to_def_id()).and_then(|def_id| tcx.impl_trait_ref(def_id))
|
||||
&& tcx.is_lang_item(trait_ref.instantiate_identity().def_id, LangItem::Drop)
|
||||
// avoid erroneous `Drop` impls from causing ICEs below
|
||||
&& let sig = tcx.fn_sig(def_id).instantiate_identity()
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ impl<'tcx> Visitor<'tcx> for PackedRefChecker<'_, 'tcx> {
|
|||
if context.is_borrow() && util::is_disaligned(self.tcx, self.body, self.typing_env, *place)
|
||||
{
|
||||
let def_id = self.body.source.instance.def_id();
|
||||
if let Some(impl_def_id) = self.tcx.impl_of_method(def_id)
|
||||
if let Some(impl_def_id) = self.tcx.impl_of_assoc(def_id)
|
||||
&& self.tcx.is_builtin_derived(impl_def_id)
|
||||
{
|
||||
// If we ever reach here it means that the generated derive
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ fn is_eligible_for_coverage(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
|
|||
// Don't instrument functions with `#[automatically_derived]` on their
|
||||
// enclosing impl block, on the assumption that most users won't care about
|
||||
// coverage for derived impls.
|
||||
if let Some(impl_of) = tcx.impl_of_method(def_id.to_def_id())
|
||||
if let Some(impl_of) = tcx.impl_of_assoc(def_id.to_def_id())
|
||||
&& tcx.is_automatically_derived(impl_of)
|
||||
{
|
||||
trace!("InstrumentCoverage skipped for {def_id:?} (automatically derived)");
|
||||
|
|
|
|||
|
|
@ -656,7 +656,7 @@ fn characteristic_def_id_of_mono_item<'tcx>(
|
|||
return characteristic_def_id_of_type(self_ty).or(Some(def_id));
|
||||
}
|
||||
|
||||
if let Some(impl_def_id) = tcx.impl_of_method(def_id) {
|
||||
if let Some(impl_def_id) = tcx.impl_of_assoc(def_id) {
|
||||
if tcx.sess.opts.incremental.is_some()
|
||||
&& tcx
|
||||
.trait_id_of_impl(impl_def_id)
|
||||
|
|
|
|||
|
|
@ -368,7 +368,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
|
|||
/// will be ignored for the purposes of dead code analysis (see PR #85200
|
||||
/// for discussion).
|
||||
fn should_ignore_item(&mut self, def_id: DefId) -> bool {
|
||||
if let Some(impl_of) = self.tcx.impl_of_method(def_id) {
|
||||
if let Some(impl_of) = self.tcx.impl_of_assoc(def_id) {
|
||||
if !self.tcx.is_automatically_derived(impl_of) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -466,7 +466,7 @@ fn implemented_method<'tcx>(
|
|||
let method_id;
|
||||
let trait_id;
|
||||
let trait_method;
|
||||
let ancestor = if let Some(impl_id) = tcx.impl_of_method(instance.def_id()) {
|
||||
let ancestor = if let Some(impl_id) = tcx.impl_of_assoc(instance.def_id()) {
|
||||
// Implementation in an `impl` block
|
||||
trait_ref = tcx.impl_trait_ref(impl_id)?;
|
||||
let impl_method = tcx.associated_item(instance.def_id());
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for AssigningClones {
|
|||
// That is overly conservative - the lint should fire even if there was no initializer,
|
||||
// but the variable has been initialized before `lhs` was evaluated.
|
||||
&& path_to_local(lhs).is_none_or(|lhs| local_is_initialized(cx, lhs))
|
||||
&& let Some(resolved_impl) = cx.tcx.impl_of_method(resolved_fn.def_id())
|
||||
&& let Some(resolved_impl) = cx.tcx.impl_of_assoc(resolved_fn.def_id())
|
||||
// Derived forms don't implement `clone_from`/`clone_into`.
|
||||
// See https://github.com/rust-lang/rust/pull/98445#issuecomment-1190681305
|
||||
&& !cx.tcx.is_builtin_derived(resolved_impl)
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ fn is_used_as_unaligned(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
|
|||
ExprKind::MethodCall(name, self_arg, ..) if self_arg.hir_id == e.hir_id => {
|
||||
if matches!(name.ident.name, sym::read_unaligned | sym::write_unaligned)
|
||||
&& let Some(def_id) = cx.typeck_results().type_dependent_def_id(parent.hir_id)
|
||||
&& let Some(def_id) = cx.tcx.impl_of_method(def_id)
|
||||
&& let Some(def_id) = cx.tcx.impl_of_assoc(def_id)
|
||||
&& cx.tcx.type_of(def_id).instantiate_identity().is_raw_ptr()
|
||||
{
|
||||
true
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ fn get_const_name_and_ty_name(
|
|||
} else {
|
||||
return None;
|
||||
}
|
||||
} else if let Some(impl_id) = cx.tcx.impl_of_method(method_def_id)
|
||||
} else if let Some(impl_id) = cx.tcx.impl_of_assoc(method_def_id)
|
||||
&& let Some(ty_name) = get_primitive_ty_name(cx.tcx.type_of(impl_id).instantiate_identity())
|
||||
&& matches!(
|
||||
method_name,
|
||||
|
|
|
|||
|
|
@ -339,7 +339,7 @@ fn check_with_condition<'tcx>(
|
|||
ExprKind::Path(QPath::TypeRelative(_, name)) => {
|
||||
if name.ident.name == sym::MIN
|
||||
&& let Some(const_id) = cx.typeck_results().type_dependent_def_id(cond_num_val.hir_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_method(const_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_assoc(const_id)
|
||||
&& let None = cx.tcx.impl_trait_ref(impl_id) // An inherent impl
|
||||
&& cx.tcx.type_of(impl_id).instantiate_identity().is_integral()
|
||||
{
|
||||
|
|
@ -350,7 +350,7 @@ fn check_with_condition<'tcx>(
|
|||
if let ExprKind::Path(QPath::TypeRelative(_, name)) = func.kind
|
||||
&& name.ident.name == sym::min_value
|
||||
&& let Some(func_id) = cx.typeck_results().type_dependent_def_id(func.hir_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_method(func_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_assoc(func_id)
|
||||
&& let None = cx.tcx.impl_trait_ref(impl_id) // An inherent impl
|
||||
&& cx.tcx.type_of(impl_id).instantiate_identity().is_integral()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ pub(super) fn check<'tcx>(
|
|||
bytes_recv: &'tcx hir::Expr<'_>,
|
||||
) {
|
||||
if let Some(bytes_id) = cx.typeck_results().type_dependent_def_id(count_recv.hir_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_method(bytes_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_assoc(bytes_id)
|
||||
&& cx.tcx.type_of(impl_id).instantiate_identity().is_str()
|
||||
&& let ty = cx.typeck_results().expr_ty(bytes_recv).peel_refs()
|
||||
&& (ty.is_str() || is_type_lang_item(cx, ty, hir::LangItem::String))
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ pub(super) fn check<'tcx>(
|
|||
}
|
||||
|
||||
if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_method(method_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_assoc(method_id)
|
||||
&& cx.tcx.type_of(impl_id).instantiate_identity().is_str()
|
||||
&& let ExprKind::Lit(Spanned {
|
||||
node: LitKind::Str(ext_literal, ..),
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ pub(super) fn check<'tcx>(
|
|||
arg: &'tcx hir::Expr<'_>,
|
||||
) {
|
||||
if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_method(method_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_assoc(method_id)
|
||||
&& let identity = cx.tcx.type_of(impl_id).instantiate_identity()
|
||||
&& let hir::ExprKind::Lit(Spanned {
|
||||
node: LitKind::Int(Pu128(0), _),
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ pub fn is_clone_like(cx: &LateContext<'_>, method_name: Symbol, method_def_id: h
|
|||
sym::to_path_buf => is_diag_item_method(cx, method_def_id, sym::Path),
|
||||
sym::to_vec => cx
|
||||
.tcx
|
||||
.impl_of_method(method_def_id)
|
||||
.impl_of_assoc(method_def_id)
|
||||
.filter(|&impl_did| {
|
||||
cx.tcx.type_of(impl_did).instantiate_identity().is_slice() && cx.tcx.impl_trait_ref(impl_did).is_none()
|
||||
})
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ pub(super) fn check<'tcx>(
|
|||
map_expr: &'tcx Expr<'_>,
|
||||
) {
|
||||
if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_method(method_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_assoc(method_id)
|
||||
&& is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).instantiate_identity(), sym::Option)
|
||||
&& let ExprKind::Call(err_path, [err_arg]) = or_expr.kind
|
||||
&& is_res_lang_ctor(cx, path_res(cx, err_path), ResultErr)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ fn should_run_lint(cx: &LateContext<'_>, e: &hir::Expr<'_>, method_id: DefId) ->
|
|||
return true;
|
||||
}
|
||||
// We check if it's an `Option` or a `Result`.
|
||||
if let Some(id) = cx.tcx.impl_of_method(method_id) {
|
||||
if let Some(id) = cx.tcx.impl_of_assoc(method_id) {
|
||||
let identity = cx.tcx.type_of(id).instantiate_identity();
|
||||
if !is_type_diagnostic_item(cx, identity, sym::Option) && !is_type_diagnostic_item(cx, identity, sym::Result) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use super::MAP_ERR_IGNORE;
|
|||
|
||||
pub(super) fn check(cx: &LateContext<'_>, e: &Expr<'_>, arg: &Expr<'_>) {
|
||||
if let Some(method_id) = cx.typeck_results().type_dependent_def_id(e.hir_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_method(method_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_assoc(method_id)
|
||||
&& is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).instantiate_identity(), sym::Result)
|
||||
&& let ExprKind::Closure(&Closure {
|
||||
capture_clause: CaptureBy::Ref,
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, ex: &'tcx Expr<'tcx>, recv: &'
|
|||
&& let (_, ref_depth, Mutability::Mut) = peel_mid_ty_refs_is_mutable(cx.typeck_results().expr_ty(recv))
|
||||
&& ref_depth >= 1
|
||||
&& let Some(method_id) = cx.typeck_results().type_dependent_def_id(ex.hir_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_method(method_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_assoc(method_id)
|
||||
&& is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).instantiate_identity(), sym::Mutex)
|
||||
{
|
||||
span_lint_and_sugg(
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ fn is_open_options(cx: &LateContext<'_>, ty: Ty<'_>) -> bool {
|
|||
|
||||
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, recv: &'tcx Expr<'_>) {
|
||||
if let Some(method_id) = cx.typeck_results().type_dependent_def_id(e.hir_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_method(method_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_assoc(method_id)
|
||||
&& is_open_options(cx, cx.tcx.type_of(impl_id).instantiate_identity())
|
||||
{
|
||||
let mut options = Vec::new();
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use super::PATH_BUF_PUSH_OVERWRITE;
|
|||
|
||||
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, arg: &'tcx Expr<'_>) {
|
||||
if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_method(method_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_assoc(method_id)
|
||||
&& is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).instantiate_identity(), sym::PathBuf)
|
||||
&& let ExprKind::Lit(lit) = arg.kind
|
||||
&& let LitKind::Str(ref path_lit, _) = lit.node
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use super::STABLE_SORT_PRIMITIVE;
|
|||
|
||||
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, recv: &'tcx Expr<'_>) {
|
||||
if let Some(method_id) = cx.typeck_results().type_dependent_def_id(e.hir_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_method(method_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_assoc(method_id)
|
||||
&& cx.tcx.type_of(impl_id).instantiate_identity().is_slice()
|
||||
&& let Some(slice_type) = is_slice_of_primitives(cx, recv)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use super::SUSPICIOUS_SPLITN;
|
|||
pub(super) fn check(cx: &LateContext<'_>, method_name: Symbol, expr: &Expr<'_>, self_arg: &Expr<'_>, count: u128) {
|
||||
if count <= 1
|
||||
&& let Some(call_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_method(call_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_assoc(call_id)
|
||||
&& cx.tcx.impl_trait_ref(impl_id).is_none()
|
||||
&& let self_ty = cx.tcx.type_of(impl_id).instantiate_identity()
|
||||
&& (self_ty.is_slice() || self_ty.is_str())
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ fn mirrored_exprs(a_expr: &Expr<'_>, a_ident: &Ident, b_expr: &Expr<'_>, b_ident
|
|||
|
||||
fn detect_lint(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, arg: &Expr<'_>) -> Option<LintTrigger> {
|
||||
if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_method(method_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_assoc(method_id)
|
||||
&& cx.tcx.type_of(impl_id).instantiate_identity().is_slice()
|
||||
&& let ExprKind::Closure(&Closure { body, .. }) = arg.kind
|
||||
&& let closure_body = cx.tcx.hir_body(body)
|
||||
|
|
|
|||
|
|
@ -694,7 +694,7 @@ fn check_if_applicable_to_argument<'tcx>(cx: &LateContext<'tcx>, arg: &Expr<'tcx
|
|||
sym::to_string => cx.tcx.is_diagnostic_item(sym::to_string_method, method_def_id),
|
||||
sym::to_vec => cx
|
||||
.tcx
|
||||
.impl_of_method(method_def_id)
|
||||
.impl_of_assoc(method_def_id)
|
||||
.filter(|&impl_did| cx.tcx.type_of(impl_did).instantiate_identity().is_slice())
|
||||
.is_some(),
|
||||
_ => false,
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, call_name: Symbo
|
|||
applicability,
|
||||
);
|
||||
}
|
||||
} else if let Some(impl_id) = cx.tcx.impl_of_method(def_id)
|
||||
} else if let Some(impl_id) = cx.tcx.impl_of_assoc(def_id)
|
||||
&& let Some(adt) = cx.tcx.type_of(impl_id).instantiate_identity().ty_adt_def()
|
||||
&& matches!(cx.tcx.get_diagnostic_name(adt.did()), Some(sym::Option | sym::Result))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ pub(super) fn check<'tcx>(
|
|||
name_span: Span,
|
||||
) {
|
||||
if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_method(method_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_assoc(method_id)
|
||||
&& is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).instantiate_identity(), sym::Vec)
|
||||
&& let ExprKind::Lit(Spanned {
|
||||
node: LitKind::Int(Pu128(0), _),
|
||||
|
|
|
|||
|
|
@ -179,7 +179,7 @@ fn in_impl<'tcx>(
|
|||
bin_op: DefId,
|
||||
) -> Option<(&'tcx rustc_hir::Ty<'tcx>, &'tcx rustc_hir::Ty<'tcx>)> {
|
||||
if let Some(block) = get_enclosing_block(cx, e.hir_id)
|
||||
&& let Some(impl_def_id) = cx.tcx.impl_of_method(block.hir_id.owner.to_def_id())
|
||||
&& let Some(impl_def_id) = cx.tcx.impl_of_assoc(block.hir_id.owner.to_def_id())
|
||||
&& let item = cx.tcx.hir_expect_item(impl_def_id.expect_local())
|
||||
&& let ItemKind::Impl(item) = &item.kind
|
||||
&& let Some(of_trait) = &item.of_trait
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ impl<'tcx> LateLintPass<'tcx> for ReturnSelfNotMustUse {
|
|||
) {
|
||||
if matches!(kind, FnKind::Method(_, _))
|
||||
// We are only interested in methods, not in functions or associated functions.
|
||||
&& let Some(impl_def) = cx.tcx.impl_of_method(fn_def.to_def_id())
|
||||
&& let Some(impl_def) = cx.tcx.impl_of_assoc(fn_def.to_def_id())
|
||||
// We don't want this method to be te implementation of a trait because the
|
||||
// `#[must_use]` should be put on the trait definition directly.
|
||||
&& cx.tcx.trait_id_of_impl(impl_def).is_none()
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount {
|
|||
/// get desugared to match.
|
||||
fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx hir::Block<'tcx>) {
|
||||
let fn_def_id = block.hir_id.owner.to_def_id();
|
||||
if let Some(impl_id) = cx.tcx.impl_of_method(fn_def_id)
|
||||
if let Some(impl_id) = cx.tcx.impl_of_assoc(fn_def_id)
|
||||
&& let Some(trait_id) = cx.tcx.trait_id_of_impl(impl_id)
|
||||
{
|
||||
// We don't want to lint inside io::Read or io::Write implementations, as the author has more
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ impl ops::BitOrAssign for EagernessSuggestion {
|
|||
fn fn_eagerness(cx: &LateContext<'_>, fn_id: DefId, name: Symbol, have_one_arg: bool) -> EagernessSuggestion {
|
||||
use EagernessSuggestion::{Eager, Lazy, NoChange};
|
||||
|
||||
let ty = match cx.tcx.impl_of_method(fn_id) {
|
||||
let ty = match cx.tcx.impl_of_assoc(fn_id) {
|
||||
Some(id) => cx.tcx.type_of(id).instantiate_identity(),
|
||||
None => return Lazy,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -357,7 +357,7 @@ pub fn is_inherent_method_call(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
|||
|
||||
/// Checks if a method is defined in an impl of a diagnostic item
|
||||
pub fn is_diag_item_method(cx: &LateContext<'_>, def_id: DefId, diag_item: Symbol) -> bool {
|
||||
if let Some(impl_did) = cx.tcx.impl_of_method(def_id)
|
||||
if let Some(impl_did) = cx.tcx.impl_of_assoc(def_id)
|
||||
&& let Some(adt) = cx.tcx.type_of(impl_did).instantiate_identity().ty_adt_def()
|
||||
{
|
||||
return cx.tcx.is_diagnostic_item(diag_item, adt.did());
|
||||
|
|
@ -620,7 +620,7 @@ fn is_default_equivalent_ctor(cx: &LateContext<'_>, def_id: DefId, path: &QPath<
|
|||
|
||||
if let QPath::TypeRelative(_, method) = path
|
||||
&& method.ident.name == sym::new
|
||||
&& let Some(impl_did) = cx.tcx.impl_of_method(def_id)
|
||||
&& let Some(impl_did) = cx.tcx.impl_of_assoc(def_id)
|
||||
&& let Some(adt) = cx.tcx.type_of(impl_did).instantiate_identity().ty_adt_def()
|
||||
{
|
||||
return std_types_symbols.iter().any(|&symbol| {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue