Skip to content

Commit f5ce0e5

Browse files
committed
rustc_lint: only query typeck_tables_of when a lint needs it.
1 parent 80bcbf5 commit f5ce0e5

File tree

100 files changed

+361
-366
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+361
-366
lines changed

clippy_lints/src/arithmetic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
8686
_ => (),
8787
}
8888

89-
let (l_ty, r_ty) = (cx.tables.expr_ty(l), cx.tables.expr_ty(r));
89+
let (l_ty, r_ty) = (cx.tables().expr_ty(l), cx.tables().expr_ty(r));
9090
if l_ty.peel_refs().is_integral() && r_ty.peel_refs().is_integral() {
9191
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
9292
self.expr_span = Some(expr.span);
@@ -96,8 +96,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
9696
}
9797
},
9898
hir::ExprKind::Unary(hir::UnOp::UnNeg, arg) => {
99-
let ty = cx.tables.expr_ty(arg);
100-
if constant_simple(cx, cx.tables, expr).is_none() {
99+
let ty = cx.tables().expr_ty(arg);
100+
if constant_simple(cx, cx.tables(), expr).is_none() {
101101
if ty.is_integral() {
102102
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
103103
self.expr_span = Some(expr.span);

clippy_lints/src/assertions_on_constants.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
7272
}
7373
if_chain! {
7474
if let ExprKind::Unary(_, ref lit) = e.kind;
75-
if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.tables, lit);
75+
if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.tables(), lit);
7676
if is_true;
7777
then {
7878
lint_true(true);
@@ -121,7 +121,7 @@ fn match_assert_with_message<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx E
121121
if let ExprKind::DropTemps(ref expr) = expr.kind;
122122
if let ExprKind::Unary(UnOp::UnNot, ref expr) = expr.kind;
123123
// bind the first argument of the `assert!` macro
124-
if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.tables, expr);
124+
if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.tables(), expr);
125125
// arm 1 pattern
126126
if let PatKind::Lit(ref lit_expr) = arms[0].pat.kind;
127127
if let ExprKind::Lit(ref lit) = lit_expr.kind;

clippy_lints/src/assign_ops.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
8282
hir::ExprKind::Assign(assignee, e, _) => {
8383
if let hir::ExprKind::Binary(op, l, r) = &e.kind {
8484
let lint = |assignee: &hir::Expr<'_>, rhs: &hir::Expr<'_>| {
85-
let ty = cx.tables.expr_ty(assignee);
86-
let rty = cx.tables.expr_ty(rhs);
85+
let ty = cx.tables().expr_ty(assignee);
86+
let rty = cx.tables().expr_ty(rhs);
8787
macro_rules! ops {
8888
($op:expr,
8989
$cx:expr,
@@ -167,7 +167,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
167167
// a = b commutative_op a
168168
// Limited to primitive type as these ops are know to be commutative
169169
if SpanlessEq::new(cx).ignore_fn().eq_expr(assignee, r)
170-
&& cx.tables.expr_ty(assignee).is_primitive_ty()
170+
&& cx.tables().expr_ty(assignee).is_primitive_ty()
171171
{
172172
match op.node {
173173
hir::BinOpKind::Add

clippy_lints/src/atomic_ordering.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const ATOMIC_TYPES: [&str; 12] = [
5353
];
5454

5555
fn type_is_atomic(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool {
56-
if let ty::Adt(&ty::AdtDef { did, .. }, _) = cx.tables.expr_ty(expr).kind {
56+
if let ty::Adt(&ty::AdtDef { did, .. }, _) = cx.tables().expr_ty(expr).kind {
5757
ATOMIC_TYPES
5858
.iter()
5959
.any(|ty| match_def_path(cx, did, &["core", "sync", "atomic", ty]))
@@ -76,7 +76,7 @@ fn check_atomic_load_store(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
7676
if method == "load" || method == "store";
7777
let ordering_arg = if method == "load" { &args[1] } else { &args[2] };
7878
if let ExprKind::Path(ref ordering_qpath) = ordering_arg.kind;
79-
if let Some(ordering_def_id) = cx.tables.qpath_res(ordering_qpath, ordering_arg.hir_id).opt_def_id();
79+
if let Some(ordering_def_id) = cx.tables().qpath_res(ordering_qpath, ordering_arg.hir_id).opt_def_id();
8080
then {
8181
if method == "load" &&
8282
match_ordering_def_path(cx, ordering_def_id, &["Release", "AcqRel"]) {
@@ -107,12 +107,12 @@ fn check_memory_fence(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
107107
if_chain! {
108108
if let ExprKind::Call(ref func, ref args) = expr.kind;
109109
if let ExprKind::Path(ref func_qpath) = func.kind;
110-
if let Some(def_id) = cx.tables.qpath_res(func_qpath, func.hir_id).opt_def_id();
110+
if let Some(def_id) = cx.tables().qpath_res(func_qpath, func.hir_id).opt_def_id();
111111
if ["fence", "compiler_fence"]
112112
.iter()
113113
.any(|func| match_def_path(cx, def_id, &["core", "sync", "atomic", func]));
114114
if let ExprKind::Path(ref ordering_qpath) = &args[0].kind;
115-
if let Some(ordering_def_id) = cx.tables.qpath_res(ordering_qpath, args[0].hir_id).opt_def_id();
115+
if let Some(ordering_def_id) = cx.tables().qpath_res(ordering_qpath, args[0].hir_id).opt_def_id();
116116
if match_ordering_def_path(cx, ordering_def_id, &["Relaxed"]);
117117
then {
118118
span_lint_and_help(

clippy_lints/src/bit_mask.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ fn check_ineffective_gt(cx: &LateContext<'_, '_>, span: Span, m: u128, c: u128,
319319
}
320320

321321
fn fetch_int_literal(cx: &LateContext<'_, '_>, lit: &Expr<'_>) -> Option<u128> {
322-
match constant(cx, cx.tables, lit)?.0 {
322+
match constant(cx, cx.tables(), lit)?.0 {
323323
Constant::Int(n) => Some(n),
324324
_ => None,
325325
}

clippy_lints/src/booleans.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ fn simplify_not(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option<String> {
248248
})
249249
},
250250
ExprKind::MethodCall(path, _, args, _) if args.len() == 1 => {
251-
let type_of_receiver = cx.tables.expr_ty(&args[0]);
251+
let type_of_receiver = cx.tables().expr_ty(&args[0]);
252252
if !is_type_diagnostic_item(cx, type_of_receiver, sym!(option_type))
253253
&& !is_type_diagnostic_item(cx, type_of_receiver, sym!(result_type))
254254
{
@@ -450,7 +450,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
450450
self.bool_expr(e)
451451
},
452452
ExprKind::Unary(UnOp::UnNot, inner) => {
453-
if self.cx.tables.node_types()[inner.hir_id].is_bool() {
453+
if self.cx.tables().node_types()[inner.hir_id].is_bool() {
454454
self.bool_expr(e);
455455
} else {
456456
walk_expr(self, e);
@@ -465,7 +465,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
465465
}
466466

467467
fn implements_ord<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, expr: &Expr<'_>) -> bool {
468-
let ty = cx.tables.expr_ty(expr);
468+
let ty = cx.tables().expr_ty(expr);
469469
get_trait_def_id(cx, &paths::ORD).map_or(false, |id| implements_trait(cx, ty, id, &[]))
470470
}
471471

clippy_lints/src/bytecount.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
5353
if let ExprKind::Binary(ref op, ref l, ref r) = body.value.kind;
5454
if op.node == BinOpKind::Eq;
5555
if match_type(cx,
56-
walk_ptrs_ty(cx.tables.expr_ty(&filter_args[0])),
56+
walk_ptrs_ty(cx.tables().expr_ty(&filter_args[0])),
5757
&paths::SLICE_ITER);
5858
then {
5959
let needle = match get_path_name(l) {
@@ -63,7 +63,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
6363
_ => { return; }
6464
}
6565
};
66-
if ty::Uint(UintTy::U8) != walk_ptrs_ty(cx.tables.expr_ty(needle)).kind {
66+
if ty::Uint(UintTy::U8) != walk_ptrs_ty(cx.tables().expr_ty(needle)).kind {
6767
return;
6868
}
6969
let haystack = if let ExprKind::MethodCall(ref path, _, ref args, _) =

clippy_lints/src/cognitive_complexity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl CognitiveComplexity {
6060
let mut helper = CCHelper { cc: 1, returns: 0 };
6161
helper.visit_expr(expr);
6262
let CCHelper { cc, returns } = helper;
63-
let ret_ty = cx.tables.node_type(expr.hir_id);
63+
let ret_ty = cx.tables().node_type(expr.hir_id);
6464
let ret_adjust = if is_type_diagnostic_item(cx, ret_ty, sym!(result_type)) {
6565
returns
6666
} else {

clippy_lints/src/comparison_chain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ComparisonChain {
9999
}
100100

101101
// Check that the type being compared implements `core::cmp::Ord`
102-
let ty = cx.tables.expr_ty(lhs1);
102+
let ty = cx.tables().expr_ty(lhs1);
103103
let is_ord = get_trait_def_id(cx, &paths::ORD).map_or(false, |id| implements_trait(cx, ty, id, &[]));
104104

105105
if !is_ord {

clippy_lints/src/copies.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ fn lint_same_then_else(cx: &LateContext<'_, '_>, blocks: &[&Block<'_>]) {
192192
/// Implementation of `IFS_SAME_COND`.
193193
fn lint_same_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) {
194194
let hash: &dyn Fn(&&Expr<'_>) -> u64 = &|expr| -> u64 {
195-
let mut h = SpanlessHash::new(cx, cx.tables);
195+
let mut h = SpanlessHash::new(cx, cx.tables());
196196
h.hash_expr(expr);
197197
h.finish()
198198
};
@@ -215,7 +215,7 @@ fn lint_same_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) {
215215
/// Implementation of `SAME_FUNCTIONS_IN_IF_CONDITION`.
216216
fn lint_same_fns_in_if_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) {
217217
let hash: &dyn Fn(&&Expr<'_>) -> u64 = &|expr| -> u64 {
218-
let mut h = SpanlessHash::new(cx, cx.tables);
218+
let mut h = SpanlessHash::new(cx, cx.tables());
219219
h.hash_expr(expr);
220220
h.finish()
221221
};
@@ -251,7 +251,7 @@ fn lint_match_arms<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr<'_>) {
251251

252252
if let ExprKind::Match(_, ref arms, MatchSource::Normal) = expr.kind {
253253
let hash = |&(_, arm): &(usize, &Arm<'_>)| -> u64 {
254-
let mut h = SpanlessHash::new(cx, cx.tables);
254+
let mut h = SpanlessHash::new(cx, cx.tables());
255255
h.hash_expr(&arm.body);
256256
h.finish()
257257
};
@@ -320,7 +320,7 @@ fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat<'_>) -> FxHashMap<Sy
320320
},
321321
PatKind::Binding(.., ident, ref as_pat) => {
322322
if let Entry::Vacant(v) = map.entry(ident.name) {
323-
v.insert(cx.tables.pat_ty(pat));
323+
v.insert(cx.tables().pat_ty(pat));
324324
}
325325
if let Some(ref as_pat) = *as_pat {
326326
bindings_impl(cx, as_pat, map);

0 commit comments

Comments
 (0)