Rename TypeckTables to TypeckResults.
This commit is contained in:
parent
62db617e40
commit
5a20489c5c
@ -86,7 +86,7 @@ impl<'tcx> LateLintPass<'tcx> for Arithmetic {
|
||||
_ => (),
|
||||
}
|
||||
|
||||
let (l_ty, r_ty) = (cx.tables().expr_ty(l), cx.tables().expr_ty(r));
|
||||
let (l_ty, r_ty) = (cx.typeck_results().expr_ty(l), cx.typeck_results().expr_ty(r));
|
||||
if l_ty.peel_refs().is_integral() && r_ty.peel_refs().is_integral() {
|
||||
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
|
||||
self.expr_span = Some(expr.span);
|
||||
@ -96,8 +96,8 @@ impl<'tcx> LateLintPass<'tcx> for Arithmetic {
|
||||
}
|
||||
},
|
||||
hir::ExprKind::Unary(hir::UnOp::UnNeg, arg) => {
|
||||
let ty = cx.tables().expr_ty(arg);
|
||||
if constant_simple(cx, cx.tables(), expr).is_none() {
|
||||
let ty = cx.typeck_results().expr_ty(arg);
|
||||
if constant_simple(cx, cx.typeck_results(), expr).is_none() {
|
||||
if ty.is_integral() {
|
||||
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
|
||||
self.expr_span = Some(expr.span);
|
||||
|
@ -72,7 +72,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnConstants {
|
||||
}
|
||||
if_chain! {
|
||||
if let ExprKind::Unary(_, ref lit) = e.kind;
|
||||
if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.tables(), lit);
|
||||
if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.typeck_results(), lit);
|
||||
if is_true;
|
||||
then {
|
||||
lint_true(true);
|
||||
@ -121,7 +121,7 @@ fn match_assert_with_message<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>)
|
||||
if let ExprKind::DropTemps(ref expr) = expr.kind;
|
||||
if let ExprKind::Unary(UnOp::UnNot, ref expr) = expr.kind;
|
||||
// bind the first argument of the `assert!` macro
|
||||
if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.tables(), expr);
|
||||
if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.typeck_results(), expr);
|
||||
// arm 1 pattern
|
||||
if let PatKind::Lit(ref lit_expr) = arms[0].pat.kind;
|
||||
if let ExprKind::Lit(ref lit) = lit_expr.kind;
|
||||
|
@ -82,8 +82,8 @@ impl<'tcx> LateLintPass<'tcx> for AssignOps {
|
||||
hir::ExprKind::Assign(assignee, e, _) => {
|
||||
if let hir::ExprKind::Binary(op, l, r) = &e.kind {
|
||||
let lint = |assignee: &hir::Expr<'_>, rhs: &hir::Expr<'_>| {
|
||||
let ty = cx.tables().expr_ty(assignee);
|
||||
let rty = cx.tables().expr_ty(rhs);
|
||||
let ty = cx.typeck_results().expr_ty(assignee);
|
||||
let rty = cx.typeck_results().expr_ty(rhs);
|
||||
macro_rules! ops {
|
||||
($op:expr,
|
||||
$cx:expr,
|
||||
@ -167,7 +167,7 @@ impl<'tcx> LateLintPass<'tcx> for AssignOps {
|
||||
// a = b commutative_op a
|
||||
// Limited to primitive type as these ops are know to be commutative
|
||||
if SpanlessEq::new(cx).ignore_fn().eq_expr(assignee, r)
|
||||
&& cx.tables().expr_ty(assignee).is_primitive_ty()
|
||||
&& cx.typeck_results().expr_ty(assignee).is_primitive_ty()
|
||||
{
|
||||
match op.node {
|
||||
hir::BinOpKind::Add
|
||||
|
@ -53,7 +53,7 @@ const ATOMIC_TYPES: [&str; 12] = [
|
||||
];
|
||||
|
||||
fn type_is_atomic(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||
if let ty::Adt(&ty::AdtDef { did, .. }, _) = cx.tables().expr_ty(expr).kind {
|
||||
if let ty::Adt(&ty::AdtDef { did, .. }, _) = cx.typeck_results().expr_ty(expr).kind {
|
||||
ATOMIC_TYPES
|
||||
.iter()
|
||||
.any(|ty| match_def_path(cx, did, &["core", "sync", "atomic", ty]))
|
||||
|
@ -461,7 +461,7 @@ fn check_clippy_lint_names(cx: &LateContext<'_>, ident: &str, items: &[NestedMet
|
||||
|
||||
fn is_relevant_item(cx: &LateContext<'_>, item: &Item<'_>) -> bool {
|
||||
if let ItemKind::Fn(_, _, eid) = item.kind {
|
||||
is_relevant_expr(cx, cx.tcx.body_tables(eid), &cx.tcx.hir().body(eid).value)
|
||||
is_relevant_expr(cx, cx.tcx.typeck_body(eid), &cx.tcx.hir().body(eid).value)
|
||||
} else {
|
||||
true
|
||||
}
|
||||
@ -469,7 +469,7 @@ fn is_relevant_item(cx: &LateContext<'_>, item: &Item<'_>) -> bool {
|
||||
|
||||
fn is_relevant_impl(cx: &LateContext<'_>, item: &ImplItem<'_>) -> bool {
|
||||
match item.kind {
|
||||
ImplItemKind::Fn(_, eid) => is_relevant_expr(cx, cx.tcx.body_tables(eid), &cx.tcx.hir().body(eid).value),
|
||||
ImplItemKind::Fn(_, eid) => is_relevant_expr(cx, cx.tcx.typeck_body(eid), &cx.tcx.hir().body(eid).value),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@ -478,31 +478,34 @@ fn is_relevant_trait(cx: &LateContext<'_>, item: &TraitItem<'_>) -> bool {
|
||||
match item.kind {
|
||||
TraitItemKind::Fn(_, TraitFn::Required(_)) => true,
|
||||
TraitItemKind::Fn(_, TraitFn::Provided(eid)) => {
|
||||
is_relevant_expr(cx, cx.tcx.body_tables(eid), &cx.tcx.hir().body(eid).value)
|
||||
is_relevant_expr(cx, cx.tcx.typeck_body(eid), &cx.tcx.hir().body(eid).value)
|
||||
},
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn is_relevant_block(cx: &LateContext<'_>, tables: &ty::TypeckTables<'_>, block: &Block<'_>) -> bool {
|
||||
fn is_relevant_block(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_>, block: &Block<'_>) -> bool {
|
||||
block.stmts.first().map_or(
|
||||
block.expr.as_ref().map_or(false, |e| is_relevant_expr(cx, tables, e)),
|
||||
block
|
||||
.expr
|
||||
.as_ref()
|
||||
.map_or(false, |e| is_relevant_expr(cx, typeck_results, e)),
|
||||
|stmt| match &stmt.kind {
|
||||
StmtKind::Local(_) => true,
|
||||
StmtKind::Expr(expr) | StmtKind::Semi(expr) => is_relevant_expr(cx, tables, expr),
|
||||
StmtKind::Expr(expr) | StmtKind::Semi(expr) => is_relevant_expr(cx, typeck_results, expr),
|
||||
_ => false,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn is_relevant_expr(cx: &LateContext<'_>, tables: &ty::TypeckTables<'_>, expr: &Expr<'_>) -> bool {
|
||||
fn is_relevant_expr(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_>, expr: &Expr<'_>) -> bool {
|
||||
match &expr.kind {
|
||||
ExprKind::Block(block, _) => is_relevant_block(cx, tables, block),
|
||||
ExprKind::Ret(Some(e)) => is_relevant_expr(cx, tables, e),
|
||||
ExprKind::Block(block, _) => is_relevant_block(cx, typeck_results, block),
|
||||
ExprKind::Ret(Some(e)) => is_relevant_expr(cx, typeck_results, e),
|
||||
ExprKind::Ret(None) | ExprKind::Break(_, None) => false,
|
||||
ExprKind::Call(path_expr, _) => {
|
||||
if let ExprKind::Path(qpath) = &path_expr.kind {
|
||||
tables
|
||||
typeck_results
|
||||
.qpath_res(qpath, path_expr.hir_id)
|
||||
.opt_def_id()
|
||||
.map_or(true, |fun_id| !match_def_path(cx, fun_id, &paths::BEGIN_PANIC))
|
||||
|
@ -59,8 +59,8 @@ impl LateLintPass<'_> for AwaitHoldingLock {
|
||||
hir_id: body.value.hir_id,
|
||||
};
|
||||
let def_id = cx.tcx.hir().body_owner_def_id(body_id);
|
||||
let tables = cx.tcx.typeck_tables_of(def_id);
|
||||
check_interior_types(cx, &tables.generator_interior_types, body.value.span);
|
||||
let typeck_results = cx.tcx.typeck(def_id);
|
||||
check_interior_types(cx, &typeck_results.generator_interior_types, body.value.span);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -319,7 +319,7 @@ fn check_ineffective_gt(cx: &LateContext<'_>, span: Span, m: u128, c: u128, op:
|
||||
}
|
||||
|
||||
fn fetch_int_literal(cx: &LateContext<'_>, lit: &Expr<'_>) -> Option<u128> {
|
||||
match constant(cx, cx.tables(), lit)?.0 {
|
||||
match constant(cx, cx.typeck_results(), lit)?.0 {
|
||||
Constant::Int(n) => Some(n),
|
||||
_ => None,
|
||||
}
|
||||
|
@ -111,8 +111,12 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
|
||||
match &e.kind {
|
||||
ExprKind::Unary(UnOp::UnNot, inner) => return Ok(Bool::Not(box self.run(inner)?)),
|
||||
ExprKind::Binary(binop, lhs, rhs) => match &binop.node {
|
||||
BinOpKind::Or => return Ok(Bool::Or(self.extract(BinOpKind::Or, &[lhs, rhs], Vec::new())?)),
|
||||
BinOpKind::And => return Ok(Bool::And(self.extract(BinOpKind::And, &[lhs, rhs], Vec::new())?)),
|
||||
BinOpKind::Or => {
|
||||
return Ok(Bool::Or(self.extract(BinOpKind::Or, &[lhs, rhs], Vec::new())?));
|
||||
},
|
||||
BinOpKind::And => {
|
||||
return Ok(Bool::And(self.extract(BinOpKind::And, &[lhs, rhs], Vec::new())?));
|
||||
},
|
||||
_ => (),
|
||||
},
|
||||
ExprKind::Lit(lit) => match lit.node {
|
||||
@ -248,7 +252,7 @@ fn simplify_not(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<String> {
|
||||
})
|
||||
},
|
||||
ExprKind::MethodCall(path, _, args, _) if args.len() == 1 => {
|
||||
let type_of_receiver = cx.tables().expr_ty(&args[0]);
|
||||
let type_of_receiver = cx.typeck_results().expr_ty(&args[0]);
|
||||
if !is_type_diagnostic_item(cx, type_of_receiver, sym!(option_type))
|
||||
&& !is_type_diagnostic_item(cx, type_of_receiver, sym!(result_type))
|
||||
{
|
||||
@ -450,7 +454,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
|
||||
self.bool_expr(e)
|
||||
},
|
||||
ExprKind::Unary(UnOp::UnNot, inner) => {
|
||||
if self.cx.tables().node_types()[inner.hir_id].is_bool() {
|
||||
if self.cx.typeck_results().node_types()[inner.hir_id].is_bool() {
|
||||
self.bool_expr(e);
|
||||
} else {
|
||||
walk_expr(self, e);
|
||||
@ -465,7 +469,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
|
||||
}
|
||||
|
||||
fn implements_ord<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> bool {
|
||||
let ty = cx.tables().expr_ty(expr);
|
||||
let ty = cx.typeck_results().expr_ty(expr);
|
||||
get_trait_def_id(cx, &paths::ORD).map_or(false, |id| implements_trait(cx, ty, id, &[]))
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for ByteCount {
|
||||
if let ExprKind::Binary(ref op, ref l, ref r) = body.value.kind;
|
||||
if op.node == BinOpKind::Eq;
|
||||
if match_type(cx,
|
||||
walk_ptrs_ty(cx.tables().expr_ty(&filter_args[0])),
|
||||
walk_ptrs_ty(cx.typeck_results().expr_ty(&filter_args[0])),
|
||||
&paths::SLICE_ITER);
|
||||
then {
|
||||
let needle = match get_path_name(l) {
|
||||
@ -63,7 +63,7 @@ impl<'tcx> LateLintPass<'tcx> for ByteCount {
|
||||
_ => { return; }
|
||||
}
|
||||
};
|
||||
if ty::Uint(UintTy::U8) != walk_ptrs_ty(cx.tables().expr_ty(needle)).kind {
|
||||
if ty::Uint(UintTy::U8) != walk_ptrs_ty(cx.typeck_results().expr_ty(needle)).kind {
|
||||
return;
|
||||
}
|
||||
let haystack = if let ExprKind::MethodCall(ref path, _, ref args, _) =
|
||||
|
@ -60,7 +60,7 @@ impl CognitiveComplexity {
|
||||
let mut helper = CCHelper { cc: 1, returns: 0 };
|
||||
helper.visit_expr(expr);
|
||||
let CCHelper { cc, returns } = helper;
|
||||
let ret_ty = cx.tables().node_type(expr.hir_id);
|
||||
let ret_ty = cx.typeck_results().node_type(expr.hir_id);
|
||||
let ret_adjust = if is_type_diagnostic_item(cx, ret_ty, sym!(result_type)) {
|
||||
returns
|
||||
} else {
|
||||
|
@ -99,7 +99,7 @@ impl<'tcx> LateLintPass<'tcx> for ComparisonChain {
|
||||
}
|
||||
|
||||
// Check that the type being compared implements `core::cmp::Ord`
|
||||
let ty = cx.tables().expr_ty(lhs1);
|
||||
let ty = cx.typeck_results().expr_ty(lhs1);
|
||||
let is_ord = get_trait_def_id(cx, &paths::ORD).map_or(false, |id| implements_trait(cx, ty, id, &[]));
|
||||
|
||||
if !is_ord {
|
||||
|
@ -174,12 +174,12 @@ pub fn lit_to_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant {
|
||||
|
||||
pub fn constant<'tcx>(
|
||||
lcx: &LateContext<'tcx>,
|
||||
tables: &ty::TypeckTables<'tcx>,
|
||||
typeck_results: &ty::TypeckResults<'tcx>,
|
||||
e: &Expr<'_>,
|
||||
) -> Option<(Constant, bool)> {
|
||||
let mut cx = ConstEvalLateContext {
|
||||
lcx,
|
||||
tables,
|
||||
typeck_results,
|
||||
param_env: lcx.param_env,
|
||||
needed_resolution: false,
|
||||
substs: lcx.tcx.intern_substs(&[]),
|
||||
@ -189,20 +189,20 @@ pub fn constant<'tcx>(
|
||||
|
||||
pub fn constant_simple<'tcx>(
|
||||
lcx: &LateContext<'tcx>,
|
||||
tables: &ty::TypeckTables<'tcx>,
|
||||
typeck_results: &ty::TypeckResults<'tcx>,
|
||||
e: &Expr<'_>,
|
||||
) -> Option<Constant> {
|
||||
constant(lcx, tables, e).and_then(|(cst, res)| if res { None } else { Some(cst) })
|
||||
constant(lcx, typeck_results, e).and_then(|(cst, res)| if res { None } else { Some(cst) })
|
||||
}
|
||||
|
||||
/// Creates a `ConstEvalLateContext` from the given `LateContext` and `TypeckTables`.
|
||||
/// Creates a `ConstEvalLateContext` from the given `LateContext` and `TypeckResults`.
|
||||
pub fn constant_context<'a, 'tcx>(
|
||||
lcx: &'a LateContext<'tcx>,
|
||||
tables: &'a ty::TypeckTables<'tcx>,
|
||||
typeck_results: &'a ty::TypeckResults<'tcx>,
|
||||
) -> ConstEvalLateContext<'a, 'tcx> {
|
||||
ConstEvalLateContext {
|
||||
lcx,
|
||||
tables,
|
||||
typeck_results,
|
||||
param_env: lcx.param_env,
|
||||
needed_resolution: false,
|
||||
substs: lcx.tcx.intern_substs(&[]),
|
||||
@ -211,7 +211,7 @@ pub fn constant_context<'a, 'tcx>(
|
||||
|
||||
pub struct ConstEvalLateContext<'a, 'tcx> {
|
||||
lcx: &'a LateContext<'tcx>,
|
||||
tables: &'a ty::TypeckTables<'tcx>,
|
||||
typeck_results: &'a ty::TypeckResults<'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
needed_resolution: bool,
|
||||
substs: SubstsRef<'tcx>,
|
||||
@ -224,21 +224,21 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
|
||||
return self.ifthenelse(cond, then, otherwise);
|
||||
}
|
||||
match e.kind {
|
||||
ExprKind::Path(ref qpath) => self.fetch_path(qpath, e.hir_id, self.tables.expr_ty(e)),
|
||||
ExprKind::Path(ref qpath) => self.fetch_path(qpath, e.hir_id, self.typeck_results.expr_ty(e)),
|
||||
ExprKind::Block(ref block, _) => self.block(block),
|
||||
ExprKind::Lit(ref lit) => Some(lit_to_constant(&lit.node, self.tables.expr_ty_opt(e))),
|
||||
ExprKind::Lit(ref lit) => Some(lit_to_constant(&lit.node, self.typeck_results.expr_ty_opt(e))),
|
||||
ExprKind::Array(ref vec) => self.multi(vec).map(Constant::Vec),
|
||||
ExprKind::Tup(ref tup) => self.multi(tup).map(Constant::Tuple),
|
||||
ExprKind::Repeat(ref value, _) => {
|
||||
let n = match self.tables.expr_ty(e).kind {
|
||||
let n = match self.typeck_results.expr_ty(e).kind {
|
||||
ty::Array(_, n) => n.try_eval_usize(self.lcx.tcx, self.lcx.param_env)?,
|
||||
_ => span_bug!(e.span, "typeck error"),
|
||||
};
|
||||
self.expr(value).map(|v| Constant::Repeat(Box::new(v), n))
|
||||
},
|
||||
ExprKind::Unary(op, ref operand) => self.expr(operand).and_then(|o| match op {
|
||||
UnOp::UnNot => self.constant_not(&o, self.tables.expr_ty(e)),
|
||||
UnOp::UnNeg => self.constant_negate(&o, self.tables.expr_ty(e)),
|
||||
UnOp::UnNot => self.constant_not(&o, self.typeck_results.expr_ty(e)),
|
||||
UnOp::UnNeg => self.constant_negate(&o, self.typeck_results.expr_ty(e)),
|
||||
UnOp::UnDeref => Some(o),
|
||||
}),
|
||||
ExprKind::Binary(op, ref left, ref right) => self.binop(op, left, right),
|
||||
@ -247,7 +247,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
|
||||
if_chain! {
|
||||
if args.is_empty();
|
||||
if let ExprKind::Path(qpath) = &callee.kind;
|
||||
let res = self.tables.qpath_res(qpath, callee.hir_id);
|
||||
let res = self.typeck_results.qpath_res(qpath, callee.hir_id);
|
||||
if let Some(def_id) = res.opt_def_id();
|
||||
let def_path: Vec<_> = self.lcx.get_def_path(def_id).into_iter().map(Symbol::as_str).collect();
|
||||
let def_path: Vec<&str> = def_path.iter().take(4).map(|s| &**s).collect();
|
||||
@ -319,10 +319,10 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
|
||||
|
||||
/// Lookup a possibly constant expression from a `ExprKind::Path`.
|
||||
fn fetch_path(&mut self, qpath: &QPath<'_>, id: HirId, ty: Ty<'tcx>) -> Option<Constant> {
|
||||
let res = self.tables.qpath_res(qpath, id);
|
||||
let res = self.typeck_results.qpath_res(qpath, id);
|
||||
match res {
|
||||
Res::Def(DefKind::Const | DefKind::AssocConst, def_id) => {
|
||||
let substs = self.tables.node_substs(id);
|
||||
let substs = self.typeck_results.node_substs(id);
|
||||
let substs = if self.substs.is_empty() {
|
||||
substs
|
||||
} else {
|
||||
@ -332,7 +332,13 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
|
||||
let result = self
|
||||
.lcx
|
||||
.tcx
|
||||
.const_eval_resolve(self.param_env, ty::WithOptConstParam::unknown(def_id), substs, None, None)
|
||||
.const_eval_resolve(
|
||||
self.param_env,
|
||||
ty::WithOptConstParam::unknown(def_id),
|
||||
substs,
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.ok()
|
||||
.map(|val| rustc_middle::ty::Const::from_value(self.lcx.tcx, val, ty))?;
|
||||
let result = miri_to_const(&result);
|
||||
@ -396,7 +402,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
|
||||
let l = self.expr(left)?;
|
||||
let r = self.expr(right);
|
||||
match (l, r) {
|
||||
(Constant::Int(l), Some(Constant::Int(r))) => match self.tables.expr_ty_opt(left)?.kind {
|
||||
(Constant::Int(l), Some(Constant::Int(r))) => match self.typeck_results.expr_ty_opt(left)?.kind {
|
||||
ty::Int(ity) => {
|
||||
let l = sext(self.lcx.tcx, l, ity);
|
||||
let r = sext(self.lcx.tcx, r, ity);
|
||||
@ -488,7 +494,8 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
|
||||
pub fn miri_to_const(result: &ty::Const<'_>) -> Option<Constant> {
|
||||
use rustc_middle::mir::interpret::{ConstValue, Scalar};
|
||||
match result.val {
|
||||
ty::ConstKind::Value(ConstValue::Scalar(Scalar::Raw { data: d, .. })) => match result.ty.kind {
|
||||
ty::ConstKind::Value(ConstValue::Scalar(Scalar::Raw { data: d, .. })) => {
|
||||
match result.ty.kind {
|
||||
ty::Bool => Some(Constant::Bool(d == 1)),
|
||||
ty::Uint(_) | ty::Int(_) => Some(Constant::Int(d)),
|
||||
ty::Float(FloatTy::F32) => Some(Constant::F32(f32::from_bits(
|
||||
@ -505,6 +512,7 @@ pub fn miri_to_const(result: &ty::Const<'_>) -> Option<Constant> {
|
||||
},
|
||||
// FIXME: implement other conversions.
|
||||
_ => None,
|
||||
}
|
||||
},
|
||||
ty::ConstKind::Value(ConstValue::Slice { data, start, end }) => match result.ty.kind {
|
||||
ty::Ref(_, tam, _) => match tam.kind {
|
||||
|
@ -320,7 +320,7 @@ fn bindings<'tcx>(cx: &LateContext<'tcx>, pat: &Pat<'_>) -> FxHashMap<Symbol, Ty
|
||||
},
|
||||
PatKind::Binding(.., ident, ref as_pat) => {
|
||||
if let Entry::Vacant(v) = map.entry(ident.name) {
|
||||
v.insert(cx.tables().pat_ty(pat));
|
||||
v.insert(cx.typeck_results().pat_ty(pat));
|
||||
}
|
||||
if let Some(ref as_pat) = *as_pat {
|
||||
bindings_impl(cx, as_pat, map);
|
||||
|
@ -54,7 +54,7 @@ impl<'tcx> LateLintPass<'tcx> for DefaultTraitAccess {
|
||||
|
||||
// TODO: Work out a way to put "whatever the imported way of referencing
|
||||
// this type in this file" rather than a fully-qualified type.
|
||||
let expr_ty = cx.tables().expr_ty(expr);
|
||||
let expr_ty = cx.typeck_results().expr_ty(expr);
|
||||
if let ty::Adt(..) = expr_ty.kind {
|
||||
let replacement = format!("{}::default()", expr_ty);
|
||||
span_lint_and_sugg(
|
||||
|
@ -74,7 +74,7 @@ fn lint_deref(cx: &LateContext<'_>, method_name: &str, call_expr: &Expr<'_>, var
|
||||
match method_name {
|
||||
"deref" => {
|
||||
let impls_deref_trait = cx.tcx.lang_items().deref_trait().map_or(false, |id| {
|
||||
implements_trait(cx, cx.tables().expr_ty(&call_expr), id, &[])
|
||||
implements_trait(cx, cx.typeck_results().expr_ty(&call_expr), id, &[])
|
||||
});
|
||||
if impls_deref_trait {
|
||||
span_lint_and_sugg(
|
||||
@ -90,7 +90,7 @@ fn lint_deref(cx: &LateContext<'_>, method_name: &str, call_expr: &Expr<'_>, var
|
||||
},
|
||||
"deref_mut" => {
|
||||
let impls_deref_mut_trait = cx.tcx.lang_items().deref_mut_trait().map_or(false, |id| {
|
||||
implements_trait(cx, cx.tables().expr_ty(&call_expr), id, &[])
|
||||
implements_trait(cx, cx.typeck_results().expr_ty(&call_expr), id, &[])
|
||||
});
|
||||
if impls_deref_mut_trait {
|
||||
span_lint_and_sugg(
|
||||
|
@ -119,7 +119,7 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
|
||||
let lint;
|
||||
let msg;
|
||||
let arg = &args[0];
|
||||
let arg_ty = cx.tables().expr_ty(arg);
|
||||
let arg_ty = cx.typeck_results().expr_ty(arg);
|
||||
|
||||
if let ty::Ref(..) = arg_ty.kind {
|
||||
if match_def_path(cx, def_id, &paths::DROP) {
|
||||
|
@ -43,8 +43,8 @@ impl<'tcx> LateLintPass<'tcx> for DurationSubsec {
|
||||
if_chain! {
|
||||
if let ExprKind::Binary(Spanned { node: BinOpKind::Div, .. }, ref left, ref right) = expr.kind;
|
||||
if let ExprKind::MethodCall(ref method_path, _ , ref args, _) = left.kind;
|
||||
if match_type(cx, walk_ptrs_ty(cx.tables().expr_ty(&args[0])), &paths::DURATION);
|
||||
if let Some((Constant::Int(divisor), _)) = constant(cx, cx.tables(), right);
|
||||
if match_type(cx, walk_ptrs_ty(cx.typeck_results().expr_ty(&args[0])), &paths::DURATION);
|
||||
if let Some((Constant::Int(divisor), _)) = constant(cx, cx.typeck_results(), right);
|
||||
then {
|
||||
let suggested_fn = match (method_path.ident.as_str().as_ref(), divisor) {
|
||||
("subsec_micros", 1_000) | ("subsec_nanos", 1_000_000) => "subsec_millis",
|
||||
|
@ -106,7 +106,7 @@ fn check_cond<'a>(cx: &LateContext<'_>, check: &'a Expr<'a>) -> Option<(&'static
|
||||
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref key) = params[1].kind;
|
||||
then {
|
||||
let map = ¶ms[0];
|
||||
let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(map));
|
||||
let obj_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(map));
|
||||
|
||||
return if match_type(cx, obj_ty, &paths::BTREEMAP) {
|
||||
Some(("BTreeMap", map, key))
|
||||
|
@ -103,8 +103,8 @@ impl<'tcx> LateLintPass<'tcx> for EqOp {
|
||||
(&ExprKind::Lit(..), _) | (_, &ExprKind::Lit(..)) => {},
|
||||
// &foo == &bar
|
||||
(&ExprKind::AddrOf(BorrowKind::Ref, _, ref l), &ExprKind::AddrOf(BorrowKind::Ref, _, ref r)) => {
|
||||
let lty = cx.tables().expr_ty(l);
|
||||
let rty = cx.tables().expr_ty(r);
|
||||
let lty = cx.typeck_results().expr_ty(l);
|
||||
let rty = cx.typeck_results().expr_ty(r);
|
||||
let lcpy = is_copy(cx, lty);
|
||||
let rcpy = is_copy(cx, rty);
|
||||
// either operator autorefs or both args are copyable
|
||||
@ -126,7 +126,7 @@ impl<'tcx> LateLintPass<'tcx> for EqOp {
|
||||
)
|
||||
} else if lcpy
|
||||
&& !rcpy
|
||||
&& implements_trait(cx, lty, trait_id, &[cx.tables().expr_ty(right).into()])
|
||||
&& implements_trait(cx, lty, trait_id, &[cx.typeck_results().expr_ty(right).into()])
|
||||
{
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
@ -145,7 +145,7 @@ impl<'tcx> LateLintPass<'tcx> for EqOp {
|
||||
)
|
||||
} else if !lcpy
|
||||
&& rcpy
|
||||
&& implements_trait(cx, cx.tables().expr_ty(left), trait_id, &[rty.into()])
|
||||
&& implements_trait(cx, cx.typeck_results().expr_ty(left), trait_id, &[rty.into()])
|
||||
{
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
@ -166,10 +166,10 @@ impl<'tcx> LateLintPass<'tcx> for EqOp {
|
||||
},
|
||||
// &foo == bar
|
||||
(&ExprKind::AddrOf(BorrowKind::Ref, _, ref l), _) => {
|
||||
let lty = cx.tables().expr_ty(l);
|
||||
let lty = cx.typeck_results().expr_ty(l);
|
||||
let lcpy = is_copy(cx, lty);
|
||||
if (requires_ref || lcpy)
|
||||
&& implements_trait(cx, lty, trait_id, &[cx.tables().expr_ty(right).into()])
|
||||
&& implements_trait(cx, lty, trait_id, &[cx.typeck_results().expr_ty(right).into()])
|
||||
{
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
@ -190,10 +190,10 @@ impl<'tcx> LateLintPass<'tcx> for EqOp {
|
||||
},
|
||||
// foo == &bar
|
||||
(_, &ExprKind::AddrOf(BorrowKind::Ref, _, ref r)) => {
|
||||
let rty = cx.tables().expr_ty(r);
|
||||
let rty = cx.typeck_results().expr_ty(r);
|
||||
let rcpy = is_copy(cx, rty);
|
||||
if (requires_ref || rcpy)
|
||||
&& implements_trait(cx, cx.tables().expr_ty(left), trait_id, &[rty.into()])
|
||||
&& implements_trait(cx, cx.typeck_results().expr_ty(left), trait_id, &[rty.into()])
|
||||
{
|
||||
span_lint_and_then(cx, OP_REF, e.span, "taken reference of right operand", |diag| {
|
||||
let rsnip = snippet(cx, r.span, "...").to_string();
|
||||
|
@ -48,7 +48,7 @@ impl<'tcx> LateLintPass<'tcx> for ErasingOp {
|
||||
}
|
||||
|
||||
fn check(cx: &LateContext<'_>, e: &Expr<'_>, span: Span) {
|
||||
if let Some(Constant::Int(0)) = constant_simple(cx, cx.tables(), e) {
|
||||
if let Some(Constant::Int(0)) = constant_simple(cx, cx.typeck_results(), e) {
|
||||
span_lint(
|
||||
cx,
|
||||
ERASING_OP,
|
||||
|
@ -84,7 +84,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
|
||||
|
||||
let fn_def_id = cx.tcx.hir().local_def_id(hir_id);
|
||||
cx.tcx.infer_ctxt().enter(|infcx| {
|
||||
ExprUseVisitor::new(&mut v, &infcx, fn_def_id, cx.param_env, cx.tables()).consume_body(body);
|
||||
ExprUseVisitor::new(&mut v, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body);
|
||||
});
|
||||
|
||||
for node in v.set {
|
||||
|
@ -97,7 +97,7 @@ fn check_closure(cx: &LateContext<'_>, expr: &Expr<'_>) {
|
||||
// Are the expression or the arguments type-adjusted? Then we need the closure
|
||||
if !(is_adjusted(cx, ex) || args.iter().any(|arg| is_adjusted(cx, arg)));
|
||||
|
||||
let fn_ty = cx.tables().expr_ty(caller);
|
||||
let fn_ty = cx.typeck_results().expr_ty(caller);
|
||||
|
||||
if matches!(fn_ty.kind, ty::FnDef(_, _) | ty::FnPtr(_) | ty::Closure(_, _));
|
||||
|
||||
@ -128,7 +128,7 @@ fn check_closure(cx: &LateContext<'_>, expr: &Expr<'_>) {
|
||||
// Are the expression or the arguments type-adjusted? Then we need the closure
|
||||
if !(is_adjusted(cx, ex) || args.iter().skip(1).any(|arg| is_adjusted(cx, arg)));
|
||||
|
||||
let method_def_id = cx.tables().type_dependent_def_id(ex.hir_id).unwrap();
|
||||
let method_def_id = cx.typeck_results().type_dependent_def_id(ex.hir_id).unwrap();
|
||||
if !type_is_unsafe_function(cx, cx.tcx.type_of(method_def_id));
|
||||
|
||||
if compare_inputs(&mut iter_input_pats(decl, body), &mut args.iter());
|
||||
@ -153,7 +153,7 @@ fn check_closure(cx: &LateContext<'_>, expr: &Expr<'_>) {
|
||||
/// Tries to determine the type for universal function call to be used instead of the closure
|
||||
fn get_ufcs_type_name(cx: &LateContext<'_>, method_def_id: def_id::DefId, self_arg: &Expr<'_>) -> Option<String> {
|
||||
let expected_type_of_self = &cx.tcx.fn_sig(method_def_id).inputs_and_output().skip_binder()[0];
|
||||
let actual_type_of_self = &cx.tables().node_type(self_arg.hir_id);
|
||||
let actual_type_of_self = &cx.typeck_results().node_type(self_arg.hir_id);
|
||||
|
||||
if let Some(trait_id) = cx.tcx.trait_of_item(method_def_id) {
|
||||
if match_borrow_depth(expected_type_of_self, &actual_type_of_self)
|
||||
|
@ -137,7 +137,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> {
|
||||
match e.kind {
|
||||
ExprKind::Continue(_) | ExprKind::Break(_, _) | ExprKind::Ret(_) => self.report_diverging_sub_expr(e),
|
||||
ExprKind::Call(ref func, _) => {
|
||||
let typ = self.cx.tables().expr_ty(func);
|
||||
let typ = self.cx.typeck_results().expr_ty(func);
|
||||
match typ.kind {
|
||||
ty::FnDef(..) | ty::FnPtr(_) => {
|
||||
let sig = typ.fn_sig(self.cx.tcx);
|
||||
@ -149,7 +149,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> {
|
||||
}
|
||||
},
|
||||
ExprKind::MethodCall(..) => {
|
||||
let borrowed_table = self.cx.tables();
|
||||
let borrowed_table = self.cx.typeck_results();
|
||||
if borrowed_table.expr_ty(e).is_never() {
|
||||
self.report_diverging_sub_expr(e);
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h
|
||||
|
||||
struct FindPanicUnwrap<'a, 'tcx> {
|
||||
lcx: &'a LateContext<'tcx>,
|
||||
tables: &'tcx ty::TypeckTables<'tcx>,
|
||||
typeck_results: &'tcx ty::TypeckResults<'tcx>,
|
||||
result: Vec<Span>,
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h
|
||||
|
||||
// check for `unwrap`
|
||||
if let Some(arglists) = method_chain_args(expr, &["unwrap"]) {
|
||||
let reciever_ty = walk_ptrs_ty(self.tables.expr_ty(&arglists[0][0]));
|
||||
let reciever_ty = walk_ptrs_ty(self.typeck_results.expr_ty(&arglists[0][0]));
|
||||
if is_type_diagnostic_item(self.lcx, reciever_ty, sym!(option_type))
|
||||
|| is_type_diagnostic_item(self.lcx, reciever_ty, sym!(result_type))
|
||||
{
|
||||
@ -124,7 +124,7 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h
|
||||
let impl_item_def_id = cx.tcx.hir().local_def_id(impl_item.id.hir_id);
|
||||
let mut fpu = FindPanicUnwrap {
|
||||
lcx: cx,
|
||||
tables: cx.tcx.typeck_tables_of(impl_item_def_id),
|
||||
typeck_results: cx.tcx.typeck(impl_item_def_id),
|
||||
result: Vec::new(),
|
||||
};
|
||||
fpu.visit_expr(&body.value);
|
||||
|
@ -61,7 +61,7 @@ declare_lint_pass!(FloatLiteral => [EXCESSIVE_PRECISION, LOSSY_FLOAT_LITERAL]);
|
||||
impl<'tcx> LateLintPass<'tcx> for FloatLiteral {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
|
||||
if_chain! {
|
||||
let ty = cx.tables().expr_ty(expr);
|
||||
let ty = cx.typeck_results().expr_ty(expr);
|
||||
if let ty::Float(fty) = ty.kind;
|
||||
if let hir::ExprKind::Lit(ref lit) = expr.kind;
|
||||
if let LitKind::Float(sym, lit_float_ty) = lit.node;
|
||||
|
@ -112,7 +112,7 @@ declare_lint_pass!(FloatingPointArithmetic => [
|
||||
// Returns the specialized log method for a given base if base is constant
|
||||
// and is one of 2, 10 and e
|
||||
fn get_specialized_log_method(cx: &LateContext<'_>, base: &Expr<'_>) -> Option<&'static str> {
|
||||
if let Some((value, _)) = constant(cx, cx.tables(), base) {
|
||||
if let Some((value, _)) = constant(cx, cx.typeck_results(), base) {
|
||||
if F32(2.0) == value || F64(2.0) == value {
|
||||
return Some("log2");
|
||||
} else if F32(10.0) == value || F64(10.0) == value {
|
||||
@ -136,7 +136,7 @@ fn prepare_receiver_sugg<'a>(cx: &LateContext<'_>, mut expr: &'a Expr<'a>) -> Su
|
||||
if_chain! {
|
||||
// if the expression is a float literal and it is unsuffixed then
|
||||
// add a suffix so the suggestion is valid and unambiguous
|
||||
if let ty::Float(float_ty) = cx.tables().expr_ty(expr).kind;
|
||||
if let ty::Float(float_ty) = cx.typeck_results().expr_ty(expr).kind;
|
||||
if let ExprKind::Lit(lit) = &expr.kind;
|
||||
if let ast::LitKind::Float(sym, ast::LitFloatType::Unsuffixed) = lit.node;
|
||||
then {
|
||||
@ -188,7 +188,10 @@ fn check_ln1p(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) {
|
||||
rhs,
|
||||
) = &args[0].kind
|
||||
{
|
||||
let recv = match (constant(cx, cx.tables(), lhs), constant(cx, cx.tables(), rhs)) {
|
||||
let recv = match (
|
||||
constant(cx, cx.typeck_results(), lhs),
|
||||
constant(cx, cx.typeck_results(), rhs),
|
||||
) {
|
||||
(Some((value, _)), _) if F32(1.0) == value || F64(1.0) == value => rhs,
|
||||
(_, Some((value, _))) if F32(1.0) == value || F64(1.0) == value => lhs,
|
||||
_ => return,
|
||||
@ -233,7 +236,7 @@ fn get_integer_from_float_constant(value: &Constant) -> Option<i32> {
|
||||
|
||||
fn check_powf(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) {
|
||||
// Check receiver
|
||||
if let Some((value, _)) = constant(cx, cx.tables(), &args[0]) {
|
||||
if let Some((value, _)) = constant(cx, cx.typeck_results(), &args[0]) {
|
||||
let method = if F32(f32_consts::E) == value || F64(f64_consts::E) == value {
|
||||
"exp"
|
||||
} else if F32(2.0) == value || F64(2.0) == value {
|
||||
@ -254,7 +257,7 @@ fn check_powf(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) {
|
||||
}
|
||||
|
||||
// Check argument
|
||||
if let Some((value, _)) = constant(cx, cx.tables(), &args[1]) {
|
||||
if let Some((value, _)) = constant(cx, cx.typeck_results(), &args[1]) {
|
||||
let (lint, help, suggestion) = if F32(1.0 / 2.0) == value || F64(1.0 / 2.0) == value {
|
||||
(
|
||||
SUBOPTIMAL_FLOPS,
|
||||
@ -294,7 +297,7 @@ fn check_powf(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) {
|
||||
}
|
||||
|
||||
fn check_powi(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) {
|
||||
if let Some((value, _)) = constant(cx, cx.tables(), &args[1]) {
|
||||
if let Some((value, _)) = constant(cx, cx.typeck_results(), &args[1]) {
|
||||
if value == Int(2) {
|
||||
if let Some(parent) = get_parent_expr(cx, expr) {
|
||||
if let Some(grandparent) = get_parent_expr(cx, parent) {
|
||||
@ -382,8 +385,8 @@ fn detect_hypot(cx: &LateContext<'_>, args: &[Expr<'_>]) -> Option<String> {
|
||||
_
|
||||
) = add_rhs.kind;
|
||||
if lmethod_name.as_str() == "powi" && rmethod_name.as_str() == "powi";
|
||||
if let Some((lvalue, _)) = constant(cx, cx.tables(), &largs[1]);
|
||||
if let Some((rvalue, _)) = constant(cx, cx.tables(), &rargs[1]);
|
||||
if let Some((lvalue, _)) = constant(cx, cx.typeck_results(), &largs[1]);
|
||||
if let Some((rvalue, _)) = constant(cx, cx.typeck_results(), &rargs[1]);
|
||||
if Int(2) == lvalue && Int(2) == rvalue;
|
||||
then {
|
||||
return Some(format!("{}.hypot({})", Sugg::hir(cx, &largs[0], ".."), Sugg::hir(cx, &rargs[0], "..")));
|
||||
@ -413,11 +416,11 @@ fn check_hypot(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) {
|
||||
fn check_expm1(cx: &LateContext<'_>, expr: &Expr<'_>) {
|
||||
if_chain! {
|
||||
if let ExprKind::Binary(Spanned { node: BinOpKind::Sub, .. }, ref lhs, ref rhs) = expr.kind;
|
||||
if cx.tables().expr_ty(lhs).is_floating_point();
|
||||
if let Some((value, _)) = constant(cx, cx.tables(), rhs);
|
||||
if cx.typeck_results().expr_ty(lhs).is_floating_point();
|
||||
if let Some((value, _)) = constant(cx, cx.typeck_results(), rhs);
|
||||
if F32(1.0) == value || F64(1.0) == value;
|
||||
if let ExprKind::MethodCall(ref path, _, ref method_args, _) = lhs.kind;
|
||||
if cx.tables().expr_ty(&method_args[0]).is_floating_point();
|
||||
if cx.typeck_results().expr_ty(&method_args[0]).is_floating_point();
|
||||
if path.ident.name.as_str() == "exp";
|
||||
then {
|
||||
span_lint_and_sugg(
|
||||
@ -439,8 +442,8 @@ fn check_expm1(cx: &LateContext<'_>, expr: &Expr<'_>) {
|
||||
fn is_float_mul_expr<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<(&'a Expr<'a>, &'a Expr<'a>)> {
|
||||
if_chain! {
|
||||
if let ExprKind::Binary(Spanned { node: BinOpKind::Mul, .. }, ref lhs, ref rhs) = &expr.kind;
|
||||
if cx.tables().expr_ty(lhs).is_floating_point();
|
||||
if cx.tables().expr_ty(rhs).is_floating_point();
|
||||
if cx.typeck_results().expr_ty(lhs).is_floating_point();
|
||||
if cx.typeck_results().expr_ty(rhs).is_floating_point();
|
||||
then {
|
||||
return Some((lhs, rhs));
|
||||
}
|
||||
@ -527,7 +530,7 @@ fn are_exprs_equal(cx: &LateContext<'_>, expr1: &Expr<'_>, expr2: &Expr<'_>) ->
|
||||
|
||||
/// Returns true iff expr is some zero literal
|
||||
fn is_zero(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||
match constant_simple(cx, cx.tables(), expr) {
|
||||
match constant_simple(cx, cx.typeck_results(), expr) {
|
||||
Some(Constant::Int(i)) => i == 0,
|
||||
Some(Constant::F32(f)) => f == 0.0,
|
||||
Some(Constant::F64(f)) => f == 0.0,
|
||||
@ -662,8 +665,8 @@ fn check_radians(cx: &LateContext<'_>, expr: &Expr<'_>) {
|
||||
mul_lhs,
|
||||
mul_rhs,
|
||||
) = &div_lhs.kind;
|
||||
if let Some((rvalue, _)) = constant(cx, cx.tables(), div_rhs);
|
||||
if let Some((lvalue, _)) = constant(cx, cx.tables(), mul_rhs);
|
||||
if let Some((rvalue, _)) = constant(cx, cx.typeck_results(), div_rhs);
|
||||
if let Some((lvalue, _)) = constant(cx, cx.typeck_results(), mul_rhs);
|
||||
then {
|
||||
// TODO: also check for constant values near PI/180 or 180/PI
|
||||
if (F32(f32_consts::PI) == rvalue || F64(f64_consts::PI) == rvalue) &&
|
||||
@ -699,7 +702,7 @@ fn check_radians(cx: &LateContext<'_>, expr: &Expr<'_>) {
|
||||
impl<'tcx> LateLintPass<'tcx> for FloatingPointArithmetic {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if let ExprKind::MethodCall(ref path, _, args, _) = &expr.kind {
|
||||
let recv_ty = cx.tables().expr_ty(&args[0]);
|
||||
let recv_ty = cx.typeck_results().expr_ty(&args[0]);
|
||||
|
||||
if recv_ty.is_floating_point() {
|
||||
match &*path.ident.name.as_str() {
|
||||
|
@ -90,7 +90,7 @@ fn on_argumentv1_new<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, arms: &
|
||||
if let PatKind::Tuple(ref pats, None) = arms[0].pat.kind;
|
||||
if pats.len() == 1;
|
||||
then {
|
||||
let ty = walk_ptrs_ty(cx.tables().pat_ty(&pats[0]));
|
||||
let ty = walk_ptrs_ty(cx.typeck_results().pat_ty(&pats[0]));
|
||||
if ty.kind != rustc_middle::ty::Str && !is_type_diagnostic_item(cx, ty, sym!(string_type)) {
|
||||
return None;
|
||||
}
|
||||
|
@ -392,11 +392,11 @@ impl<'tcx> Functions {
|
||||
.collect::<FxHashSet<_>>();
|
||||
|
||||
if !raw_ptrs.is_empty() {
|
||||
let tables = cx.tcx.body_tables(body.id());
|
||||
let typeck_results = cx.tcx.typeck_body(body.id());
|
||||
let mut v = DerefVisitor {
|
||||
cx,
|
||||
ptrs: raw_ptrs,
|
||||
tables,
|
||||
typeck_results,
|
||||
};
|
||||
|
||||
intravisit::walk_expr(&mut v, expr);
|
||||
@ -494,13 +494,8 @@ fn is_mutable_pat(cx: &LateContext<'_>, pat: &hir::Pat<'_>, tys: &mut FxHashSet<
|
||||
return false; // ignore `_` patterns
|
||||
}
|
||||
let def_id = pat.hir_id.owner.to_def_id();
|
||||
if cx.tcx.has_typeck_tables(def_id) {
|
||||
is_mutable_ty(
|
||||
cx,
|
||||
&cx.tcx.typeck_tables_of(def_id.expect_local()).pat_ty(pat),
|
||||
pat.span,
|
||||
tys,
|
||||
)
|
||||
if cx.tcx.has_typeck_results(def_id) {
|
||||
is_mutable_ty(cx, &cx.tcx.typeck(def_id.expect_local()).pat_ty(pat), pat.span, tys)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
@ -539,7 +534,7 @@ fn raw_ptr_arg(arg: &hir::Param<'_>, ty: &hir::Ty<'_>) -> Option<hir::HirId> {
|
||||
struct DerefVisitor<'a, 'tcx> {
|
||||
cx: &'a LateContext<'tcx>,
|
||||
ptrs: FxHashSet<hir::HirId>,
|
||||
tables: &'a ty::TypeckTables<'tcx>,
|
||||
typeck_results: &'a ty::TypeckResults<'tcx>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> {
|
||||
@ -548,7 +543,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) {
|
||||
match expr.kind {
|
||||
hir::ExprKind::Call(ref f, args) => {
|
||||
let ty = self.tables.expr_ty(f);
|
||||
let ty = self.typeck_results.expr_ty(f);
|
||||
|
||||
if type_is_unsafe_function(self.cx, ty) {
|
||||
for arg in args {
|
||||
@ -557,7 +552,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> {
|
||||
}
|
||||
},
|
||||
hir::ExprKind::MethodCall(_, _, args, _) => {
|
||||
let def_id = self.tables.type_dependent_def_id(expr.hir_id).unwrap();
|
||||
let def_id = self.typeck_results.type_dependent_def_id(expr.hir_id).unwrap();
|
||||
let base_type = self.cx.tcx.type_of(def_id);
|
||||
|
||||
if type_is_unsafe_function(self.cx, base_type) {
|
||||
@ -614,10 +609,10 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> {
|
||||
let mut tys = FxHashSet::default();
|
||||
for arg in args {
|
||||
let def_id = arg.hir_id.owner.to_def_id();
|
||||
if self.cx.tcx.has_typeck_tables(def_id)
|
||||
if self.cx.tcx.has_typeck_results(def_id)
|
||||
&& is_mutable_ty(
|
||||
self.cx,
|
||||
self.cx.tcx.typeck_tables_of(def_id.expect_local()).expr_ty(arg),
|
||||
self.cx.tcx.typeck(def_id.expect_local()).expr_ty(arg),
|
||||
arg.span,
|
||||
&mut tys,
|
||||
)
|
||||
|
@ -54,7 +54,7 @@ impl<'tcx> LateLintPass<'tcx> for GetLastWithLen {
|
||||
|
||||
// Argument 0 (the struct we're calling the method on) is a vector
|
||||
if let Some(struct_calling_on) = args.get(0);
|
||||
let struct_ty = cx.tables().expr_ty(struct_calling_on);
|
||||
let struct_ty = cx.typeck_results().expr_ty(struct_calling_on);
|
||||
if is_type_diagnostic_item(cx, struct_ty, sym!(vec_type));
|
||||
|
||||
// Argument to "get" is a subtraction
|
||||
|
@ -62,8 +62,8 @@ fn is_allowed(cx: &LateContext<'_>, cmp: BinOp, left: &Expr<'_>, right: &Expr<'_
|
||||
// `1 << 0` is a common pattern in bit manipulation code
|
||||
if_chain! {
|
||||
if let BinOpKind::Shl = cmp.node;
|
||||
if let Some(Constant::Int(0)) = constant_simple(cx, cx.tables(), right);
|
||||
if let Some(Constant::Int(1)) = constant_simple(cx, cx.tables(), left);
|
||||
if let Some(Constant::Int(0)) = constant_simple(cx, cx.typeck_results(), right);
|
||||
if let Some(Constant::Int(1)) = constant_simple(cx, cx.typeck_results(), left);
|
||||
then {
|
||||
return true;
|
||||
}
|
||||
@ -74,8 +74,8 @@ fn is_allowed(cx: &LateContext<'_>, cmp: BinOp, left: &Expr<'_>, right: &Expr<'_
|
||||
|
||||
#[allow(clippy::cast_possible_wrap)]
|
||||
fn check(cx: &LateContext<'_>, e: &Expr<'_>, m: i8, span: Span, arg: Span) {
|
||||
if let Some(Constant::Int(v)) = constant_simple(cx, cx.tables(), e) {
|
||||
let check = match cx.tables().expr_ty(e).kind {
|
||||
if let Some(Constant::Int(v)) = constant_simple(cx, cx.typeck_results(), e) {
|
||||
let check = match cx.typeck_results().expr_ty(e).kind {
|
||||
ty::Int(ity) => unsext(cx.tcx, -1_i128, ity),
|
||||
ty::Uint(uty) => clip(cx.tcx, !0, uty),
|
||||
_ => return,
|
||||
|
@ -146,7 +146,7 @@ fn is_mutex_lock_call<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Opt
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(path, _span, args, _) = &expr.kind;
|
||||
if path.ident.to_string() == "lock";
|
||||
let ty = cx.tables().expr_ty(&args[0]);
|
||||
let ty = cx.typeck_results().expr_ty(&args[0]);
|
||||
if is_type_diagnostic_item(cx, ty, sym!(mutex_type));
|
||||
then {
|
||||
Some(&args[0])
|
||||
|
@ -45,7 +45,7 @@ impl<'tcx> LateLintPass<'tcx> for OkIfLet {
|
||||
if let ExprKind::MethodCall(_, ok_span, ref result_types, _) = op.kind; //check is expr.ok() has type Result<T,E>.ok(, _)
|
||||
if let PatKind::TupleStruct(QPath::Resolved(_, ref x), ref y, _) = body[0].pat.kind; //get operation
|
||||
if method_chain_args(op, &["ok"]).is_some(); //test to see if using ok() methoduse std::marker::Sized;
|
||||
if is_type_diagnostic_item(cx, cx.tables().expr_ty(&result_types[0]), sym!(result_type));
|
||||
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&result_types[0]), sym!(result_type));
|
||||
if rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_path(x, false)) == "Some";
|
||||
|
||||
then {
|
||||
|
@ -81,7 +81,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
|
||||
};
|
||||
|
||||
// Check if the variable in the condition statement is an integer
|
||||
if !cx.tables().expr_ty(cond_var).is_integral() {
|
||||
if !cx.typeck_results().expr_ty(cond_var).is_integral() {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
|
||||
ExprKind::Lit(ref cond_lit) => {
|
||||
// Check if the constant is zero
|
||||
if let LitKind::Int(0, _) = cond_lit.node {
|
||||
if cx.tables().expr_ty(cond_left).is_signed() {
|
||||
if cx.typeck_results().expr_ty(cond_left).is_signed() {
|
||||
} else {
|
||||
print_lint_and_sugg(cx, &var_name, expr);
|
||||
};
|
||||
|
@ -88,7 +88,7 @@ declare_lint_pass!(IndexingSlicing => [INDEXING_SLICING, OUT_OF_BOUNDS_INDEXING]
|
||||
impl<'tcx> LateLintPass<'tcx> for IndexingSlicing {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if let ExprKind::Index(ref array, ref index) = &expr.kind {
|
||||
let ty = cx.tables().expr_ty(array);
|
||||
let ty = cx.typeck_results().expr_ty(array);
|
||||
if let Some(range) = higher::range(cx, index) {
|
||||
// Ranged indexes, i.e., &x[n..m], &x[n..], &x[..n] and &x[..]
|
||||
if let ty::Array(_, s) = ty.kind {
|
||||
@ -143,7 +143,7 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing {
|
||||
// Catchall non-range index, i.e., [n] or [n << m]
|
||||
if let ty::Array(..) = ty.kind {
|
||||
// Index is a constant uint.
|
||||
if let Some(..) = constant(cx, cx.tables(), index) {
|
||||
if let Some(..) = constant(cx, cx.typeck_results(), index) {
|
||||
// Let rustc's `const_err` lint handle constant `usize` indexing on arrays.
|
||||
return;
|
||||
}
|
||||
@ -169,14 +169,18 @@ fn to_const_range<'tcx>(
|
||||
range: higher::Range<'_>,
|
||||
array_size: u128,
|
||||
) -> (Option<u128>, Option<u128>) {
|
||||
let s = range.start.map(|expr| constant(cx, cx.tables(), expr).map(|(c, _)| c));
|
||||
let s = range
|
||||
.start
|
||||
.map(|expr| constant(cx, cx.typeck_results(), expr).map(|(c, _)| c));
|
||||
let start = match s {
|
||||
Some(Some(Constant::Int(x))) => Some(x),
|
||||
Some(_) => None,
|
||||
None => Some(0),
|
||||
};
|
||||
|
||||
let e = range.end.map(|expr| constant(cx, cx.tables(), expr).map(|(c, _)| c));
|
||||
let e = range
|
||||
.end
|
||||
.map(|expr| constant(cx, cx.typeck_results(), expr).map(|(c, _)| c));
|
||||
let end = match e {
|
||||
Some(Some(Constant::Int(x))) => {
|
||||
if range.limits == RangeLimits::Closed {
|
||||
|
@ -231,13 +231,13 @@ fn complete_infinite_iter(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness {
|
||||
}
|
||||
if method.ident.name == sym!(last) && args.len() == 1 {
|
||||
let not_double_ended = get_trait_def_id(cx, &paths::DOUBLE_ENDED_ITERATOR).map_or(false, |id| {
|
||||
!implements_trait(cx, cx.tables().expr_ty(&args[0]), id, &[])
|
||||
!implements_trait(cx, cx.typeck_results().expr_ty(&args[0]), id, &[])
|
||||
});
|
||||
if not_double_ended {
|
||||
return is_infinite(cx, &args[0]);
|
||||
}
|
||||
} else if method.ident.name == sym!(collect) {
|
||||
let ty = cx.tables().expr_ty(expr);
|
||||
let ty = cx.typeck_results().expr_ty(expr);
|
||||
if INFINITE_COLLECTORS.iter().any(|path| match_type(cx, ty, path)) {
|
||||
return is_infinite(cx, &args[0]);
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ fn is_integer_division<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>)
|
||||
if let hir::ExprKind::Binary(binop, left, right) = &expr.kind;
|
||||
if let hir::BinOpKind::Div = &binop.node;
|
||||
then {
|
||||
let (left_ty, right_ty) = (cx.tables().expr_ty(left), cx.tables().expr_ty(right));
|
||||
let (left_ty, right_ty) = (cx.typeck_results().expr_ty(left), cx.typeck_results().expr_ty(right));
|
||||
return left_ty.is_integral() && right_ty.is_integral();
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeStackArrays {
|
||||
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
|
||||
if_chain! {
|
||||
if let ExprKind::Repeat(_, _) = expr.kind;
|
||||
if let ty::Array(element_type, cst) = cx.tables().expr_ty(expr).kind;
|
||||
if let ty::Array(element_type, cst) = cx.typeck_results().expr_ty(expr).kind;
|
||||
if let ConstKind::Value(val) = cst.val;
|
||||
if let ConstValue::Scalar(element_count) = val;
|
||||
if let Ok(element_count) = element_count.to_machine_usize(&cx.tcx);
|
||||
|
@ -300,7 +300,7 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
let ty = &walk_ptrs_ty(cx.tables().expr_ty(expr));
|
||||
let ty = &walk_ptrs_ty(cx.typeck_results().expr_ty(expr));
|
||||
match ty.kind {
|
||||
ty::Dynamic(ref tt, ..) => tt.principal().map_or(false, |principal| {
|
||||
cx.tcx
|
||||
|
@ -73,7 +73,7 @@ impl<'tcx> LateLintPass<'tcx> for LetIfSeq {
|
||||
then {
|
||||
let span = stmt.span.to(if_.span);
|
||||
|
||||
let has_interior_mutability = !cx.tables().node_type(canonical_id).is_freeze(
|
||||
let has_interior_mutability = !cx.typeck_results().node_type(canonical_id).is_freeze(
|
||||
cx.tcx.at(span),
|
||||
cx.param_env,
|
||||
);
|
||||
|
@ -76,7 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
|
||||
if let PatKind::Wild = local.pat.kind;
|
||||
if let Some(ref init) = local.init;
|
||||
then {
|
||||
let init_ty = cx.tables().expr_ty(init);
|
||||
let init_ty = cx.typeck_results().expr_ty(init);
|
||||
let contains_sync_guard = init_ty.walk().any(|inner| match inner.unpack() {
|
||||
GenericArgKind::Type(inner_ty) => {
|
||||
SYNC_GUARD_PATHS.iter().any(|path| match_type(cx, inner_ty, path))
|
||||
@ -94,7 +94,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
|
||||
"consider using an underscore-prefixed named \
|
||||
binding or dropping explicitly with `std::mem::drop`"
|
||||
)
|
||||
} else if is_must_use_ty(cx, cx.tables().expr_ty(init)) {
|
||||
} else if is_must_use_ty(cx, cx.typeck_results().expr_ty(init)) {
|
||||
span_lint_and_help(
|
||||
cx,
|
||||
LET_UNDERSCORE_MUST_USE,
|
||||
|
@ -535,7 +535,7 @@ impl<'tcx> LateLintPass<'tcx> for Loops {
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(..) | ExprKind::Call(..) = iter_expr.kind;
|
||||
if let Some(iter_def_id) = get_trait_def_id(cx, &paths::ITERATOR);
|
||||
if implements_trait(cx, cx.tables().expr_ty(iter_expr), iter_def_id, &[]);
|
||||
if implements_trait(cx, cx.typeck_results().expr_ty(iter_expr), iter_def_id, &[]);
|
||||
then {
|
||||
return;
|
||||
}
|
||||
@ -981,8 +981,8 @@ fn detect_manual_memcpy<'tcx>(
|
||||
if_chain! {
|
||||
if let ExprKind::Index(seqexpr_left, idx_left) = lhs.kind;
|
||||
if let ExprKind::Index(seqexpr_right, idx_right) = rhs.kind;
|
||||
if is_slice_like(cx, cx.tables().expr_ty(seqexpr_left))
|
||||
&& is_slice_like(cx, cx.tables().expr_ty(seqexpr_right));
|
||||
if is_slice_like(cx, cx.typeck_results().expr_ty(seqexpr_left))
|
||||
&& is_slice_like(cx, cx.typeck_results().expr_ty(seqexpr_right));
|
||||
if let Some(offset_left) = get_offset(cx, &idx_left, canonical_id);
|
||||
if let Some(offset_right) = get_offset(cx, &idx_right, canonical_id);
|
||||
|
||||
@ -1250,8 +1250,8 @@ fn check_for_loop_arg(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>, expr:
|
||||
lint_iter_method(cx, args, arg, method_name);
|
||||
}
|
||||
} else if method_name == "into_iter" && match_trait_method(cx, arg, &paths::INTO_ITERATOR) {
|
||||
let receiver_ty = cx.tables().expr_ty(&args[0]);
|
||||
let receiver_ty_adjusted = cx.tables().expr_ty_adjusted(&args[0]);
|
||||
let receiver_ty = cx.typeck_results().expr_ty(&args[0]);
|
||||
let receiver_ty_adjusted = cx.typeck_results().expr_ty_adjusted(&args[0]);
|
||||
if TyS::same_type(receiver_ty, receiver_ty_adjusted) {
|
||||
let mut applicability = Applicability::MachineApplicable;
|
||||
let object = snippet_with_applicability(cx, args[0].span, "_", &mut applicability);
|
||||
@ -1296,7 +1296,7 @@ fn check_for_loop_arg(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>, expr:
|
||||
|
||||
/// Checks for `for` loops over `Option`s and `Result`s.
|
||||
fn check_arg_type(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>) {
|
||||
let ty = cx.tables().expr_ty(arg);
|
||||
let ty = cx.typeck_results().expr_ty(arg);
|
||||
if is_type_diagnostic_item(cx, ty, sym!(option_type)) {
|
||||
span_lint_and_help(
|
||||
cx,
|
||||
@ -1400,8 +1400,9 @@ fn check_for_loop_explicit_counter<'tcx>(
|
||||
/// If `arg` was the argument to a `for` loop, return the "cleanest" way of writing the
|
||||
/// actual `Iterator` that the loop uses.
|
||||
fn make_iterator_snippet(cx: &LateContext<'_>, arg: &Expr<'_>, applic_ref: &mut Applicability) -> String {
|
||||
let impls_iterator = get_trait_def_id(cx, &paths::ITERATOR)
|
||||
.map_or(false, |id| implements_trait(cx, cx.tables().expr_ty(arg), id, &[]));
|
||||
let impls_iterator = get_trait_def_id(cx, &paths::ITERATOR).map_or(false, |id| {
|
||||
implements_trait(cx, cx.typeck_results().expr_ty(arg), id, &[])
|
||||
});
|
||||
if impls_iterator {
|
||||
format!(
|
||||
"{}",
|
||||
@ -1412,7 +1413,7 @@ fn make_iterator_snippet(cx: &LateContext<'_>, arg: &Expr<'_>, applic_ref: &mut
|
||||
// (&mut x).into_iter() ==> x.iter_mut()
|
||||
match &arg.kind {
|
||||
ExprKind::AddrOf(BorrowKind::Ref, mutability, arg_inner)
|
||||
if has_iter_method(cx, cx.tables().expr_ty(&arg_inner)).is_some() =>
|
||||
if has_iter_method(cx, cx.typeck_results().expr_ty(&arg_inner)).is_some() =>
|
||||
{
|
||||
let meth_name = match mutability {
|
||||
Mutability::Mut => "iter_mut",
|
||||
@ -1445,7 +1446,7 @@ fn check_for_loop_over_map_kv<'tcx>(
|
||||
if let PatKind::Tuple(ref pat, _) = pat.kind {
|
||||
if pat.len() == 2 {
|
||||
let arg_span = arg.span;
|
||||
let (new_pat_span, kind, ty, mutbl) = match cx.tables().expr_ty(arg).kind {
|
||||
let (new_pat_span, kind, ty, mutbl) = match cx.typeck_results().expr_ty(arg).kind {
|
||||
ty::Ref(_, ty, mutbl) => match (&pat[0].kind, &pat[1].kind) {
|
||||
(key, _) if pat_is_wild(key, body) => (pat[1].span, "value", ty, mutbl),
|
||||
(_, value) if pat_is_wild(value, body) => (pat[0].span, "key", ty, Mutability::Not),
|
||||
@ -1590,7 +1591,14 @@ fn check_for_mutation<'tcx>(
|
||||
};
|
||||
let def_id = body.hir_id.owner.to_def_id();
|
||||
cx.tcx.infer_ctxt().enter(|infcx| {
|
||||
ExprUseVisitor::new(&mut delegate, &infcx, def_id.expect_local(), cx.param_env, cx.tables()).walk_expr(body);
|
||||
ExprUseVisitor::new(
|
||||
&mut delegate,
|
||||
&infcx,
|
||||
def_id.expect_local(),
|
||||
cx.param_env,
|
||||
cx.typeck_results(),
|
||||
)
|
||||
.walk_expr(body);
|
||||
});
|
||||
delegate.mutation_span()
|
||||
}
|
||||
@ -1684,7 +1692,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
|
||||
if index_used_directly {
|
||||
self.indexed_directly.insert(
|
||||
seqvar.segments[0].ident.name,
|
||||
(Some(extent), self.cx.tables().node_type(seqexpr.hir_id)),
|
||||
(Some(extent), self.cx.typeck_results().node_type(seqexpr.hir_id)),
|
||||
);
|
||||
}
|
||||
return false; // no need to walk further *on the variable*
|
||||
@ -1696,7 +1704,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
|
||||
if index_used_directly {
|
||||
self.indexed_directly.insert(
|
||||
seqvar.segments[0].ident.name,
|
||||
(None, self.cx.tables().node_type(seqexpr.hir_id)),
|
||||
(None, self.cx.typeck_results().node_type(seqexpr.hir_id)),
|
||||
);
|
||||
}
|
||||
return false; // no need to walk further *on the variable*
|
||||
@ -1764,7 +1772,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
|
||||
ExprKind::Call(ref f, args) => {
|
||||
self.visit_expr(f);
|
||||
for expr in args {
|
||||
let ty = self.cx.tables().expr_ty_adjusted(expr);
|
||||
let ty = self.cx.typeck_results().expr_ty_adjusted(expr);
|
||||
self.prefer_mutable = false;
|
||||
if let ty::Ref(_, _, mutbl) = ty.kind {
|
||||
if mutbl == Mutability::Mut {
|
||||
@ -1775,7 +1783,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
|
||||
}
|
||||
},
|
||||
ExprKind::MethodCall(_, _, args, _) => {
|
||||
let def_id = self.cx.tables().type_dependent_def_id(expr.hir_id).unwrap();
|
||||
let def_id = self.cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap();
|
||||
for (ty, expr) in self.cx.tcx.fn_sig(def_id).inputs().skip_binder().iter().zip(args) {
|
||||
self.prefer_mutable = false;
|
||||
if let ty::Ref(_, _, mutbl) = ty.kind {
|
||||
@ -1862,7 +1870,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarUsedAfterLoopVisitor<'a, 'tcx> {
|
||||
fn is_ref_iterable_type(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
|
||||
// no walk_ptrs_ty: calling iter() on a reference can make sense because it
|
||||
// will allow further borrows afterwards
|
||||
let ty = cx.tables().expr_ty(e);
|
||||
let ty = cx.typeck_results().expr_ty(e);
|
||||
is_iterable_array(ty, cx) ||
|
||||
is_type_diagnostic_item(cx, ty, sym!(vec_type)) ||
|
||||
match_type(cx, ty, &paths::LINKED_LIST) ||
|
||||
@ -2221,7 +2229,7 @@ fn path_name(e: &Expr<'_>) -> Option<Name> {
|
||||
}
|
||||
|
||||
fn check_infinite_loop<'tcx>(cx: &LateContext<'tcx>, cond: &'tcx Expr<'_>, expr: &'tcx Expr<'_>) {
|
||||
if constant(cx, cx.tables(), cond).is_some() {
|
||||
if constant(cx, cx.typeck_results(), cond).is_some() {
|
||||
// A pure constant condition (e.g., `while false`) is not linted.
|
||||
return;
|
||||
}
|
||||
@ -2357,7 +2365,7 @@ fn check_needless_collect<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) {
|
||||
if let Some(ref generic_args) = chain_method.args;
|
||||
if let Some(GenericArg::Type(ref ty)) = generic_args.args.get(0);
|
||||
then {
|
||||
let ty = cx.tables().node_type(ty.hir_id);
|
||||
let ty = cx.typeck_results().node_type(ty.hir_id);
|
||||
if is_type_diagnostic_item(cx, ty, sym!(vec_type)) ||
|
||||
is_type_diagnostic_item(cx, ty, sym!(vecdeque_type)) ||
|
||||
match_type(cx, ty, &paths::BTREEMAP) ||
|
||||
|
@ -52,7 +52,7 @@ impl<'tcx> LateLintPass<'tcx> for MapClone {
|
||||
if let hir::ExprKind::MethodCall(ref method, _, ref args, _) = e.kind;
|
||||
if args.len() == 2;
|
||||
if method.ident.as_str() == "map";
|
||||
let ty = cx.tables().expr_ty(&args[0]);
|
||||
let ty = cx.typeck_results().expr_ty(&args[0]);
|
||||
if is_type_diagnostic_item(cx, ty, sym!(option_type)) || match_trait_method(cx, e, &paths::ITERATOR);
|
||||
if let hir::ExprKind::Closure(_, _, body_id, _, _) = args[1].kind;
|
||||
let closure_body = cx.tcx.hir().body(body_id);
|
||||
@ -70,7 +70,7 @@ impl<'tcx> LateLintPass<'tcx> for MapClone {
|
||||
match closure_expr.kind {
|
||||
hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner) => {
|
||||
if ident_eq(name, inner) {
|
||||
if let ty::Ref(.., Mutability::Not) = cx.tables().expr_ty(inner).kind {
|
||||
if let ty::Ref(.., Mutability::Not) = cx.typeck_results().expr_ty(inner).kind {
|
||||
lint(cx, e.span, args[0].span, true);
|
||||
}
|
||||
}
|
||||
@ -79,7 +79,7 @@ impl<'tcx> LateLintPass<'tcx> for MapClone {
|
||||
if ident_eq(name, &obj[0]) && method.ident.as_str() == "clone"
|
||||
&& match_trait_method(cx, closure_expr, &paths::CLONE_TRAIT) {
|
||||
|
||||
let obj_ty = cx.tables().expr_ty(&obj[0]);
|
||||
let obj_ty = cx.typeck_results().expr_ty(&obj[0]);
|
||||
if let ty::Ref(_, ty, _) = obj_ty.kind {
|
||||
let copy = is_copy(cx, ty);
|
||||
lint(cx, e.span, args[0].span, copy);
|
||||
|
@ -63,7 +63,7 @@ fn get_map_argument<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<&'a
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(ref method, _, ref args, _) = expr.kind;
|
||||
if args.len() == 2 && method.ident.as_str() == "map";
|
||||
let caller_ty = cx.tables().expr_ty(&args[0]);
|
||||
let caller_ty = cx.typeck_results().expr_ty(&args[0]);
|
||||
if match_trait_method(cx, expr, &paths::ITERATOR)
|
||||
|| is_type_diagnostic_item(cx, caller_ty, sym!(result_type))
|
||||
|| is_type_diagnostic_item(cx, caller_ty, sym!(option_type));
|
||||
@ -119,7 +119,7 @@ fn is_body_identity_function(cx: &LateContext<'_>, func: &Body<'_>) -> bool {
|
||||
/// Returns true iff an expression returns the same thing as a parameter's pattern
|
||||
fn match_expr_param(cx: &LateContext<'_>, expr: &Expr<'_>, pat: &Pat<'_>) -> bool {
|
||||
if let PatKind::Binding(_, _, ident, _) = pat.kind {
|
||||
match_var(expr, ident.name) && !(cx.tables().hir_owner == expr.hir_id.owner && is_adjusted(cx, expr))
|
||||
match_var(expr, ident.name) && !(cx.typeck_results().hir_owner == expr.hir_id.owner && is_adjusted(cx, expr))
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ fn is_unit_type(ty: Ty<'_>) -> bool {
|
||||
}
|
||||
|
||||
fn is_unit_function(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool {
|
||||
let ty = cx.tables().expr_ty(expr);
|
||||
let ty = cx.typeck_results().expr_ty(expr);
|
||||
|
||||
if let ty::FnDef(id, _) = ty.kind {
|
||||
if let Some(fn_type) = cx.tcx.fn_sig(id).no_bound_vars() {
|
||||
@ -112,7 +112,7 @@ fn is_unit_function(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool {
|
||||
}
|
||||
|
||||
fn is_unit_expression(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool {
|
||||
is_unit_type(cx.tables().expr_ty(expr))
|
||||
is_unit_type(cx.typeck_results().expr_ty(expr))
|
||||
}
|
||||
|
||||
/// The expression inside a closure may or may not have surrounding braces and
|
||||
@ -205,9 +205,10 @@ fn suggestion_msg(function_type: &str, map_type: &str) -> String {
|
||||
fn lint_map_unit_fn(cx: &LateContext<'_>, stmt: &hir::Stmt<'_>, expr: &hir::Expr<'_>, map_args: &[hir::Expr<'_>]) {
|
||||
let var_arg = &map_args[0];
|
||||
|
||||
let (map_type, variant, lint) = if is_type_diagnostic_item(cx, cx.tables().expr_ty(var_arg), sym!(option_type)) {
|
||||
let (map_type, variant, lint) =
|
||||
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(var_arg), sym!(option_type)) {
|
||||
("Option", "Some", OPTION_MAP_UNIT_FN)
|
||||
} else if is_type_diagnostic_item(cx, cx.tables().expr_ty(var_arg), sym!(result_type)) {
|
||||
} else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(var_arg), sym!(result_type)) {
|
||||
("Result", "Ok", RESULT_MAP_UNIT_FN)
|
||||
} else {
|
||||
return;
|
||||
|
@ -88,13 +88,13 @@ fn is_vec_indexing<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Opti
|
||||
}
|
||||
|
||||
fn is_vector(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||
let ty = cx.tables().expr_ty(expr);
|
||||
let ty = cx.typeck_results().expr_ty(expr);
|
||||
let ty = walk_ptrs_ty(ty);
|
||||
is_type_diagnostic_item(cx, ty, sym!(vec_type))
|
||||
}
|
||||
|
||||
fn is_full_range(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||
let ty = cx.tables().expr_ty(expr);
|
||||
let ty = cx.typeck_results().expr_ty(expr);
|
||||
let ty = walk_ptrs_ty(ty);
|
||||
match_type(cx, ty, &utils::paths::RANGE_FULL)
|
||||
}
|
||||
|
@ -620,7 +620,7 @@ fn check_single_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], exp
|
||||
return;
|
||||
};
|
||||
|
||||
let ty = cx.tables().expr_ty(ex);
|
||||
let ty = cx.typeck_results().expr_ty(ex);
|
||||
if ty.kind != ty::Bool || is_allowed(cx, MATCH_BOOL, ex.hir_id) {
|
||||
check_single_match_single_pattern(cx, ex, arms, expr, els);
|
||||
check_single_match_opt_like(cx, ex, arms, expr, ty, els);
|
||||
@ -712,7 +712,7 @@ fn check_single_match_opt_like(
|
||||
|
||||
fn check_match_bool(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) {
|
||||
// Type of expression is `bool`.
|
||||
if cx.tables().expr_ty(ex).kind == ty::Bool {
|
||||
if cx.typeck_results().expr_ty(ex).kind == ty::Bool {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
MATCH_BOOL,
|
||||
@ -775,8 +775,8 @@ fn check_match_bool(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr:
|
||||
}
|
||||
|
||||
fn check_overlapping_arms<'tcx>(cx: &LateContext<'tcx>, ex: &'tcx Expr<'_>, arms: &'tcx [Arm<'_>]) {
|
||||
if arms.len() >= 2 && cx.tables().expr_ty(ex).is_integral() {
|
||||
let ranges = all_ranges(cx, arms, cx.tables().expr_ty(ex));
|
||||
if arms.len() >= 2 && cx.typeck_results().expr_ty(ex).is_integral() {
|
||||
let ranges = all_ranges(cx, arms, cx.typeck_results().expr_ty(ex));
|
||||
let type_ranges = type_ranges(&ranges);
|
||||
if !type_ranges.is_empty() {
|
||||
if let Some((start, end)) = overlapping(&type_ranges) {
|
||||
@ -794,7 +794,7 @@ fn check_overlapping_arms<'tcx>(cx: &LateContext<'tcx>, ex: &'tcx Expr<'_>, arms
|
||||
}
|
||||
|
||||
fn check_wild_err_arm(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) {
|
||||
let ex_ty = walk_ptrs_ty(cx.tables().expr_ty(ex));
|
||||
let ex_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(ex));
|
||||
if is_type_diagnostic_item(cx, ex_ty, sym!(result_type)) {
|
||||
for arm in arms {
|
||||
if let PatKind::TupleStruct(ref path, ref inner, _) = arm.pat.kind {
|
||||
@ -835,7 +835,7 @@ fn check_wild_err_arm(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) {
|
||||
}
|
||||
|
||||
fn check_wild_enum_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) {
|
||||
let ty = cx.tables().expr_ty(ex);
|
||||
let ty = cx.typeck_results().expr_ty(ex);
|
||||
if !ty.is_enum() {
|
||||
// If there isn't a nice closed set of possible values that can be conveniently enumerated,
|
||||
// don't complain about not enumerating the mall.
|
||||
@ -1010,8 +1010,8 @@ fn check_match_as_ref(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], exp
|
||||
"as_mut"
|
||||
};
|
||||
|
||||
let output_ty = cx.tables().expr_ty(expr);
|
||||
let input_ty = cx.tables().expr_ty(ex);
|
||||
let output_ty = cx.typeck_results().expr_ty(expr);
|
||||
let input_ty = cx.typeck_results().expr_ty(ex);
|
||||
|
||||
let cast = if_chain! {
|
||||
if let ty::Adt(_, substs) = input_ty.kind;
|
||||
@ -1079,7 +1079,7 @@ fn check_match_like_matches<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>)
|
||||
fn find_matches_sugg(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>, desugared: bool) {
|
||||
if_chain! {
|
||||
if arms.len() == 2;
|
||||
if cx.tables().expr_ty(expr).is_bool();
|
||||
if cx.typeck_results().expr_ty(expr).is_bool();
|
||||
if is_wild(&arms[1].pat);
|
||||
if let Some(first) = find_bool_lit(&arms[0].body.kind, desugared);
|
||||
if let Some(second) = find_bool_lit(&arms[1].body.kind, desugared);
|
||||
@ -1154,13 +1154,13 @@ fn check_match_single_binding<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[A
|
||||
match match_body.kind {
|
||||
ExprKind::Block(block, _) => {
|
||||
// macro + expr_ty(body) == ()
|
||||
if block.span.from_expansion() && cx.tables().expr_ty(&match_body).is_unit() {
|
||||
if block.span.from_expansion() && cx.typeck_results().expr_ty(&match_body).is_unit() {
|
||||
snippet_body.push(';');
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
// expr_ty(body) == ()
|
||||
if cx.tables().expr_ty(&match_body).is_unit() {
|
||||
if cx.typeck_results().expr_ty(&match_body).is_unit() {
|
||||
snippet_body.push(';');
|
||||
}
|
||||
},
|
||||
@ -1255,11 +1255,11 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>)
|
||||
{
|
||||
if let PatKind::Range(ref lhs, ref rhs, range_end) = pat.kind {
|
||||
let lhs = match lhs {
|
||||
Some(lhs) => constant(cx, cx.tables(), lhs)?.0,
|
||||
Some(lhs) => constant(cx, cx.typeck_results(), lhs)?.0,
|
||||
None => miri_to_const(ty.numeric_min_val(cx.tcx)?)?,
|
||||
};
|
||||
let rhs = match rhs {
|
||||
Some(rhs) => constant(cx, cx.tables(), rhs)?.0,
|
||||
Some(rhs) => constant(cx, cx.typeck_results(), rhs)?.0,
|
||||
None => miri_to_const(ty.numeric_max_val(cx.tcx)?)?,
|
||||
};
|
||||
let rhs = match range_end {
|
||||
@ -1273,7 +1273,7 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>)
|
||||
}
|
||||
|
||||
if let PatKind::Lit(ref value) = pat.kind {
|
||||
let value = constant(cx, cx.tables(), value)?.0;
|
||||
let value = constant(cx, cx.typeck_results(), value)?.0;
|
||||
return Some(SpannedRange {
|
||||
span: pat.span,
|
||||
node: (value.clone(), Bound::Included(value)),
|
||||
|
@ -38,7 +38,7 @@ impl<'tcx> LateLintPass<'tcx> for MemDiscriminant {
|
||||
if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id();
|
||||
if match_def_path(cx, def_id, &paths::MEM_DISCRIMINANT);
|
||||
// type is non-enum
|
||||
let ty_param = cx.tables().node_substs(func.hir_id).type_at(0);
|
||||
let ty_param = cx.typeck_results().node_substs(func.hir_id).type_at(0);
|
||||
if !ty_param.is_enum();
|
||||
|
||||
then {
|
||||
|
@ -31,7 +31,7 @@ impl<'tcx> LateLintPass<'tcx> for MemForget {
|
||||
if let ExprKind::Path(ref qpath) = path_expr.kind {
|
||||
if let Some(def_id) = qpath_res(cx, qpath, path_expr.hir_id).opt_def_id() {
|
||||
if match_def_path(cx, def_id, &paths::MEM_FORGET) {
|
||||
let forgot_ty = cx.tables().expr_ty(&args[0]);
|
||||
let forgot_ty = cx.typeck_results().expr_ty(&args[0]);
|
||||
|
||||
if forgot_ty.ty_adt_def().map_or(false, |def| def.has_dtor(cx.tcx)) {
|
||||
span_lint(cx, MEM_FORGET, e.span, "usage of `mem::forget` on `Drop` type");
|
||||
|
@ -138,7 +138,7 @@ fn check_replace_option_with_none(cx: &LateContext<'_>, src: &Expr<'_>, dest: &E
|
||||
fn check_replace_with_uninit(cx: &LateContext<'_>, src: &Expr<'_>, dest: &Expr<'_>, expr_span: Span) {
|
||||
if_chain! {
|
||||
// check if replacement is mem::MaybeUninit::uninit().assume_init()
|
||||
if let Some(method_def_id) = cx.tables().type_dependent_def_id(src.hir_id);
|
||||
if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(src.hir_id);
|
||||
if cx.tcx.is_diagnostic_item(sym::assume_init, method_def_id);
|
||||
then {
|
||||
let mut applicability = Applicability::MachineApplicable;
|
||||
@ -179,7 +179,7 @@ fn check_replace_with_uninit(cx: &LateContext<'_>, src: &Expr<'_>, dest: &Expr<'
|
||||
applicability,
|
||||
);
|
||||
} else if cx.tcx.is_diagnostic_item(sym::mem_zeroed, repl_def_id) &&
|
||||
!cx.tables().expr_ty(src).is_primitive() {
|
||||
!cx.typeck_results().expr_ty(src).is_primitive() {
|
||||
span_lint_and_help(
|
||||
cx,
|
||||
MEM_REPLACE_WITH_UNINIT,
|
||||
|
@ -157,7 +157,7 @@ pub(crate) trait BindInsteadOfMap {
|
||||
|
||||
/// Lint use of `_.and_then(|x| Some(y))` for `Option`s
|
||||
fn lint(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) {
|
||||
if !match_type(cx, cx.tables().expr_ty(&args[0]), Self::TYPE_QPATH) {
|
||||
if !match_type(cx, cx.typeck_results().expr_ty(&args[0]), Self::TYPE_QPATH) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -11,9 +11,9 @@ use rustc_middle::ty::{self, Ty};
|
||||
/// Checks for the `INEFFICIENT_TO_STRING` lint
|
||||
pub fn lint<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>, arg_ty: Ty<'tcx>) {
|
||||
if_chain! {
|
||||
if let Some(to_string_meth_did) = cx.tables().type_dependent_def_id(expr.hir_id);
|
||||
if let Some(to_string_meth_did) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
|
||||
if match_def_path(cx, to_string_meth_did, &paths::TO_STRING_METHOD);
|
||||
if let Some(substs) = cx.tables().node_substs_opt(expr.hir_id);
|
||||
if let Some(substs) = cx.typeck_results().node_substs_opt(expr.hir_id);
|
||||
let self_ty = substs.type_at(0);
|
||||
let (deref_self_ty, deref_count) = walk_ptrs_ty_depth(self_ty);
|
||||
if deref_count >= 1;
|
||||
|
@ -11,7 +11,7 @@ pub fn lint(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[&[hir::Expr<'_>]
|
||||
let arith_lhs = &args[1][0];
|
||||
let arith_rhs = &args[1][1];
|
||||
|
||||
let ty = cx.tables().expr_ty(arith_lhs);
|
||||
let ty = cx.typeck_results().expr_ty(arith_lhs);
|
||||
if !ty.is_integral() {
|
||||
return;
|
||||
}
|
||||
@ -101,7 +101,7 @@ fn is_min_or_max<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>) -> Option<M
|
||||
}
|
||||
}
|
||||
|
||||
let ty = cx.tables().expr_ty(expr);
|
||||
let ty = cx.typeck_results().expr_ty(expr);
|
||||
let ty_str = ty.to_string();
|
||||
|
||||
// `std::T::MAX` `std::T::MIN` constants
|
||||
|
@ -1433,7 +1433,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
|
||||
lint_or_fun_call(cx, expr, *method_span, &method_call.ident.as_str(), args);
|
||||
lint_expect_fun_call(cx, expr, *method_span, &method_call.ident.as_str(), args);
|
||||
|
||||
let self_ty = cx.tables().expr_ty_adjusted(&args[0]);
|
||||
let self_ty = cx.typeck_results().expr_ty_adjusted(&args[0]);
|
||||
if args.len() == 1 && method_call.ident.name == sym!(clone) {
|
||||
lint_clone_on_copy(cx, expr, &args[0], self_ty);
|
||||
lint_clone_on_ref_ptr(cx, expr, &args[0]);
|
||||
@ -1639,7 +1639,7 @@ fn lint_or_fun_call<'tcx>(
|
||||
if let hir::ExprKind::Path(ref qpath) = fun.kind;
|
||||
let path = &*last_path_segment(qpath).ident.as_str();
|
||||
if ["default", "new"].contains(&path);
|
||||
let arg_ty = cx.tables().expr_ty(arg);
|
||||
let arg_ty = cx.typeck_results().expr_ty(arg);
|
||||
if let Some(default_trait_id) = get_trait_def_id(cx, &paths::DEFAULT_TRAIT);
|
||||
if implements_trait(cx, arg_ty, default_trait_id, &[]);
|
||||
|
||||
@ -1679,7 +1679,7 @@ fn lint_or_fun_call<'tcx>(
|
||||
) {
|
||||
if let hir::ExprKind::MethodCall(ref path, _, ref args, _) = &arg.kind {
|
||||
if path.ident.as_str() == "len" {
|
||||
let ty = walk_ptrs_ty(cx.tables().expr_ty(&args[0]));
|
||||
let ty = walk_ptrs_ty(cx.typeck_results().expr_ty(&args[0]));
|
||||
|
||||
match ty.kind {
|
||||
ty::Slice(_) | ty::Array(_, _) => return,
|
||||
@ -1707,7 +1707,7 @@ fn lint_or_fun_call<'tcx>(
|
||||
if { finder.visit_expr(&arg); finder.found };
|
||||
if !contains_return(&arg);
|
||||
|
||||
let self_ty = cx.tables().expr_ty(self_expr);
|
||||
let self_ty = cx.typeck_results().expr_ty(self_expr);
|
||||
|
||||
if let Some(&(_, fn_has_arguments, poss, suffix)) =
|
||||
know_types.iter().find(|&&i| match_type(cx, self_ty, i.0));
|
||||
@ -1786,7 +1786,7 @@ fn lint_expect_fun_call(
|
||||
if call_args.len() == 1
|
||||
&& (method_name.ident.name == sym!(as_str) || method_name.ident.name == sym!(as_ref))
|
||||
&& {
|
||||
let arg_type = cx.tables().expr_ty(&call_args[0]);
|
||||
let arg_type = cx.typeck_results().expr_ty(&call_args[0]);
|
||||
let base_type = walk_ptrs_ty(arg_type);
|
||||
base_type.kind == ty::Str || is_type_diagnostic_item(cx, base_type, sym!(string_type))
|
||||
}
|
||||
@ -1805,7 +1805,7 @@ fn lint_expect_fun_call(
|
||||
// Only `&'static str` or `String` can be used directly in the `panic!`. Other types should be
|
||||
// converted to string.
|
||||
fn requires_to_string(cx: &LateContext<'_>, arg: &hir::Expr<'_>) -> bool {
|
||||
let arg_ty = cx.tables().expr_ty(arg);
|
||||
let arg_ty = cx.typeck_results().expr_ty(arg);
|
||||
if is_type_diagnostic_item(cx, arg_ty, sym!(string_type)) {
|
||||
return false;
|
||||
}
|
||||
@ -1835,15 +1835,16 @@ fn lint_expect_fun_call(
|
||||
false
|
||||
}
|
||||
},
|
||||
hir::ExprKind::MethodCall(..) => cx
|
||||
.tables()
|
||||
hir::ExprKind::MethodCall(..) => {
|
||||
cx.typeck_results()
|
||||
.type_dependent_def_id(arg.hir_id)
|
||||
.map_or(false, |method_id| {
|
||||
matches!(
|
||||
cx.tcx.fn_sig(method_id).output().skip_binder().kind,
|
||||
ty::Ref(ty::ReStatic, ..)
|
||||
)
|
||||
}),
|
||||
})
|
||||
},
|
||||
hir::ExprKind::Path(ref p) => matches!(
|
||||
cx.qpath_res(p, arg.hir_id),
|
||||
hir::def::Res::Def(hir::def::DefKind::Const | hir::def::DefKind::Static, _)
|
||||
@ -1891,7 +1892,7 @@ fn lint_expect_fun_call(
|
||||
return;
|
||||
}
|
||||
|
||||
let receiver_type = cx.tables().expr_ty_adjusted(&args[0]);
|
||||
let receiver_type = cx.typeck_results().expr_ty_adjusted(&args[0]);
|
||||
let closure_args = if is_type_diagnostic_item(cx, receiver_type, sym!(option_type)) {
|
||||
"||"
|
||||
} else if is_type_diagnostic_item(cx, receiver_type, sym!(result_type)) {
|
||||
@ -1957,7 +1958,7 @@ fn lint_expect_fun_call(
|
||||
|
||||
/// Checks for the `CLONE_ON_COPY` lint.
|
||||
fn lint_clone_on_copy(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>, arg_ty: Ty<'_>) {
|
||||
let ty = cx.tables().expr_ty(expr);
|
||||
let ty = cx.typeck_results().expr_ty(expr);
|
||||
if let ty::Ref(_, inner, _) = arg_ty.kind {
|
||||
if let ty::Ref(_, innermost, _) = inner.kind {
|
||||
span_lint_and_then(
|
||||
@ -2005,7 +2006,9 @@ fn lint_clone_on_copy(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Exp
|
||||
// &*x is a nop, &x.clone() is not
|
||||
hir::ExprKind::AddrOf(..) => return,
|
||||
// (*x).func() is useless, x.clone().func() can work in case func borrows mutably
|
||||
hir::ExprKind::MethodCall(_, _, parent_args, _) if expr.hir_id == parent_args[0].hir_id => return,
|
||||
hir::ExprKind::MethodCall(_, _, parent_args, _) if expr.hir_id == parent_args[0].hir_id => {
|
||||
return;
|
||||
},
|
||||
|
||||
_ => {},
|
||||
},
|
||||
@ -2021,11 +2024,11 @@ fn lint_clone_on_copy(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Exp
|
||||
}
|
||||
|
||||
// x.clone() might have dereferenced x, possibly through Deref impls
|
||||
if cx.tables().expr_ty(arg) == ty {
|
||||
if cx.typeck_results().expr_ty(arg) == ty {
|
||||
snip = Some(("try removing the `clone` call", format!("{}", snippet)));
|
||||
} else {
|
||||
let deref_count = cx
|
||||
.tables()
|
||||
.typeck_results()
|
||||
.expr_adjustments(arg)
|
||||
.iter()
|
||||
.filter(|adj| matches!(adj.kind, ty::adjustment::Adjust::Deref(_)))
|
||||
@ -2045,7 +2048,7 @@ fn lint_clone_on_copy(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Exp
|
||||
}
|
||||
|
||||
fn lint_clone_on_ref_ptr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>) {
|
||||
let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(arg));
|
||||
let obj_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(arg));
|
||||
|
||||
if let ty::Adt(_, subst) = obj_ty.kind {
|
||||
let caller_type = if is_type_diagnostic_item(cx, obj_ty, sym::Rc) {
|
||||
@ -2079,7 +2082,7 @@ fn lint_string_extend(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::E
|
||||
let arg = &args[1];
|
||||
if let Some(arglists) = method_chain_args(arg, &["chars"]) {
|
||||
let target = &arglists[0][0];
|
||||
let self_ty = walk_ptrs_ty(cx.tables().expr_ty(target));
|
||||
let self_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(target));
|
||||
let ref_str = if self_ty.kind == ty::Str {
|
||||
""
|
||||
} else if is_type_diagnostic_item(cx, self_ty, sym!(string_type)) {
|
||||
@ -2107,7 +2110,7 @@ fn lint_string_extend(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::E
|
||||
}
|
||||
|
||||
fn lint_extend(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) {
|
||||
let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(&args[0]));
|
||||
let obj_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(&args[0]));
|
||||
if is_type_diagnostic_item(cx, obj_ty, sym!(string_type)) {
|
||||
lint_string_extend(cx, expr, args);
|
||||
}
|
||||
@ -2115,7 +2118,7 @@ fn lint_extend(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>
|
||||
|
||||
fn lint_cstring_as_ptr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, source: &hir::Expr<'_>, unwrap: &hir::Expr<'_>) {
|
||||
if_chain! {
|
||||
let source_type = cx.tables().expr_ty(source);
|
||||
let source_type = cx.typeck_results().expr_ty(source);
|
||||
if let ty::Adt(def, substs) = source_type.kind;
|
||||
if cx.tcx.is_diagnostic_item(sym!(result_type), def.did);
|
||||
if match_type(cx, substs.type_at(0), &paths::CSTRING);
|
||||
@ -2135,8 +2138,8 @@ fn lint_cstring_as_ptr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, source: &hir:
|
||||
|
||||
fn lint_iter_cloned_collect<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, iter_args: &'tcx [hir::Expr<'_>]) {
|
||||
if_chain! {
|
||||
if is_type_diagnostic_item(cx, cx.tables().expr_ty(expr), sym!(vec_type));
|
||||
if let Some(slice) = derefs_to_slice(cx, &iter_args[0], cx.tables().expr_ty(&iter_args[0]));
|
||||
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(expr), sym!(vec_type));
|
||||
if let Some(slice) = derefs_to_slice(cx, &iter_args[0], cx.typeck_results().expr_ty(&iter_args[0]));
|
||||
if let Some(to_replace) = expr.span.trim_start(slice.span.source_callsite());
|
||||
|
||||
then {
|
||||
@ -2243,7 +2246,7 @@ fn lint_unnecessary_fold(cx: &LateContext<'_>, expr: &hir::Expr<'_>, fold_args:
|
||||
|
||||
fn lint_step_by<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, args: &'tcx [hir::Expr<'_>]) {
|
||||
if match_trait_method(cx, expr, &paths::ITERATOR) {
|
||||
if let Some((Constant::Int(0), _)) = constant(cx, cx.tables(), &args[1]) {
|
||||
if let Some((Constant::Int(0), _)) = constant(cx, cx.typeck_results(), &args[1]) {
|
||||
span_lint(
|
||||
cx,
|
||||
ITERATOR_STEP_BY_ZERO,
|
||||
@ -2267,7 +2270,7 @@ fn lint_iter_next<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, iter_
|
||||
parent_expr_opt = get_parent_expr(cx, parent_expr);
|
||||
}
|
||||
|
||||
if derefs_to_slice(cx, caller_expr, cx.tables().expr_ty(caller_expr)).is_some() {
|
||||
if derefs_to_slice(cx, caller_expr, cx.typeck_results().expr_ty(caller_expr)).is_some() {
|
||||
// caller is a Slice
|
||||
if_chain! {
|
||||
if let hir::ExprKind::Index(ref caller_var, ref index_expr) = &caller_expr.kind;
|
||||
@ -2288,8 +2291,11 @@ fn lint_iter_next<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, iter_
|
||||
);
|
||||
}
|
||||
}
|
||||
} else if is_type_diagnostic_item(cx, cx.tables().expr_ty(caller_expr), sym!(vec_type))
|
||||
|| matches!(&walk_ptrs_ty(cx.tables().expr_ty(caller_expr)).kind, ty::Array(_, _))
|
||||
} else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(caller_expr), sym!(vec_type))
|
||||
|| matches!(
|
||||
&walk_ptrs_ty(cx.typeck_results().expr_ty(caller_expr)).kind,
|
||||
ty::Array(_, _)
|
||||
)
|
||||
{
|
||||
// caller is a Vec or an Array
|
||||
let mut applicability = Applicability::MachineApplicable;
|
||||
@ -2316,11 +2322,11 @@ fn lint_iter_nth<'tcx>(
|
||||
) {
|
||||
let iter_args = nth_and_iter_args[1];
|
||||
let mut_str = if is_mut { "_mut" } else { "" };
|
||||
let caller_type = if derefs_to_slice(cx, &iter_args[0], cx.tables().expr_ty(&iter_args[0])).is_some() {
|
||||
let caller_type = if derefs_to_slice(cx, &iter_args[0], cx.typeck_results().expr_ty(&iter_args[0])).is_some() {
|
||||
"slice"
|
||||
} else if is_type_diagnostic_item(cx, cx.tables().expr_ty(&iter_args[0]), sym!(vec_type)) {
|
||||
} else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&iter_args[0]), sym!(vec_type)) {
|
||||
"Vec"
|
||||
} else if is_type_diagnostic_item(cx, cx.tables().expr_ty(&iter_args[0]), sym!(vecdeque_type)) {
|
||||
} else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&iter_args[0]), sym!(vecdeque_type)) {
|
||||
"VecDeque"
|
||||
} else {
|
||||
let nth_args = nth_and_iter_args[0];
|
||||
@ -2341,7 +2347,7 @@ fn lint_iter_nth<'tcx>(
|
||||
fn lint_iter_nth_zero<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, nth_args: &'tcx [hir::Expr<'_>]) {
|
||||
if_chain! {
|
||||
if match_trait_method(cx, expr, &paths::ITERATOR);
|
||||
if let Some((Constant::Int(0), _)) = constant(cx, cx.tables(), &nth_args[1]);
|
||||
if let Some((Constant::Int(0), _)) = constant(cx, cx.typeck_results(), &nth_args[1]);
|
||||
then {
|
||||
let mut applicability = Applicability::MachineApplicable;
|
||||
span_lint_and_sugg(
|
||||
@ -2361,7 +2367,7 @@ fn lint_get_unwrap<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, get_args:
|
||||
// Note: we don't want to lint `get_mut().unwrap` for `HashMap` or `BTreeMap`,
|
||||
// because they do not implement `IndexMut`
|
||||
let mut applicability = Applicability::MachineApplicable;
|
||||
let expr_ty = cx.tables().expr_ty(&get_args[0]);
|
||||
let expr_ty = cx.typeck_results().expr_ty(&get_args[0]);
|
||||
let get_args_str = if get_args.len() > 1 {
|
||||
snippet_with_applicability(cx, get_args[1].span, "_", &mut applicability)
|
||||
} else {
|
||||
@ -2463,7 +2469,7 @@ fn derefs_to_slice<'tcx>(
|
||||
}
|
||||
|
||||
if let hir::ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind {
|
||||
if path.ident.name == sym!(iter) && may_slice(cx, cx.tables().expr_ty(&args[0])) {
|
||||
if path.ident.name == sym!(iter) && may_slice(cx, cx.typeck_results().expr_ty(&args[0])) {
|
||||
Some(&args[0])
|
||||
} else {
|
||||
None
|
||||
@ -2486,7 +2492,7 @@ fn derefs_to_slice<'tcx>(
|
||||
|
||||
/// lint use of `unwrap()` for `Option`s and `Result`s
|
||||
fn lint_unwrap(cx: &LateContext<'_>, expr: &hir::Expr<'_>, unwrap_args: &[hir::Expr<'_>]) {
|
||||
let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(&unwrap_args[0]));
|
||||
let obj_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(&unwrap_args[0]));
|
||||
|
||||
let mess = if is_type_diagnostic_item(cx, obj_ty, sym!(option_type)) {
|
||||
Some((UNWRAP_USED, "an Option", "None"))
|
||||
@ -2514,7 +2520,7 @@ fn lint_unwrap(cx: &LateContext<'_>, expr: &hir::Expr<'_>, unwrap_args: &[hir::E
|
||||
|
||||
/// lint use of `expect()` for `Option`s and `Result`s
|
||||
fn lint_expect(cx: &LateContext<'_>, expr: &hir::Expr<'_>, expect_args: &[hir::Expr<'_>]) {
|
||||
let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(&expect_args[0]));
|
||||
let obj_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(&expect_args[0]));
|
||||
|
||||
let mess = if is_type_diagnostic_item(cx, obj_ty, sym!(option_type)) {
|
||||
Some((EXPECT_USED, "an Option", "None"))
|
||||
@ -2540,8 +2546,8 @@ fn lint_expect(cx: &LateContext<'_>, expr: &hir::Expr<'_>, expect_args: &[hir::E
|
||||
fn lint_ok_expect(cx: &LateContext<'_>, expr: &hir::Expr<'_>, ok_args: &[hir::Expr<'_>]) {
|
||||
if_chain! {
|
||||
// lint if the caller of `ok()` is a `Result`
|
||||
if is_type_diagnostic_item(cx, cx.tables().expr_ty(&ok_args[0]), sym!(result_type));
|
||||
let result_type = cx.tables().expr_ty(&ok_args[0]);
|
||||
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&ok_args[0]), sym!(result_type));
|
||||
let result_type = cx.typeck_results().expr_ty(&ok_args[0]);
|
||||
if let Some(error_type) = get_error_type(cx, result_type);
|
||||
if has_debug_impl(error_type, cx);
|
||||
|
||||
@ -2579,7 +2585,7 @@ fn lint_map_flatten<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, map
|
||||
}
|
||||
|
||||
// lint if caller of `.map().flatten()` is an Option
|
||||
if is_type_diagnostic_item(cx, cx.tables().expr_ty(&map_args[0]), sym!(option_type)) {
|
||||
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&map_args[0]), sym!(option_type)) {
|
||||
let msg = "called `map(..).flatten()` on an `Option`. \
|
||||
This is more succinctly expressed by calling `.and_then(..)`";
|
||||
let self_snippet = snippet(cx, map_args[0].span, "..");
|
||||
@ -2605,8 +2611,8 @@ fn lint_map_unwrap_or_else<'tcx>(
|
||||
unwrap_args: &'tcx [hir::Expr<'_>],
|
||||
) {
|
||||
// lint if the caller of `map()` is an `Option`
|
||||
let is_option = is_type_diagnostic_item(cx, cx.tables().expr_ty(&map_args[0]), sym!(option_type));
|
||||
let is_result = is_type_diagnostic_item(cx, cx.tables().expr_ty(&map_args[0]), sym!(result_type));
|
||||
let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&map_args[0]), sym!(option_type));
|
||||
let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&map_args[0]), sym!(result_type));
|
||||
|
||||
if is_option || is_result {
|
||||
// Don't make a suggestion that may fail to compile due to mutably borrowing
|
||||
@ -2656,8 +2662,8 @@ fn lint_map_unwrap_or_else<'tcx>(
|
||||
|
||||
/// lint use of `_.map_or(None, _)` for `Option`s and `Result`s
|
||||
fn lint_map_or_none<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, map_or_args: &'tcx [hir::Expr<'_>]) {
|
||||
let is_option = is_type_diagnostic_item(cx, cx.tables().expr_ty(&map_or_args[0]), sym!(option_type));
|
||||
let is_result = is_type_diagnostic_item(cx, cx.tables().expr_ty(&map_or_args[0]), sym!(result_type));
|
||||
let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&map_or_args[0]), sym!(option_type));
|
||||
let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&map_or_args[0]), sym!(result_type));
|
||||
|
||||
// There are two variants of this `map_or` lint:
|
||||
// (1) using `map_or` as an adapter from `Result<T,E>` to `Option<T>`
|
||||
@ -3014,7 +3020,7 @@ fn lint_chars_cmp(
|
||||
if segment.ident.name == sym!(Some);
|
||||
then {
|
||||
let mut applicability = Applicability::MachineApplicable;
|
||||
let self_ty = walk_ptrs_ty(cx.tables().expr_ty_adjusted(&args[0][0]));
|
||||
let self_ty = walk_ptrs_ty(cx.typeck_results().expr_ty_adjusted(&args[0][0]));
|
||||
|
||||
if self_ty.kind != ty::Str {
|
||||
return false;
|
||||
@ -3142,8 +3148,8 @@ fn lint_asref(cx: &LateContext<'_>, expr: &hir::Expr<'_>, call_name: &str, as_re
|
||||
if match_trait_method(cx, expr, &paths::ASREF_TRAIT) || match_trait_method(cx, expr, &paths::ASMUT_TRAIT) {
|
||||
// check if the type after `as_ref` or `as_mut` is the same as before
|
||||
let recvr = &as_ref_args[0];
|
||||
let rcv_ty = cx.tables().expr_ty(recvr);
|
||||
let res_ty = cx.tables().expr_ty(expr);
|
||||
let rcv_ty = cx.typeck_results().expr_ty(recvr);
|
||||
let res_ty = cx.typeck_results().expr_ty(expr);
|
||||
let (base_res_ty, res_depth) = walk_ptrs_ty_depth(res_ty);
|
||||
let (base_rcv_ty, rcv_depth) = walk_ptrs_ty_depth(rcv_ty);
|
||||
if base_rcv_ty == base_res_ty && rcv_depth >= res_depth {
|
||||
@ -3212,7 +3218,7 @@ fn lint_maybe_uninit(cx: &LateContext<'_>, expr: &hir::Expr<'_>, outer: &hir::Ex
|
||||
if args.is_empty();
|
||||
if let hir::ExprKind::Path(ref path) = callee.kind;
|
||||
if match_qpath(path, &paths::MEM_MAYBEUNINIT_UNINIT);
|
||||
if !is_maybe_uninit_ty_valid(cx, cx.tables().expr_ty_adjusted(outer));
|
||||
if !is_maybe_uninit_ty_valid(cx, cx.typeck_results().expr_ty_adjusted(outer));
|
||||
then {
|
||||
span_lint(
|
||||
cx,
|
||||
@ -3254,7 +3260,7 @@ fn lint_option_as_ref_deref<'tcx>(
|
||||
) {
|
||||
let same_mutability = |m| (is_mut && m == &hir::Mutability::Mut) || (!is_mut && m == &hir::Mutability::Not);
|
||||
|
||||
let option_ty = cx.tables().expr_ty(&as_ref_args[0]);
|
||||
let option_ty = cx.typeck_results().expr_ty(&as_ref_args[0]);
|
||||
if !is_type_diagnostic_item(cx, option_ty, sym!(option_type)) {
|
||||
return;
|
||||
}
|
||||
@ -3284,10 +3290,10 @@ fn lint_option_as_ref_deref<'tcx>(
|
||||
if let hir::ExprKind::Path(qpath) = &args[0].kind;
|
||||
if let hir::def::Res::Local(local_id) = cx.qpath_res(qpath, args[0].hir_id);
|
||||
if closure_body.params[0].pat.hir_id == local_id;
|
||||
let adj = cx.tables().expr_adjustments(&args[0]).iter().map(|x| &x.kind).collect::<Box<[_]>>();
|
||||
let adj = cx.typeck_results().expr_adjustments(&args[0]).iter().map(|x| &x.kind).collect::<Box<[_]>>();
|
||||
if let [ty::adjustment::Adjust::Deref(None), ty::adjustment::Adjust::Borrow(_)] = *adj;
|
||||
then {
|
||||
let method_did = cx.tables().type_dependent_def_id(closure_expr.hir_id).unwrap();
|
||||
let method_did = cx.typeck_results().type_dependent_def_id(closure_expr.hir_id).unwrap();
|
||||
deref_aliases.iter().any(|path| match_def_path(cx, method_did, path))
|
||||
} else {
|
||||
false
|
||||
@ -3577,7 +3583,7 @@ fn contains_return(expr: &hir::Expr<'_>) -> bool {
|
||||
fn check_pointer_offset(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) {
|
||||
if_chain! {
|
||||
if args.len() == 2;
|
||||
if let ty::RawPtr(ty::TypeAndMut { ref ty, .. }) = cx.tables().expr_ty(&args[0]).kind;
|
||||
if let ty::RawPtr(ty::TypeAndMut { ref ty, .. }) = cx.typeck_results().expr_ty(&args[0]).kind;
|
||||
if let Ok(layout) = cx.tcx.layout_of(cx.param_env.and(ty));
|
||||
if layout.is_zst();
|
||||
then {
|
||||
@ -3587,7 +3593,7 @@ fn check_pointer_offset(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir:
|
||||
}
|
||||
|
||||
fn lint_filetype_is_file(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) {
|
||||
let ty = cx.tables().expr_ty(&args[0]);
|
||||
let ty = cx.typeck_results().expr_ty(&args[0]);
|
||||
|
||||
if !match_type(cx, ty, &paths::FILE_TYPE) {
|
||||
return;
|
||||
|
@ -20,8 +20,8 @@ pub(super) fn lint<'tcx>(
|
||||
map_span: Span,
|
||||
) {
|
||||
// lint if the caller of `map()` is an `Option`
|
||||
if is_type_diagnostic_item(cx, cx.tables().expr_ty(&map_args[0]), sym!(option_type)) {
|
||||
if !is_copy(cx, cx.tables().expr_ty(&unwrap_args[1])) {
|
||||
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&map_args[0]), sym!(option_type)) {
|
||||
if !is_copy(cx, cx.typeck_results().expr_ty(&unwrap_args[1])) {
|
||||
// Do not lint if the `map` argument uses identifiers in the `map`
|
||||
// argument that are also used in the `unwrap_or` argument
|
||||
|
||||
|
@ -36,7 +36,7 @@ impl<'tcx> LateLintPass<'tcx> for MinMaxPass {
|
||||
}
|
||||
match (
|
||||
outer_max,
|
||||
Constant::partial_cmp(cx.tcx, cx.tables().expr_ty(ie), &outer_c, &inner_c),
|
||||
Constant::partial_cmp(cx.tcx, cx.typeck_results().expr_ty(ie), &outer_c, &inner_c),
|
||||
) {
|
||||
(_, None) | (MinMax::Max, Some(Ordering::Less)) | (MinMax::Min, Some(Ordering::Greater)) => (),
|
||||
_ => {
|
||||
@ -62,7 +62,7 @@ enum MinMax {
|
||||
fn min_max<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<(MinMax, Constant, &'a Expr<'a>)> {
|
||||
if let ExprKind::Call(ref path, ref args) = expr.kind {
|
||||
if let ExprKind::Path(ref qpath) = path.kind {
|
||||
cx.tables()
|
||||
cx.typeck_results()
|
||||
.qpath_res(qpath, path.hir_id)
|
||||
.opt_def_id()
|
||||
.and_then(|def_id| {
|
||||
@ -86,10 +86,10 @@ fn fetch_const<'a>(cx: &LateContext<'_>, args: &'a [Expr<'a>], m: MinMax) -> Opt
|
||||
if args.len() != 2 {
|
||||
return None;
|
||||
}
|
||||
constant_simple(cx, cx.tables(), &args[0]).map_or_else(
|
||||
|| constant_simple(cx, cx.tables(), &args[1]).map(|c| (m, c, &args[0])),
|
||||
constant_simple(cx, cx.typeck_results(), &args[0]).map_or_else(
|
||||
|| constant_simple(cx, cx.typeck_results(), &args[1]).map(|c| (m, c, &args[0])),
|
||||
|c| {
|
||||
if constant_simple(cx, cx.tables(), &args[1]).is_none() {
|
||||
if constant_simple(cx, cx.typeck_results(), &args[1]).is_none() {
|
||||
// otherwise ignore
|
||||
Some((m, c, &args[1]))
|
||||
} else {
|
||||
|
@ -496,7 +496,7 @@ fn get_lint_and_message(
|
||||
fn check_nan(cx: &LateContext<'_>, expr: &Expr<'_>, cmp_expr: &Expr<'_>) {
|
||||
if_chain! {
|
||||
if !in_constant(cx, cmp_expr.hir_id);
|
||||
if let Some((value, _)) = constant(cx, cx.tables(), expr);
|
||||
if let Some((value, _)) = constant(cx, cx.typeck_results(), expr);
|
||||
then {
|
||||
let needs_lint = match value {
|
||||
Constant::F32(num) => num.is_nan(),
|
||||
@ -517,7 +517,7 @@ fn check_nan(cx: &LateContext<'_>, expr: &Expr<'_>, cmp_expr: &Expr<'_>) {
|
||||
}
|
||||
|
||||
fn is_named_constant<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> bool {
|
||||
if let Some((_, res)) = constant(cx, cx.tables(), expr) {
|
||||
if let Some((_, res)) = constant(cx, cx.typeck_results(), expr) {
|
||||
res
|
||||
} else {
|
||||
false
|
||||
@ -525,7 +525,7 @@ fn is_named_constant<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> bool
|
||||
}
|
||||
|
||||
fn is_allowed<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> bool {
|
||||
match constant(cx, cx.tables(), expr) {
|
||||
match constant(cx, cx.typeck_results(), expr) {
|
||||
Some((Constant::F32(f), _)) => f == 0.0 || f.is_infinite(),
|
||||
Some((Constant::F64(f), _)) => f == 0.0 || f.is_infinite(),
|
||||
Some((Constant::Vec(vec), _)) => vec.iter().all(|f| match f {
|
||||
@ -557,7 +557,7 @@ fn is_signum(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||
}
|
||||
|
||||
fn is_float(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||
let value = &walk_ptrs_ty(cx.tables().expr_ty(expr)).kind;
|
||||
let value = &walk_ptrs_ty(cx.typeck_results().expr_ty(expr)).kind;
|
||||
|
||||
if let ty::Array(arr_ty, _) = value {
|
||||
return matches!(arr_ty.kind, ty::Float(_));
|
||||
@ -567,7 +567,7 @@ fn is_float(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||
}
|
||||
|
||||
fn is_array(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||
matches!(&walk_ptrs_ty(cx.tables().expr_ty(expr)).kind, ty::Array(_, _))
|
||||
matches!(&walk_ptrs_ty(cx.typeck_results().expr_ty(expr)).kind, ty::Array(_, _))
|
||||
}
|
||||
|
||||
fn check_to_owned(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left: bool) {
|
||||
@ -593,7 +593,7 @@ fn check_to_owned(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left:
|
||||
let (arg_ty, snip) = match expr.kind {
|
||||
ExprKind::MethodCall(.., ref args, _) if args.len() == 1 => {
|
||||
if match_trait_method(cx, expr, &paths::TO_STRING) || match_trait_method(cx, expr, &paths::TO_OWNED) {
|
||||
(cx.tables().expr_ty(&args[0]), snippet(cx, args[0].span, ".."))
|
||||
(cx.typeck_results().expr_ty(&args[0]), snippet(cx, args[0].span, ".."))
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
@ -601,7 +601,7 @@ fn check_to_owned(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left:
|
||||
ExprKind::Call(ref path, ref v) if v.len() == 1 => {
|
||||
if let ExprKind::Path(ref path) = path.kind {
|
||||
if match_qpath(path, &["String", "from_str"]) || match_qpath(path, &["String", "from"]) {
|
||||
(cx.tables().expr_ty(&v[0]), snippet(cx, v[0].span, ".."))
|
||||
(cx.typeck_results().expr_ty(&v[0]), snippet(cx, v[0].span, ".."))
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
@ -612,7 +612,7 @@ fn check_to_owned(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left:
|
||||
_ => return,
|
||||
};
|
||||
|
||||
let other_ty = cx.tables().expr_ty(other);
|
||||
let other_ty = cx.typeck_results().expr_ty(other);
|
||||
|
||||
let without_deref = symmetric_partial_eq(cx, arg_ty, other_ty).unwrap_or_default();
|
||||
let with_deref = arg_ty
|
||||
|
@ -37,8 +37,8 @@ struct OperandInfo {
|
||||
}
|
||||
|
||||
fn analyze_operand(operand: &Expr<'_>, cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<OperandInfo> {
|
||||
match constant(cx, cx.tables(), operand) {
|
||||
Some((Constant::Int(v), _)) => match cx.tables().expr_ty(expr).kind {
|
||||
match constant(cx, cx.typeck_results(), operand) {
|
||||
Some((Constant::Int(v), _)) => match cx.typeck_results().expr_ty(expr).kind {
|
||||
ty::Int(ity) => {
|
||||
let value = sext(cx.tcx, v, ity);
|
||||
return Some(OperandInfo {
|
||||
@ -106,7 +106,7 @@ fn check_const_operands<'tcx>(
|
||||
}
|
||||
|
||||
fn check_non_const_operands<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, operand: &Expr<'_>) {
|
||||
let operand_type = cx.tables().expr_ty(operand);
|
||||
let operand_type = cx.typeck_results().expr_ty(operand);
|
||||
if might_have_negative_value(operand_type) {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
|
@ -76,7 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for MutableKeyType {
|
||||
if let hir::PatKind::Wild = local.pat.kind {
|
||||
return;
|
||||
}
|
||||
check_ty(cx, local.span, cx.tables().pat_ty(&*local.pat));
|
||||
check_ty(cx, local.span, cx.typeck_results().pat_ty(&*local.pat));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> {
|
||||
expr.span,
|
||||
"generally you want to avoid `&mut &mut _` if possible",
|
||||
);
|
||||
} else if let ty::Ref(_, _, hir::Mutability::Mut) = self.cx.tables().expr_ty(e).kind {
|
||||
} else if let ty::Ref(_, _, hir::Mutability::Mut) = self.cx.typeck_results().expr_ty(e).kind {
|
||||
span_lint(
|
||||
self.cx,
|
||||
MUT_MUT,
|
||||
|
@ -37,14 +37,14 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryMutPassed {
|
||||
check_arguments(
|
||||
cx,
|
||||
arguments,
|
||||
cx.tables().expr_ty(fn_expr),
|
||||
cx.typeck_results().expr_ty(fn_expr),
|
||||
&rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_qpath(path, false)),
|
||||
);
|
||||
}
|
||||
},
|
||||
ExprKind::MethodCall(ref path, _, ref arguments, _) => {
|
||||
let def_id = cx.tables().type_dependent_def_id(e.hir_id).unwrap();
|
||||
let substs = cx.tables().node_substs(e.hir_id);
|
||||
let def_id = cx.typeck_results().type_dependent_def_id(e.hir_id).unwrap();
|
||||
let substs = cx.typeck_results().node_substs(e.hir_id);
|
||||
let method_type = cx.tcx.type_of(def_id).subst(cx.tcx, substs);
|
||||
check_arguments(cx, arguments, method_type, &path.ident.as_str())
|
||||
},
|
||||
|
@ -135,7 +135,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MutArgVisitor<'a, 'tcx> {
|
||||
return;
|
||||
},
|
||||
ExprKind::Path(_) => {
|
||||
if let Some(adj) = self.cx.tables().adjustments().get(expr.hir_id) {
|
||||
if let Some(adj) = self.cx.typeck_results().adjustments().get(expr.hir_id) {
|
||||
if adj
|
||||
.iter()
|
||||
.any(|a| matches!(a.target.kind, ty::Ref(_, _, Mutability::Mut)))
|
||||
|
@ -66,7 +66,7 @@ declare_lint_pass!(Mutex => [MUTEX_ATOMIC, MUTEX_INTEGER]);
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for Mutex {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||
let ty = cx.tables().expr_ty(expr);
|
||||
let ty = cx.typeck_results().expr_ty(expr);
|
||||
if let ty::Adt(_, subst) = ty.kind {
|
||||
if is_type_diagnostic_item(cx, ty, sym!(mutex_type)) {
|
||||
let mutex_param = subst.type_at(0);
|
||||
|
@ -229,7 +229,10 @@ fn check_comparison<'a, 'tcx>(
|
||||
use self::Expression::{Bool, Other};
|
||||
|
||||
if let ExprKind::Binary(op, ref left_side, ref right_side) = e.kind {
|
||||
let (l_ty, r_ty) = (cx.tables().expr_ty(left_side), cx.tables().expr_ty(right_side));
|
||||
let (l_ty, r_ty) = (
|
||||
cx.typeck_results().expr_ty(left_side),
|
||||
cx.typeck_results().expr_ty(right_side),
|
||||
);
|
||||
if l_ty.is_bool() && r_ty.is_bool() {
|
||||
let mut applicability = Applicability::MachineApplicable;
|
||||
|
||||
|
@ -46,8 +46,8 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow {
|
||||
return;
|
||||
}
|
||||
if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, ref inner) = e.kind {
|
||||
if let ty::Ref(..) = cx.tables().expr_ty(inner).kind {
|
||||
for adj3 in cx.tables().expr_adjustments(e).windows(3) {
|
||||
if let ty::Ref(..) = cx.typeck_results().expr_ty(inner).kind {
|
||||
for adj3 in cx.typeck_results().expr_adjustments(e).windows(3) {
|
||||
if let [Adjustment {
|
||||
kind: Adjust::Deref(_), ..
|
||||
}, Adjustment {
|
||||
@ -85,7 +85,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow {
|
||||
}
|
||||
if_chain! {
|
||||
if let PatKind::Binding(BindingAnnotation::Ref, .., name, _) = pat.kind;
|
||||
if let ty::Ref(_, tam, mutbl) = cx.tables().pat_ty(pat).kind;
|
||||
if let ty::Ref(_, tam, mutbl) = cx.typeck_results().pat_ty(pat).kind;
|
||||
if mutbl == Mutability::Not;
|
||||
if let ty::Ref(_, _, mutbl) = tam.kind;
|
||||
// only lint immutable refs, because borrowed `&mut T` cannot be moved out
|
||||
|
@ -135,7 +135,8 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
|
||||
} = {
|
||||
let mut ctx = MovedVariablesCtxt::default();
|
||||
cx.tcx.infer_ctxt().enter(|infcx| {
|
||||
euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.tables()).consume_body(body);
|
||||
euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.typeck_results())
|
||||
.consume_body(body);
|
||||
});
|
||||
ctx
|
||||
};
|
||||
|
@ -47,7 +47,7 @@ declare_lint_pass!(NeedlessUpdate => [NEEDLESS_UPDATE]);
|
||||
impl<'tcx> LateLintPass<'tcx> for NeedlessUpdate {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if let ExprKind::Struct(_, ref fields, Some(ref base)) = expr.kind {
|
||||
let ty = cx.tables().expr_ty(expr);
|
||||
let ty = cx.typeck_results().expr_ty(expr);
|
||||
if let ty::Adt(def, _) = ty.kind {
|
||||
if fields.len() == def.non_enum_variant().fields.len() {
|
||||
span_lint(
|
||||
|
@ -56,7 +56,7 @@ impl<'tcx> LateLintPass<'tcx> for NoNegCompOpForPartialOrd {
|
||||
|
||||
then {
|
||||
|
||||
let ty = cx.tables().expr_ty(left);
|
||||
let ty = cx.typeck_results().expr_ty(left);
|
||||
|
||||
let implements_ord = {
|
||||
if let Some(id) = utils::get_trait_def_id(cx, &paths::ORD) {
|
||||
|
@ -44,8 +44,8 @@ impl<'tcx> LateLintPass<'tcx> for NegMultiply {
|
||||
fn check_mul(cx: &LateContext<'_>, span: Span, lit: &Expr<'_>, exp: &Expr<'_>) {
|
||||
if_chain! {
|
||||
if let ExprKind::Lit(ref l) = lit.kind;
|
||||
if let Constant::Int(1) = consts::lit_to_constant(&l.node, cx.tables().expr_ty_opt(lit));
|
||||
if cx.tables().expr_ty(exp).is_integral();
|
||||
if let Constant::Int(1) = consts::lit_to_constant(&l.node, cx.typeck_results().expr_ty_opt(lit));
|
||||
if cx.typeck_results().expr_ty(exp).is_integral();
|
||||
then {
|
||||
span_lint(cx, NEG_MULTIPLY, span, "Negation by multiplying with `-1`");
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ fn has_no_effect(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||
}
|
||||
match expr.kind {
|
||||
ExprKind::Lit(..) | ExprKind::Closure(..) => true,
|
||||
ExprKind::Path(..) => !has_drop(cx, cx.tables().expr_ty(expr)),
|
||||
ExprKind::Path(..) => !has_drop(cx, cx.typeck_results().expr_ty(expr)),
|
||||
ExprKind::Index(ref a, ref b) | ExprKind::Binary(_, ref a, ref b) => {
|
||||
has_no_effect(cx, a) && has_no_effect(cx, b)
|
||||
},
|
||||
@ -61,7 +61,7 @@ fn has_no_effect(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||
| ExprKind::AddrOf(_, _, ref inner)
|
||||
| ExprKind::Box(ref inner) => has_no_effect(cx, inner),
|
||||
ExprKind::Struct(_, ref fields, ref base) => {
|
||||
!has_drop(cx, cx.tables().expr_ty(expr))
|
||||
!has_drop(cx, cx.typeck_results().expr_ty(expr))
|
||||
&& fields.iter().all(|field| has_no_effect(cx, &field.expr))
|
||||
&& base.as_ref().map_or(true, |base| has_no_effect(cx, base))
|
||||
},
|
||||
@ -70,7 +70,8 @@ fn has_no_effect(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||
let res = qpath_res(cx, qpath, callee.hir_id);
|
||||
match res {
|
||||
Res::Def(DefKind::Struct | DefKind::Variant | DefKind::Ctor(..), ..) => {
|
||||
!has_drop(cx, cx.tables().expr_ty(expr)) && args.iter().all(|arg| has_no_effect(cx, arg))
|
||||
!has_drop(cx, cx.typeck_results().expr_ty(expr))
|
||||
&& args.iter().all(|arg| has_no_effect(cx, arg))
|
||||
},
|
||||
_ => false,
|
||||
}
|
||||
@ -137,7 +138,7 @@ fn reduce_expression<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<Vec
|
||||
| ExprKind::AddrOf(_, _, ref inner)
|
||||
| ExprKind::Box(ref inner) => reduce_expression(cx, inner).or_else(|| Some(vec![inner])),
|
||||
ExprKind::Struct(_, ref fields, ref base) => {
|
||||
if has_drop(cx, cx.tables().expr_ty(expr)) {
|
||||
if has_drop(cx, cx.typeck_results().expr_ty(expr)) {
|
||||
None
|
||||
} else {
|
||||
Some(fields.iter().map(|f| &f.expr).chain(base).map(Deref::deref).collect())
|
||||
@ -148,7 +149,7 @@ fn reduce_expression<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<Vec
|
||||
let res = qpath_res(cx, qpath, callee.hir_id);
|
||||
match res {
|
||||
Res::Def(DefKind::Struct | DefKind::Variant | DefKind::Ctor(..), ..)
|
||||
if !has_drop(cx, cx.tables().expr_ty(expr)) =>
|
||||
if !has_drop(cx, cx.typeck_results().expr_ty(expr)) =>
|
||||
{
|
||||
Some(args.iter().collect())
|
||||
},
|
||||
|
@ -237,13 +237,13 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst {
|
||||
}
|
||||
|
||||
let ty = if needs_check_adjustment {
|
||||
let adjustments = cx.tables().expr_adjustments(dereferenced_expr);
|
||||
let adjustments = cx.typeck_results().expr_adjustments(dereferenced_expr);
|
||||
if let Some(i) = adjustments
|
||||
.iter()
|
||||
.position(|adj| matches!(adj.kind, Adjust::Borrow(_) | Adjust::Deref(_)))
|
||||
{
|
||||
if i == 0 {
|
||||
cx.tables().expr_ty(dereferenced_expr)
|
||||
cx.typeck_results().expr_ty(dereferenced_expr)
|
||||
} else {
|
||||
adjustments[i - 1].target
|
||||
}
|
||||
@ -252,7 +252,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
cx.tables().expr_ty(dereferenced_expr)
|
||||
cx.typeck_results().expr_ty(dereferenced_expr)
|
||||
};
|
||||
|
||||
verify_ty_bound(cx, ty, Source::Expr { expr: expr.span });
|
||||
|
@ -30,7 +30,7 @@ declare_lint_pass!(OpenOptions => [NONSENSICAL_OPEN_OPTIONS]);
|
||||
impl<'tcx> LateLintPass<'tcx> for OpenOptions {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
|
||||
if let ExprKind::MethodCall(ref path, _, ref arguments, _) = e.kind {
|
||||
let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(&arguments[0]));
|
||||
let obj_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(&arguments[0]));
|
||||
if path.ident.name == sym!(open) && match_type(cx, obj_ty, &paths::OPEN_OPTIONS) {
|
||||
let mut options = Vec::new();
|
||||
get_open_options(cx, &arguments[0], &mut options);
|
||||
@ -58,7 +58,7 @@ enum OpenOption {
|
||||
|
||||
fn get_open_options(cx: &LateContext<'_>, argument: &Expr<'_>, options: &mut Vec<(OpenOption, Argument)>) {
|
||||
if let ExprKind::MethodCall(ref path, _, ref arguments, _) = argument.kind {
|
||||
let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(&arguments[0]));
|
||||
let obj_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(&arguments[0]));
|
||||
|
||||
// Only proceed if this is a call on some object of type std::fs::OpenOptions
|
||||
if match_type(cx, obj_ty, &paths::OPEN_OPTIONS) && arguments.len() >= 2 {
|
||||
|
@ -72,7 +72,8 @@ declare_lint_pass!(OptionIfLetElse => [OPTION_IF_LET_ELSE]);
|
||||
/// Returns true iff the given expression is the result of calling `Result::ok`
|
||||
fn is_result_ok(cx: &LateContext<'_>, expr: &'_ Expr<'_>) -> bool {
|
||||
if let ExprKind::MethodCall(ref path, _, &[ref receiver], _) = &expr.kind {
|
||||
path.ident.name.to_ident_string() == "ok" && match_type(cx, &cx.tables().expr_ty(&receiver), &paths::RESULT)
|
||||
path.ident.name.to_ident_string() == "ok"
|
||||
&& match_type(cx, &cx.typeck_results().expr_ty(&receiver), &paths::RESULT)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
@ -36,8 +36,8 @@ impl<'tcx> LateLintPass<'tcx> for OverflowCheckConditional {
|
||||
if let ExprKind::Path(QPath::Resolved(_, ref path2)) = ident2.kind;
|
||||
if let ExprKind::Path(QPath::Resolved(_, ref path3)) = second.kind;
|
||||
if eq(&path1.segments[0], &path3.segments[0]) || eq(&path2.segments[0], &path3.segments[0]);
|
||||
if cx.tables().expr_ty(ident1).is_integral();
|
||||
if cx.tables().expr_ty(ident2).is_integral();
|
||||
if cx.typeck_results().expr_ty(ident1).is_integral();
|
||||
if cx.typeck_results().expr_ty(ident2).is_integral();
|
||||
then {
|
||||
if let BinOpKind::Lt = op.node {
|
||||
if let BinOpKind::Add = op2.node {
|
||||
@ -61,8 +61,8 @@ impl<'tcx> LateLintPass<'tcx> for OverflowCheckConditional {
|
||||
if let ExprKind::Path(QPath::Resolved(_, ref path2)) = ident2.kind;
|
||||
if let ExprKind::Path(QPath::Resolved(_, ref path3)) = first.kind;
|
||||
if eq(&path1.segments[0], &path3.segments[0]) || eq(&path2.segments[0], &path3.segments[0]);
|
||||
if cx.tables().expr_ty(ident1).is_integral();
|
||||
if cx.tables().expr_ty(ident2).is_integral();
|
||||
if cx.typeck_results().expr_ty(ident1).is_integral();
|
||||
if cx.typeck_results().expr_ty(ident2).is_integral();
|
||||
then {
|
||||
if let BinOpKind::Gt = op.node {
|
||||
if let BinOpKind::Add = op2.node {
|
||||
|
@ -46,7 +46,7 @@ impl<'tcx> LateLintPass<'tcx> for PathBufPushOverwrite {
|
||||
if let ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind;
|
||||
if path.ident.name == sym!(push);
|
||||
if args.len() == 2;
|
||||
if match_type(cx, walk_ptrs_ty(cx.tables().expr_ty(&args[0])), &paths::PATH_BUF);
|
||||
if match_type(cx, walk_ptrs_ty(cx.typeck_results().expr_ty(&args[0])), &paths::PATH_BUF);
|
||||
if let Some(get_index_arg) = args.get(1);
|
||||
if let ExprKind::Lit(ref lit) = get_index_arg.kind;
|
||||
if let LitKind::Str(ref path_lit, _) = lit.node;
|
||||
|
@ -87,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for PatternTypeMismatch {
|
||||
fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) {
|
||||
if let StmtKind::Local(ref local) = stmt.kind {
|
||||
if let Some(init) = &local.init {
|
||||
if let Some(init_ty) = cx.tables().node_type_opt(init.hir_id) {
|
||||
if let Some(init_ty) = cx.typeck_results().node_type_opt(init.hir_id) {
|
||||
let pat = &local.pat;
|
||||
if in_external_macro(cx.sess(), pat.span) {
|
||||
return;
|
||||
@ -106,7 +106,7 @@ impl<'tcx> LateLintPass<'tcx> for PatternTypeMismatch {
|
||||
if let ExprKind::Match(ref expr, arms, source) = expr.kind {
|
||||
match source {
|
||||
MatchSource::Normal | MatchSource::IfLetDesugar { .. } | MatchSource::WhileLetDesugar => {
|
||||
if let Some(expr_ty) = cx.tables().node_type_opt(expr.hir_id) {
|
||||
if let Some(expr_ty) = cx.typeck_results().node_type_opt(expr.hir_id) {
|
||||
'pattern_checks: for arm in arms {
|
||||
let pat = &arm.pat;
|
||||
if in_external_macro(cx.sess(), pat.span) {
|
||||
@ -132,7 +132,7 @@ impl<'tcx> LateLintPass<'tcx> for PatternTypeMismatch {
|
||||
_: Span,
|
||||
hir_id: HirId,
|
||||
) {
|
||||
if let Some(fn_sig) = cx.tables().liberated_fn_sigs().get(hir_id) {
|
||||
if let Some(fn_sig) = cx.typeck_results().liberated_fn_sigs().get(hir_id) {
|
||||
for (param, ty) in body.params.iter().zip(fn_sig.inputs().iter()) {
|
||||
apply_lint(cx, ¶m.pat, ty, DerefPossible::Impossible);
|
||||
}
|
||||
|
@ -105,12 +105,12 @@ fn expr_as_ptr_offset_call<'tcx>(
|
||||
|
||||
// Is the type of the expression a usize?
|
||||
fn is_expr_ty_usize<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> bool {
|
||||
cx.tables().expr_ty(expr) == cx.tcx.types.usize
|
||||
cx.typeck_results().expr_ty(expr) == cx.tcx.types.usize
|
||||
}
|
||||
|
||||
// Is the type of the expression a raw pointer?
|
||||
fn is_expr_ty_raw_ptr<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> bool {
|
||||
cx.tables().expr_ty(expr).is_unsafe_ptr()
|
||||
cx.typeck_results().expr_ty(expr).is_unsafe_ptr()
|
||||
}
|
||||
|
||||
fn build_suggestion<'tcx>(
|
||||
|
@ -135,13 +135,13 @@ impl QuestionMark {
|
||||
}
|
||||
|
||||
fn moves_by_default(cx: &LateContext<'_>, expression: &Expr<'_>) -> bool {
|
||||
let expr_ty = cx.tables().expr_ty(expression);
|
||||
let expr_ty = cx.typeck_results().expr_ty(expression);
|
||||
|
||||
!expr_ty.is_copy_modulo_regions(cx.tcx.at(expression.span), cx.param_env)
|
||||
}
|
||||
|
||||
fn is_option(cx: &LateContext<'_>, expression: &Expr<'_>) -> bool {
|
||||
let expr_ty = cx.tables().expr_ty(expression);
|
||||
let expr_ty = cx.typeck_results().expr_ty(expression);
|
||||
|
||||
is_type_diagnostic_item(cx, expr_ty, sym!(option_type))
|
||||
}
|
||||
|
@ -280,10 +280,10 @@ fn check_reversed_empty_range(cx: &LateContext<'_>, expr: &Expr<'_>) {
|
||||
|
||||
if_chain! {
|
||||
if let Some(higher::Range { start: Some(start), end: Some(end), limits }) = higher::range(cx, expr);
|
||||
let ty = cx.tables().expr_ty(start);
|
||||
let ty = cx.typeck_results().expr_ty(start);
|
||||
if let ty::Int(_) | ty::Uint(_) = ty.kind;
|
||||
if let Some((start_idx, _)) = constant(cx, cx.tables(), start);
|
||||
if let Some((end_idx, _)) = constant(cx, cx.tables(), end);
|
||||
if let Some((start_idx, _)) = constant(cx, cx.typeck_results(), start);
|
||||
if let Some((end_idx, _)) = constant(cx, cx.typeck_results(), end);
|
||||
if let Some(ordering) = Constant::partial_cmp(cx.tcx, ty, &start_idx, &end_idx);
|
||||
if is_empty_range(limits, ordering);
|
||||
then {
|
||||
|
@ -89,7 +89,7 @@ fn str_span(base: Span, c: regex_syntax::ast::Span, offset: u16) -> Span {
|
||||
}
|
||||
|
||||
fn const_str<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> Option<String> {
|
||||
constant(cx, cx.tables(), e).and_then(|(c, _)| match c {
|
||||
constant(cx, cx.typeck_results(), e).and_then(|(c, _)| match c {
|
||||
Constant::Str(s) => Some(s),
|
||||
_ => None,
|
||||
})
|
||||
|
@ -41,10 +41,10 @@ impl<'tcx> LateLintPass<'tcx> for RepeatOnce {
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind;
|
||||
if path.ident.name == sym!(repeat);
|
||||
if let Some(Constant::Int(1)) = constant_context(cx, cx.tables()).expr(&args[1]);
|
||||
if let Some(Constant::Int(1)) = constant_context(cx, cx.typeck_results()).expr(&args[1]);
|
||||
if !in_macro(args[0].span);
|
||||
then {
|
||||
let ty = walk_ptrs_ty(cx.tables().expr_ty(&args[0]));
|
||||
let ty = walk_ptrs_ty(cx.typeck_results().expr_ty(&args[0]));
|
||||
if ty.is_str() {
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
|
@ -164,7 +164,7 @@ fn check_local<'tcx>(cx: &LateContext<'tcx>, local: &'tcx Local<'_>, bindings: &
|
||||
}
|
||||
|
||||
fn is_binding(cx: &LateContext<'_>, pat_id: HirId) -> bool {
|
||||
let var_ty = cx.tables().node_type_opt(pat_id);
|
||||
let var_ty = cx.typeck_results().node_type_opt(pat_id);
|
||||
var_ty.map_or(false, |var_ty| !matches!(var_ty.kind, ty::Adt(..)))
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,7 @@ impl<'tcx> LateLintPass<'tcx> for StringAdd {
|
||||
}
|
||||
|
||||
fn is_string(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
|
||||
is_type_diagnostic_item(cx, walk_ptrs_ty(cx.tables().expr_ty(e)), sym!(string_type))
|
||||
is_type_diagnostic_item(cx, walk_ptrs_ty(cx.typeck_results().expr_ty(e)), sym!(string_type))
|
||||
}
|
||||
|
||||
fn is_add(cx: &LateContext<'_>, src: &Expr<'_>, target: &Expr<'_>) -> bool {
|
||||
|
@ -194,7 +194,7 @@ fn check_for_slice<'a>(cx: &LateContext<'_>, lhs1: &'a Expr<'_>, lhs2: &'a Expr<
|
||||
if let ExprKind::Index(ref lhs1, ref idx1) = lhs1.kind {
|
||||
if let ExprKind::Index(ref lhs2, ref idx2) = lhs2.kind {
|
||||
if SpanlessEq::new(cx).ignore_fn().eq_expr(lhs1, lhs2) {
|
||||
let ty = walk_ptrs_ty(cx.tables().expr_ty(lhs1));
|
||||
let ty = walk_ptrs_ty(cx.typeck_results().expr_ty(lhs1));
|
||||
|
||||
if matches!(ty.kind, ty::Slice(_))
|
||||
|| matches!(ty.kind, ty::Array(_, _))
|
||||
|
@ -43,7 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for ToDigitIsSome {
|
||||
if_chain! {
|
||||
if let [char_arg, radix_arg] = &**to_digit_args;
|
||||
if to_digits_path.ident.name.as_str() == "to_digit";
|
||||
let char_arg_ty = cx.tables().expr_ty_adjusted(char_arg);
|
||||
let char_arg_ty = cx.typeck_results().expr_ty_adjusted(char_arg);
|
||||
if char_arg_ty.kind == ty::Char;
|
||||
then {
|
||||
Some((true, char_arg, radix_arg))
|
||||
|
@ -302,8 +302,8 @@ impl<'tcx> LateLintPass<'tcx> for Transmute {
|
||||
if let Some(def_id) = cx.qpath_res(qpath, path_expr.hir_id).opt_def_id();
|
||||
if match_def_path(cx, def_id, &paths::TRANSMUTE);
|
||||
then {
|
||||
let from_ty = cx.tables().expr_ty(&args[0]);
|
||||
let to_ty = cx.tables().expr_ty(e);
|
||||
let from_ty = cx.typeck_results().expr_ty(&args[0]);
|
||||
let to_ty = cx.typeck_results().expr_ty(e);
|
||||
|
||||
match (&from_ty.kind, &to_ty.kind) {
|
||||
_ if from_ty == to_ty => span_lint(
|
||||
|
@ -44,7 +44,7 @@ impl<'tcx> LateLintPass<'tcx> for TransmutingNull {
|
||||
then {
|
||||
|
||||
// Catching transmute over constants that resolve to `null`.
|
||||
let mut const_eval_context = constant_context(cx, cx.tables());
|
||||
let mut const_eval_context = constant_context(cx, cx.typeck_results());
|
||||
if_chain! {
|
||||
if let ExprKind::Path(ref _qpath) = args[0].kind;
|
||||
let x = const_eval_context.expr(&args[0]);
|
||||
|
@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for TryErr {
|
||||
if let Some(return_type) = find_err_return_type(cx, &expr.kind);
|
||||
|
||||
then {
|
||||
let err_type = cx.tables().expr_ty(err_arg);
|
||||
let err_type = cx.typeck_results().expr_ty(err_arg);
|
||||
let origin_snippet = if err_arg.span.from_expansion() {
|
||||
snippet_with_macro_callsite(cx, err_arg.span, "_")
|
||||
} else {
|
||||
@ -114,7 +114,7 @@ fn find_err_return_type_arm<'tcx>(cx: &LateContext<'tcx>, arm: &'tcx Arm<'_>) ->
|
||||
if match_qpath(from_error_fn, &paths::TRY_FROM_ERROR);
|
||||
if let Some(from_error_arg) = from_error_args.get(0);
|
||||
then {
|
||||
Some(cx.tables().expr_ty(from_error_arg))
|
||||
Some(cx.typeck_results().expr_ty(from_error_arg))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ use rustc_hir::{
|
||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||
use rustc_middle::hir::map::Map;
|
||||
use rustc_middle::lint::in_external_macro;
|
||||
use rustc_middle::ty::{self, InferTy, Ty, TyCtxt, TyS, TypeckTables};
|
||||
use rustc_middle::ty::{self, InferTy, Ty, TyCtxt, TyS, TypeckResults};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
|
||||
use rustc_span::hygiene::{ExpnKind, MacroKind};
|
||||
use rustc_span::source_map::Span;
|
||||
@ -595,7 +595,7 @@ declare_lint_pass!(LetUnitValue => [LET_UNIT_VALUE]);
|
||||
impl<'tcx> LateLintPass<'tcx> for LetUnitValue {
|
||||
fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) {
|
||||
if let StmtKind::Local(ref local) = stmt.kind {
|
||||
if is_unit(cx.tables().pat_ty(&local.pat)) {
|
||||
if is_unit(cx.typeck_results().pat_ty(&local.pat)) {
|
||||
if in_external_macro(cx.sess(), stmt.span) || local.pat.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
@ -680,7 +680,7 @@ impl<'tcx> LateLintPass<'tcx> for UnitCmp {
|
||||
if let ExpnKind::Macro(MacroKind::Bang, symbol) = callee.kind {
|
||||
if let ExprKind::Binary(ref cmp, ref left, _) = expr.kind {
|
||||
let op = cmp.node;
|
||||
if op.is_comparison() && is_unit(cx.tables().expr_ty(left)) {
|
||||
if op.is_comparison() && is_unit(cx.typeck_results().expr_ty(left)) {
|
||||
let result = match &*symbol.as_str() {
|
||||
"assert_eq" | "debug_assert_eq" => "succeed",
|
||||
"assert_ne" | "debug_assert_ne" => "fail",
|
||||
@ -704,7 +704,7 @@ impl<'tcx> LateLintPass<'tcx> for UnitCmp {
|
||||
}
|
||||
if let ExprKind::Binary(ref cmp, ref left, _) = expr.kind {
|
||||
let op = cmp.node;
|
||||
if op.is_comparison() && is_unit(cx.tables().expr_ty(left)) {
|
||||
if op.is_comparison() && is_unit(cx.typeck_results().expr_ty(left)) {
|
||||
let result = match op {
|
||||
BinOpKind::Eq | BinOpKind::Le | BinOpKind::Ge => "true",
|
||||
_ => "false",
|
||||
@ -774,7 +774,7 @@ impl<'tcx> LateLintPass<'tcx> for UnitArg {
|
||||
let args_to_recover = args
|
||||
.iter()
|
||||
.filter(|arg| {
|
||||
if is_unit(cx.tables().expr_ty(arg)) && !is_unit_literal(arg) {
|
||||
if is_unit(cx.typeck_results().expr_ty(arg)) && !is_unit_literal(arg) {
|
||||
!matches!(&arg.kind, ExprKind::Match(.., MatchSource::TryDesugar))
|
||||
} else {
|
||||
false
|
||||
@ -1232,7 +1232,7 @@ fn check_loss_of_sign(cx: &LateContext<'_>, expr: &Expr<'_>, op: &Expr<'_>, cast
|
||||
}
|
||||
|
||||
// don't lint for positive constants
|
||||
let const_val = constant(cx, &cx.tables(), op);
|
||||
let const_val = constant(cx, &cx.typeck_results(), op);
|
||||
if_chain! {
|
||||
if let Some((const_val, _)) = const_val;
|
||||
if let Constant::Int(n) = const_val;
|
||||
@ -1398,7 +1398,7 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
|
||||
return;
|
||||
}
|
||||
if let ExprKind::Cast(ref ex, _) = expr.kind {
|
||||
let (cast_from, cast_to) = (cx.tables().expr_ty(ex), cx.tables().expr_ty(expr));
|
||||
let (cast_from, cast_to) = (cx.typeck_results().expr_ty(ex), cx.typeck_results().expr_ty(expr));
|
||||
lint_fn_to_numeric_cast(cx, expr, ex, cast_from, cast_to);
|
||||
if let ExprKind::Lit(ref lit) = ex.kind {
|
||||
if_chain! {
|
||||
@ -1786,7 +1786,7 @@ impl<'tcx> LateLintPass<'tcx> for CharLitAsU8 {
|
||||
if let ExprKind::Cast(e, _) = &expr.kind;
|
||||
if let ExprKind::Lit(l) = &e.kind;
|
||||
if let LitKind::Char(c) = l.node;
|
||||
if ty::Uint(UintTy::U8) == cx.tables().expr_ty(expr).kind;
|
||||
if ty::Uint(UintTy::U8) == cx.typeck_results().expr_ty(expr).kind;
|
||||
then {
|
||||
let mut applicability = Applicability::MachineApplicable;
|
||||
let snippet = snippet_with_applicability(cx, e.span, "'x'", &mut applicability);
|
||||
@ -1862,8 +1862,8 @@ enum AbsurdComparisonResult {
|
||||
|
||||
fn is_cast_between_fixed_and_target<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> bool {
|
||||
if let ExprKind::Cast(ref cast_exp, _) = expr.kind {
|
||||
let precast_ty = cx.tables().expr_ty(cast_exp);
|
||||
let cast_ty = cx.tables().expr_ty(expr);
|
||||
let precast_ty = cx.typeck_results().expr_ty(cast_exp);
|
||||
let cast_ty = cx.typeck_results().expr_ty(expr);
|
||||
|
||||
return is_isize_or_usize(precast_ty) != is_isize_or_usize(cast_ty);
|
||||
}
|
||||
@ -1883,7 +1883,7 @@ fn detect_absurd_comparison<'tcx>(
|
||||
|
||||
// absurd comparison only makes sense on primitive types
|
||||
// primitive types don't implement comparison operators with each other
|
||||
if cx.tables().expr_ty(lhs) != cx.tables().expr_ty(rhs) {
|
||||
if cx.typeck_results().expr_ty(lhs) != cx.typeck_results().expr_ty(rhs) {
|
||||
return None;
|
||||
}
|
||||
|
||||
@ -1921,9 +1921,9 @@ fn detect_absurd_comparison<'tcx>(
|
||||
fn detect_extreme_expr<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<ExtremeExpr<'tcx>> {
|
||||
use crate::types::ExtremeType::{Maximum, Minimum};
|
||||
|
||||
let ty = cx.tables().expr_ty(expr);
|
||||
let ty = cx.typeck_results().expr_ty(expr);
|
||||
|
||||
let cv = constant(cx, cx.tables(), expr)?.0;
|
||||
let cv = constant(cx, cx.typeck_results(), expr)?.0;
|
||||
|
||||
let which = match (&ty.kind, cv) {
|
||||
(&ty::Bool, Constant::Bool(false)) | (&ty::Uint(_), Constant::Int(0)) => Minimum,
|
||||
@ -2053,8 +2053,8 @@ impl Ord for FullInt {
|
||||
|
||||
fn numeric_cast_precast_bounds<'a>(cx: &LateContext<'_>, expr: &'a Expr<'_>) -> Option<(FullInt, FullInt)> {
|
||||
if let ExprKind::Cast(ref cast_exp, _) = expr.kind {
|
||||
let pre_cast_ty = cx.tables().expr_ty(cast_exp);
|
||||
let cast_ty = cx.tables().expr_ty(expr);
|
||||
let pre_cast_ty = cx.typeck_results().expr_ty(cast_exp);
|
||||
let cast_ty = cx.typeck_results().expr_ty(expr);
|
||||
// if it's a cast from i32 to u32 wrapping will invalidate all these checks
|
||||
if cx.layout_of(pre_cast_ty).ok().map(|l| l.size) == cx.layout_of(cast_ty).ok().map(|l| l.size) {
|
||||
return None;
|
||||
@ -2084,9 +2084,9 @@ fn numeric_cast_precast_bounds<'a>(cx: &LateContext<'_>, expr: &'a Expr<'_>) ->
|
||||
}
|
||||
|
||||
fn node_as_const_fullint<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<FullInt> {
|
||||
let val = constant(cx, cx.tables(), expr)?.0;
|
||||
let val = constant(cx, cx.typeck_results(), expr)?.0;
|
||||
if let Constant::Int(const_int) = val {
|
||||
match cx.tables().expr_ty(expr).kind {
|
||||
match cx.typeck_results().expr_ty(expr).kind {
|
||||
ty::Int(ity) => Some(FullInt::S(sext(cx.tcx, const_int, ity))),
|
||||
ty::Uint(_) => Some(FullInt::U(const_int)),
|
||||
_ => None,
|
||||
@ -2472,7 +2472,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ImplicitHasherTypeVisitor<'a, 'tcx> {
|
||||
/// Looks for default-hasher-dependent constructors like `HashMap::new`.
|
||||
struct ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> {
|
||||
cx: &'a LateContext<'tcx>,
|
||||
maybe_typeck_tables: Option<&'tcx TypeckTables<'tcx>>,
|
||||
maybe_typeck_results: Option<&'tcx TypeckResults<'tcx>>,
|
||||
target: &'b ImplicitHasherType<'tcx>,
|
||||
suggestions: BTreeMap<Span, String>,
|
||||
}
|
||||
@ -2481,7 +2481,7 @@ impl<'a, 'b, 'tcx> ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> {
|
||||
fn new(cx: &'a LateContext<'tcx>, target: &'b ImplicitHasherType<'tcx>) -> Self {
|
||||
Self {
|
||||
cx,
|
||||
maybe_typeck_tables: cx.maybe_typeck_tables(),
|
||||
maybe_typeck_results: cx.maybe_typeck_results(),
|
||||
target,
|
||||
suggestions: BTreeMap::new(),
|
||||
}
|
||||
@ -2492,9 +2492,9 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 't
|
||||
type Map = Map<'tcx>;
|
||||
|
||||
fn visit_body(&mut self, body: &'tcx Body<'_>) {
|
||||
let old_maybe_typeck_tables = self.maybe_typeck_tables.replace(self.cx.tcx.body_tables(body.id()));
|
||||
let old_maybe_typeck_results = self.maybe_typeck_results.replace(self.cx.tcx.typeck_body(body.id()));
|
||||
walk_body(self, body);
|
||||
self.maybe_typeck_tables = old_maybe_typeck_tables;
|
||||
self.maybe_typeck_results = old_maybe_typeck_results;
|
||||
}
|
||||
|
||||
fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
|
||||
@ -2503,7 +2503,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 't
|
||||
if let ExprKind::Path(QPath::TypeRelative(ref ty, ref method)) = fun.kind;
|
||||
if let TyKind::Path(QPath::Resolved(None, ty_path)) = ty.kind;
|
||||
then {
|
||||
if !TyS::same_type(self.target.ty(), self.maybe_typeck_tables.unwrap().expr_ty(e)) {
|
||||
if !TyS::same_type(self.target.ty(), self.maybe_typeck_results.unwrap().expr_ty(e)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -2589,7 +2589,7 @@ impl<'tcx> LateLintPass<'tcx> for RefToMut {
|
||||
if let TyKind::Ptr(MutTy { mutbl: Mutability::Mut, .. }) = t.kind;
|
||||
if let ExprKind::Cast(e, t) = &e.kind;
|
||||
if let TyKind::Ptr(MutTy { mutbl: Mutability::Not, .. }) = t.kind;
|
||||
if let ty::Ref(..) = cx.tables().node_type(e.hir_id).kind;
|
||||
if let ty::Ref(..) = cx.typeck_results().node_type(e.hir_id).kind;
|
||||
then {
|
||||
span_lint(
|
||||
cx,
|
||||
|
@ -65,14 +65,14 @@ impl LateLintPass<'_> for UnnamedAddress {
|
||||
}
|
||||
|
||||
fn is_trait_ptr(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||
match cx.tables().expr_ty_adjusted(expr).kind {
|
||||
match cx.typeck_results().expr_ty_adjusted(expr).kind {
|
||||
ty::RawPtr(ty::TypeAndMut { ty, .. }) => ty.is_trait(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn is_fn_def(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||
matches!(cx.tables().expr_ty(expr).kind, ty::FnDef(..))
|
||||
matches!(cx.typeck_results().expr_ty(expr).kind, ty::FnDef(..))
|
||||
}
|
||||
|
||||
if_chain! {
|
||||
@ -98,7 +98,7 @@ impl LateLintPass<'_> for UnnamedAddress {
|
||||
if match_def_path(cx, def_id, &paths::PTR_EQ) ||
|
||||
match_def_path(cx, def_id, &paths::RC_PTR_EQ) ||
|
||||
match_def_path(cx, def_id, &paths::ARC_PTR_EQ);
|
||||
let ty_param = cx.tables().node_substs(func.hir_id).type_at(0);
|
||||
let ty_param = cx.typeck_results().node_substs(func.hir_id).type_at(0);
|
||||
if ty_param.is_trait();
|
||||
then {
|
||||
span_lint_and_help(
|
||||
@ -115,8 +115,8 @@ impl LateLintPass<'_> for UnnamedAddress {
|
||||
if_chain! {
|
||||
if let ExprKind::Binary(binop, ref left, ref right) = expr.kind;
|
||||
if is_comparison(binop.node);
|
||||
if cx.tables().expr_ty_adjusted(left).is_fn_ptr() &&
|
||||
cx.tables().expr_ty_adjusted(right).is_fn_ptr();
|
||||
if cx.typeck_results().expr_ty_adjusted(left).is_fn_ptr() &&
|
||||
cx.typeck_results().expr_ty_adjusted(right).is_fn_ptr();
|
||||
if is_fn_def(cx, left) || is_fn_def(cx, right);
|
||||
then {
|
||||
span_lint(
|
||||
|
@ -176,7 +176,7 @@ fn detect_lint(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<LintTrigger> {
|
||||
if let name = name_ident.ident.name.to_ident_string();
|
||||
if name == "sort_by" || name == "sort_unstable_by";
|
||||
if let [vec, Expr { kind: ExprKind::Closure(_, _, closure_body_id, _, _), .. }] = args;
|
||||
if utils::match_type(cx, &cx.tables().expr_ty(vec), &paths::VEC);
|
||||
if utils::match_type(cx, &cx.typeck_results().expr_ty(vec), &paths::VEC);
|
||||
if let closure_body = cx.tcx.hir().body(*closure_body_id);
|
||||
if let &[
|
||||
Param { pat: Pat { kind: PatKind::Binding(_, _, left_ident, _), .. }, ..},
|
||||
|
@ -114,7 +114,7 @@ fn collect_unwrap_info<'tcx>(
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(method_name, _, args, _) = &expr.kind;
|
||||
if let ExprKind::Path(QPath::Resolved(None, path)) = &args[0].kind;
|
||||
let ty = cx.tables().expr_ty(&args[0]);
|
||||
let ty = cx.typeck_results().expr_ty(&args[0]);
|
||||
let name = method_name.ident.as_str();
|
||||
if is_relevant_option_call(cx, ty, &name) || is_relevant_result_call(cx, ty, &name);
|
||||
then {
|
||||
|
@ -63,8 +63,8 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
|
||||
|
||||
ExprKind::MethodCall(ref name, .., ref args, _) => {
|
||||
if match_trait_method(cx, e, &paths::INTO) && &*name.ident.as_str() == "into" {
|
||||
let a = cx.tables().expr_ty(e);
|
||||
let b = cx.tables().expr_ty(&args[0]);
|
||||
let a = cx.typeck_results().expr_ty(e);
|
||||
let b = cx.typeck_results().expr_ty(&args[0]);
|
||||
if TyS::same_type(a, b) {
|
||||
let sugg = snippet_with_macro_callsite(cx, args[0].span, "<expr>").to_string();
|
||||
span_lint_and_sugg(
|
||||
@ -79,8 +79,8 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
|
||||
}
|
||||
}
|
||||
if match_trait_method(cx, e, &paths::INTO_ITERATOR) && &*name.ident.as_str() == "into_iter" {
|
||||
let a = cx.tables().expr_ty(e);
|
||||
let b = cx.tables().expr_ty(&args[0]);
|
||||
let a = cx.typeck_results().expr_ty(e);
|
||||
let b = cx.typeck_results().expr_ty(&args[0]);
|
||||
if TyS::same_type(a, b) {
|
||||
let sugg = snippet(cx, args[0].span, "<expr>").into_owned();
|
||||
span_lint_and_sugg(
|
||||
@ -96,8 +96,8 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
|
||||
}
|
||||
if match_trait_method(cx, e, &paths::TRY_INTO_TRAIT) && &*name.ident.as_str() == "try_into" {
|
||||
if_chain! {
|
||||
let a = cx.tables().expr_ty(e);
|
||||
let b = cx.tables().expr_ty(&args[0]);
|
||||
let a = cx.typeck_results().expr_ty(e);
|
||||
let b = cx.typeck_results().expr_ty(&args[0]);
|
||||
if is_type_diagnostic_item(cx, a, sym!(result_type));
|
||||
if let ty::Adt(_, substs) = a.kind;
|
||||
if let Some(a_type) = substs.types().next();
|
||||
@ -122,8 +122,8 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
|
||||
if args.len() == 1;
|
||||
if let ExprKind::Path(ref qpath) = path.kind;
|
||||
if let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id();
|
||||
let a = cx.tables().expr_ty(e);
|
||||
let b = cx.tables().expr_ty(&args[0]);
|
||||
let a = cx.typeck_results().expr_ty(e);
|
||||
let b = cx.typeck_results().expr_ty(&args[0]);
|
||||
|
||||
then {
|
||||
if_chain! {
|
||||
|
@ -56,7 +56,7 @@ pub fn range<'a, 'tcx>(cx: &LateContext<'tcx>, expr: &'a hir::Expr<'_>) -> Optio
|
||||
Some(expr)
|
||||
}
|
||||
|
||||
let def_path = match cx.tables().expr_ty(expr).kind {
|
||||
let def_path = match cx.typeck_results().expr_ty(expr).kind {
|
||||
ty::Adt(def, _) => cx.tcx.def_path(def.did),
|
||||
_ => return None,
|
||||
};
|
||||
|
@ -9,7 +9,7 @@ use rustc_hir::{
|
||||
};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::ich::StableHashingContextProvider;
|
||||
use rustc_middle::ty::TypeckTables;
|
||||
use rustc_middle::ty::TypeckResults;
|
||||
use rustc_span::Symbol;
|
||||
use std::hash::Hash;
|
||||
|
||||
@ -22,7 +22,7 @@ use std::hash::Hash;
|
||||
pub struct SpanlessEq<'a, 'tcx> {
|
||||
/// Context used to evaluate constant expressions.
|
||||
cx: &'a LateContext<'tcx>,
|
||||
maybe_typeck_tables: Option<&'tcx TypeckTables<'tcx>>,
|
||||
maybe_typeck_results: Option<&'tcx TypeckResults<'tcx>>,
|
||||
/// If is true, never consider as equal expressions containing function
|
||||
/// calls.
|
||||
ignore_fn: bool,
|
||||
@ -32,7 +32,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
|
||||
pub fn new(cx: &'a LateContext<'tcx>) -> Self {
|
||||
Self {
|
||||
cx,
|
||||
maybe_typeck_tables: cx.maybe_typeck_tables(),
|
||||
maybe_typeck_results: cx.maybe_typeck_results(),
|
||||
ignore_fn: false,
|
||||
}
|
||||
}
|
||||
@ -71,10 +71,10 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
|
||||
return false;
|
||||
}
|
||||
|
||||
if let Some(tables) = self.maybe_typeck_tables {
|
||||
if let Some(typeck_results) = self.maybe_typeck_results {
|
||||
if let (Some(l), Some(r)) = (
|
||||
constant_simple(self.cx, tables, left),
|
||||
constant_simple(self.cx, tables, right),
|
||||
constant_simple(self.cx, typeck_results, left),
|
||||
constant_simple(self.cx, typeck_results, right),
|
||||
) {
|
||||
if l == r {
|
||||
return true;
|
||||
@ -137,9 +137,9 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
|
||||
!self.ignore_fn && self.eq_path_segment(l_path, r_path) && self.eq_exprs(l_args, r_args)
|
||||
},
|
||||
(&ExprKind::Repeat(ref le, ref ll_id), &ExprKind::Repeat(ref re, ref rl_id)) => {
|
||||
let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(ll_id.body));
|
||||
let mut celcx = constant_context(self.cx, self.cx.tcx.typeck_body(ll_id.body));
|
||||
let ll = celcx.expr(&self.cx.tcx.hir().body(ll_id.body).value);
|
||||
let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(rl_id.body));
|
||||
let mut celcx = constant_context(self.cx, self.cx.tcx.typeck_body(rl_id.body));
|
||||
let rl = celcx.expr(&self.cx.tcx.hir().body(rl_id.body).value);
|
||||
|
||||
self.eq_expr(le, re) && ll == rl
|
||||
@ -272,18 +272,18 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
|
||||
match (left, right) {
|
||||
(&TyKind::Slice(ref l_vec), &TyKind::Slice(ref r_vec)) => self.eq_ty(l_vec, r_vec),
|
||||
(&TyKind::Array(ref lt, ref ll_id), &TyKind::Array(ref rt, ref rl_id)) => {
|
||||
let old_maybe_typeck_tables = self.maybe_typeck_tables;
|
||||
let old_maybe_typeck_results = self.maybe_typeck_results;
|
||||
|
||||
let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(ll_id.body));
|
||||
self.maybe_typeck_tables = Some(self.cx.tcx.body_tables(ll_id.body));
|
||||
let mut celcx = constant_context(self.cx, self.cx.tcx.typeck_body(ll_id.body));
|
||||
self.maybe_typeck_results = Some(self.cx.tcx.typeck_body(ll_id.body));
|
||||
let ll = celcx.expr(&self.cx.tcx.hir().body(ll_id.body).value);
|
||||
|
||||
let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(rl_id.body));
|
||||
self.maybe_typeck_tables = Some(self.cx.tcx.body_tables(rl_id.body));
|
||||
let mut celcx = constant_context(self.cx, self.cx.tcx.typeck_body(rl_id.body));
|
||||
self.maybe_typeck_results = Some(self.cx.tcx.typeck_body(rl_id.body));
|
||||
let rl = celcx.expr(&self.cx.tcx.hir().body(rl_id.body).value);
|
||||
|
||||
let eq_ty = self.eq_ty(lt, rt);
|
||||
self.maybe_typeck_tables = old_maybe_typeck_tables;
|
||||
self.maybe_typeck_results = old_maybe_typeck_results;
|
||||
eq_ty && ll == rl
|
||||
},
|
||||
(&TyKind::Ptr(ref l_mut), &TyKind::Ptr(ref r_mut)) => {
|
||||
@ -348,7 +348,7 @@ pub fn over<X>(left: &[X], right: &[X], mut eq_fn: impl FnMut(&X, &X) -> bool) -
|
||||
pub struct SpanlessHash<'a, 'tcx> {
|
||||
/// Context used to evaluate constant expressions.
|
||||
cx: &'a LateContext<'tcx>,
|
||||
maybe_typeck_tables: Option<&'tcx TypeckTables<'tcx>>,
|
||||
maybe_typeck_results: Option<&'tcx TypeckResults<'tcx>>,
|
||||
s: StableHasher,
|
||||
}
|
||||
|
||||
@ -356,7 +356,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
||||
pub fn new(cx: &'a LateContext<'tcx>) -> Self {
|
||||
Self {
|
||||
cx,
|
||||
maybe_typeck_tables: cx.maybe_typeck_tables(),
|
||||
maybe_typeck_results: cx.maybe_typeck_results(),
|
||||
s: StableHasher::new(),
|
||||
}
|
||||
}
|
||||
@ -386,8 +386,8 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
||||
#[allow(clippy::many_single_char_names, clippy::too_many_lines)]
|
||||
pub fn hash_expr(&mut self, e: &Expr<'_>) {
|
||||
let simple_const = self
|
||||
.maybe_typeck_tables
|
||||
.and_then(|tables| constant_simple(self.cx, tables, e));
|
||||
.maybe_typeck_results
|
||||
.and_then(|typeck_results| constant_simple(self.cx, typeck_results, e));
|
||||
|
||||
// const hashing may result in the same hash as some unrelated node, so add a sort of
|
||||
// discriminant depending on which path we're choosing next
|
||||
@ -458,7 +458,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
||||
CaptureBy::Ref => 1,
|
||||
}
|
||||
.hash(&mut self.s);
|
||||
// closures inherit TypeckTables
|
||||
// closures inherit TypeckResults
|
||||
self.hash_expr(&self.cx.tcx.hir().body(eid).value);
|
||||
},
|
||||
ExprKind::Field(ref e, ref f) => {
|
||||
@ -602,7 +602,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
||||
self.hash_name(path.ident.name);
|
||||
},
|
||||
}
|
||||
// self.maybe_typeck_tables.unwrap().qpath_res(p, id).hash(&mut self.s);
|
||||
// self.maybe_typeck_results.unwrap().qpath_res(p, id).hash(&mut self.s);
|
||||
}
|
||||
|
||||
pub fn hash_path(&mut self, p: &Path<'_>) {
|
||||
@ -725,10 +725,10 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
||||
}
|
||||
|
||||
pub fn hash_body(&mut self, body_id: BodyId) {
|
||||
// swap out TypeckTables when hashing a body
|
||||
let old_maybe_typeck_tables = self.maybe_typeck_tables.replace(self.cx.tcx.body_tables(body_id));
|
||||
// swap out TypeckResults when hashing a body
|
||||
let old_maybe_typeck_results = self.maybe_typeck_results.replace(self.cx.tcx.typeck_body(body_id));
|
||||
self.hash_expr(&self.cx.tcx.hir().body(body_id).value);
|
||||
self.maybe_typeck_tables = old_maybe_typeck_tables;
|
||||
self.maybe_typeck_results = old_maybe_typeck_results;
|
||||
}
|
||||
|
||||
fn hash_generic_args(&mut self, arg_list: &[GenericArg<'_>]) {
|
||||
|
@ -114,7 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector {
|
||||
}
|
||||
match stmt.kind {
|
||||
hir::StmtKind::Local(ref local) => {
|
||||
println!("local variable of type {}", cx.tables().node_type(local.hir_id));
|
||||
println!("local variable of type {}", cx.typeck_results().node_type(local.hir_id));
|
||||
println!("pattern:");
|
||||
print_pat(cx, &local.pat, 0);
|
||||
if let Some(ref e) = local.init {
|
||||
@ -144,8 +144,12 @@ fn has_attr(sess: &Session, attrs: &[Attribute]) -> bool {
|
||||
fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) {
|
||||
let ind = " ".repeat(indent);
|
||||
println!("{}+", ind);
|
||||
println!("{}ty: {}", ind, cx.tables().expr_ty(expr));
|
||||
println!("{}adjustments: {:?}", ind, cx.tables().adjustments().get(expr.hir_id));
|
||||
println!("{}ty: {}", ind, cx.typeck_results().expr_ty(expr));
|
||||
println!(
|
||||
"{}adjustments: {:?}",
|
||||
ind,
|
||||
cx.typeck_results().adjustments().get(expr.hir_id)
|
||||
);
|
||||
match expr.kind {
|
||||
hir::ExprKind::Box(ref e) => {
|
||||
println!("{}Box", ind);
|
||||
|
@ -405,7 +405,7 @@ impl<'tcx> LateLintPass<'tcx> for CompilerLintFunctions {
|
||||
if let ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind;
|
||||
let fn_name = path.ident;
|
||||
if let Some(sugg) = self.map.get(&*fn_name.as_str());
|
||||
let ty = walk_ptrs_ty(cx.tables().expr_ty(&args[0]));
|
||||
let ty = walk_ptrs_ty(cx.typeck_results().expr_ty(&args[0]));
|
||||
if match_type(cx, ty, &paths::EARLY_CONTEXT)
|
||||
|| match_type(cx, ty, &paths::LATE_CONTEXT);
|
||||
then {
|
||||
@ -438,7 +438,7 @@ impl<'tcx> LateLintPass<'tcx> for OuterExpnDataPass {
|
||||
let args = arg_lists[1];
|
||||
if args.len() == 1;
|
||||
let self_arg = &args[0];
|
||||
let self_ty = walk_ptrs_ty(cx.tables().expr_ty(self_arg));
|
||||
let self_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(self_arg));
|
||||
if match_type(cx, self_ty, &paths::SYNTAX_CONTEXT);
|
||||
then {
|
||||
span_lint_and_sugg(
|
||||
|
@ -144,7 +144,7 @@ pub fn is_type_diagnostic_item(cx: &LateContext<'_>, ty: Ty<'_>, diag_item: Symb
|
||||
|
||||
/// Checks if the method call given in `expr` belongs to the given trait.
|
||||
pub fn match_trait_method(cx: &LateContext<'_>, expr: &Expr<'_>, path: &[&str]) -> bool {
|
||||
let def_id = cx.tables().type_dependent_def_id(expr.hir_id).unwrap();
|
||||
let def_id = cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap();
|
||||
let trt_id = cx.tcx.trait_of_item(def_id);
|
||||
trt_id.map_or(false, |trt_id| match_def_path(cx, trt_id, path))
|
||||
}
|
||||
@ -278,10 +278,8 @@ pub fn qpath_res(cx: &LateContext<'_>, qpath: &hir::QPath<'_>, id: hir::HirId) -
|
||||
match qpath {
|
||||
hir::QPath::Resolved(_, path) => path.res,
|
||||
hir::QPath::TypeRelative(..) => {
|
||||
if cx.tcx.has_typeck_tables(id.owner.to_def_id()) {
|
||||
cx.tcx
|
||||
.typeck_tables_of(id.owner.to_def_id().expect_local())
|
||||
.qpath_res(qpath, id)
|
||||
if cx.tcx.has_typeck_results(id.owner.to_def_id()) {
|
||||
cx.tcx.typeck(id.owner.to_def_id().expect_local()).qpath_res(qpath, id)
|
||||
} else {
|
||||
Res::Err
|
||||
}
|
||||
@ -772,7 +770,7 @@ pub fn is_integer_const(cx: &LateContext<'_>, e: &Expr<'_>, value: u128) -> bool
|
||||
let parent_item = map.get_parent_item(e.hir_id);
|
||||
if let Some((Constant::Int(v), _)) = map
|
||||
.maybe_body_owned_by(parent_item)
|
||||
.and_then(|body_id| constant(cx, cx.tcx.body_tables(body_id), e))
|
||||
.and_then(|body_id| constant(cx, cx.tcx.typeck_body(body_id), e))
|
||||
{
|
||||
value == v
|
||||
} else {
|
||||
@ -799,7 +797,7 @@ pub fn is_integer_literal(expr: &Expr<'_>, value: u128) -> bool {
|
||||
/// See `rustc_middle::ty::adjustment::Adjustment` and `rustc_typeck::check::coercion` for more
|
||||
/// information on adjustments and coercions.
|
||||
pub fn is_adjusted(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
|
||||
cx.tables().adjustments().get(e.hir_id).is_some()
|
||||
cx.typeck_results().adjustments().get(e.hir_id).is_some()
|
||||
}
|
||||
|
||||
/// Returns the pre-expansion span if is this comes from an expansion of the
|
||||
@ -916,7 +914,7 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool {
|
||||
is_enum_variant(cx, qpath, pat.hir_id) || are_refutable(cx, pats.iter().map(|pat| &**pat))
|
||||
},
|
||||
PatKind::Slice(ref head, ref middle, ref tail) => {
|
||||
match &cx.tables().node_type(pat.hir_id).kind {
|
||||
match &cx.typeck_results().node_type(pat.hir_id).kind {
|
||||
ty::Slice(..) => {
|
||||
// [..] is the only irrefutable slice pattern.
|
||||
!head.is_empty() || middle.is_none() || !tail.is_empty()
|
||||
@ -1299,7 +1297,7 @@ pub fn is_must_use_func_call(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||
None
|
||||
}
|
||||
},
|
||||
ExprKind::MethodCall(_, _, _, _) => cx.tables().type_dependent_def_id(expr.hir_id),
|
||||
ExprKind::MethodCall(_, _, _, _) => cx.typeck_results().type_dependent_def_id(expr.hir_id),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
@ -1359,14 +1357,14 @@ pub fn fn_has_unsatisfiable_preds(cx: &LateContext<'_>, did: DefId) -> bool {
|
||||
/// Returns the `DefId` of the callee if the given expression is a function or method call.
|
||||
pub fn fn_def_id(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<DefId> {
|
||||
match &expr.kind {
|
||||
ExprKind::MethodCall(..) => cx.tables().type_dependent_def_id(expr.hir_id),
|
||||
ExprKind::MethodCall(..) => cx.typeck_results().type_dependent_def_id(expr.hir_id),
|
||||
ExprKind::Call(
|
||||
Expr {
|
||||
kind: ExprKind::Path(qpath),
|
||||
..
|
||||
},
|
||||
..,
|
||||
) => cx.tables().qpath_res(qpath, expr.hir_id).opt_def_id(),
|
||||
) => cx.typeck_results().qpath_res(qpath, expr.hir_id).opt_def_id(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,14 @@ pub fn mutated_variables<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) ->
|
||||
};
|
||||
let def_id = expr.hir_id.owner.to_def_id();
|
||||
cx.tcx.infer_ctxt().enter(|infcx| {
|
||||
ExprUseVisitor::new(&mut delegate, &infcx, def_id.expect_local(), cx.param_env, cx.tables()).walk_expr(expr);
|
||||
ExprUseVisitor::new(
|
||||
&mut delegate,
|
||||
&infcx,
|
||||
def_id.expect_local(),
|
||||
cx.param_env,
|
||||
cx.typeck_results(),
|
||||
)
|
||||
.walk_expr(expr);
|
||||
});
|
||||
|
||||
if delegate.skip {
|
||||
|
@ -37,7 +37,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessVec {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||
// search for `&vec![_]` expressions where the adjusted type is `&[_]`
|
||||
if_chain! {
|
||||
if let ty::Ref(_, ty, _) = cx.tables().expr_ty_adjusted(expr).kind;
|
||||
if let ty::Ref(_, ty, _) = cx.typeck_results().expr_ty_adjusted(expr).kind;
|
||||
if let ty::Slice(..) = ty.kind;
|
||||
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref addressee) = expr.kind;
|
||||
if let Some(vec_args) = higher::vec_macro(cx, addressee);
|
||||
@ -50,7 +50,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessVec {
|
||||
if_chain! {
|
||||
if let Some((_, arg, _)) = higher::for_loop(expr);
|
||||
if let Some(vec_args) = higher::vec_macro(cx, arg);
|
||||
if is_copy(cx, vec_type(cx.tables().expr_ty_adjusted(arg)));
|
||||
if is_copy(cx, vec_type(cx.typeck_results().expr_ty_adjusted(arg)));
|
||||
then {
|
||||
// report the error around the `vec!` not inside `<std macros>:`
|
||||
let span = arg.span
|
||||
@ -70,7 +70,7 @@ fn check_vec_macro<'tcx>(cx: &LateContext<'tcx>, vec_args: &higher::VecArgs<'tcx
|
||||
let mut applicability = Applicability::MachineApplicable;
|
||||
let snippet = match *vec_args {
|
||||
higher::VecArgs::Repeat(elem, len) => {
|
||||
if constant(cx, cx.tables(), len).is_some() {
|
||||
if constant(cx, cx.typeck_results(), len).is_some() {
|
||||
format!(
|
||||
"&[{}; {}]",
|
||||
snippet_with_applicability(cx, elem.span, "elem", &mut applicability),
|
||||
|
@ -32,7 +32,7 @@ impl<'tcx> LateLintPass<'tcx> for VecResizeToZero {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if_chain! {
|
||||
if let hir::ExprKind::MethodCall(path_segment, _, ref args, _) = expr.kind;
|
||||
if let Some(method_def_id) = cx.tables().type_dependent_def_id(expr.hir_id);
|
||||
if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
|
||||
if match_def_path(cx, method_def_id, &paths::VEC_RESIZE) && args.len() == 3;
|
||||
if let ExprKind::Lit(Spanned { node: LitKind::Int(0, _), .. }) = args[1].kind;
|
||||
if let ExprKind::Lit(Spanned { node: LitKind::Int(..), .. }) = args[2].kind;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user