Auto merge of #143357 - cjgillot:no-assoc-item-kind, r=compiler-errors
Retire hir::*ItemRef. This information was kept for various places that iterate on HIR to know about trait-items and impl-items. This PR replaces them by uses of the `associated_items` query that contain pretty much the same information. This shortens many spans to just `def_span`, which can be easier to read.
This commit is contained in:
commit
434fb311f1
29 changed files with 220 additions and 256 deletions
|
|
@ -8,11 +8,13 @@ use clippy_utils::diagnostics::span_lint_and_note;
|
|||
use clippy_utils::is_cfg_test;
|
||||
use rustc_attr_data_structures::AttributeKind;
|
||||
use rustc_hir::{
|
||||
AssocItemKind, Attribute, FieldDef, HirId, ImplItemRef, IsAuto, Item, ItemKind, Mod, QPath, TraitItemRef, TyKind,
|
||||
Attribute, FieldDef, HirId, IsAuto, ImplItemId, Item, ItemKind, Mod, OwnerId, QPath, TraitItemId, TyKind,
|
||||
Variant, VariantData,
|
||||
};
|
||||
use rustc_middle::ty::AssocKind;
|
||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||
use rustc_session::impl_lint_pass;
|
||||
use rustc_span::Ident;
|
||||
|
||||
declare_clippy_lint! {
|
||||
/// ### What it does
|
||||
|
|
@ -194,22 +196,22 @@ impl ArbitrarySourceItemOrdering {
|
|||
}
|
||||
|
||||
/// Produces a linting warning for incorrectly ordered impl items.
|
||||
fn lint_impl_item<T: LintContext>(&self, cx: &T, item: &ImplItemRef, before_item: &ImplItemRef) {
|
||||
fn lint_impl_item(&self, cx: &LateContext<'_>, item: ImplItemId, before_item: ImplItemId) {
|
||||
span_lint_and_note(
|
||||
cx,
|
||||
ARBITRARY_SOURCE_ITEM_ORDERING,
|
||||
item.span,
|
||||
cx.tcx.def_span(item.owner_id),
|
||||
format!(
|
||||
"incorrect ordering of impl items (defined order: {:?})",
|
||||
self.assoc_types_order
|
||||
),
|
||||
Some(before_item.span),
|
||||
format!("should be placed before `{}`", before_item.ident.name),
|
||||
Some(cx.tcx.def_span(before_item.owner_id)),
|
||||
format!("should be placed before `{}`", cx.tcx.item_name(before_item.owner_id)),
|
||||
);
|
||||
}
|
||||
|
||||
/// Produces a linting warning for incorrectly ordered item members.
|
||||
fn lint_member_name<T: LintContext>(cx: &T, ident: &rustc_span::Ident, before_ident: &rustc_span::Ident) {
|
||||
fn lint_member_name<T: LintContext>(cx: &T, ident: Ident, before_ident: Ident) {
|
||||
span_lint_and_note(
|
||||
cx,
|
||||
ARBITRARY_SOURCE_ITEM_ORDERING,
|
||||
|
|
@ -220,7 +222,7 @@ impl ArbitrarySourceItemOrdering {
|
|||
);
|
||||
}
|
||||
|
||||
fn lint_member_item<T: LintContext>(cx: &T, item: &Item<'_>, before_item: &Item<'_>, msg: &'static str) {
|
||||
fn lint_member_item(cx: &LateContext<'_>, item: &Item<'_>, before_item: &Item<'_>, msg: &'static str) {
|
||||
let span = if let Some(ident) = item.kind.ident() {
|
||||
ident.span
|
||||
} else {
|
||||
|
|
@ -245,17 +247,17 @@ impl ArbitrarySourceItemOrdering {
|
|||
}
|
||||
|
||||
/// Produces a linting warning for incorrectly ordered trait items.
|
||||
fn lint_trait_item<T: LintContext>(&self, cx: &T, item: &TraitItemRef, before_item: &TraitItemRef) {
|
||||
fn lint_trait_item(&self, cx: &LateContext<'_>, item: TraitItemId, before_item: TraitItemId) {
|
||||
span_lint_and_note(
|
||||
cx,
|
||||
ARBITRARY_SOURCE_ITEM_ORDERING,
|
||||
item.span,
|
||||
cx.tcx.def_span(item.owner_id),
|
||||
format!(
|
||||
"incorrect ordering of trait items (defined order: {:?})",
|
||||
self.assoc_types_order
|
||||
),
|
||||
Some(before_item.span),
|
||||
format!("should be placed before `{}`", before_item.ident.name),
|
||||
Some(cx.tcx.def_span(before_item.owner_id)),
|
||||
format!("should be placed before `{}`", cx.tcx.item_name(before_item.owner_id)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -283,7 +285,7 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
|
|||
&& cur_v.ident.name.as_str() > variant.ident.name.as_str()
|
||||
&& cur_v.span != variant.span
|
||||
{
|
||||
Self::lint_member_name(cx, &variant.ident, &cur_v.ident);
|
||||
Self::lint_member_name(cx, variant.ident, cur_v.ident);
|
||||
}
|
||||
cur_v = Some(variant);
|
||||
}
|
||||
|
|
@ -299,7 +301,7 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
|
|||
&& cur_f.ident.name.as_str() > field.ident.name.as_str()
|
||||
&& cur_f.span != field.span
|
||||
{
|
||||
Self::lint_member_name(cx, &field.ident, &cur_f.ident);
|
||||
Self::lint_member_name(cx, field.ident, cur_f.ident);
|
||||
}
|
||||
cur_f = Some(field);
|
||||
}
|
||||
|
|
@ -307,49 +309,53 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
|
|||
ItemKind::Trait(is_auto, _safety, _ident, _generics, _generic_bounds, item_ref)
|
||||
if self.enable_ordering_for_trait && *is_auto == IsAuto::No =>
|
||||
{
|
||||
let mut cur_t: Option<&TraitItemRef> = None;
|
||||
let mut cur_t: Option<(TraitItemId, Ident)> = None;
|
||||
|
||||
for item in *item_ref {
|
||||
if item.span.in_external_macro(cx.sess().source_map()) {
|
||||
for &item in *item_ref {
|
||||
let span = cx.tcx.def_span(item.owner_id);
|
||||
let ident = cx.tcx.item_ident(item.owner_id);
|
||||
if span.in_external_macro(cx.sess().source_map()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Some(cur_t) = cur_t {
|
||||
let cur_t_kind = convert_assoc_item_kind(cur_t.kind);
|
||||
if let Some((cur_t, cur_ident)) = cur_t {
|
||||
let cur_t_kind = convert_assoc_item_kind(cx, cur_t.owner_id);
|
||||
let cur_t_kind_index = self.assoc_types_order.index_of(&cur_t_kind);
|
||||
let item_kind = convert_assoc_item_kind(item.kind);
|
||||
let item_kind = convert_assoc_item_kind(cx, item.owner_id);
|
||||
let item_kind_index = self.assoc_types_order.index_of(&item_kind);
|
||||
|
||||
if cur_t_kind == item_kind && cur_t.ident.name.as_str() > item.ident.name.as_str() {
|
||||
Self::lint_member_name(cx, &item.ident, &cur_t.ident);
|
||||
if cur_t_kind == item_kind && cur_ident.name.as_str() > ident.name.as_str() {
|
||||
Self::lint_member_name(cx, ident, cur_ident);
|
||||
} else if cur_t_kind_index > item_kind_index {
|
||||
self.lint_trait_item(cx, item, cur_t);
|
||||
}
|
||||
}
|
||||
cur_t = Some(item);
|
||||
cur_t = Some((item, ident));
|
||||
}
|
||||
},
|
||||
ItemKind::Impl(trait_impl) if self.enable_ordering_for_impl => {
|
||||
let mut cur_t: Option<&ImplItemRef> = None;
|
||||
let mut cur_t: Option<(ImplItemId, Ident)> = None;
|
||||
|
||||
for item in trait_impl.items {
|
||||
if item.span.in_external_macro(cx.sess().source_map()) {
|
||||
for &item in trait_impl.items {
|
||||
let span = cx.tcx.def_span(item.owner_id);
|
||||
let ident = cx.tcx.item_ident(item.owner_id);
|
||||
if span.in_external_macro(cx.sess().source_map()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Some(cur_t) = cur_t {
|
||||
let cur_t_kind = convert_assoc_item_kind(cur_t.kind);
|
||||
if let Some((cur_t, cur_ident)) = cur_t {
|
||||
let cur_t_kind = convert_assoc_item_kind(cx, cur_t.owner_id);
|
||||
let cur_t_kind_index = self.assoc_types_order.index_of(&cur_t_kind);
|
||||
let item_kind = convert_assoc_item_kind(item.kind);
|
||||
let item_kind = convert_assoc_item_kind(cx, item.owner_id);
|
||||
let item_kind_index = self.assoc_types_order.index_of(&item_kind);
|
||||
|
||||
if cur_t_kind == item_kind && cur_t.ident.name.as_str() > item.ident.name.as_str() {
|
||||
Self::lint_member_name(cx, &item.ident, &cur_t.ident);
|
||||
if cur_t_kind == item_kind && cur_ident.name.as_str() > ident.name.as_str() {
|
||||
Self::lint_member_name(cx, ident, cur_ident);
|
||||
} else if cur_t_kind_index > item_kind_index {
|
||||
self.lint_impl_item(cx, item, cur_t);
|
||||
}
|
||||
}
|
||||
cur_t = Some(item);
|
||||
cur_t = Some((item, ident));
|
||||
}
|
||||
},
|
||||
_ => {}, // Catch-all for `ItemKinds` that don't have fields.
|
||||
|
|
@ -458,18 +464,19 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
|
|||
}
|
||||
}
|
||||
|
||||
/// Converts a [`rustc_hir::AssocItemKind`] to a
|
||||
/// [`SourceItemOrderingTraitAssocItemKind`].
|
||||
/// Converts a [`ty::AssocKind`] to a [`SourceItemOrderingTraitAssocItemKind`].
|
||||
///
|
||||
/// This is implemented here because `rustc_hir` is not a dependency of
|
||||
/// `clippy_config`.
|
||||
fn convert_assoc_item_kind(value: AssocItemKind) -> SourceItemOrderingTraitAssocItemKind {
|
||||
fn convert_assoc_item_kind(cx: &LateContext<'_>, owner_id: OwnerId) -> SourceItemOrderingTraitAssocItemKind {
|
||||
let kind = cx.tcx.associated_item(owner_id.def_id).kind;
|
||||
|
||||
#[allow(clippy::enum_glob_use)] // Very local glob use for legibility.
|
||||
use SourceItemOrderingTraitAssocItemKind::*;
|
||||
match value {
|
||||
AssocItemKind::Const => Const,
|
||||
AssocItemKind::Type => Type,
|
||||
AssocItemKind::Fn { .. } => Fn,
|
||||
match kind {
|
||||
AssocKind::Const{..} => Const,
|
||||
AssocKind::Type {..}=> Type,
|
||||
AssocKind::Fn { .. } => Fn,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -192,7 +192,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
|
|||
&& !item.span.from_expansion()
|
||||
&& let Some(def_id) = trait_ref.trait_def_id()
|
||||
&& cx.tcx.is_diagnostic_item(sym::Default, def_id)
|
||||
&& let impl_item_hir = child.id.hir_id()
|
||||
&& let impl_item_hir = child.hir_id()
|
||||
&& let Node::ImplItem(impl_item) = cx.tcx.hir_node(impl_item_hir)
|
||||
&& let ImplItemKind::Fn(_, b) = &impl_item.kind
|
||||
&& let Body { value: func_expr, .. } = cx.tcx.hir_body(*b)
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ impl LateLintPass<'_> for EmptyDrop {
|
|||
..
|
||||
}) = item.kind
|
||||
&& trait_ref.trait_def_id() == cx.tcx.lang_items().drop_trait()
|
||||
&& let impl_item_hir = child.id.hir_id()
|
||||
&& let impl_item_hir = child.hir_id()
|
||||
&& let Node::ImplItem(impl_item) = cx.tcx.hir_node(impl_item_hir)
|
||||
&& let ImplItemKind::Fn(_, b) = &impl_item.kind
|
||||
&& let Body { value: func_expr, .. } = cx.tcx.hir_body(*b)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
use clippy_config::Conf;
|
||||
use clippy_utils::diagnostics::span_lint_hir;
|
||||
use rustc_abi::ExternAbi;
|
||||
use rustc_hir::{AssocItemKind, Body, FnDecl, HirId, HirIdSet, Impl, ItemKind, Node, Pat, PatKind, intravisit};
|
||||
use rustc_hir::{Body, FnDecl, HirId, HirIdSet, Node, Pat, PatKind, intravisit};
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::mir::FakeReadCause;
|
||||
|
|
@ -84,23 +85,18 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
|
|||
.def_id;
|
||||
|
||||
let mut trait_self_ty = None;
|
||||
if let Node::Item(item) = cx.tcx.hir_node_by_def_id(parent_id) {
|
||||
match cx.tcx.def_kind(parent_id) {
|
||||
// If the method is an impl for a trait, don't warn.
|
||||
if let ItemKind::Impl(Impl { of_trait: Some(_), .. }) = item.kind {
|
||||
return;
|
||||
DefKind::Impl { of_trait: true } => {
|
||||
return
|
||||
}
|
||||
|
||||
// find `self` ty for this trait if relevant
|
||||
if let ItemKind::Trait(_, _, _, _, _, items) = item.kind {
|
||||
for trait_item in items {
|
||||
if trait_item.id.owner_id.def_id == fn_def_id
|
||||
// be sure we have `self` parameter in this function
|
||||
&& trait_item.kind == (AssocItemKind::Fn { has_self: true })
|
||||
{
|
||||
trait_self_ty = Some(TraitRef::identity(cx.tcx, trait_item.id.owner_id.to_def_id()).self_ty());
|
||||
}
|
||||
}
|
||||
DefKind::Trait => {
|
||||
trait_self_ty = Some(TraitRef::identity(cx.tcx, parent_id.to_def_id()).self_ty());
|
||||
}
|
||||
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let mut v = EscapeDelegate {
|
||||
|
|
|
|||
|
|
@ -52,20 +52,20 @@ declare_lint_pass!(FallibleImplFrom => [FALLIBLE_IMPL_FROM]);
|
|||
impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom {
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
|
||||
// check for `impl From<???> for ..`
|
||||
if let hir::ItemKind::Impl(impl_) = &item.kind
|
||||
if let hir::ItemKind::Impl(_) = &item.kind
|
||||
&& let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id)
|
||||
&& cx
|
||||
.tcx
|
||||
.is_diagnostic_item(sym::From, impl_trait_ref.skip_binder().def_id)
|
||||
{
|
||||
lint_impl_body(cx, item.span, impl_.items);
|
||||
lint_impl_body(cx, item.owner_id, item.span);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn lint_impl_body(cx: &LateContext<'_>, impl_span: Span, impl_items: &[hir::ImplItemRef]) {
|
||||
fn lint_impl_body(cx: &LateContext<'_>, item_def_id: hir::OwnerId, impl_span: Span) {
|
||||
use rustc_hir::intravisit::{self, Visitor};
|
||||
use rustc_hir::{Expr, ImplItemKind};
|
||||
use rustc_hir::Expr;
|
||||
|
||||
struct FindPanicUnwrap<'a, 'tcx> {
|
||||
lcx: &'a LateContext<'tcx>,
|
||||
|
|
@ -96,35 +96,35 @@ fn lint_impl_body(cx: &LateContext<'_>, impl_span: Span, impl_items: &[hir::Impl
|
|||
}
|
||||
}
|
||||
|
||||
for impl_item in impl_items {
|
||||
if impl_item.ident.name == sym::from
|
||||
&& let ImplItemKind::Fn(_, body_id) = cx.tcx.hir_impl_item(impl_item.id).kind
|
||||
{
|
||||
// check the body for `begin_panic` or `unwrap`
|
||||
let body = cx.tcx.hir_body(body_id);
|
||||
let mut fpu = FindPanicUnwrap {
|
||||
lcx: cx,
|
||||
typeck_results: cx.tcx.typeck(impl_item.id.owner_id.def_id),
|
||||
result: Vec::new(),
|
||||
};
|
||||
fpu.visit_expr(body.value);
|
||||
for impl_item in cx.tcx.associated_items(item_def_id)
|
||||
.filter_by_name_unhygienic_and_kind(sym::from, ty::AssocTag::Fn)
|
||||
{
|
||||
let impl_item_def_id= impl_item.def_id.expect_local();
|
||||
|
||||
// if we've found one, lint
|
||||
if !fpu.result.is_empty() {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
FALLIBLE_IMPL_FROM,
|
||||
impl_span,
|
||||
"consider implementing `TryFrom` instead",
|
||||
move |diag| {
|
||||
diag.help(
|
||||
"`From` is intended for infallible conversions only. \
|
||||
Use `TryFrom` if there's a possibility for the conversion to fail",
|
||||
);
|
||||
diag.span_note(fpu.result, "potential failure(s)");
|
||||
},
|
||||
);
|
||||
}
|
||||
// check the body for `begin_panic` or `unwrap`
|
||||
let body = cx.tcx.hir_body_owned_by(impl_item_def_id);
|
||||
let mut fpu = FindPanicUnwrap {
|
||||
lcx: cx,
|
||||
typeck_results: cx.tcx.typeck(impl_item_def_id),
|
||||
result: Vec::new(),
|
||||
};
|
||||
fpu.visit_expr(body.value);
|
||||
|
||||
// if we've found one, lint
|
||||
if !fpu.result.is_empty() {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
FALLIBLE_IMPL_FROM,
|
||||
impl_span,
|
||||
"consider implementing `TryFrom` instead",
|
||||
move |diag| {
|
||||
diag.help(
|
||||
"`From` is intended for infallible conversions only. \
|
||||
Use `TryFrom` if there's a possibility for the conversion to fail",
|
||||
);
|
||||
diag.span_note(fpu.result, "potential failure(s)");
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use clippy_utils::source::SpanRangeExt;
|
|||
use rustc_errors::Applicability;
|
||||
use rustc_hir::intravisit::{Visitor, walk_path};
|
||||
use rustc_hir::{
|
||||
FnRetTy, GenericArg, GenericArgs, HirId, Impl, ImplItemKind, ImplItemRef, Item, ItemKind, PatKind, Path,
|
||||
FnRetTy, GenericArg, GenericArgs, HirId, Impl, ImplItemKind, ImplItemId, Item, ItemKind, PatKind, Path,
|
||||
PathSegment, Ty, TyKind,
|
||||
};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
|
|
@ -102,7 +102,7 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto {
|
|||
middle_trait_ref.self_ty()
|
||||
);
|
||||
if let Some(suggestions) =
|
||||
convert_to_from(cx, into_trait_seg, target_ty.as_unambig_ty(), self_ty, impl_item_ref)
|
||||
convert_to_from(cx, into_trait_seg, target_ty.as_unambig_ty(), self_ty, *impl_item_ref)
|
||||
{
|
||||
diag.multipart_suggestion(message, suggestions, Applicability::MachineApplicable);
|
||||
} else {
|
||||
|
|
@ -164,14 +164,14 @@ fn convert_to_from(
|
|||
into_trait_seg: &PathSegment<'_>,
|
||||
target_ty: &Ty<'_>,
|
||||
self_ty: &Ty<'_>,
|
||||
impl_item_ref: &ImplItemRef,
|
||||
impl_item_ref: ImplItemId,
|
||||
) -> Option<Vec<(Span, String)>> {
|
||||
if !target_ty.find_self_aliases().is_empty() {
|
||||
// It's tricky to expand self-aliases correctly, we'll ignore it to not cause a
|
||||
// bad suggestion/fix.
|
||||
return None;
|
||||
}
|
||||
let impl_item = cx.tcx.hir_impl_item(impl_item_ref.id);
|
||||
let impl_item = cx.tcx.hir_impl_item(impl_item_ref);
|
||||
let ImplItemKind::Fn(ref sig, body_id) = impl_item.kind else {
|
||||
return None;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_then;
|
|||
use rustc_errors::{Applicability, MultiSpan};
|
||||
use rustc_hir::def_id::{DefId, DefIdSet};
|
||||
use rustc_hir::hir_id::OwnerId;
|
||||
use rustc_hir::{Impl, ImplItem, ImplItemKind, ImplItemRef, ItemKind, Node, TraitRef};
|
||||
use rustc_hir::{Impl, ImplItem, ImplItemKind, ItemKind, Node, TraitRef};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_span::Span;
|
||||
use rustc_span::symbol::{Ident, kw};
|
||||
|
|
@ -15,11 +15,10 @@ pub(super) fn check_impl_item(cx: &LateContext<'_>, item: &ImplItem<'_>, ignored
|
|||
&& let parent_node = cx.tcx.parent_hir_node(item.hir_id())
|
||||
&& let Node::Item(parent_item) = parent_node
|
||||
&& let ItemKind::Impl(Impl {
|
||||
items,
|
||||
of_trait: Some(trait_ref),
|
||||
..
|
||||
}) = &parent_item.kind
|
||||
&& let Some(did) = trait_item_def_id_of_impl(items, item.owner_id)
|
||||
&& let Some(did) = trait_item_def_id_of_impl(cx, item.owner_id)
|
||||
&& !is_from_ignored_trait(trait_ref, ignored_traits)
|
||||
{
|
||||
let mut param_idents_iter = cx.tcx.hir_body_param_idents(body_id);
|
||||
|
|
@ -93,14 +92,8 @@ impl RenamedFnArgs {
|
|||
}
|
||||
|
||||
/// Get the [`trait_item_def_id`](ImplItemRef::trait_item_def_id) of a relevant impl item.
|
||||
fn trait_item_def_id_of_impl(items: &[ImplItemRef], target: OwnerId) -> Option<DefId> {
|
||||
items.iter().find_map(|item| {
|
||||
if item.id.owner_id == target {
|
||||
item.trait_item_def_id
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
fn trait_item_def_id_of_impl(cx: &LateContext<'_>, target: OwnerId) -> Option<DefId> {
|
||||
cx.tcx.associated_item(target).trait_item_def_id
|
||||
}
|
||||
|
||||
fn is_from_ignored_trait(of_trait: &TraitRef<'_>, ignored_traits: &DefIdSet) -> bool {
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher {
|
|||
});
|
||||
|
||||
let mut ctr_vis = ImplicitHasherConstructorVisitor::new(cx, target);
|
||||
for item in impl_.items.iter().map(|item| cx.tcx.hir_impl_item(item.id)) {
|
||||
for item in impl_.items.iter().map(|&item| cx.tcx.hir_impl_item(item)) {
|
||||
ctr_vis.visit_impl_item(item);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
use clippy_utils::diagnostics::span_lint;
|
||||
use clippy_utils::sym;
|
||||
use rustc_errors::MultiSpan;
|
||||
use rustc_hir::{AssocItemKind, Item, ItemKind};
|
||||
use rustc_hir::{Item, ItemKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty::AssocTag;
|
||||
use rustc_session::declare_lint_pass;
|
||||
|
||||
declare_clippy_lint! {
|
||||
|
|
@ -51,25 +52,23 @@ impl<'tcx> LateLintPass<'tcx> for InfallibleTryFrom {
|
|||
if !cx.tcx.is_diagnostic_item(sym::TryFrom, trait_def_id) {
|
||||
return;
|
||||
}
|
||||
for ii in imp.items {
|
||||
if ii.kind == AssocItemKind::Type {
|
||||
let ii = cx.tcx.hir_impl_item(ii.id);
|
||||
if ii.ident.name != sym::Error {
|
||||
continue;
|
||||
}
|
||||
let ii_ty = ii.expect_type();
|
||||
let ii_ty_span = ii_ty.span;
|
||||
let ii_ty = clippy_utils::ty::ty_from_hir_ty(cx, ii_ty);
|
||||
if !ii_ty.is_inhabited_from(cx.tcx, ii.owner_id.to_def_id(), cx.typing_env()) {
|
||||
let mut span = MultiSpan::from_span(cx.tcx.def_span(item.owner_id.to_def_id()));
|
||||
span.push_span_label(ii_ty_span, "infallible error type");
|
||||
span_lint(
|
||||
cx,
|
||||
INFALLIBLE_TRY_FROM,
|
||||
span,
|
||||
"infallible TryFrom impl; consider implementing From, instead",
|
||||
);
|
||||
}
|
||||
for ii in cx.tcx.associated_items(item.owner_id.def_id)
|
||||
.filter_by_name_unhygienic_and_kind(sym::Error, AssocTag::Type)
|
||||
{
|
||||
let ii_ty = cx.tcx.type_of(ii.def_id).instantiate_identity();
|
||||
if !ii_ty.is_inhabited_from(cx.tcx, ii.def_id, cx.typing_env()) {
|
||||
let mut span = MultiSpan::from_span(cx.tcx.def_span(item.owner_id.to_def_id()));
|
||||
let ii_ty_span = cx.tcx.hir_node_by_def_id(ii.def_id.expect_local())
|
||||
.expect_impl_item()
|
||||
.expect_type()
|
||||
.span;
|
||||
span.push_span_label(ii_ty_span, "infallible error type");
|
||||
span_lint(
|
||||
cx,
|
||||
INFALLIBLE_TRY_FROM,
|
||||
span,
|
||||
"infallible TryFrom impl; consider implementing From, instead",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -139,13 +139,12 @@ impl LateLintPass<'_> for IterWithoutIntoIter {
|
|||
// We can't check inherent impls for slices, but we know that they have an `iter(_mut)` method
|
||||
ty.peel_refs().is_slice() || get_adt_inherent_method(cx, ty, expected_method_name).is_some()
|
||||
})
|
||||
&& let Some(iter_assoc_span) = imp.items.iter().find_map(|item| {
|
||||
if item.ident.name == sym::IntoIter {
|
||||
Some(cx.tcx.hir_impl_item(item.id).expect_type().span)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
&& let Some(iter_assoc_span) = cx.tcx.associated_items(item.owner_id)
|
||||
.filter_by_name_unhygienic_and_kind(sym::IntoIter, ty::AssocTag::Type)
|
||||
.next()
|
||||
.map(|assoc_item| {
|
||||
cx.tcx.hir_node_by_def_id(assoc_item.def_id.expect_local()).expect_impl_item().expect_type().span
|
||||
})
|
||||
&& is_ty_exported(cx, ty)
|
||||
{
|
||||
span_lint_and_then(
|
||||
|
|
|
|||
|
|
@ -10,14 +10,15 @@ use rustc_errors::Applicability;
|
|||
use rustc_hir::def::Res;
|
||||
use rustc_hir::def_id::{DefId, DefIdSet};
|
||||
use rustc_hir::{
|
||||
AssocItemKind, BinOpKind, Expr, ExprKind, FnRetTy, GenericArg, GenericBound, HirId, ImplItem, ImplItemKind,
|
||||
BinOpKind, Expr, ExprKind, FnRetTy, GenericArg, GenericBound, HirId, ImplItem, ImplItemKind,
|
||||
ImplicitSelfKind, Item, ItemKind, Mutability, Node, OpaqueTyOrigin, PatExprKind, PatKind, PathSegment, PrimTy,
|
||||
QPath, TraitItemRef, TyKind,
|
||||
QPath, TraitItemId, TyKind,
|
||||
};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty::{self, FnSig, Ty};
|
||||
use rustc_session::declare_lint_pass;
|
||||
use rustc_span::source_map::Spanned;
|
||||
use rustc_span::symbol::kw;
|
||||
use rustc_span::{Ident, Span, Symbol};
|
||||
use rustc_trait_selection::traits::supertrait_def_ids;
|
||||
|
||||
|
|
@ -264,22 +265,13 @@ fn span_without_enclosing_paren(cx: &LateContext<'_>, span: Span) -> Span {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, ident: Ident, trait_items: &[TraitItemRef]) {
|
||||
fn is_named_self(cx: &LateContext<'_>, item: &TraitItemRef, name: Symbol) -> bool {
|
||||
item.ident.name == name
|
||||
&& if let AssocItemKind::Fn { has_self } = item.kind {
|
||||
has_self && {
|
||||
cx.tcx
|
||||
.fn_sig(item.id.owner_id)
|
||||
.skip_binder()
|
||||
.inputs()
|
||||
.skip_binder()
|
||||
.len()
|
||||
== 1
|
||||
}
|
||||
} else {
|
||||
false
|
||||
}
|
||||
fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, ident: Ident, trait_items: &[TraitItemId]) {
|
||||
fn is_named_self(cx: &LateContext<'_>, item: &TraitItemId, name: Symbol) -> bool {
|
||||
cx.tcx.item_name(item.owner_id) == name
|
||||
&& matches!(
|
||||
cx.tcx.fn_arg_idents(item.owner_id),
|
||||
[Some(Ident { name: kw::SelfLower, .. })],
|
||||
)
|
||||
}
|
||||
|
||||
// fill the set with current and super traits
|
||||
|
|
|
|||
|
|
@ -716,7 +716,7 @@ fn report_extra_impl_lifetimes<'tcx>(cx: &LateContext<'tcx>, impl_: &'tcx Impl<'
|
|||
walk_trait_ref(&mut checker, trait_ref);
|
||||
}
|
||||
walk_unambig_ty(&mut checker, impl_.self_ty);
|
||||
for item in impl_.items {
|
||||
for &item in impl_.items {
|
||||
walk_impl_item_ref(&mut checker, item);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use rustc_ast::LitKind;
|
|||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::{
|
||||
Block, Expr, ExprKind, Impl, ImplItem, ImplItemKind, Item, ItemKind, LangItem, Node, QPath, TyKind, VariantData,
|
||||
Block, Expr, ExprKind, Impl, Item, ItemKind, LangItem, Node, QPath, TyKind, VariantData,
|
||||
};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty::{Ty, TypeckResults};
|
||||
|
|
@ -200,7 +200,7 @@ fn check_struct<'tcx>(
|
|||
impl<'tcx> LateLintPass<'tcx> for MissingFieldsInDebug {
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
|
||||
// is this an `impl Debug for X` block?
|
||||
if let ItemKind::Impl(Impl { of_trait: Some(trait_ref), self_ty, items, .. }) = item.kind
|
||||
if let ItemKind::Impl(Impl { of_trait: Some(trait_ref), self_ty, .. }) = item.kind
|
||||
&& let Res::Def(DefKind::Trait, trait_def_id) = trait_ref.path.res
|
||||
&& let TyKind::Path(QPath::Resolved(_, self_path)) = &self_ty.kind
|
||||
// make sure that the self type is either a struct, an enum or a union
|
||||
|
|
@ -212,9 +212,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingFieldsInDebug {
|
|||
&& !cx.tcx.is_automatically_derived(item.owner_id.to_def_id())
|
||||
&& !item.span.from_expansion()
|
||||
// find `Debug::fmt` function
|
||||
&& let Some(fmt_item) = items.iter().find(|i| i.ident.name == sym::fmt)
|
||||
&& let ImplItem { kind: ImplItemKind::Fn(_, body_id), .. } = cx.tcx.hir_impl_item(fmt_item.id)
|
||||
&& let body = cx.tcx.hir_body(*body_id)
|
||||
&& let Some(fmt_item) = cx.tcx.associated_items(item.owner_id).filter_by_name_unhygienic(sym::fmt).next()
|
||||
&& let body = cx.tcx.hir_body_owned_by(fmt_item.def_id.expect_local())
|
||||
&& let ExprKind::Block(block, _) = body.value.kind
|
||||
// inspect `self`
|
||||
&& let self_ty = cx.tcx.type_of(self_path_did).skip_binder().peel_refs()
|
||||
|
|
@ -222,7 +221,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingFieldsInDebug {
|
|||
&& let Some(self_def_id) = self_adt.did().as_local()
|
||||
&& let Node::Item(self_item) = cx.tcx.hir_node_by_def_id(self_def_id)
|
||||
// NB: can't call cx.typeck_results() as we are not in a body
|
||||
&& let typeck_results = cx.tcx.typeck_body(*body_id)
|
||||
&& let typeck_results = cx.tcx.typeck_body(body.id())
|
||||
&& should_lint(cx, typeck_results, block)
|
||||
// we intentionally only lint structs, see lint description
|
||||
&& let ItemKind::Struct(_, _, data) = &self_item.kind
|
||||
|
|
|
|||
|
|
@ -104,16 +104,16 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
|
|||
hir::ItemKind::Trait(ref _is_auto, ref _unsafe, _ident, _generics, _bounds, trait_items) => {
|
||||
// note: we need to check if the trait is exported so we can't use
|
||||
// `LateLintPass::check_trait_item` here.
|
||||
for tit in trait_items {
|
||||
let tit_ = cx.tcx.hir_trait_item(tit.id);
|
||||
for &tit in trait_items {
|
||||
let tit_ = cx.tcx.hir_trait_item(tit);
|
||||
match tit_.kind {
|
||||
hir::TraitItemKind::Const(..) | hir::TraitItemKind::Type(..) => {},
|
||||
hir::TraitItemKind::Fn(..) => {
|
||||
if cx.tcx.defaultness(tit.id.owner_id).has_value() {
|
||||
if cx.tcx.defaultness(tit.owner_id).has_value() {
|
||||
// trait method with default body needs inline in case
|
||||
// an impl is not provided
|
||||
let desc = "a default trait method";
|
||||
let item = cx.tcx.hir_trait_item(tit.id);
|
||||
let item = cx.tcx.hir_trait_item(tit);
|
||||
let attrs = cx.tcx.hir_attrs(item.hir_id());
|
||||
check_missing_inline_attrs(cx, attrs, item.span, desc);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,15 +61,14 @@ impl<'tcx> LateLintPass<'tcx> for MissingTraitMethods {
|
|||
if !is_lint_allowed(cx, MISSING_TRAIT_METHODS, item.hir_id())
|
||||
&& span_is_local(item.span)
|
||||
&& let ItemKind::Impl(Impl {
|
||||
items,
|
||||
of_trait: Some(trait_ref),
|
||||
..
|
||||
}) = item.kind
|
||||
&& let Some(trait_id) = trait_ref.trait_def_id()
|
||||
{
|
||||
let trait_item_ids: DefIdSet = items
|
||||
.iter()
|
||||
.filter_map(|impl_item| impl_item.trait_item_def_id)
|
||||
let trait_item_ids: DefIdSet = cx.tcx.associated_items(item.owner_id)
|
||||
.in_definition_order()
|
||||
.filter_map(|assoc_item| assoc_item.trait_item_def_id)
|
||||
.collect();
|
||||
|
||||
for assoc in cx
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use rustc_errors::Applicability;
|
|||
use rustc_hir as hir;
|
||||
use rustc_hir::HirIdSet;
|
||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||
use rustc_middle::ty::AssocKind;
|
||||
use rustc_session::impl_lint_pass;
|
||||
use rustc_span::sym;
|
||||
|
||||
|
|
@ -61,18 +62,18 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
|
|||
of_trait: None,
|
||||
generics,
|
||||
self_ty: impl_self_ty,
|
||||
items,
|
||||
..
|
||||
}) = item.kind
|
||||
{
|
||||
for assoc_item in *items {
|
||||
if assoc_item.kind == (hir::AssocItemKind::Fn { has_self: false }) {
|
||||
let impl_item = cx.tcx.hir_impl_item(assoc_item.id);
|
||||
for assoc_item in cx.tcx.associated_items(item.owner_id.def_id)
|
||||
.filter_by_name_unhygienic(sym::new)
|
||||
{
|
||||
if let AssocKind::Fn { has_self: false, .. } = assoc_item.kind {
|
||||
let impl_item = cx.tcx.hir_node_by_def_id(assoc_item.def_id.expect_local()).expect_impl_item();
|
||||
if impl_item.span.in_external_macro(cx.sess().source_map()) {
|
||||
return;
|
||||
}
|
||||
if let hir::ImplItemKind::Fn(ref sig, _) = impl_item.kind {
|
||||
let name = impl_item.ident.name;
|
||||
let id = impl_item.owner_id;
|
||||
if sig.header.is_unsafe() {
|
||||
// can't be implemented for unsafe new
|
||||
|
|
@ -88,11 +89,9 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
|
|||
return;
|
||||
}
|
||||
if sig.decl.inputs.is_empty()
|
||||
&& name == sym::new
|
||||
&& cx.effective_visibilities.is_reachable(impl_item.owner_id.def_id)
|
||||
&& let self_def_id = cx.tcx.hir_get_parent_item(id.into())
|
||||
&& let self_ty = cx.tcx.type_of(self_def_id).instantiate_identity()
|
||||
&& self_ty == return_ty(cx, id)
|
||||
&& let self_ty = cx.tcx.type_of(item.owner_id).instantiate_identity()
|
||||
&& self_ty == return_ty(cx, impl_item.owner_id)
|
||||
&& let Some(default_trait_id) = cx.tcx.get_diagnostic_item(sym::Default)
|
||||
{
|
||||
if self.impling_types.is_none() {
|
||||
|
|
@ -111,7 +110,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
|
|||
// Check if a Default implementation exists for the Self type, regardless of
|
||||
// generics
|
||||
if let Some(ref impling_types) = self.impling_types
|
||||
&& let self_def = cx.tcx.type_of(self_def_id).instantiate_identity()
|
||||
&& let self_def = cx.tcx.type_of(item.owner_id).instantiate_identity()
|
||||
&& let Some(self_def) = self_def.ty_adt_def()
|
||||
&& let Some(self_local_did) = self_def.did().as_local()
|
||||
&& let self_id = cx.tcx.local_def_id_to_hir_id(self_local_did)
|
||||
|
|
|
|||
|
|
@ -43,12 +43,12 @@ impl<'tcx> LateLintPass<'tcx> for PartialEqNeImpl {
|
|||
&& trait_ref.path.res.def_id() == eq_trait
|
||||
{
|
||||
for impl_item in *impl_items {
|
||||
if impl_item.ident.name == sym::ne {
|
||||
if cx.tcx.item_name(impl_item.owner_id) == sym::ne {
|
||||
span_lint_hir(
|
||||
cx,
|
||||
PARTIALEQ_NE_IMPL,
|
||||
impl_item.id.hir_id(),
|
||||
impl_item.span,
|
||||
impl_item.hir_id(),
|
||||
cx.tcx.def_span(impl_item.owner_id),
|
||||
"re-implementing `PartialEq::ne` is unnecessary",
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use rustc_data_structures::fx::FxHashMap;
|
|||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::{HirId, Impl, ItemKind, Node, Path, QPath, TraitRef, TyKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty::AssocItem;
|
||||
use rustc_middle::ty::{AssocKind, AssocItem};
|
||||
use rustc_session::declare_lint_pass;
|
||||
use rustc_span::Span;
|
||||
use rustc_span::symbol::Symbol;
|
||||
|
|
@ -54,7 +54,6 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod {
|
|||
if matches!(cx.tcx.def_kind(id.owner_id), DefKind::Impl { .. })
|
||||
&& let item = cx.tcx.hir_item(id)
|
||||
&& let ItemKind::Impl(Impl {
|
||||
items,
|
||||
of_trait,
|
||||
self_ty,
|
||||
..
|
||||
|
|
@ -115,13 +114,11 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod {
|
|||
}
|
||||
};
|
||||
|
||||
for impl_item_ref in (*items)
|
||||
.iter()
|
||||
.filter(|impl_item_ref| matches!(impl_item_ref.kind, rustc_hir::AssocItemKind::Fn { .. }))
|
||||
{
|
||||
let method_name = impl_item_ref.ident.name;
|
||||
methods_in_trait.remove(&method_name);
|
||||
check_trait_method(method_name, impl_item_ref.span);
|
||||
for assoc_item in cx.tcx.associated_items(id.owner_id).in_definition_order() {
|
||||
if let AssocKind::Fn { name, .. } = assoc_item.kind {
|
||||
methods_in_trait.remove(&name);
|
||||
check_trait_method(name, cx.tcx.def_span(assoc_item.def_id));
|
||||
}
|
||||
}
|
||||
|
||||
for method_name in methods_in_trait {
|
||||
|
|
@ -129,14 +126,11 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod {
|
|||
}
|
||||
},
|
||||
None => {
|
||||
for impl_item_ref in (*items)
|
||||
.iter()
|
||||
.filter(|impl_item_ref| matches!(impl_item_ref.kind, rustc_hir::AssocItemKind::Fn { .. }))
|
||||
{
|
||||
let method_name = impl_item_ref.ident.name;
|
||||
let impl_span = impl_item_ref.span;
|
||||
let hir_id = impl_item_ref.id.hir_id();
|
||||
if let Some(trait_spans) = existing_name.trait_methods.get(&method_name) {
|
||||
for assoc_item in cx.tcx.associated_items(id.owner_id).in_definition_order() {
|
||||
let AssocKind::Fn { name, .. } = assoc_item.kind else { continue };
|
||||
let impl_span = cx.tcx.def_span(assoc_item.def_id);
|
||||
let hir_id = cx.tcx.local_def_id_to_hir_id(assoc_item.def_id.expect_local());
|
||||
if let Some(trait_spans) = existing_name.trait_methods.get(&name) {
|
||||
span_lint_hir_and_then(
|
||||
cx,
|
||||
SAME_NAME_METHOD,
|
||||
|
|
@ -148,12 +142,12 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod {
|
|||
// iterate on trait_spans?
|
||||
diag.span_note(
|
||||
trait_spans[0],
|
||||
format!("existing `{method_name}` defined here"),
|
||||
format!("existing `{name}` defined here"),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
existing_name.impl_methods.insert(method_name, (impl_span, hir_id));
|
||||
existing_name.impl_methods.insert(name, (impl_span, hir_id));
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,9 +36,9 @@ impl<'tcx> LateLintPass<'tcx> for SerdeApi {
|
|||
let mut seen_str = None;
|
||||
let mut seen_string = None;
|
||||
for item in *items {
|
||||
match item.ident.name {
|
||||
sym::visit_str => seen_str = Some(item.span),
|
||||
sym::visit_string => seen_string = Some(item.span),
|
||||
match cx.tcx.item_name(item.owner_id) {
|
||||
sym::visit_str => seen_str = Some(cx.tcx.def_span(item.owner_id)),
|
||||
sym::visit_string => seen_string = Some(cx.tcx.def_span(item.owner_id)),
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use rustc_data_structures::fx::FxHashMap;
|
|||
use rustc_hir::def::Namespace::{MacroNS, TypeNS, ValueNS};
|
||||
use rustc_hir::def::{DefKind, Namespace, Res};
|
||||
use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId};
|
||||
use rustc_hir::{ImplItemRef, ItemKind, Node, OwnerId, TraitItemRef, UseKind};
|
||||
use rustc_hir::{ItemKind, Node, UseKind};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::ty::fast_reject::SimplifiedType;
|
||||
use rustc_middle::ty::{FloatTy, IntTy, Ty, TyCtxt, UintTy};
|
||||
|
|
@ -284,14 +284,6 @@ fn local_item_child_by_name(tcx: TyCtxt<'_>, local_id: LocalDefId, ns: PathNS, n
|
|||
_ => return None,
|
||||
};
|
||||
|
||||
let res = |ident: Ident, owner_id: OwnerId| {
|
||||
if ident.name == name && ns.matches(tcx.def_kind(owner_id).ns()) {
|
||||
Some(owner_id.to_def_id())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
match item_kind {
|
||||
ItemKind::Mod(_, r#mod) => r#mod.item_ids.iter().find_map(|&item_id| {
|
||||
let item = tcx.hir_item(item_id);
|
||||
|
|
@ -307,17 +299,19 @@ fn local_item_child_by_name(tcx: TyCtxt<'_>, local_id: LocalDefId, ns: PathNS, n
|
|||
} else {
|
||||
None
|
||||
}
|
||||
} else if let Some(ident) = item.kind.ident()
|
||||
&& ident.name == name
|
||||
&& ns.matches(tcx.def_kind(item.owner_id).ns())
|
||||
{
|
||||
Some(item.owner_id.to_def_id())
|
||||
} else {
|
||||
res(item.kind.ident()?, item_id.owner_id)
|
||||
None
|
||||
}
|
||||
}),
|
||||
ItemKind::Impl(r#impl) => r#impl
|
||||
.items
|
||||
.iter()
|
||||
.find_map(|&ImplItemRef { ident, id, .. }| res(ident, id.owner_id)),
|
||||
ItemKind::Trait(.., trait_item_refs) => trait_item_refs
|
||||
.iter()
|
||||
.find_map(|&TraitItemRef { ident, id, .. }| res(ident, id.owner_id)),
|
||||
ItemKind::Impl(..) | ItemKind::Trait(..)
|
||||
=> tcx.associated_items(local_id).filter_by_name_unhygienic(name)
|
||||
.find(|assoc_item| ns.matches(Some(assoc_item.namespace())))
|
||||
.map(|assoc_item| assoc_item.def_id),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -136,13 +136,13 @@ error: incorrect ordering of trait items (defined order: [Const, Type, Fn])
|
|||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:155:5
|
||||
|
|
||||
LL | const A: bool;
|
||||
| ^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
note: should be placed before `SomeType`
|
||||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:153:5
|
||||
|
|
||||
LL | type SomeType;
|
||||
| ^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: incorrect ordering of items (must be alphabetically ordered)
|
||||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:171:11
|
||||
|
|
@ -172,13 +172,13 @@ error: incorrect ordering of impl items (defined order: [Const, Type, Fn])
|
|||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:189:5
|
||||
|
|
||||
LL | const A: bool = false;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
note: should be placed before `SomeType`
|
||||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:187:5
|
||||
|
|
||||
LL | type SomeType = ();
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 15 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -136,13 +136,13 @@ error: incorrect ordering of trait items (defined order: [Const, Type, Fn])
|
|||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:155:5
|
||||
|
|
||||
LL | const A: bool;
|
||||
| ^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
note: should be placed before `SomeType`
|
||||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:153:5
|
||||
|
|
||||
LL | type SomeType;
|
||||
| ^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: incorrect ordering of items (must be alphabetically ordered)
|
||||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:171:11
|
||||
|
|
@ -172,13 +172,13 @@ error: incorrect ordering of impl items (defined order: [Const, Type, Fn])
|
|||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:189:5
|
||||
|
|
||||
LL | const A: bool = false;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
note: should be placed before `SomeType`
|
||||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:187:5
|
||||
|
|
||||
LL | type SomeType = ();
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 15 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -211,13 +211,13 @@ error: incorrect ordering of trait items (defined order: [Const, Type, Fn])
|
|||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:155:5
|
||||
|
|
||||
LL | const A: bool;
|
||||
| ^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
note: should be placed before `SomeType`
|
||||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:153:5
|
||||
|
|
||||
LL | type SomeType;
|
||||
| ^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: incorrect ordering of items (must be alphabetically ordered)
|
||||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:171:11
|
||||
|
|
@ -247,13 +247,13 @@ error: incorrect ordering of impl items (defined order: [Const, Type, Fn])
|
|||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:189:5
|
||||
|
|
||||
LL | const A: bool = false;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
note: should be placed before `SomeType`
|
||||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:187:5
|
||||
|
|
||||
LL | type SomeType = ();
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: incorrect ordering of items (must be alphabetically ordered)
|
||||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:207:11
|
||||
|
|
|
|||
|
|
@ -28,25 +28,25 @@ error: incorrect ordering of impl items (defined order: [Fn, Type, Const])
|
|||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:119:5
|
||||
|
|
||||
LL | type SomeType = ();
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
note: should be placed before `A`
|
||||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:117:5
|
||||
|
|
||||
LL | const A: bool = false;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: incorrect ordering of impl items (defined order: [Fn, Type, Const])
|
||||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:122:5
|
||||
|
|
||||
LL | fn a() {}
|
||||
| ^^^^^^^^^
|
||||
| ^^^^^^
|
||||
|
|
||||
note: should be placed before `SomeType`
|
||||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:119:5
|
||||
|
|
||||
LL | type SomeType = ();
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: incorrect ordering of items (must be alphabetically ordered)
|
||||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:149:8
|
||||
|
|
@ -76,13 +76,13 @@ error: incorrect ordering of trait items (defined order: [Fn, Type, Const])
|
|||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:163:5
|
||||
|
|
||||
LL | type SomeType;
|
||||
| ^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
note: should be placed before `A`
|
||||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:161:5
|
||||
|
|
||||
LL | const A: bool;
|
||||
| ^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: incorrect ordering of trait items (defined order: [Fn, Type, Const])
|
||||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:166:5
|
||||
|
|
@ -94,7 +94,7 @@ note: should be placed before `SomeType`
|
|||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:163:5
|
||||
|
|
||||
LL | type SomeType;
|
||||
| ^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -16,25 +16,25 @@ error: incorrect ordering of impl items (defined order: [Const, Type, Fn])
|
|||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.rs:46:5
|
||||
|
|
||||
LL | type SomeType = i8;
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
note: should be placed before `a`
|
||||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.rs:43:5
|
||||
|
|
||||
LL | fn a() {}
|
||||
| ^^^^^^^^^
|
||||
| ^^^^^^
|
||||
|
||||
error: incorrect ordering of impl items (defined order: [Const, Type, Fn])
|
||||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.rs:49:5
|
||||
|
|
||||
LL | const A: bool = true;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
note: should be placed before `SomeType`
|
||||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.rs:46:5
|
||||
|
|
||||
LL | type SomeType = i8;
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -28,13 +28,13 @@ error: incorrect ordering of trait items (defined order: [Const, Type, Fn])
|
|||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.rs:45:5
|
||||
|
|
||||
LL | const A: bool;
|
||||
| ^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
note: should be placed before `SomeType`
|
||||
--> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.rs:43:5
|
||||
|
|
||||
LL | type SomeType;
|
||||
| ^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,8 @@
|
|||
error: re-implementing `PartialEq::ne` is unnecessary
|
||||
--> tests/ui/partialeq_ne_impl.rs:9:5
|
||||
|
|
||||
LL | / fn ne(&self, _: &Foo) -> bool {
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | false
|
||||
LL | | }
|
||||
| |_____^
|
||||
LL | fn ne(&self, _: &Foo) -> bool {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::partialeq-ne-impl` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::partialeq_ne_impl)]`
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ error: method's name is the same as an existing method in a trait
|
|||
--> tests/ui/same_name_method.rs:20:13
|
||||
|
|
||||
LL | fn foo() {}
|
||||
| ^^^^^^^^^^^
|
||||
| ^^^^^^^^
|
||||
|
|
||||
note: existing `foo` defined here
|
||||
--> tests/ui/same_name_method.rs:25:13
|
||||
|
|
||||
LL | fn foo() {}
|
||||
| ^^^^^^^^^^^
|
||||
| ^^^^^^^^
|
||||
= note: `-D clippy::same-name-method` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::same_name_method)]`
|
||||
|
||||
|
|
@ -16,7 +16,7 @@ error: method's name is the same as an existing method in a trait
|
|||
--> tests/ui/same_name_method.rs:35:13
|
||||
|
|
||||
LL | fn clone() {}
|
||||
| ^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
note: existing `clone` defined here
|
||||
--> tests/ui/same_name_method.rs:31:18
|
||||
|
|
@ -28,19 +28,19 @@ error: method's name is the same as an existing method in a trait
|
|||
--> tests/ui/same_name_method.rs:46:13
|
||||
|
|
||||
LL | fn foo() {}
|
||||
| ^^^^^^^^^^^
|
||||
| ^^^^^^^^
|
||||
|
|
||||
note: existing `foo` defined here
|
||||
--> tests/ui/same_name_method.rs:51:13
|
||||
|
|
||||
LL | fn foo() {}
|
||||
| ^^^^^^^^^^^
|
||||
| ^^^^^^^^
|
||||
|
||||
error: method's name is the same as an existing method in a trait
|
||||
--> tests/ui/same_name_method.rs:61:13
|
||||
|
|
||||
LL | fn foo() {}
|
||||
| ^^^^^^^^^^^
|
||||
| ^^^^^^^^
|
||||
|
|
||||
note: existing `foo` defined here
|
||||
--> tests/ui/same_name_method.rs:65:9
|
||||
|
|
@ -52,7 +52,7 @@ error: method's name is the same as an existing method in a trait
|
|||
--> tests/ui/same_name_method.rs:74:13
|
||||
|
|
||||
LL | fn foo() {}
|
||||
| ^^^^^^^^^^^
|
||||
| ^^^^^^^^
|
||||
|
|
||||
note: existing `foo` defined here
|
||||
--> tests/ui/same_name_method.rs:79:9
|
||||
|
|
@ -64,7 +64,7 @@ error: method's name is the same as an existing method in a trait
|
|||
--> tests/ui/same_name_method.rs:74:13
|
||||
|
|
||||
LL | fn foo() {}
|
||||
| ^^^^^^^^^^^
|
||||
| ^^^^^^^^
|
||||
|
|
||||
note: existing `foo` defined here
|
||||
--> tests/ui/same_name_method.rs:81:9
|
||||
|
|
|
|||
|
|
@ -5,10 +5,7 @@ LL | / fn visit_string<E>(self, _v: String) -> Result<Self::Value, E>
|
|||
LL | |
|
||||
LL | | where
|
||||
LL | | E: serde::de::Error,
|
||||
LL | | {
|
||||
LL | | unimplemented!()
|
||||
LL | | }
|
||||
| |_____^
|
||||
| |____________________________^
|
||||
|
|
||||
= note: `-D clippy::serde-api-misuse` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::serde_api_misuse)]`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue