Separate out a hir::Impl struct
This makes it possible to pass the `Impl` directly to functions, instead of having to pass each of the many fields one at a time. It also simplifies matches in many cases.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
use crate::utils::{is_copy, match_path, paths, span_lint_and_note};
|
use crate::utils::{is_copy, match_path, paths, span_lint_and_note};
|
||||||
use rustc_hir::{Item, ItemKind};
|
use rustc_hir::{Item, ItemKind, Impl};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
|
|
||||||
@@ -33,10 +33,10 @@ declare_lint_pass!(CopyIterator => [COPY_ITERATOR]);
|
|||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for CopyIterator {
|
impl<'tcx> LateLintPass<'tcx> for CopyIterator {
|
||||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||||
if let ItemKind::Impl {
|
if let ItemKind::Impl(Impl {
|
||||||
of_trait: Some(ref trait_ref),
|
of_trait: Some(ref trait_ref),
|
||||||
..
|
..
|
||||||
} = item.kind
|
}) = item.kind
|
||||||
{
|
{
|
||||||
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.hir_id));
|
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.hir_id));
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use if_chain::if_chain;
|
|||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::intravisit::{walk_expr, walk_fn, walk_item, FnKind, NestedVisitorMap, Visitor};
|
use rustc_hir::intravisit::{walk_expr, walk_fn, walk_item, FnKind, NestedVisitorMap, Visitor};
|
||||||
use rustc_hir::{
|
use rustc_hir::{
|
||||||
BlockCheckMode, BodyId, Expr, ExprKind, FnDecl, HirId, Item, ItemKind, TraitRef, UnsafeSource, Unsafety,
|
BlockCheckMode, BodyId, Expr, ExprKind, FnDecl, HirId, Item, ItemKind, Impl, TraitRef, UnsafeSource, Unsafety,
|
||||||
};
|
};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::hir::map::Map;
|
use rustc_middle::hir::map::Map;
|
||||||
@@ -164,10 +164,10 @@ declare_lint_pass!(Derive => [
|
|||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for Derive {
|
impl<'tcx> LateLintPass<'tcx> for Derive {
|
||||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||||
if let ItemKind::Impl {
|
if let ItemKind::Impl(Impl {
|
||||||
of_trait: Some(ref trait_ref),
|
of_trait: Some(ref trait_ref),
|
||||||
..
|
..
|
||||||
} = item.kind
|
}) = item.kind
|
||||||
{
|
{
|
||||||
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.hir_id));
|
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.hir_id));
|
||||||
let is_automatically_derived = is_automatically_derived(&*item.attrs);
|
let is_automatically_derived = is_automatically_derived(&*item.attrs);
|
||||||
|
|||||||
@@ -182,11 +182,8 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
|
|||||||
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, Some(body_id));
|
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, Some(body_id));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
hir::ItemKind::Impl {
|
hir::ItemKind::Impl(ref impl_) => {
|
||||||
of_trait: ref trait_ref,
|
self.in_trait_impl = impl_.of_trait.is_some();
|
||||||
..
|
|
||||||
} => {
|
|
||||||
self.in_trait_impl = trait_ref.is_some();
|
|
||||||
},
|
},
|
||||||
_ => {},
|
_ => {},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use rustc_hir::intravisit;
|
use rustc_hir::intravisit;
|
||||||
use rustc_hir::{self, Body, FnDecl, HirId, HirIdSet, ItemKind, Node};
|
use rustc_hir::{self, Body, FnDecl, HirId, HirIdSet, ItemKind, Impl, Node};
|
||||||
use rustc_infer::infer::TyCtxtInferExt;
|
use rustc_infer::infer::TyCtxtInferExt;
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::ty::{self, Ty};
|
use rustc_middle::ty::{self, Ty};
|
||||||
@@ -77,7 +77,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
|
|||||||
let parent_node = cx.tcx.hir().find(parent_id);
|
let parent_node = cx.tcx.hir().find(parent_id);
|
||||||
|
|
||||||
if let Some(Node::Item(item)) = parent_node {
|
if let Some(Node::Item(item)) = parent_node {
|
||||||
if let ItemKind::Impl { of_trait: Some(_), .. } = item.kind {
|
if let ItemKind::Impl(Impl { of_trait: Some(_), .. }) = item.kind {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,11 +57,11 @@ impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom {
|
|||||||
// check for `impl From<???> for ..`
|
// check for `impl From<???> for ..`
|
||||||
let impl_def_id = cx.tcx.hir().local_def_id(item.hir_id);
|
let impl_def_id = cx.tcx.hir().local_def_id(item.hir_id);
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let hir::ItemKind::Impl{ items: impl_items, .. } = item.kind;
|
if let hir::ItemKind::Impl(impl_) = &item.kind;
|
||||||
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_def_id);
|
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_def_id);
|
||||||
if match_def_path(cx, impl_trait_ref.def_id, &FROM_TRAIT);
|
if match_def_path(cx, impl_trait_ref.def_id, &FROM_TRAIT);
|
||||||
then {
|
then {
|
||||||
lint_impl_body(cx, item.span, impl_items);
|
lint_impl_body(cx, item.span, impl_.items);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use crate::utils::{in_macro, span_lint_and_then};
|
use crate::utils::{in_macro, span_lint_and_then};
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_hir::{def_id, Crate, Item, ItemKind};
|
use rustc_hir::{def_id, Crate, Item, ItemKind, Impl};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
@@ -49,11 +49,11 @@ impl_lint_pass!(MultipleInherentImpl => [MULTIPLE_INHERENT_IMPL]);
|
|||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl {
|
impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl {
|
||||||
fn check_item(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
fn check_item(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||||
if let ItemKind::Impl {
|
if let ItemKind::Impl(Impl {
|
||||||
ref generics,
|
ref generics,
|
||||||
of_trait: None,
|
of_trait: None,
|
||||||
..
|
..
|
||||||
} = item.kind
|
}) = item.kind
|
||||||
{
|
{
|
||||||
// Remember for each inherent implementation encountered its span and generics
|
// Remember for each inherent implementation encountered its span and generics
|
||||||
// but filter out implementations that have generic params (type or lifetime)
|
// but filter out implementations that have generic params (type or lifetime)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use rustc_ast::ast::LitKind;
|
|||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::{AssocItemKind, BinOpKind, Expr, ExprKind, ImplItemRef, Item, ItemKind, TraitItemRef};
|
use rustc_hir::{AssocItemKind, BinOpKind, Expr, ExprKind, ImplItemRef, Item, ItemKind, Impl, TraitItemRef};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::ty;
|
use rustc_middle::ty;
|
||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
@@ -115,11 +115,11 @@ impl<'tcx> LateLintPass<'tcx> for LenZero {
|
|||||||
|
|
||||||
match item.kind {
|
match item.kind {
|
||||||
ItemKind::Trait(_, _, _, _, ref trait_items) => check_trait_items(cx, item, trait_items),
|
ItemKind::Trait(_, _, _, _, ref trait_items) => check_trait_items(cx, item, trait_items),
|
||||||
ItemKind::Impl {
|
ItemKind::Impl(Impl {
|
||||||
of_trait: None,
|
of_trait: None,
|
||||||
items: ref impl_items,
|
items: ref impl_items,
|
||||||
..
|
..
|
||||||
} => check_impl_items(cx, item, impl_items),
|
}) => check_impl_items(cx, item, impl_items),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1626,7 +1626,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
|
|||||||
let self_ty = cx.tcx.type_of(def_id);
|
let self_ty = cx.tcx.type_of(def_id);
|
||||||
|
|
||||||
// if this impl block implements a trait, lint in trait definition instead
|
// if this impl block implements a trait, lint in trait definition instead
|
||||||
if let hir::ItemKind::Impl { of_trait: Some(_), .. } = item.kind {
|
if let hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = item.kind {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use rustc_ast::ast::Attribute;
|
|||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_errors::{Applicability, DiagnosticBuilder};
|
use rustc_errors::{Applicability, DiagnosticBuilder};
|
||||||
use rustc_hir::intravisit::FnKind;
|
use rustc_hir::intravisit::FnKind;
|
||||||
use rustc_hir::{BindingAnnotation, Body, FnDecl, GenericArg, HirId, ItemKind, Node, PatKind, QPath, TyKind};
|
use rustc_hir::{BindingAnnotation, Body, FnDecl, GenericArg, HirId, ItemKind, Impl, Node, PatKind, QPath, TyKind};
|
||||||
use rustc_infer::infer::TyCtxtInferExt;
|
use rustc_infer::infer::TyCtxtInferExt;
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::ty::{self, TypeFoldable};
|
use rustc_middle::ty::{self, TypeFoldable};
|
||||||
@@ -92,7 +92,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
|
|||||||
if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) {
|
if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) {
|
||||||
if matches!(
|
if matches!(
|
||||||
item.kind,
|
item.kind,
|
||||||
ItemKind::Impl { of_trait: Some(_), .. } | ItemKind::Trait(..)
|
ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..)
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,9 +60,9 @@ impl_lint_pass!(NewWithoutDefault => [NEW_WITHOUT_DEFAULT]);
|
|||||||
impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
|
impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
|
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
|
||||||
if let hir::ItemKind::Impl {
|
if let hir::ItemKind::Impl(hir::Impl {
|
||||||
of_trait: None, items, ..
|
of_trait: None, items, ..
|
||||||
} = item.kind
|
}) = item.kind
|
||||||
{
|
{
|
||||||
for assoc_item in items {
|
for assoc_item in items {
|
||||||
if let hir::AssocItemKind::Fn { has_self: false } = assoc_item.kind {
|
if let hir::AssocItemKind::Fn { has_self: false } = assoc_item.kind {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use std::ptr;
|
|||||||
use rustc_hir::def::{DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::{
|
use rustc_hir::{
|
||||||
BodyId, Expr, ExprKind, HirId, ImplItem, ImplItemKind, Item, ItemKind, Node, TraitItem, TraitItemKind, UnOp,
|
BodyId, Expr, ExprKind, HirId, Impl, ImplItem, ImplItemKind, Item, ItemKind, Node, TraitItem, TraitItemKind, UnOp,
|
||||||
};
|
};
|
||||||
use rustc_infer::traits::specialization_graph;
|
use rustc_infer::traits::specialization_graph;
|
||||||
use rustc_lint::{LateContext, LateLintPass, Lint};
|
use rustc_lint::{LateContext, LateLintPass, Lint};
|
||||||
@@ -275,10 +275,10 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst {
|
|||||||
let item = cx.tcx.hir().expect_item(item_hir_id);
|
let item = cx.tcx.hir().expect_item(item_hir_id);
|
||||||
|
|
||||||
match &item.kind {
|
match &item.kind {
|
||||||
ItemKind::Impl {
|
ItemKind::Impl(Impl {
|
||||||
of_trait: Some(of_trait_ref),
|
of_trait: Some(of_trait_ref),
|
||||||
..
|
..
|
||||||
} => {
|
}) => {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
// Lint a trait impl item only when the definition is a generic type,
|
// Lint a trait impl item only when the definition is a generic type,
|
||||||
// assuming a assoc const is not meant to be a interior mutable type.
|
// assuming a assoc const is not meant to be a interior mutable type.
|
||||||
@@ -317,7 +317,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ItemKind::Impl { of_trait: None, .. } => {
|
ItemKind::Impl(Impl { of_trait: None, .. }) => {
|
||||||
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
|
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
|
||||||
// Normalize assoc types originated from generic params.
|
// Normalize assoc types originated from generic params.
|
||||||
let normalized = cx.tcx.normalize_erasing_regions(cx.param_env, ty);
|
let normalized = cx.tcx.normalize_erasing_regions(cx.param_env, ty);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::utils::{is_automatically_derived, span_lint_hir};
|
use crate::utils::{is_automatically_derived, span_lint_hir};
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
use rustc_hir::{Item, ItemKind};
|
use rustc_hir::{Item, ItemKind, Impl};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
use rustc_span::sym;
|
use rustc_span::sym;
|
||||||
@@ -34,7 +34,7 @@ declare_lint_pass!(PartialEqNeImpl => [PARTIALEQ_NE_IMPL]);
|
|||||||
impl<'tcx> LateLintPass<'tcx> for PartialEqNeImpl {
|
impl<'tcx> LateLintPass<'tcx> for PartialEqNeImpl {
|
||||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let ItemKind::Impl{ of_trait: Some(ref trait_ref), items: impl_items, .. } = item.kind;
|
if let ItemKind::Impl(Impl { of_trait: Some(ref trait_ref), items: impl_items, .. }) = item.kind;
|
||||||
if !is_automatically_derived(&*item.attrs);
|
if !is_automatically_derived(&*item.attrs);
|
||||||
if let Some(eq_trait) = cx.tcx.lang_items().eq_trait();
|
if let Some(eq_trait) = cx.tcx.lang_items().eq_trait();
|
||||||
if trait_ref.path.res.def_id() == eq_trait;
|
if trait_ref.path.res.def_id() == eq_trait;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use rustc_ast::attr;
|
|||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::intravisit::FnKind;
|
use rustc_hir::intravisit::FnKind;
|
||||||
use rustc_hir::{BindingAnnotation, Body, FnDecl, HirId, ItemKind, MutTy, Mutability, Node, PatKind};
|
use rustc_hir::{BindingAnnotation, Body, FnDecl, HirId, ItemKind, MutTy, Mutability, Node, PatKind, Impl};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::ty;
|
use rustc_middle::ty;
|
||||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||||
@@ -246,7 +246,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue {
|
|||||||
if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) {
|
if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) {
|
||||||
if matches!(
|
if matches!(
|
||||||
item.kind,
|
item.kind,
|
||||||
ItemKind::Impl { of_trait: Some(_), .. } | ItemKind::Trait(..)
|
ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..)
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use crate::utils::{
|
|||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir::{
|
use rustc_hir::{
|
||||||
BinOpKind, BodyId, Expr, ExprKind, FnDecl, FnRetTy, GenericArg, HirId, ImplItem, ImplItemKind, Item, ItemKind,
|
BinOpKind, BodyId, Expr, ExprKind, FnDecl, FnRetTy, GenericArg, HirId, ImplItem, ImplItemKind, Item, ItemKind, Impl,
|
||||||
Lifetime, MutTy, Mutability, Node, PathSegment, QPath, TraitFn, TraitItem, TraitItemKind, Ty, TyKind,
|
Lifetime, MutTy, Mutability, Node, PathSegment, QPath, TraitFn, TraitItem, TraitItemKind, Ty, TyKind,
|
||||||
};
|
};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
@@ -132,7 +132,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
|
|||||||
if let ImplItemKind::Fn(ref sig, body_id) = item.kind {
|
if let ImplItemKind::Fn(ref sig, body_id) = item.kind {
|
||||||
let parent_item = cx.tcx.hir().get_parent_item(item.hir_id);
|
let parent_item = cx.tcx.hir().get_parent_item(item.hir_id);
|
||||||
if let Some(Node::Item(it)) = cx.tcx.hir().find(parent_item) {
|
if let Some(Node::Item(it)) = cx.tcx.hir().find(parent_item) {
|
||||||
if let ItemKind::Impl { of_trait: Some(_), .. } = it.kind {
|
if let ItemKind::Impl(Impl { of_trait: Some(_), .. }) = it.kind {
|
||||||
return; // ignore trait impls
|
return; // ignore trait impls
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::utils::{get_trait_def_id, paths, span_lint};
|
use crate::utils::{get_trait_def_id, paths, span_lint};
|
||||||
use rustc_hir::{Item, ItemKind};
|
use rustc_hir::{Item, ItemKind, Impl};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
|
|
||||||
@@ -22,11 +22,11 @@ declare_lint_pass!(SerdeAPI => [SERDE_API_MISUSE]);
|
|||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for SerdeAPI {
|
impl<'tcx> LateLintPass<'tcx> for SerdeAPI {
|
||||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||||
if let ItemKind::Impl {
|
if let ItemKind::Impl(Impl {
|
||||||
of_trait: Some(ref trait_ref),
|
of_trait: Some(ref trait_ref),
|
||||||
items,
|
items,
|
||||||
..
|
..
|
||||||
} = item.kind
|
}) = item.kind
|
||||||
{
|
{
|
||||||
let did = trait_ref.path.res.def_id();
|
let did = trait_ref.path.res.def_id();
|
||||||
if let Some(visit_did) = get_trait_def_id(cx, &paths::SERDE_DE_VISITOR) {
|
if let Some(visit_did) = get_trait_def_id(cx, &paths::SERDE_DE_VISITOR) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use crate::utils::{match_def_path, match_trait_method, paths, qpath_res, span_lint};
|
use crate::utils::{match_def_path, match_trait_method, paths, qpath_res, span_lint};
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
use rustc_hir::def::Res;
|
use rustc_hir::def::Res;
|
||||||
use rustc_hir::{Expr, ExprKind, HirId, ImplItem, ImplItemKind, Item, ItemKind};
|
use rustc_hir::{Expr, ExprKind, HirId, ImplItem, ImplItemKind, Item, ItemKind, Impl};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||||
|
|
||||||
@@ -111,7 +111,7 @@ impl LateLintPass<'_> for ToStringInDisplay {
|
|||||||
|
|
||||||
fn is_display_impl(cx: &LateContext<'_>, item: &Item<'_>) -> bool {
|
fn is_display_impl(cx: &LateContext<'_>, item: &Item<'_>) -> bool {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let ItemKind::Impl { of_trait: Some(trait_ref), .. } = &item.kind;
|
if let ItemKind::Impl(Impl { of_trait: Some(trait_ref), .. }) = &item.kind;
|
||||||
if let Some(did) = trait_ref.trait_def_id();
|
if let Some(did) = trait_ref.trait_def_id();
|
||||||
then {
|
then {
|
||||||
match_def_path(cx, did, &paths::DISPLAY_TRAIT)
|
match_def_path(cx, did, &paths::DISPLAY_TRAIT)
|
||||||
|
|||||||
@@ -258,7 +258,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
|
|||||||
fn check_fn(&mut self, cx: &LateContext<'_>, _: FnKind<'_>, decl: &FnDecl<'_>, _: &Body<'_>, _: Span, id: HirId) {
|
fn check_fn(&mut self, cx: &LateContext<'_>, _: FnKind<'_>, decl: &FnDecl<'_>, _: &Body<'_>, _: Span, id: HirId) {
|
||||||
// Skip trait implementations; see issue #605.
|
// Skip trait implementations; see issue #605.
|
||||||
if let Some(hir::Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_item(id)) {
|
if let Some(hir::Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_item(id)) {
|
||||||
if let ItemKind::Impl { of_trait: Some(_), .. } = item.kind {
|
if let ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = item.kind {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2558,21 +2558,16 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
match item.kind {
|
match item.kind {
|
||||||
ItemKind::Impl {
|
ItemKind::Impl(ref impl_) => {
|
||||||
ref generics,
|
|
||||||
self_ty: ref ty,
|
|
||||||
ref items,
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
let mut vis = ImplicitHasherTypeVisitor::new(cx);
|
let mut vis = ImplicitHasherTypeVisitor::new(cx);
|
||||||
vis.visit_ty(ty);
|
vis.visit_ty(impl_.self_ty);
|
||||||
|
|
||||||
for target in &vis.found {
|
for target in &vis.found {
|
||||||
if differing_macro_contexts(item.span, target.span()) {
|
if differing_macro_contexts(item.span, target.span()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let generics_suggestion_span = generics.span.substitute_dummy({
|
let generics_suggestion_span = impl_.generics.span.substitute_dummy({
|
||||||
let pos = snippet_opt(cx, item.span.until(target.span()))
|
let pos = snippet_opt(cx, item.span.until(target.span()))
|
||||||
.and_then(|snip| Some(item.span.lo() + BytePos(snip.find("impl")? as u32 + 4)));
|
.and_then(|snip| Some(item.span.lo() + BytePos(snip.find("impl")? as u32 + 4)));
|
||||||
if let Some(pos) = pos {
|
if let Some(pos) = pos {
|
||||||
@@ -2583,7 +2578,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let mut ctr_vis = ImplicitHasherConstructorVisitor::new(cx, target);
|
let mut ctr_vis = ImplicitHasherConstructorVisitor::new(cx, target);
|
||||||
for item in 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.id)) {
|
||||||
ctr_vis.visit_impl_item(item);
|
ctr_vis.visit_impl_item(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2596,7 +2591,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher {
|
|||||||
target.type_name()
|
target.type_name()
|
||||||
),
|
),
|
||||||
move |diag| {
|
move |diag| {
|
||||||
suggestion(cx, diag, generics.span, generics_suggestion_span, target, ctr_vis);
|
suggestion(cx, diag, impl_.generics.span, generics_suggestion_span, target, ctr_vis);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use crate::utils::{
|
|||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir::intravisit::FnKind;
|
use rustc_hir::intravisit::FnKind;
|
||||||
use rustc_hir::{Body, ExprKind, FnDecl, HirId, ItemKind, Node};
|
use rustc_hir::{Body, ExprKind, FnDecl, HirId, ItemKind, Impl, Node};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::ty::subst::GenericArgKind;
|
use rustc_middle::ty::subst::GenericArgKind;
|
||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
@@ -77,7 +77,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps {
|
|||||||
if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) {
|
if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) {
|
||||||
if matches!(
|
if matches!(
|
||||||
item.kind,
|
item.kind,
|
||||||
ItemKind::Impl { of_trait: Some(_), .. } | ItemKind::Trait(..)
|
ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..)
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
use rustc_hir::def::Res;
|
use rustc_hir::def::Res;
|
||||||
use rustc_hir::intravisit::{walk_path, NestedVisitorMap, Visitor};
|
use rustc_hir::intravisit::{walk_path, NestedVisitorMap, Visitor};
|
||||||
use rustc_hir::{HirId, ImplItem, ImplItemKind, ItemKind, Path};
|
use rustc_hir::{HirId, ImplItem, ImplItemKind, ItemKind, Impl, Path};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::hir::map::Map;
|
use rustc_middle::hir::map::Map;
|
||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
@@ -49,7 +49,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedSelf {
|
|||||||
let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
|
let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
|
||||||
let assoc_item = cx.tcx.associated_item(def_id);
|
let assoc_item = cx.tcx.associated_item(def_id);
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let ItemKind::Impl { of_trait: None, .. } = parent_item.kind;
|
if let ItemKind::Impl(Impl { of_trait: None, .. }) = parent_item.kind;
|
||||||
if assoc_item.fn_has_self_parameter;
|
if assoc_item.fn_has_self_parameter;
|
||||||
if let ImplItemKind::Fn(.., body_id) = &impl_item.kind;
|
if let ImplItemKind::Fn(.., body_id) = &impl_item.kind;
|
||||||
let body = cx.tcx.hir().body(*body_id);
|
let body = cx.tcx.hir().body(*body_id);
|
||||||
|
|||||||
@@ -181,8 +181,8 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let ItemKind::Impl{ self_ty: ref item_type, items: refs, .. } = item.kind;
|
if let ItemKind::Impl(impl_) = &item.kind;
|
||||||
if let TyKind::Path(QPath::Resolved(_, ref item_path)) = item_type.kind;
|
if let TyKind::Path(QPath::Resolved(_, ref item_path)) = impl_.self_ty.kind;
|
||||||
then {
|
then {
|
||||||
let parameters = &item_path.segments.last().expect(SEGMENTS_MSG).args;
|
let parameters = &item_path.segments.last().expect(SEGMENTS_MSG).args;
|
||||||
let should_check = parameters.as_ref().map_or(
|
let should_check = parameters.as_ref().map_or(
|
||||||
@@ -200,7 +200,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
|
|||||||
let impl_trait_ref = cx.tcx.impl_trait_ref(impl_def_id);
|
let impl_trait_ref = cx.tcx.impl_trait_ref(impl_def_id);
|
||||||
|
|
||||||
if let Some(impl_trait_ref) = impl_trait_ref {
|
if let Some(impl_trait_ref) = impl_trait_ref {
|
||||||
for impl_item_ref in refs {
|
for impl_item_ref in impl_.items {
|
||||||
let impl_item = cx.tcx.hir().impl_item(impl_item_ref.id);
|
let impl_item = cx.tcx.hir().impl_item(impl_item_ref.id);
|
||||||
if let ImplItemKind::Fn(FnSig{ decl: impl_decl, .. }, impl_body_id)
|
if let ImplItemKind::Fn(FnSig{ decl: impl_decl, .. }, impl_body_id)
|
||||||
= &impl_item.kind {
|
= &impl_item.kind {
|
||||||
@@ -213,7 +213,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for impl_item_ref in refs {
|
for impl_item_ref in impl_.items {
|
||||||
let impl_item = cx.tcx.hir().impl_item(impl_item_ref.id);
|
let impl_item = cx.tcx.hir().impl_item(impl_item_ref.id);
|
||||||
visitor.visit_impl_item(impl_item);
|
visitor.visit_impl_item(impl_item);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -423,13 +423,13 @@ fn print_item(cx: &LateContext<'_>, item: &hir::Item<'_>) {
|
|||||||
hir::ItemKind::TraitAlias(..) => {
|
hir::ItemKind::TraitAlias(..) => {
|
||||||
println!("trait alias");
|
println!("trait alias");
|
||||||
},
|
},
|
||||||
hir::ItemKind::Impl {
|
hir::ItemKind::Impl(hir::Impl {
|
||||||
of_trait: Some(ref _trait_ref),
|
of_trait: Some(ref _trait_ref),
|
||||||
..
|
..
|
||||||
} => {
|
}) => {
|
||||||
println!("trait impl");
|
println!("trait impl");
|
||||||
},
|
},
|
||||||
hir::ItemKind::Impl { of_trait: None, .. } => {
|
hir::ItemKind::Impl(hir::Impl { of_trait: None, .. }) => {
|
||||||
println!("impl");
|
println!("impl");
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -352,11 +352,11 @@ impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass {
|
|||||||
} else if is_expn_of(item.span, "impl_lint_pass").is_some()
|
} else if is_expn_of(item.span, "impl_lint_pass").is_some()
|
||||||
|| is_expn_of(item.span, "declare_lint_pass").is_some()
|
|| is_expn_of(item.span, "declare_lint_pass").is_some()
|
||||||
{
|
{
|
||||||
if let hir::ItemKind::Impl {
|
if let hir::ItemKind::Impl(hir::Impl {
|
||||||
of_trait: None,
|
of_trait: None,
|
||||||
items: ref impl_item_refs,
|
items: ref impl_item_refs,
|
||||||
..
|
..
|
||||||
} = item.kind
|
}) = item.kind
|
||||||
{
|
{
|
||||||
let mut collector = LintCollector {
|
let mut collector = LintCollector {
|
||||||
output: &mut self.registered_lints,
|
output: &mut self.registered_lints,
|
||||||
|
|||||||
@@ -439,8 +439,8 @@ pub fn trait_ref_of_method<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Optio
|
|||||||
if_chain! {
|
if_chain! {
|
||||||
if parent_impl != hir::CRATE_HIR_ID;
|
if parent_impl != hir::CRATE_HIR_ID;
|
||||||
if let hir::Node::Item(item) = cx.tcx.hir().get(parent_impl);
|
if let hir::Node::Item(item) = cx.tcx.hir().get(parent_impl);
|
||||||
if let hir::ItemKind::Impl{ of_trait: trait_ref, .. } = &item.kind;
|
if let hir::ItemKind::Impl(impl_) = &item.kind;
|
||||||
then { return trait_ref.as_ref(); }
|
then { return impl_.of_trait.as_ref(); }
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@@ -1530,7 +1530,7 @@ pub fn is_no_std_crate(krate: &Crate<'_>) -> bool {
|
|||||||
/// ```
|
/// ```
|
||||||
pub fn is_trait_impl_item(cx: &LateContext<'_>, hir_id: HirId) -> bool {
|
pub fn is_trait_impl_item(cx: &LateContext<'_>, hir_id: HirId) -> bool {
|
||||||
if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) {
|
if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) {
|
||||||
matches!(item.kind, ItemKind::Impl { of_trait: Some(_), .. })
|
matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }))
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ impl LateLintPass<'_> for ZeroSizedMapValues {
|
|||||||
fn in_trait_impl(cx: &LateContext<'_>, hir_id: HirId) -> bool {
|
fn in_trait_impl(cx: &LateContext<'_>, hir_id: HirId) -> bool {
|
||||||
let parent_id = cx.tcx.hir().get_parent_item(hir_id);
|
let parent_id = cx.tcx.hir().get_parent_item(hir_id);
|
||||||
if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_item(parent_id)) {
|
if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_item(parent_id)) {
|
||||||
if let ItemKind::Impl { of_trait: Some(_), .. } = item.kind {
|
if let ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = item.kind {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user