Skip to content

Commit 5d78250

Browse files
committed
align with rust-lang/rust/#58992
1 parent 77ba504 commit 5d78250

11 files changed

+42
-46
lines changed

clippy_lints/src/eta_reduction.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ fn get_type_name(cx: &LateContext<'_, '_>, kind: &ty::TyKind<'_>) -> String {
182182

183183
fn compare_inputs(closure_inputs: &mut dyn Iterator<Item = &Arg>, call_args: &mut dyn Iterator<Item = &Expr>) -> bool {
184184
for (closure_input, function_arg) in closure_inputs.zip(call_args) {
185-
if let PatKind::Binding(_, _, _, ident, _) = closure_input.pat.node {
185+
if let PatKind::Binding(_, _, ident, _) = closure_input.pat.node {
186186
// XXXManishearth Should I be checking the binding mode here?
187187
if let ExprKind::Path(QPath::Resolved(None, ref p)) = function_arg.node {
188188
if p.segments.len() != 1 {

clippy_lints/src/functions.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use rustc::ty;
88
use rustc::{declare_tool_lint, lint_array};
99
use rustc_data_structures::fx::FxHashSet;
1010
use rustc_target::spec::abi::Abi;
11-
use syntax::ast;
1211
use syntax::source_map::Span;
1312

1413
declare_clippy_lint! {
@@ -278,8 +277,8 @@ impl<'a, 'tcx> Functions {
278277
}
279278
}
280279

281-
fn raw_ptr_arg(arg: &hir::Arg, ty: &hir::Ty) -> Option<ast::NodeId> {
282-
if let (&hir::PatKind::Binding(_, id, _, _, _), &hir::TyKind::Ptr(_)) = (&arg.pat.node, &ty.node) {
280+
fn raw_ptr_arg(arg: &hir::Arg, ty: &hir::Ty) -> Option<hir::HirId> {
281+
if let (&hir::PatKind::Binding(_, id, _, _), &hir::TyKind::Ptr(_)) = (&arg.pat.node, &ty.node) {
283282
Some(id)
284283
} else {
285284
None
@@ -288,7 +287,7 @@ fn raw_ptr_arg(arg: &hir::Arg, ty: &hir::Ty) -> Option<ast::NodeId> {
288287

289288
struct DerefVisitor<'a, 'tcx: 'a> {
290289
cx: &'a LateContext<'a, 'tcx>,
291-
ptrs: FxHashSet<ast::NodeId>,
290+
ptrs: FxHashSet<hir::HirId>,
292291
tables: &'a ty::TypeckTables<'tcx>,
293292
}
294293

@@ -329,7 +328,7 @@ impl<'a, 'tcx: 'a> DerefVisitor<'a, 'tcx> {
329328
fn check_arg(&self, ptr: &hir::Expr) {
330329
if let hir::ExprKind::Path(ref qpath) = ptr.node {
331330
if let Def::Local(id) = self.cx.tables.qpath_def(qpath, ptr.hir_id) {
332-
if self.ptrs.contains(&id) {
331+
if self.ptrs.contains(&self.cx.tcx.hir().node_to_hir_id(id)) {
333332
span_lint(
334333
self.cx,
335334
NOT_UNSAFE_PTR_ARG_DEREF,

clippy_lints/src/let_if_seq.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use rustc::hir::BindingAnnotation;
66
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
77
use rustc::{declare_tool_lint, lint_array};
88
use rustc_errors::Applicability;
9-
use syntax::ast;
109

1110
declare_clippy_lint! {
1211
/// **What it does:** Checks for variable declarations immediately followed by a
@@ -73,7 +72,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
7372
if_chain! {
7473
if let Some(expr) = it.peek();
7574
if let hir::StmtKind::Local(ref local) = stmt.node;
76-
if let hir::PatKind::Binding(mode, canonical_id, _, ident, None) = local.pat.node;
75+
if let hir::PatKind::Binding(mode, canonical_id, ident, None) = local.pat.node;
7776
if let hir::StmtKind::Expr(ref if_) = expr.node;
7877
if let hir::ExprKind::If(ref cond, ref then, ref else_) = if_.node;
7978
if !used_in_expr(cx, canonical_id, cond);
@@ -142,7 +141,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
142141

143142
struct UsedVisitor<'a, 'tcx: 'a> {
144143
cx: &'a LateContext<'a, 'tcx>,
145-
id: ast::NodeId,
144+
id: hir::HirId,
146145
used: bool,
147146
}
148147

@@ -151,7 +150,7 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for UsedVisitor<'a, 'tcx> {
151150
if_chain! {
152151
if let hir::ExprKind::Path(ref qpath) = expr.node;
153152
if let Def::Local(local_id) = self.cx.tables.qpath_def(qpath, expr.hir_id);
154-
if self.id == local_id;
153+
if self.id == self.cx.tcx.hir().node_to_hir_id(local_id);
155154
then {
156155
self.used = true;
157156
return;
@@ -166,7 +165,7 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for UsedVisitor<'a, 'tcx> {
166165

167166
fn check_assign<'a, 'tcx>(
168167
cx: &LateContext<'a, 'tcx>,
169-
decl: ast::NodeId,
168+
decl: hir::HirId,
170169
block: &'tcx hir::Block,
171170
) -> Option<&'tcx hir::Expr> {
172171
if_chain! {
@@ -176,7 +175,7 @@ fn check_assign<'a, 'tcx>(
176175
if let hir::ExprKind::Assign(ref var, ref value) = expr.node;
177176
if let hir::ExprKind::Path(ref qpath) = var.node;
178177
if let Def::Local(local_id) = cx.tables.qpath_def(qpath, var.hir_id);
179-
if decl == local_id;
178+
if decl == cx.tcx.hir().node_to_hir_id(local_id);
180179
then {
181180
let mut v = UsedVisitor {
182181
cx,
@@ -199,7 +198,7 @@ fn check_assign<'a, 'tcx>(
199198
None
200199
}
201200

202-
fn used_in_expr<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, id: ast::NodeId, expr: &'tcx hir::Expr) -> bool {
201+
fn used_in_expr<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, id: hir::HirId, expr: &'tcx hir::Expr) -> bool {
203202
let mut v = UsedVisitor { cx, id, used: false };
204203
hir::intravisit::walk_expr(&mut v, expr);
205204
v.used

clippy_lints/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ pub mod zero_div_zero;
272272
pub use crate::utils::conf::Conf;
273273

274274
mod reexport {
275-
crate use syntax::ast::{Name, NodeId};
275+
crate use syntax::ast::Name;
276276
}
277277

278278
/// Register all pre expansion lints

clippy_lints/src/loops.rs

+19-20
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
486486
// check for never_loop
487487
match expr.node {
488488
ExprKind::While(_, ref block, _) | ExprKind::Loop(ref block, _, _) => {
489-
let node_id = cx.tcx.hir().hir_to_node_id(expr.hir_id);
490-
match never_loop_block(block, node_id) {
489+
match never_loop_block(block, expr.hir_id) {
491490
NeverLoopResult::AlwaysBreak => {
492491
span_lint(cx, NEVER_LOOP, expr.span, "this loop never actually loops")
493492
},
@@ -664,7 +663,7 @@ fn combine_branches(b1: NeverLoopResult, b2: NeverLoopResult) -> NeverLoopResult
664663
}
665664
}
666665

667-
fn never_loop_block(block: &Block, main_loop_id: NodeId) -> NeverLoopResult {
666+
fn never_loop_block(block: &Block, main_loop_id: HirId) -> NeverLoopResult {
668667
let stmts = block.stmts.iter().map(stmt_to_expr);
669668
let expr = once(block.expr.as_ref().map(|p| &**p));
670669
let mut iter = stmts.chain(expr).filter_map(|e| e);
@@ -679,7 +678,7 @@ fn stmt_to_expr(stmt: &Stmt) -> Option<&Expr> {
679678
}
680679
}
681680

682-
fn never_loop_expr(expr: &Expr, main_loop_id: NodeId) -> NeverLoopResult {
681+
fn never_loop_expr(expr: &Expr, main_loop_id: HirId) -> NeverLoopResult {
683682
match expr.node {
684683
ExprKind::Box(ref e)
685684
| ExprKind::Unary(_, ref e)
@@ -753,17 +752,17 @@ fn never_loop_expr(expr: &Expr, main_loop_id: NodeId) -> NeverLoopResult {
753752
}
754753
}
755754

756-
fn never_loop_expr_seq<'a, T: Iterator<Item = &'a Expr>>(es: &mut T, main_loop_id: NodeId) -> NeverLoopResult {
755+
fn never_loop_expr_seq<'a, T: Iterator<Item = &'a Expr>>(es: &mut T, main_loop_id: HirId) -> NeverLoopResult {
757756
es.map(|e| never_loop_expr(e, main_loop_id))
758757
.fold(NeverLoopResult::Otherwise, combine_seq)
759758
}
760759

761-
fn never_loop_expr_all<'a, T: Iterator<Item = &'a Expr>>(es: &mut T, main_loop_id: NodeId) -> NeverLoopResult {
760+
fn never_loop_expr_all<'a, T: Iterator<Item = &'a Expr>>(es: &mut T, main_loop_id: HirId) -> NeverLoopResult {
762761
es.map(|e| never_loop_expr(e, main_loop_id))
763762
.fold(NeverLoopResult::Otherwise, combine_both)
764763
}
765764

766-
fn never_loop_expr_branch<'a, T: Iterator<Item = &'a Expr>>(e: &mut T, main_loop_id: NodeId) -> NeverLoopResult {
765+
fn never_loop_expr_branch<'a, T: Iterator<Item = &'a Expr>>(e: &mut T, main_loop_id: HirId) -> NeverLoopResult {
767766
e.map(|e| never_loop_expr(e, main_loop_id))
768767
.fold(NeverLoopResult::AlwaysBreak, combine_branches)
769768
}
@@ -784,14 +783,14 @@ fn check_for_loop<'a, 'tcx>(
784783
detect_manual_memcpy(cx, pat, arg, body, expr);
785784
}
786785

787-
fn same_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var: ast::NodeId) -> bool {
786+
fn same_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var: HirId) -> bool {
788787
if_chain! {
789788
if let ExprKind::Path(ref qpath) = expr.node;
790789
if let QPath::Resolved(None, ref path) = *qpath;
791790
if path.segments.len() == 1;
792791
if let Def::Local(local_id) = cx.tables.qpath_def(qpath, expr.hir_id);
793792
// our variable!
794-
if local_id == var;
793+
if cx.tcx.hir().node_to_hir_id(local_id) == var;
795794
then {
796795
return true;
797796
}
@@ -833,8 +832,8 @@ fn is_slice_like<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'_>) -> bool {
833832
is_slice || match_type(cx, ty, &paths::VEC) || match_type(cx, ty, &paths::VEC_DEQUE)
834833
}
835834

836-
fn get_fixed_offset_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var: ast::NodeId) -> Option<FixedOffsetVar> {
837-
fn extract_offset<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, e: &Expr, var: ast::NodeId) -> Option<String> {
835+
fn get_fixed_offset_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var: HirId) -> Option<FixedOffsetVar> {
836+
fn extract_offset<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, e: &Expr, var: HirId) -> Option<String> {
838837
match e.node {
839838
ExprKind::Lit(ref l) => match l.node {
840839
ast::LitKind::Int(x, _ty) => Some(x.to_string()),
@@ -889,7 +888,7 @@ fn get_fixed_offset_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var:
889888
fn fetch_cloned_fixed_offset_var<'a, 'tcx>(
890889
cx: &LateContext<'a, 'tcx>,
891890
expr: &Expr,
892-
var: ast::NodeId,
891+
var: HirId,
893892
) -> Option<FixedOffsetVar> {
894893
if_chain! {
895894
if let ExprKind::MethodCall(ref method, _, ref args) = expr.node;
@@ -907,12 +906,12 @@ fn fetch_cloned_fixed_offset_var<'a, 'tcx>(
907906
fn get_indexed_assignments<'a, 'tcx>(
908907
cx: &LateContext<'a, 'tcx>,
909908
body: &Expr,
910-
var: ast::NodeId,
909+
var: HirId,
911910
) -> Vec<(FixedOffsetVar, FixedOffsetVar)> {
912911
fn get_assignment<'a, 'tcx>(
913912
cx: &LateContext<'a, 'tcx>,
914913
e: &Expr,
915-
var: ast::NodeId,
914+
var: HirId,
916915
) -> Option<(FixedOffsetVar, FixedOffsetVar)> {
917916
if let ExprKind::Assign(ref lhs, ref rhs) = e.node {
918917
match (
@@ -970,7 +969,7 @@ fn detect_manual_memcpy<'a, 'tcx>(
970969
}) = higher::range(cx, arg)
971970
{
972971
// the var must be a single name
973-
if let PatKind::Binding(_, canonical_id, _, _, _) = pat.node {
972+
if let PatKind::Binding(_, canonical_id, _, _) = pat.node {
974973
let print_sum = |arg1: &Offset, arg2: &Offset| -> String {
975974
match (&arg1.value[..], arg1.negate, &arg2.value[..], arg2.negate) {
976975
("0", _, "0", _) => "".into(),
@@ -1087,7 +1086,7 @@ fn check_for_loop_range<'a, 'tcx>(
10871086
}) = higher::range(cx, arg)
10881087
{
10891088
// the var must be a single name
1090-
if let PatKind::Binding(_, canonical_id, _, ident, _) = pat.node {
1089+
if let PatKind::Binding(_, canonical_id, ident, _) = pat.node {
10911090
let mut visitor = VarVisitor {
10921091
cx,
10931092
var: canonical_id,
@@ -1711,7 +1710,7 @@ impl<'tcx> Visitor<'tcx> for UsedVisitor {
17111710

17121711
struct LocalUsedVisitor<'a, 'tcx: 'a> {
17131712
cx: &'a LateContext<'a, 'tcx>,
1714-
local: ast::NodeId,
1713+
local: HirId,
17151714
used: bool,
17161715
}
17171716

@@ -1733,7 +1732,7 @@ struct VarVisitor<'a, 'tcx: 'a> {
17331732
/// context reference
17341733
cx: &'a LateContext<'a, 'tcx>,
17351734
/// var name to look for as index
1736-
var: ast::NodeId,
1735+
var: HirId,
17371736
/// indexed variables that are used mutably
17381737
indexed_mut: FxHashSet<Name>,
17391738
/// indirectly indexed variables (`v[(i + 4) % N]`), the extend is `None` for global
@@ -1841,15 +1840,15 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
18411840
then {
18421841
match self.cx.tables.qpath_def(qpath, expr.hir_id) {
18431842
Def::Upvar(local_id, ..) => {
1844-
if local_id == self.var {
1843+
if self.cx.tcx.hir().node_to_hir_id(local_id) == self.var {
18451844
// we are not indexing anything, record that
18461845
self.nonindex = true;
18471846
}
18481847
}
18491848
Def::Local(local_id) =>
18501849
{
18511850

1852-
if local_id == self.var {
1851+
if self.cx.tcx.hir().node_to_hir_id(local_id) == self.var {
18531852
self.nonindex = true;
18541853
} else {
18551854
// not the correct variable, but still a variable

clippy_lints/src/matches.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ fn check_wild_enum_match(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm]) {
482482
for pat in &arm.pats {
483483
if let PatKind::Wild = pat.node {
484484
wildcard_span = Some(pat.span);
485-
} else if let PatKind::Binding(_, _, _, ident, None) = pat.node {
485+
} else if let PatKind::Binding(_, _, ident, None) = pat.node {
486486
wildcard_span = Some(pat.span);
487487
wildcard_ident = Some(ident);
488488
}

clippy_lints/src/missing_inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline {
115115
// trait method with default body needs inline in case
116116
// an impl is not provided
117117
let desc = "a default trait method";
118-
let item = cx.tcx.hir().expect_trait_item_by_hir_id(tit.id.hir_id);
118+
let item = cx.tcx.hir().expect_trait_item(tit.id.hir_id);
119119
check_missing_inline_attrs(cx, &item.attrs, item.span, desc);
120120
}
121121
},

clippy_lints/src/needless_pass_by_value.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
209209
if !implements_borrow_trait;
210210
if !all_borrowable_trait;
211211

212-
if let PatKind::Binding(mode, _, canonical_id, ..) = arg.pat.node;
212+
if let PatKind::Binding(mode, canonical_id, ..) = arg.pat.node;
213213
if !moved_vars.contains(&canonical_id);
214214
then {
215215
if mode == BindingAnnotation::Mutable || mode == BindingAnnotation::RefMut {

clippy_lints/src/unused_io_amount.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedIoAmount {
5050
};
5151

5252
match expr.node {
53-
hir::ExprKind::Match(ref res, _, _) if is_try(expr).is_some() => {
53+
hir::ExprKind::Match(ref res, _, _) if is_try(cx, expr).is_some() => {
5454
if let hir::ExprKind::Call(ref func, ref args) = res.node {
5555
if let hir::ExprKind::Path(ref path) = func.node {
5656
if match_qpath(path, &paths::TRY_INTO_RESULT) && args.len() == 1 {

clippy_lints/src/utils/internal_lints.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
164164
output: &mut self.registered_lints,
165165
cx,
166166
};
167-
let node_id = cx.tcx.hir().hir_to_node_id(impl_item_refs[0].id.hir_id);
168-
let body_id = cx.tcx.hir().body_owned_by(node_id);
167+
let body_id = cx.tcx.hir().body_owned_by(impl_item_refs[0].id.hir_id);
169168
collector.visit_expr(&cx.tcx.hir().body(body_id).value);
170169
}
171170
}

clippy_lints/src/utils/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -829,15 +829,15 @@ pub fn iter_input_pats<'tcx>(decl: &FnDecl, body: &'tcx Body) -> impl Iterator<I
829829

830830
/// Check if a given expression is a match expression
831831
/// expanded from `?` operator or `try` macro.
832-
pub fn is_try(expr: &Expr) -> Option<&Expr> {
833-
fn is_ok(arm: &Arm) -> bool {
832+
pub fn is_try<'a>(cx: &'_ LateContext<'_, '_>, expr: &'a Expr) -> Option<&'a Expr> {
833+
fn is_ok(cx: &'_ LateContext<'_, '_>, arm: &Arm) -> bool {
834834
if_chain! {
835835
if let PatKind::TupleStruct(ref path, ref pat, None) = arm.pats[0].node;
836836
if match_qpath(path, &paths::RESULT_OK[1..]);
837-
if let PatKind::Binding(_, defid, _, _, None) = pat[0].node;
837+
if let PatKind::Binding(_, hir_id, _, None) = pat[0].node;
838838
if let ExprKind::Path(QPath::Resolved(None, ref path)) = arm.body.node;
839839
if let Def::Local(lid) = path.def;
840-
if lid == defid;
840+
if cx.tcx.hir().node_to_hir_id(lid) == hir_id;
841841
then {
842842
return true;
843843
}
@@ -863,8 +863,8 @@ pub fn is_try(expr: &Expr) -> Option<&Expr> {
863863
if arms.len() == 2;
864864
if arms[0].pats.len() == 1 && arms[0].guard.is_none();
865865
if arms[1].pats.len() == 1 && arms[1].guard.is_none();
866-
if (is_ok(&arms[0]) && is_err(&arms[1])) ||
867-
(is_ok(&arms[1]) && is_err(&arms[0]));
866+
if (is_ok(cx, &arms[0]) && is_err(&arms[1])) ||
867+
(is_ok(cx, &arms[1]) && is_err(&arms[0]));
868868
then {
869869
return Some(expr);
870870
}

0 commit comments

Comments
 (0)