mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +00:00
align with rust-lang/rust/#58836
This commit is contained in:
parent
f2587703cc
commit
f3363b9cf2
20 changed files with 80 additions and 82 deletions
|
@ -44,7 +44,7 @@ impl LintPass for CopyIterator {
|
||||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyIterator {
|
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyIterator {
|
||||||
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
|
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
|
||||||
if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.node {
|
if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.node {
|
||||||
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.id));
|
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id_from_hir_id(item.hir_id));
|
||||||
|
|
||||||
if is_copy(cx, ty) && match_path(&trait_ref.path, &paths::ITERATOR) {
|
if is_copy(cx, ty) && match_path(&trait_ref.path, &paths::ITERATOR) {
|
||||||
span_note_and_lint(
|
span_note_and_lint(
|
||||||
|
|
|
@ -77,7 +77,7 @@ impl LintPass for Derive {
|
||||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Derive {
|
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Derive {
|
||||||
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
|
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
|
||||||
if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.node {
|
if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.node {
|
||||||
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.id));
|
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id_from_hir_id(item.hir_id));
|
||||||
let is_automatically_derived = is_automatically_derived(&*item.attrs);
|
let is_automatically_derived = is_automatically_derived(&*item.attrs);
|
||||||
|
|
||||||
check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived);
|
check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived);
|
||||||
|
|
|
@ -38,7 +38,7 @@ impl LintPass for EmptyEnum {
|
||||||
|
|
||||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EmptyEnum {
|
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EmptyEnum {
|
||||||
fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item) {
|
fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item) {
|
||||||
let did = cx.tcx.hir().local_def_id(item.id);
|
let did = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
|
||||||
if let ItemKind::Enum(..) = item.node {
|
if let ItemKind::Enum(..) = item.node {
|
||||||
let ty = cx.tcx.type_of(did);
|
let ty = cx.tcx.type_of(did);
|
||||||
let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
|
let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
|
||||||
|
|
|
@ -6,9 +6,8 @@ use rustc::middle::expr_use_visitor::*;
|
||||||
use rustc::middle::mem_categorization::{cmt_, Categorization};
|
use rustc::middle::mem_categorization::{cmt_, Categorization};
|
||||||
use rustc::ty::layout::LayoutOf;
|
use rustc::ty::layout::LayoutOf;
|
||||||
use rustc::ty::{self, Ty};
|
use rustc::ty::{self, Ty};
|
||||||
use rustc::util::nodemap::NodeSet;
|
use rustc::util::nodemap::HirIdSet;
|
||||||
use rustc::{declare_tool_lint, lint_array};
|
use rustc::{declare_tool_lint, lint_array};
|
||||||
use syntax::ast::NodeId;
|
|
||||||
use syntax::source_map::Span;
|
use syntax::source_map::Span;
|
||||||
|
|
||||||
pub struct Pass {
|
pub struct Pass {
|
||||||
|
@ -44,7 +43,7 @@ fn is_non_trait_box(ty: Ty<'_>) -> bool {
|
||||||
|
|
||||||
struct EscapeDelegate<'a, 'tcx: 'a> {
|
struct EscapeDelegate<'a, 'tcx: 'a> {
|
||||||
cx: &'a LateContext<'a, 'tcx>,
|
cx: &'a LateContext<'a, 'tcx>,
|
||||||
set: NodeSet,
|
set: HirIdSet,
|
||||||
too_large_for_stack: u64,
|
too_large_for_stack: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +79,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
||||||
|
|
||||||
let mut v = EscapeDelegate {
|
let mut v = EscapeDelegate {
|
||||||
cx,
|
cx,
|
||||||
set: NodeSet::default(),
|
set: HirIdSet::default(),
|
||||||
too_large_for_stack: self.too_large_for_stack,
|
too_large_for_stack: self.too_large_for_stack,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -92,7 +91,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
||||||
span_lint(
|
span_lint(
|
||||||
cx,
|
cx,
|
||||||
BOXED_LOCAL,
|
BOXED_LOCAL,
|
||||||
cx.tcx.hir().span(node),
|
cx.tcx.hir().span_by_hir_id(node),
|
||||||
"local variable doesn't need to be boxed here",
|
"local variable doesn't need to be boxed here",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -111,13 +110,15 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
|
||||||
fn matched_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: MatchMode) {}
|
fn matched_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: MatchMode) {}
|
||||||
fn consume_pat(&mut self, consume_pat: &Pat, cmt: &cmt_<'tcx>, _: ConsumeMode) {
|
fn consume_pat(&mut self, consume_pat: &Pat, cmt: &cmt_<'tcx>, _: ConsumeMode) {
|
||||||
let map = &self.cx.tcx.hir();
|
let map = &self.cx.tcx.hir();
|
||||||
if map.is_argument(consume_pat.id) {
|
if map.is_argument(map.hir_to_node_id(consume_pat.hir_id)) {
|
||||||
// Skip closure arguments
|
// Skip closure arguments
|
||||||
if let Some(Node::Expr(..)) = map.find(map.get_parent_node(consume_pat.id)) {
|
if let Some(Node::Expr(..)) = map.find_by_hir_id(
|
||||||
|
map.get_parent_node_by_hir_id(consume_pat.hir_id))
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
|
if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
|
||||||
self.set.insert(consume_pat.id);
|
self.set.insert(consume_pat.hir_id);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -129,7 +130,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
|
||||||
if let ExprKind::Box(..) = ex.node {
|
if let ExprKind::Box(..) = ex.node {
|
||||||
if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
|
if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
|
||||||
// let x = box (...)
|
// let x = box (...)
|
||||||
self.set.insert(consume_pat.id);
|
self.set.insert(consume_pat.hir_id);
|
||||||
}
|
}
|
||||||
// TODO Box::new
|
// TODO Box::new
|
||||||
// TODO vec![]
|
// TODO vec![]
|
||||||
|
@ -143,7 +144,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
|
||||||
if self.set.contains(&lid) {
|
if self.set.contains(&lid) {
|
||||||
// let y = x where x is known
|
// let y = x where x is known
|
||||||
// remove x, insert y
|
// remove x, insert y
|
||||||
self.set.insert(consume_pat.id);
|
self.set.insert(consume_pat.hir_id);
|
||||||
self.set.remove(&lid);
|
self.set.remove(&lid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,7 +178,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn decl_without_init(&mut self, _: NodeId, _: Span) {}
|
fn decl_without_init(&mut self, _: HirId, _: Span) {}
|
||||||
fn mutate(&mut self, _: HirId, _: Span, _: &cmt_<'tcx>, _: MutateMode) {}
|
fn mutate(&mut self, _: HirId, _: Span, _: &cmt_<'tcx>, _: MutateMode) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ impl LintPass for FallibleImplFrom {
|
||||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FallibleImplFrom {
|
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FallibleImplFrom {
|
||||||
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) {
|
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) {
|
||||||
// check for `impl From<???> for ..`
|
// check for `impl From<???> for ..`
|
||||||
let impl_def_id = cx.tcx.hir().local_def_id(item.id);
|
let impl_def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let hir::ItemKind::Impl(.., ref impl_items) = item.node;
|
if let hir::ItemKind::Impl(.., ref impl_items) = item.node;
|
||||||
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);
|
||||||
|
@ -105,7 +105,7 @@ fn lint_impl_body<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, impl_span: Span, impl_it
|
||||||
then {
|
then {
|
||||||
// check the body for `begin_panic` or `unwrap`
|
// check the body for `begin_panic` or `unwrap`
|
||||||
let body = cx.tcx.hir().body(body_id);
|
let body = cx.tcx.hir().body(body_id);
|
||||||
let impl_item_def_id = cx.tcx.hir().local_def_id(impl_item.id.node_id);
|
let impl_item_def_id = cx.tcx.hir().local_def_id_from_hir_id(impl_item.id.hir_id);
|
||||||
let mut fpu = FindPanicUnwrap {
|
let mut fpu = FindPanicUnwrap {
|
||||||
tcx: cx.tcx,
|
tcx: cx.tcx,
|
||||||
tables: cx.tcx.typeck_tables_of(impl_item_def_id),
|
tables: cx.tcx.typeck_tables_of(impl_item_def_id),
|
||||||
|
|
|
@ -54,7 +54,7 @@ impl LintPass for LargeEnumVariant {
|
||||||
|
|
||||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeEnumVariant {
|
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeEnumVariant {
|
||||||
fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item) {
|
fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item) {
|
||||||
let did = cx.tcx.hir().local_def_id(item.id);
|
let did = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
|
||||||
if let ItemKind::Enum(ref def, _) = item.node {
|
if let ItemKind::Enum(ref def, _) = item.node {
|
||||||
let ty = cx.tcx.type_of(did);
|
let ty = cx.tcx.type_of(did);
|
||||||
let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
|
let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
|
||||||
|
|
|
@ -132,7 +132,7 @@ fn check_trait_items(cx: &LateContext<'_, '_>, visited_trait: &Item, trait_items
|
||||||
item.ident.name == name
|
item.ident.name == name
|
||||||
&& if let AssociatedItemKind::Method { has_self } = item.kind {
|
&& if let AssociatedItemKind::Method { has_self } = item.kind {
|
||||||
has_self && {
|
has_self && {
|
||||||
let did = cx.tcx.hir().local_def_id(item.id.node_id);
|
let did = cx.tcx.hir().local_def_id_from_hir_id(item.id.hir_id);
|
||||||
cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1
|
cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -149,9 +149,11 @@ fn check_trait_items(cx: &LateContext<'_, '_>, visited_trait: &Item, trait_items
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if cx.access_levels.is_exported(visited_trait.id) && trait_items.iter().any(|i| is_named_self(cx, i, "len")) {
|
let trait_node_id = cx.tcx.hir().hir_to_node_id(visited_trait.hir_id);
|
||||||
|
|
||||||
|
if cx.access_levels.is_exported(trait_node_id) && trait_items.iter().any(|i| is_named_self(cx, i, "len")) {
|
||||||
let mut current_and_super_traits = FxHashSet::default();
|
let mut current_and_super_traits = FxHashSet::default();
|
||||||
let visited_trait_def_id = cx.tcx.hir().local_def_id(visited_trait.id);
|
let visited_trait_def_id = cx.tcx.hir().local_def_id_from_hir_id(visited_trait.hir_id);
|
||||||
fill_trait_set(visited_trait_def_id, &mut current_and_super_traits, cx);
|
fill_trait_set(visited_trait_def_id, &mut current_and_super_traits, cx);
|
||||||
|
|
||||||
let is_empty_method_found = current_and_super_traits
|
let is_empty_method_found = current_and_super_traits
|
||||||
|
@ -183,7 +185,7 @@ fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item, impl_items: &[ImplIte
|
||||||
item.ident.name == name
|
item.ident.name == name
|
||||||
&& if let AssociatedItemKind::Method { has_self } = item.kind {
|
&& if let AssociatedItemKind::Method { has_self } = item.kind {
|
||||||
has_self && {
|
has_self && {
|
||||||
let did = cx.tcx.hir().local_def_id(item.id.node_id);
|
let did = cx.tcx.hir().local_def_id_from_hir_id(item.id.hir_id);
|
||||||
cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1
|
cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -192,7 +194,7 @@ fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item, impl_items: &[ImplIte
|
||||||
}
|
}
|
||||||
|
|
||||||
let is_empty = if let Some(is_empty) = impl_items.iter().find(|i| is_named_self(cx, i, "is_empty")) {
|
let is_empty = if let Some(is_empty) = impl_items.iter().find(|i| is_named_self(cx, i, "is_empty")) {
|
||||||
if cx.access_levels.is_exported(is_empty.id.node_id) {
|
if cx.access_levels.is_exported(cx.tcx.hir().hir_to_node_id(is_empty.id.hir_id)) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
"a private"
|
"a private"
|
||||||
|
@ -202,8 +204,8 @@ fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item, impl_items: &[ImplIte
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(i) = impl_items.iter().find(|i| is_named_self(cx, i, "len")) {
|
if let Some(i) = impl_items.iter().find(|i| is_named_self(cx, i, "len")) {
|
||||||
if cx.access_levels.is_exported(i.id.node_id) {
|
if cx.access_levels.is_exported(cx.tcx.hir().hir_to_node_id(i.id.hir_id)) {
|
||||||
let def_id = cx.tcx.hir().local_def_id(item.id);
|
let def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
|
||||||
let ty = cx.tcx.type_of(def_id);
|
let ty = cx.tcx.type_of(def_id);
|
||||||
|
|
||||||
span_lint(
|
span_lint(
|
||||||
|
|
|
@ -1562,8 +1562,8 @@ fn check_for_loop_over_map_kv<'a, 'tcx>(
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MutatePairDelegate {
|
struct MutatePairDelegate {
|
||||||
node_id_low: Option<NodeId>,
|
hir_id_low: Option<HirId>,
|
||||||
node_id_high: Option<NodeId>,
|
hir_id_high: Option<HirId>,
|
||||||
span_low: Option<Span>,
|
span_low: Option<Span>,
|
||||||
span_high: Option<Span>,
|
span_high: Option<Span>,
|
||||||
}
|
}
|
||||||
|
@ -1578,10 +1578,10 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate {
|
||||||
fn borrow(&mut self, _: HirId, sp: Span, cmt: &cmt_<'tcx>, _: ty::Region<'_>, bk: ty::BorrowKind, _: LoanCause) {
|
fn borrow(&mut self, _: HirId, sp: Span, cmt: &cmt_<'tcx>, _: ty::Region<'_>, bk: ty::BorrowKind, _: LoanCause) {
|
||||||
if let ty::BorrowKind::MutBorrow = bk {
|
if let ty::BorrowKind::MutBorrow = bk {
|
||||||
if let Categorization::Local(id) = cmt.cat {
|
if let Categorization::Local(id) = cmt.cat {
|
||||||
if Some(id) == self.node_id_low {
|
if Some(id) == self.hir_id_low {
|
||||||
self.span_low = Some(sp)
|
self.span_low = Some(sp)
|
||||||
}
|
}
|
||||||
if Some(id) == self.node_id_high {
|
if Some(id) == self.hir_id_high {
|
||||||
self.span_high = Some(sp)
|
self.span_high = Some(sp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1590,16 +1590,16 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate {
|
||||||
|
|
||||||
fn mutate(&mut self, _: HirId, sp: Span, cmt: &cmt_<'tcx>, _: MutateMode) {
|
fn mutate(&mut self, _: HirId, sp: Span, cmt: &cmt_<'tcx>, _: MutateMode) {
|
||||||
if let Categorization::Local(id) = cmt.cat {
|
if let Categorization::Local(id) = cmt.cat {
|
||||||
if Some(id) == self.node_id_low {
|
if Some(id) == self.hir_id_low {
|
||||||
self.span_low = Some(sp)
|
self.span_low = Some(sp)
|
||||||
}
|
}
|
||||||
if Some(id) == self.node_id_high {
|
if Some(id) == self.hir_id_high {
|
||||||
self.span_high = Some(sp)
|
self.span_high = Some(sp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn decl_without_init(&mut self, _: NodeId, _: Span) {}
|
fn decl_without_init(&mut self, _: HirId, _: Span) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> MutatePairDelegate {
|
impl<'tcx> MutatePairDelegate {
|
||||||
|
@ -1635,7 +1635,7 @@ fn mut_warn_with_span(cx: &LateContext<'_, '_>, span: Option<Span>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr) -> Option<NodeId> {
|
fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr) -> Option<HirId> {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let ExprKind::Path(ref qpath) = bound.node;
|
if let ExprKind::Path(ref qpath) = bound.node;
|
||||||
if let QPath::Resolved(None, _) = *qpath;
|
if let QPath::Resolved(None, _) = *qpath;
|
||||||
|
@ -1648,7 +1648,7 @@ fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr) -> Option<NodeId
|
||||||
if let PatKind::Binding(bind_ann, ..) = pat.node;
|
if let PatKind::Binding(bind_ann, ..) = pat.node;
|
||||||
if let BindingAnnotation::Mutable = bind_ann;
|
if let BindingAnnotation::Mutable = bind_ann;
|
||||||
then {
|
then {
|
||||||
return Some(node_id);
|
return Some(cx.tcx.hir().node_to_hir_id(node_id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1660,11 +1660,11 @@ fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr) -> Option<NodeId
|
||||||
fn check_for_mutation(
|
fn check_for_mutation(
|
||||||
cx: &LateContext<'_, '_>,
|
cx: &LateContext<'_, '_>,
|
||||||
body: &Expr,
|
body: &Expr,
|
||||||
bound_ids: &[Option<NodeId>],
|
bound_ids: &[Option<HirId>],
|
||||||
) -> (Option<Span>, Option<Span>) {
|
) -> (Option<Span>, Option<Span>) {
|
||||||
let mut delegate = MutatePairDelegate {
|
let mut delegate = MutatePairDelegate {
|
||||||
node_id_low: bound_ids[0],
|
hir_id_low: bound_ids[0],
|
||||||
node_id_high: bound_ids[1],
|
hir_id_high: bound_ids[1],
|
||||||
span_low: None,
|
span_low: None,
|
||||||
span_high: None,
|
span_high: None,
|
||||||
};
|
};
|
||||||
|
@ -1938,8 +1938,7 @@ fn is_iterator_used_after_while_let<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, it
|
||||||
past_while_let: false,
|
past_while_let: false,
|
||||||
var_used_after_while_let: false,
|
var_used_after_while_let: false,
|
||||||
};
|
};
|
||||||
let def_hir_id = cx.tcx.hir().node_to_hir_id(def_id);
|
if let Some(enclosing_block) = get_enclosing_block(cx, def_id) {
|
||||||
if let Some(enclosing_block) = get_enclosing_block(cx, def_hir_id) {
|
|
||||||
walk_block(&mut visitor, enclosing_block);
|
walk_block(&mut visitor, enclosing_block);
|
||||||
}
|
}
|
||||||
visitor.var_used_after_while_let
|
visitor.var_used_after_while_let
|
||||||
|
@ -1947,7 +1946,7 @@ fn is_iterator_used_after_while_let<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, it
|
||||||
|
|
||||||
struct VarUsedAfterLoopVisitor<'a, 'tcx: 'a> {
|
struct VarUsedAfterLoopVisitor<'a, 'tcx: 'a> {
|
||||||
cx: &'a LateContext<'a, 'tcx>,
|
cx: &'a LateContext<'a, 'tcx>,
|
||||||
def_id: NodeId,
|
def_id: HirId,
|
||||||
iter_expr_id: HirId,
|
iter_expr_id: HirId,
|
||||||
past_while_let: bool,
|
past_while_let: bool,
|
||||||
var_used_after_while_let: bool,
|
var_used_after_while_let: bool,
|
||||||
|
@ -2053,7 +2052,7 @@ enum VarState {
|
||||||
/// Scan a for loop for variables that are incremented exactly once.
|
/// Scan a for loop for variables that are incremented exactly once.
|
||||||
struct IncrementVisitor<'a, 'tcx: 'a> {
|
struct IncrementVisitor<'a, 'tcx: 'a> {
|
||||||
cx: &'a LateContext<'a, 'tcx>, // context reference
|
cx: &'a LateContext<'a, 'tcx>, // context reference
|
||||||
states: FxHashMap<NodeId, VarState>, // incremented variables
|
states: FxHashMap<HirId, VarState>, // incremented variables
|
||||||
depth: u32, // depth of conditional expressions
|
depth: u32, // depth of conditional expressions
|
||||||
done: bool,
|
done: bool,
|
||||||
}
|
}
|
||||||
|
@ -2108,7 +2107,7 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> {
|
||||||
struct InitializeVisitor<'a, 'tcx: 'a> {
|
struct InitializeVisitor<'a, 'tcx: 'a> {
|
||||||
cx: &'a LateContext<'a, 'tcx>, // context reference
|
cx: &'a LateContext<'a, 'tcx>, // context reference
|
||||||
end_expr: &'tcx Expr, // the for loop. Stop scanning here.
|
end_expr: &'tcx Expr, // the for loop. Stop scanning here.
|
||||||
var_id: NodeId,
|
var_id: HirId,
|
||||||
state: VarState,
|
state: VarState,
|
||||||
name: Option<Name>,
|
name: Option<Name>,
|
||||||
depth: u32, // depth of conditional expressions
|
depth: u32, // depth of conditional expressions
|
||||||
|
@ -2119,7 +2118,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
|
||||||
fn visit_stmt(&mut self, stmt: &'tcx Stmt) {
|
fn visit_stmt(&mut self, stmt: &'tcx Stmt) {
|
||||||
// Look for declarations of the variable
|
// Look for declarations of the variable
|
||||||
if let StmtKind::Local(ref local) = stmt.node {
|
if let StmtKind::Local(ref local) = stmt.node {
|
||||||
if local.pat.id == self.var_id {
|
if local.pat.hir_id == self.var_id {
|
||||||
if let PatKind::Binding(.., ident, _) = local.pat.node {
|
if let PatKind::Binding(.., ident, _) = local.pat.node {
|
||||||
self.name = Some(ident.name);
|
self.name = Some(ident.name);
|
||||||
|
|
||||||
|
@ -2191,11 +2190,11 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn var_def_id(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<NodeId> {
|
fn var_def_id(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<HirId> {
|
||||||
if let ExprKind::Path(ref qpath) = expr.node {
|
if let ExprKind::Path(ref qpath) = expr.node {
|
||||||
let path_res = cx.tables.qpath_def(qpath, expr.hir_id);
|
let path_res = cx.tables.qpath_def(qpath, expr.hir_id);
|
||||||
if let Def::Local(node_id) = path_res {
|
if let Def::Local(node_id) = path_res {
|
||||||
return Some(node_id);
|
return Some(cx.tcx.hir().node_to_hir_id(node_id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
|
@ -2376,7 +2375,7 @@ fn check_infinite_loop<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, cond: &'tcx Expr, e
|
||||||
/// All variables definition IDs are collected
|
/// All variables definition IDs are collected
|
||||||
struct VarCollectorVisitor<'a, 'tcx: 'a> {
|
struct VarCollectorVisitor<'a, 'tcx: 'a> {
|
||||||
cx: &'a LateContext<'a, 'tcx>,
|
cx: &'a LateContext<'a, 'tcx>,
|
||||||
ids: FxHashSet<NodeId>,
|
ids: FxHashSet<HirId>,
|
||||||
def_ids: FxHashMap<def_id::DefId, bool>,
|
def_ids: FxHashMap<def_id::DefId, bool>,
|
||||||
skip: bool,
|
skip: bool,
|
||||||
}
|
}
|
||||||
|
@ -2390,7 +2389,7 @@ impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> {
|
||||||
then {
|
then {
|
||||||
match def {
|
match def {
|
||||||
Def::Local(node_id) | Def::Upvar(node_id, ..) => {
|
Def::Local(node_id) | Def::Upvar(node_id, ..) => {
|
||||||
self.ids.insert(node_id);
|
self.ids.insert(self.cx.tcx.hir().node_to_hir_id(node_id));
|
||||||
},
|
},
|
||||||
Def::Static(def_id, mutable) => {
|
Def::Static(def_id, mutable) => {
|
||||||
self.def_ids.insert(def_id, mutable);
|
self.def_ids.insert(def_id, mutable);
|
||||||
|
|
|
@ -5,7 +5,6 @@ use rustc::hir;
|
||||||
use rustc::hir::def::Def;
|
use rustc::hir::def::Def;
|
||||||
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
|
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
|
||||||
use rustc::lint::LateContext;
|
use rustc::lint::LateContext;
|
||||||
use syntax::ast;
|
|
||||||
|
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
|
|
||||||
|
@ -18,7 +17,7 @@ pub(super) fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[hir::Expr
|
||||||
|
|
||||||
if let hir::ExprKind::Closure(_, _, body_id, ..) = args[1].node {
|
if let hir::ExprKind::Closure(_, _, body_id, ..) = args[1].node {
|
||||||
let body = cx.tcx.hir().body(body_id);
|
let body = cx.tcx.hir().body(body_id);
|
||||||
let arg_id = body.arguments[0].pat.id;
|
let arg_id = body.arguments[0].pat.hir_id;
|
||||||
let mutates_arg = match mutated_variables(&body.value, cx) {
|
let mutates_arg = match mutated_variables(&body.value, cx) {
|
||||||
Some(used_mutably) => used_mutably.contains(&arg_id),
|
Some(used_mutably) => used_mutably.contains(&arg_id),
|
||||||
None => true,
|
None => true,
|
||||||
|
@ -56,7 +55,7 @@ pub(super) fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[hir::Expr
|
||||||
// returns (found_mapping, found_filtering)
|
// returns (found_mapping, found_filtering)
|
||||||
fn check_expression<'a, 'tcx: 'a>(
|
fn check_expression<'a, 'tcx: 'a>(
|
||||||
cx: &'a LateContext<'a, 'tcx>,
|
cx: &'a LateContext<'a, 'tcx>,
|
||||||
arg_id: ast::NodeId,
|
arg_id: hir::HirId,
|
||||||
expr: &'tcx hir::Expr,
|
expr: &'tcx hir::Expr,
|
||||||
) -> (bool, bool) {
|
) -> (bool, bool) {
|
||||||
match &expr.node {
|
match &expr.node {
|
||||||
|
@ -69,7 +68,7 @@ fn check_expression<'a, 'tcx: 'a>(
|
||||||
if let hir::ExprKind::Path(path) = &args[0].node;
|
if let hir::ExprKind::Path(path) = &args[0].node;
|
||||||
if let Def::Local(ref local) = cx.tables.qpath_def(path, args[0].hir_id);
|
if let Def::Local(ref local) = cx.tables.qpath_def(path, args[0].hir_id);
|
||||||
then {
|
then {
|
||||||
if arg_id == *local {
|
if arg_id == cx.tcx.hir().node_to_hir_id(*local) {
|
||||||
return (false, false)
|
return (false, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,7 +112,7 @@ fn check_expression<'a, 'tcx: 'a>(
|
||||||
|
|
||||||
struct ReturnVisitor<'a, 'tcx: 'a> {
|
struct ReturnVisitor<'a, 'tcx: 'a> {
|
||||||
cx: &'a LateContext<'a, 'tcx>,
|
cx: &'a LateContext<'a, 'tcx>,
|
||||||
arg_id: ast::NodeId,
|
arg_id: hir::HirId,
|
||||||
// Found a non-None return that isn't Some(input)
|
// Found a non-None return that isn't Some(input)
|
||||||
found_mapping: bool,
|
found_mapping: bool,
|
||||||
// Found a return that isn't Some
|
// Found a return that isn't Some
|
||||||
|
@ -121,7 +120,7 @@ struct ReturnVisitor<'a, 'tcx: 'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx: 'a> ReturnVisitor<'a, 'tcx> {
|
impl<'a, 'tcx: 'a> ReturnVisitor<'a, 'tcx> {
|
||||||
fn new(cx: &'a LateContext<'a, 'tcx>, arg_id: ast::NodeId) -> ReturnVisitor<'a, 'tcx> {
|
fn new(cx: &'a LateContext<'a, 'tcx>, arg_id: hir::HirId) -> ReturnVisitor<'a, 'tcx> {
|
||||||
ReturnVisitor {
|
ReturnVisitor {
|
||||||
cx,
|
cx,
|
||||||
arg_id,
|
arg_id,
|
||||||
|
|
|
@ -124,7 +124,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
|
||||||
hir::ItemKind::Fn(..) => {
|
hir::ItemKind::Fn(..) => {
|
||||||
// ignore main()
|
// ignore main()
|
||||||
if it.ident.name == "main" {
|
if it.ident.name == "main" {
|
||||||
let def_id = cx.tcx.hir().local_def_id(it.id);
|
let def_id = cx.tcx.hir().local_def_id_from_hir_id(it.hir_id);
|
||||||
let def_key = cx.tcx.hir().def_key(def_id);
|
let def_key = cx.tcx.hir().def_key(def_id);
|
||||||
if def_key.parent == Some(hir::def_id::CRATE_DEF_INDEX) {
|
if def_key.parent == Some(hir::def_id::CRATE_DEF_INDEX) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -95,7 +95,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !cx.access_levels.is_exported(it.id) {
|
if !cx.access_levels.is_exported(cx.tcx.hir().hir_to_node_id(it.hir_id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
match it.node {
|
match it.node {
|
||||||
|
@ -115,7 +115,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline {
|
||||||
// trait method with default body needs inline in case
|
// trait method with default body needs inline in case
|
||||||
// an impl is not provided
|
// an impl is not provided
|
||||||
let desc = "a default trait method";
|
let desc = "a default trait method";
|
||||||
let item = cx.tcx.hir().expect_trait_item(tit.id.node_id);
|
let item = cx.tcx.hir().expect_trait_item_by_hir_id(tit.id.hir_id);
|
||||||
check_missing_inline_attrs(cx, &item.attrs, item.span, desc);
|
check_missing_inline_attrs(cx, &item.attrs, item.span, desc);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,13 +4,12 @@
|
||||||
|
|
||||||
use crate::utils::{in_macro, snippet_opt, span_lint_and_then};
|
use crate::utils::{in_macro, snippet_opt, span_lint_and_then};
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
use rustc::hir::{BindingAnnotation, Expr, ExprKind, Item, MutImmutable, Pat, PatKind};
|
use rustc::hir::{BindingAnnotation, Expr, ExprKind, HirId, Item, MutImmutable, Pat, PatKind};
|
||||||
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||||
use rustc::ty;
|
use rustc::ty;
|
||||||
use rustc::ty::adjustment::{Adjust, Adjustment};
|
use rustc::ty::adjustment::{Adjust, Adjustment};
|
||||||
use rustc::{declare_tool_lint, lint_array};
|
use rustc::{declare_tool_lint, lint_array};
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use syntax::ast::NodeId;
|
|
||||||
|
|
||||||
/// **What it does:** Checks for address of operations (`&`) that are going to
|
/// **What it does:** Checks for address of operations (`&`) that are going to
|
||||||
/// be dereferenced immediately by the compiler.
|
/// be dereferenced immediately by the compiler.
|
||||||
|
@ -32,7 +31,7 @@ declare_clippy_lint! {
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct NeedlessBorrow {
|
pub struct NeedlessBorrow {
|
||||||
derived_item: Option<NodeId>,
|
derived_item: Option<HirId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LintPass for NeedlessBorrow {
|
impl LintPass for NeedlessBorrow {
|
||||||
|
@ -119,13 +118,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow {
|
||||||
fn check_item(&mut self, _: &LateContext<'a, 'tcx>, item: &'tcx Item) {
|
fn check_item(&mut self, _: &LateContext<'a, 'tcx>, item: &'tcx Item) {
|
||||||
if item.attrs.iter().any(|a| a.check_name("automatically_derived")) {
|
if item.attrs.iter().any(|a| a.check_name("automatically_derived")) {
|
||||||
debug_assert!(self.derived_item.is_none());
|
debug_assert!(self.derived_item.is_none());
|
||||||
self.derived_item = Some(item.id);
|
self.derived_item = Some(item.hir_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_item_post(&mut self, _: &LateContext<'a, 'tcx>, item: &'tcx Item) {
|
fn check_item_post(&mut self, _: &LateContext<'a, 'tcx>, item: &'tcx Item) {
|
||||||
if let Some(id) = self.derived_item {
|
if let Some(id) = self.derived_item {
|
||||||
if item.id == id {
|
if item.hir_id == id {
|
||||||
self.derived_item = None;
|
self.derived_item = None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_target::spec::abi::Abi;
|
use rustc_target::spec::abi::Abi;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use syntax::ast::NodeId;
|
|
||||||
use syntax::errors::DiagnosticBuilder;
|
use syntax::errors::DiagnosticBuilder;
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
|
|
||||||
|
@ -210,7 +209,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
|
||||||
if !implements_borrow_trait;
|
if !implements_borrow_trait;
|
||||||
if !all_borrowable_trait;
|
if !all_borrowable_trait;
|
||||||
|
|
||||||
if let PatKind::Binding(mode, canonical_id, ..) = arg.pat.node;
|
if let PatKind::Binding(mode, _, canonical_id, ..) = arg.pat.node;
|
||||||
if !moved_vars.contains(&canonical_id);
|
if !moved_vars.contains(&canonical_id);
|
||||||
then {
|
then {
|
||||||
if mode == BindingAnnotation::Mutable || mode == BindingAnnotation::RefMut {
|
if mode == BindingAnnotation::Mutable || mode == BindingAnnotation::RefMut {
|
||||||
|
@ -326,10 +325,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
|
||||||
|
|
||||||
struct MovedVariablesCtxt<'a, 'tcx: 'a> {
|
struct MovedVariablesCtxt<'a, 'tcx: 'a> {
|
||||||
cx: &'a LateContext<'a, 'tcx>,
|
cx: &'a LateContext<'a, 'tcx>,
|
||||||
moved_vars: FxHashSet<NodeId>,
|
moved_vars: FxHashSet<HirId>,
|
||||||
/// Spans which need to be prefixed with `*` for dereferencing the
|
/// Spans which need to be prefixed with `*` for dereferencing the
|
||||||
/// suggested additional reference.
|
/// suggested additional reference.
|
||||||
spans_need_deref: FxHashMap<NodeId, FxHashSet<Span>>,
|
spans_need_deref: FxHashMap<HirId, FxHashSet<Span>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> MovedVariablesCtxt<'a, 'tcx> {
|
impl<'a, 'tcx> MovedVariablesCtxt<'a, 'tcx> {
|
||||||
|
@ -353,16 +352,16 @@ impl<'a, 'tcx> MovedVariablesCtxt<'a, 'tcx> {
|
||||||
let cmt = unwrap_downcast_or_interior(cmt);
|
let cmt = unwrap_downcast_or_interior(cmt);
|
||||||
|
|
||||||
if let mc::Categorization::Local(vid) = cmt.cat {
|
if let mc::Categorization::Local(vid) = cmt.cat {
|
||||||
let mut id = matched_pat.id;
|
let mut id = matched_pat.hir_id;
|
||||||
loop {
|
loop {
|
||||||
let parent = self.cx.tcx.hir().get_parent_node(id);
|
let parent = self.cx.tcx.hir().get_parent_node_by_hir_id(id);
|
||||||
if id == parent {
|
if id == parent {
|
||||||
// no parent
|
// no parent
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
id = parent;
|
id = parent;
|
||||||
|
|
||||||
if let Some(node) = self.cx.tcx.hir().find(id) {
|
if let Some(node) = self.cx.tcx.hir().find_by_hir_id(id) {
|
||||||
match node {
|
match node {
|
||||||
Node::Expr(e) => {
|
Node::Expr(e) => {
|
||||||
// `match` and `if let`
|
// `match` and `if let`
|
||||||
|
@ -432,7 +431,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
fn mutate(&mut self, _: HirId, _: Span, _: &mc::cmt_<'tcx>, _: euv::MutateMode) {}
|
fn mutate(&mut self, _: HirId, _: Span, _: &mc::cmt_<'tcx>, _: euv::MutateMode) {}
|
||||||
|
|
||||||
fn decl_without_init(&mut self, _: NodeId, _: Span) {}
|
fn decl_without_init(&mut self, _: HirId, _: Span) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unwrap_downcast_or_interior<'a, 'tcx>(mut cmt: &'a mc::cmt_<'tcx>) -> mc::cmt_<'tcx> {
|
fn unwrap_downcast_or_interior<'a, 'tcx>(mut cmt: &'a mc::cmt_<'tcx>) -> mc::cmt_<'tcx> {
|
||||||
|
|
|
@ -51,11 +51,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
||||||
then {
|
then {
|
||||||
for impl_item in impl_items {
|
for impl_item in impl_items {
|
||||||
if impl_item.ident.name == "ne" {
|
if impl_item.ident.name == "ne" {
|
||||||
let hir_id = cx.tcx.hir().node_to_hir_id(impl_item.id.node_id);
|
|
||||||
span_lint_node(
|
span_lint_node(
|
||||||
cx,
|
cx,
|
||||||
PARTIALEQ_NE_IMPL,
|
PARTIALEQ_NE_IMPL,
|
||||||
hir_id,
|
impl_item.id.hir_id,
|
||||||
impl_item.span,
|
impl_item.span,
|
||||||
"re-implementing `PartialEq::ne` is unnecessary",
|
"re-implementing `PartialEq::ne` is unnecessary",
|
||||||
);
|
);
|
||||||
|
|
|
@ -72,11 +72,11 @@ impl<'a, 'tcx> TriviallyCopyPassByRef {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_trait_method(&mut self, cx: &LateContext<'_, 'tcx>, item: &TraitItemRef) {
|
fn check_trait_method(&mut self, cx: &LateContext<'_, 'tcx>, item: &TraitItemRef) {
|
||||||
let method_def_id = cx.tcx.hir().local_def_id(item.id.node_id);
|
let method_def_id = cx.tcx.hir().local_def_id_from_hir_id(item.id.hir_id);
|
||||||
let method_sig = cx.tcx.fn_sig(method_def_id);
|
let method_sig = cx.tcx.fn_sig(method_def_id);
|
||||||
let method_sig = cx.tcx.erase_late_bound_regions(&method_sig);
|
let method_sig = cx.tcx.erase_late_bound_regions(&method_sig);
|
||||||
|
|
||||||
let decl = match cx.tcx.hir().fn_decl(item.id.node_id) {
|
let decl = match cx.tcx.hir().fn_decl_by_hir_id(item.id.hir_id) {
|
||||||
Some(b) => b,
|
Some(b) => b,
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
|
|
|
@ -2034,7 +2034,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitHasher {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !cx.access_levels.is_exported(item.id) {
|
if !cx.access_levels.is_exported(cx.tcx.hir().hir_to_node_id(item.hir_id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -192,7 +192,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UseSelf {
|
||||||
item_path,
|
item_path,
|
||||||
cx,
|
cx,
|
||||||
};
|
};
|
||||||
let impl_def_id = cx.tcx.hir().local_def_id(item.id);
|
let impl_def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
|
||||||
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 {
|
||||||
|
|
|
@ -344,7 +344,7 @@ fn print_expr(cx: &LateContext<'_, '_>, expr: &hir::Expr, indent: usize) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_item(cx: &LateContext<'_, '_>, item: &hir::Item) {
|
fn print_item(cx: &LateContext<'_, '_>, item: &hir::Item) {
|
||||||
let did = cx.tcx.hir().local_def_id(item.id);
|
let did = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
|
||||||
println!("item `{}`", item.ident.name);
|
println!("item `{}`", item.ident.name);
|
||||||
match item.vis.node {
|
match item.vis.node {
|
||||||
hir::VisibilityKind::Public => println!("public"),
|
hir::VisibilityKind::Public => println!("public"),
|
||||||
|
@ -357,7 +357,7 @@ fn print_item(cx: &LateContext<'_, '_>, item: &hir::Item) {
|
||||||
}
|
}
|
||||||
match item.node {
|
match item.node {
|
||||||
hir::ItemKind::ExternCrate(ref _renamed_from) => {
|
hir::ItemKind::ExternCrate(ref _renamed_from) => {
|
||||||
let def_id = cx.tcx.hir().local_def_id(item.id);
|
let def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
|
||||||
if let Some(crate_id) = cx.tcx.extern_mod_stmt_cnum(def_id) {
|
if let Some(crate_id) = cx.tcx.extern_mod_stmt_cnum(def_id) {
|
||||||
let source = cx.tcx.used_crate_source(crate_id);
|
let source = cx.tcx.used_crate_source(crate_id);
|
||||||
if let Some(ref src) = source.dylib {
|
if let Some(ref src) = source.dylib {
|
||||||
|
|
|
@ -164,7 +164,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
|
||||||
output: &mut self.registered_lints,
|
output: &mut self.registered_lints,
|
||||||
cx,
|
cx,
|
||||||
};
|
};
|
||||||
let body_id = cx.tcx.hir().body_owned_by(impl_item_refs[0].id.node_id);
|
let node_id = cx.tcx.hir().hir_to_node_id(impl_item_refs[0].id.hir_id);
|
||||||
|
let body_id = cx.tcx.hir().body_owned_by(node_id);
|
||||||
collector.visit_expr(&cx.tcx.hir().body(body_id).value);
|
collector.visit_expr(&cx.tcx.hir().body(body_id).value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,11 +7,10 @@ use rustc::middle::mem_categorization::cmt_;
|
||||||
use rustc::middle::mem_categorization::Categorization;
|
use rustc::middle::mem_categorization::Categorization;
|
||||||
use rustc::ty;
|
use rustc::ty;
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use syntax::ast::NodeId;
|
|
||||||
use syntax::source_map::Span;
|
use syntax::source_map::Span;
|
||||||
|
|
||||||
/// Returns a set of mutated local variable ids or None if mutations could not be determined.
|
/// Returns a set of mutated local variable ids or None if mutations could not be determined.
|
||||||
pub fn mutated_variables<'a, 'tcx: 'a>(expr: &'tcx Expr, cx: &'a LateContext<'a, 'tcx>) -> Option<FxHashSet<NodeId>> {
|
pub fn mutated_variables<'a, 'tcx: 'a>(expr: &'tcx Expr, cx: &'a LateContext<'a, 'tcx>) -> Option<FxHashSet<HirId>> {
|
||||||
let mut delegate = MutVarsDelegate {
|
let mut delegate = MutVarsDelegate {
|
||||||
used_mutably: FxHashSet::default(),
|
used_mutably: FxHashSet::default(),
|
||||||
skip: false,
|
skip: false,
|
||||||
|
@ -35,11 +34,11 @@ pub fn is_potentially_mutated<'a, 'tcx: 'a>(
|
||||||
Def::Local(id) | Def::Upvar(id, ..) => id,
|
Def::Local(id) | Def::Upvar(id, ..) => id,
|
||||||
_ => return true,
|
_ => return true,
|
||||||
};
|
};
|
||||||
mutated_variables(expr, cx).map_or(true, |mutated| mutated.contains(&id))
|
mutated_variables(expr, cx).map_or(true, |mutated| mutated.contains(&cx.tcx.hir().node_to_hir_id(id)))
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MutVarsDelegate {
|
struct MutVarsDelegate {
|
||||||
used_mutably: FxHashSet<NodeId>,
|
used_mutably: FxHashSet<HirId>,
|
||||||
skip: bool,
|
skip: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,5 +78,5 @@ impl<'tcx> Delegate<'tcx> for MutVarsDelegate {
|
||||||
self.update(&cmt.cat)
|
self.update(&cmt.cat)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn decl_without_init(&mut self, _: NodeId, _: Span) {}
|
fn decl_without_init(&mut self, _: HirId, _: Span) {}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue