Auto merge of #4591 - flip1995:rustup, r=flip1995
Rustup to rust-lang/rust#64813 cc rust-lang/rust#64843 changelog: none
This commit is contained in:
commit
edd90473ec
155 changed files with 927 additions and 982 deletions
|
@ -54,7 +54,7 @@ declare_lint_pass!(ApproxConstant => [APPROX_CONSTANT]);
|
|||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ApproxConstant {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||
if let ExprKind::Lit(lit) = &e.node {
|
||||
if let ExprKind::Lit(lit) = &e.kind {
|
||||
check_lit(cx, &lit.node, e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
|
|||
return;
|
||||
}
|
||||
}
|
||||
match &expr.node {
|
||||
match &expr.kind {
|
||||
hir::ExprKind::Binary(op, l, r) | hir::ExprKind::AssignOp(op, l, r) => {
|
||||
match op.node {
|
||||
hir::BinOpKind::And
|
||||
|
|
|
@ -32,7 +32,7 @@ declare_lint_pass!(AssertionsOnConstants => [ASSERTIONS_ON_CONSTANTS]);
|
|||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||
let lint_assert_cb = |is_debug_assert: bool| {
|
||||
if let ExprKind::Unary(_, ref lit) = e.node {
|
||||
if let ExprKind::Unary(_, ref lit) = e.kind {
|
||||
if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.tables, lit) {
|
||||
if is_true {
|
||||
span_help_and_lint(
|
||||
|
|
|
@ -59,9 +59,9 @@ declare_lint_pass!(AssignOps => [ASSIGN_OP_PATTERN, MISREFACTORED_ASSIGN_OP]);
|
|||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
|
||||
#[allow(clippy::too_many_lines)]
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
|
||||
match &expr.node {
|
||||
match &expr.kind {
|
||||
hir::ExprKind::AssignOp(op, lhs, rhs) => {
|
||||
if let hir::ExprKind::Binary(binop, l, r) = &rhs.node {
|
||||
if let hir::ExprKind::Binary(binop, l, r) = &rhs.kind {
|
||||
if op.node != binop.node {
|
||||
return;
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
|
|||
}
|
||||
},
|
||||
hir::ExprKind::Assign(assignee, e) => {
|
||||
if let hir::ExprKind::Binary(op, l, r) = &e.node {
|
||||
if let hir::ExprKind::Binary(op, l, r) = &e.kind {
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
let lint = |assignee: &hir::Expr, rhs: &hir::Expr| {
|
||||
let ty = cx.tables.expr_ty(assignee);
|
||||
|
|
|
@ -212,7 +212,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
|
|||
for item in items {
|
||||
if_chain! {
|
||||
if let NestedMetaItem::MetaItem(mi) = &item;
|
||||
if let MetaItemKind::NameValue(lit) = &mi.node;
|
||||
if let MetaItemKind::NameValue(lit) = &mi.kind;
|
||||
if mi.check_name(sym!(since));
|
||||
then {
|
||||
check_semver(cx, item.span(), lit);
|
||||
|
@ -227,7 +227,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
|
|||
if is_relevant_item(cx, item) {
|
||||
check_attrs(cx, item.span, item.ident.name, &item.attrs)
|
||||
}
|
||||
match item.node {
|
||||
match item.kind {
|
||||
ItemKind::ExternCrate(..) | ItemKind::Use(..) => {
|
||||
let skip_unused_imports = item.attrs.iter().any(|attr| attr.check_name(sym!(macro_use)));
|
||||
|
||||
|
@ -242,7 +242,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
|
|||
// whitelist `unused_imports`, `deprecated` and `unreachable_pub` for `use` items
|
||||
// and `unused_imports` for `extern crate` items with `macro_use`
|
||||
for lint in lint_list {
|
||||
match item.node {
|
||||
match item.kind {
|
||||
ItemKind::Use(..) => {
|
||||
if is_word(lint, sym!(unused_imports))
|
||||
|| is_word(lint, sym!(deprecated))
|
||||
|
@ -355,7 +355,7 @@ fn check_clippy_lint_names(cx: &LateContext<'_, '_>, items: &[NestedMetaItem]) {
|
|||
}
|
||||
|
||||
fn is_relevant_item(cx: &LateContext<'_, '_>, item: &Item) -> bool {
|
||||
if let ItemKind::Fn(_, _, _, eid) = item.node {
|
||||
if let ItemKind::Fn(_, _, _, eid) = item.kind {
|
||||
is_relevant_expr(cx, cx.tcx.body_tables(eid), &cx.tcx.hir().body(eid).value)
|
||||
} else {
|
||||
true
|
||||
|
@ -363,14 +363,14 @@ fn is_relevant_item(cx: &LateContext<'_, '_>, item: &Item) -> bool {
|
|||
}
|
||||
|
||||
fn is_relevant_impl(cx: &LateContext<'_, '_>, item: &ImplItem) -> bool {
|
||||
match item.node {
|
||||
match item.kind {
|
||||
ImplItemKind::Method(_, eid) => is_relevant_expr(cx, cx.tcx.body_tables(eid), &cx.tcx.hir().body(eid).value),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn is_relevant_trait(cx: &LateContext<'_, '_>, item: &TraitItem) -> bool {
|
||||
match item.node {
|
||||
match item.kind {
|
||||
TraitItemKind::Method(_, TraitMethod::Required(_)) => true,
|
||||
TraitItemKind::Method(_, TraitMethod::Provided(eid)) => {
|
||||
is_relevant_expr(cx, cx.tcx.body_tables(eid), &cx.tcx.hir().body(eid).value)
|
||||
|
@ -381,7 +381,7 @@ fn is_relevant_trait(cx: &LateContext<'_, '_>, item: &TraitItem) -> bool {
|
|||
|
||||
fn is_relevant_block(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, block: &Block) -> bool {
|
||||
if let Some(stmt) = block.stmts.first() {
|
||||
match &stmt.node {
|
||||
match &stmt.kind {
|
||||
StmtKind::Local(_) => true,
|
||||
StmtKind::Expr(expr) | StmtKind::Semi(expr) => is_relevant_expr(cx, tables, expr),
|
||||
_ => false,
|
||||
|
@ -392,12 +392,12 @@ fn is_relevant_block(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, bl
|
|||
}
|
||||
|
||||
fn is_relevant_expr(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, expr: &Expr) -> bool {
|
||||
match &expr.node {
|
||||
match &expr.kind {
|
||||
ExprKind::Block(block, _) => is_relevant_block(cx, tables, block),
|
||||
ExprKind::Ret(Some(e)) => is_relevant_expr(cx, tables, e),
|
||||
ExprKind::Ret(None) | ExprKind::Break(_, None) => false,
|
||||
ExprKind::Call(path_expr, _) => {
|
||||
if let ExprKind::Path(qpath) = &path_expr.node {
|
||||
if let ExprKind::Path(qpath) = &path_expr.kind {
|
||||
if let Some(fun_id) = tables.qpath_res(qpath, path_expr.hir_id).opt_def_id() {
|
||||
!match_def_path(cx, fun_id, &paths::BEGIN_PANIC)
|
||||
} else {
|
||||
|
@ -464,7 +464,7 @@ fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attrib
|
|||
}
|
||||
|
||||
fn check_semver(cx: &LateContext<'_, '_>, span: Span, lit: &Lit) {
|
||||
if let LitKind::Str(is, _) = lit.node {
|
||||
if let LitKind::Str(is, _) = lit.kind {
|
||||
if Version::parse(&is.as_str()).is_ok() {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@ impl_lint_pass!(BitMask => [BAD_BIT_MASK, INEFFECTIVE_BIT_MASK, VERBOSE_BIT_MASK
|
|||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||
if let ExprKind::Binary(cmp, left, right) = &e.node {
|
||||
if let ExprKind::Binary(cmp, left, right) = &e.kind {
|
||||
if cmp.node.is_comparison() {
|
||||
if let Some(cmp_opt) = fetch_int_literal(cx, right) {
|
||||
check_compare(cx, left, cmp.node, cmp_opt, e.span)
|
||||
|
@ -121,13 +121,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask {
|
|||
}
|
||||
}
|
||||
if_chain! {
|
||||
if let ExprKind::Binary(op, left, right) = &e.node;
|
||||
if let ExprKind::Binary(op, left, right) = &e.kind;
|
||||
if BinOpKind::Eq == op.node;
|
||||
if let ExprKind::Binary(op1, left1, right1) = &left.node;
|
||||
if let ExprKind::Binary(op1, left1, right1) = &left.kind;
|
||||
if BinOpKind::BitAnd == op1.node;
|
||||
if let ExprKind::Lit(lit) = &right1.node;
|
||||
if let ExprKind::Lit(lit) = &right1.kind;
|
||||
if let LitKind::Int(n, _) = lit.node;
|
||||
if let ExprKind::Lit(lit1) = &right.node;
|
||||
if let ExprKind::Lit(lit1) = &right.kind;
|
||||
if let LitKind::Int(0, _) = lit1.node;
|
||||
if n.leading_zeros() == n.count_zeros();
|
||||
if n > u128::from(self.verbose_bit_mask_threshold);
|
||||
|
@ -163,7 +163,7 @@ fn invert_cmp(cmp: BinOpKind) -> BinOpKind {
|
|||
}
|
||||
|
||||
fn check_compare(cx: &LateContext<'_, '_>, bit_op: &Expr, cmp_op: BinOpKind, cmp_value: u128, span: Span) {
|
||||
if let ExprKind::Binary(op, left, right) = &bit_op.node {
|
||||
if let ExprKind::Binary(op, left, right) = &bit_op.kind {
|
||||
if op.node != BinOpKind::BitAnd && op.node != BinOpKind::BitOr {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ impl_lint_pass!(BlacklistedName => [BLACKLISTED_NAME]);
|
|||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlacklistedName {
|
||||
fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
|
||||
if let PatKind::Binding(.., ident, _) = pat.node {
|
||||
if let PatKind::Binding(.., ident, _) = pat.kind {
|
||||
if self.blacklist.contains(&ident.name.to_string()) {
|
||||
span_lint(
|
||||
cx,
|
||||
|
|
|
@ -51,10 +51,10 @@ struct ExVisitor<'a, 'tcx> {
|
|||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr) {
|
||||
if let ExprKind::Closure(_, _, eid, _, _) = expr.node {
|
||||
if let ExprKind::Closure(_, _, eid, _, _) = expr.kind {
|
||||
let body = self.cx.tcx.hir().body(eid);
|
||||
let ex = &body.value;
|
||||
if matches!(ex.node, ExprKind::Block(_, _)) && !body.value.span.from_expansion() {
|
||||
if matches!(ex.kind, ExprKind::Block(_, _)) && !body.value.span.from_expansion() {
|
||||
self.found_block = Some(ex);
|
||||
return;
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
|
|||
return;
|
||||
}
|
||||
if let Some((check, then, _)) = higher::if_block(&expr) {
|
||||
if let ExprKind::Block(block, _) = &check.node {
|
||||
if let ExprKind::Block(block, _) = &check.kind {
|
||||
if block.rules == DefaultBlock {
|
||||
if block.stmts.is_empty() {
|
||||
if let Some(ex) = &block.expr {
|
||||
|
|
|
@ -81,7 +81,7 @@ struct Hir2Qmm<'a, 'tcx, 'v> {
|
|||
impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
|
||||
fn extract(&mut self, op: BinOpKind, a: &[&'v Expr], mut v: Vec<Bool>) -> Result<Vec<Bool>, String> {
|
||||
for a in a {
|
||||
if let ExprKind::Binary(binop, lhs, rhs) = &a.node {
|
||||
if let ExprKind::Binary(binop, lhs, rhs) = &a.kind {
|
||||
if binop.node == op {
|
||||
v = self.extract(op, &[lhs, rhs], v)?;
|
||||
continue;
|
||||
|
@ -107,7 +107,7 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
|
|||
|
||||
// prevent folding of `cfg!` macros and the like
|
||||
if !e.span.from_expansion() {
|
||||
match &e.node {
|
||||
match &e.kind {
|
||||
ExprKind::Unary(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())?)),
|
||||
|
@ -129,9 +129,9 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
|
|||
}
|
||||
|
||||
if_chain! {
|
||||
if let ExprKind::Binary(e_binop, e_lhs, e_rhs) = &e.node;
|
||||
if let ExprKind::Binary(e_binop, e_lhs, e_rhs) = &e.kind;
|
||||
if implements_ord(self.cx, e_lhs);
|
||||
if let ExprKind::Binary(expr_binop, expr_lhs, expr_rhs) = &expr.node;
|
||||
if let ExprKind::Binary(expr_binop, expr_lhs, expr_rhs) = &expr.kind;
|
||||
if negate(e_binop.node) == Some(expr_binop.node);
|
||||
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(e_lhs, expr_lhs);
|
||||
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(e_rhs, expr_rhs);
|
||||
|
@ -222,7 +222,7 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
|
|||
}
|
||||
|
||||
fn simplify_not(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<String> {
|
||||
match &expr.node {
|
||||
match &expr.kind {
|
||||
ExprKind::Binary(binop, lhs, rhs) => {
|
||||
if !implements_ord(cx, lhs) {
|
||||
return None;
|
||||
|
@ -437,7 +437,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
|
|||
if in_macro(e.span) {
|
||||
return;
|
||||
}
|
||||
match &e.node {
|
||||
match &e.kind {
|
||||
ExprKind::Binary(binop, _, _) if binop.node == BinOpKind::Or || binop.node == BinOpKind::And => {
|
||||
self.bool_expr(e)
|
||||
},
|
||||
|
@ -467,7 +467,7 @@ struct NotSimplificationVisitor<'a, 'tcx> {
|
|||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr) {
|
||||
if let ExprKind::Unary(UnNot, inner) = &expr.node {
|
||||
if let ExprKind::Unary(UnNot, inner) = &expr.kind {
|
||||
if let Some(suggestion) = simplify_not(self.cx, inner) {
|
||||
span_lint_and_sugg(
|
||||
self.cx,
|
||||
|
|
|
@ -37,19 +37,19 @@ declare_lint_pass!(ByteCount => [NAIVE_BYTECOUNT]);
|
|||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
|
||||
fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr) {
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(ref count, _, ref count_args) = expr.node;
|
||||
if let ExprKind::MethodCall(ref count, _, ref count_args) = expr.kind;
|
||||
if count.ident.name == sym!(count);
|
||||
if count_args.len() == 1;
|
||||
if let ExprKind::MethodCall(ref filter, _, ref filter_args) = count_args[0].node;
|
||||
if let ExprKind::MethodCall(ref filter, _, ref filter_args) = count_args[0].kind;
|
||||
if filter.ident.name == sym!(filter);
|
||||
if filter_args.len() == 2;
|
||||
if let ExprKind::Closure(_, _, body_id, _, _) = filter_args[1].node;
|
||||
if let ExprKind::Closure(_, _, body_id, _, _) = filter_args[1].kind;
|
||||
then {
|
||||
let body = cx.tcx.hir().body(body_id);
|
||||
if_chain! {
|
||||
if body.params.len() == 1;
|
||||
if let Some(argname) = get_pat_name(&body.params[0].pat);
|
||||
if let ExprKind::Binary(ref op, ref l, ref r) = body.value.node;
|
||||
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])),
|
||||
|
@ -66,7 +66,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
|
|||
return;
|
||||
}
|
||||
let haystack = if let ExprKind::MethodCall(ref path, _, ref args) =
|
||||
filter_args[0].node {
|
||||
filter_args[0].kind {
|
||||
let p = path.ident.name;
|
||||
if (p == sym!(iter) || p == sym!(iter_mut)) && args.len() == 1 {
|
||||
&args[0]
|
||||
|
@ -100,7 +100,7 @@ fn check_arg(name: Name, arg: Name, needle: &Expr) -> bool {
|
|||
}
|
||||
|
||||
fn get_path_name(expr: &Expr) -> Option<Name> {
|
||||
match expr.node {
|
||||
match expr.kind {
|
||||
ExprKind::Box(ref e) | ExprKind::AddrOf(_, ref e) | ExprKind::Unary(UnOp::UnDeref, ref e) => get_path_name(e),
|
||||
ExprKind::Block(ref b, _) => {
|
||||
if b.stmts.is_empty() {
|
||||
|
|
|
@ -44,7 +44,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CheckedConversions {
|
|||
fn check_expr(&mut self, cx: &LateContext<'_, '_>, item: &Expr) {
|
||||
let result = if_chain! {
|
||||
if !in_external_macro(cx.sess(), item.span);
|
||||
if let ExprKind::Binary(op, ref left, ref right) = &item.node;
|
||||
if let ExprKind::Binary(op, ref left, ref right) = &item.kind;
|
||||
|
||||
then {
|
||||
match op.node {
|
||||
|
@ -180,7 +180,7 @@ impl ConversionType {
|
|||
/// Check for `expr <= (to_type::max_value() as from_type)`
|
||||
fn check_upper_bound(expr: &Expr) -> Option<Conversion<'_>> {
|
||||
if_chain! {
|
||||
if let ExprKind::Binary(ref op, ref left, ref right) = &expr.node;
|
||||
if let ExprKind::Binary(ref op, ref left, ref right) = &expr.kind;
|
||||
if let Some((candidate, check)) = normalize_le_ge(op, left, right);
|
||||
if let Some((from, to)) = get_types_from_cast(check, MAX_VALUE, INTS);
|
||||
|
||||
|
@ -199,7 +199,7 @@ fn check_lower_bound(expr: &Expr) -> Option<Conversion<'_>> {
|
|||
}
|
||||
|
||||
// First of we need a binary containing the expression & the cast
|
||||
if let ExprKind::Binary(ref op, ref left, ref right) = &expr.node {
|
||||
if let ExprKind::Binary(ref op, ref left, ref right) = &expr.kind {
|
||||
normalize_le_ge(op, right, left).and_then(|(l, r)| check_function(l, r))
|
||||
} else {
|
||||
None
|
||||
|
@ -209,7 +209,7 @@ fn check_lower_bound(expr: &Expr) -> Option<Conversion<'_>> {
|
|||
/// Check for `expr >= 0`
|
||||
fn check_lower_bound_zero<'a>(candidate: &'a Expr, check: &'a Expr) -> Option<Conversion<'a>> {
|
||||
if_chain! {
|
||||
if let ExprKind::Lit(ref lit) = &check.node;
|
||||
if let ExprKind::Lit(ref lit) = &check.kind;
|
||||
if let LitKind::Int(0, _) = &lit.node;
|
||||
|
||||
then {
|
||||
|
@ -234,8 +234,8 @@ fn get_types_from_cast<'a>(expr: &'a Expr, func: &'a str, types: &'a [&str]) ->
|
|||
// `to_type::maxmin_value() as from_type`
|
||||
let call_from_cast: Option<(&Expr, &str)> = if_chain! {
|
||||
// to_type::maxmin_value(), from_type
|
||||
if let ExprKind::Cast(ref limit, ref from_type) = &expr.node;
|
||||
if let TyKind::Path(ref from_type_path) = &from_type.node;
|
||||
if let ExprKind::Cast(ref limit, ref from_type) = &expr.kind;
|
||||
if let TyKind::Path(ref from_type_path) = &from_type.kind;
|
||||
if let Some(from_sym) = int_ty_to_sym(from_type_path);
|
||||
|
||||
then {
|
||||
|
@ -249,12 +249,12 @@ fn get_types_from_cast<'a>(expr: &'a Expr, func: &'a str, types: &'a [&str]) ->
|
|||
let limit_from: Option<(&Expr, &str)> = call_from_cast.or_else(|| {
|
||||
if_chain! {
|
||||
// `from_type::from, to_type::maxmin_value()`
|
||||
if let ExprKind::Call(ref from_func, ref args) = &expr.node;
|
||||
if let ExprKind::Call(ref from_func, ref args) = &expr.kind;
|
||||
// `to_type::maxmin_value()`
|
||||
if args.len() == 1;
|
||||
if let limit = &args[0];
|
||||
// `from_type::from`
|
||||
if let ExprKind::Path(ref path) = &from_func.node;
|
||||
if let ExprKind::Path(ref path) = &from_func.kind;
|
||||
if let Some(from_sym) = get_implementing_type(path, INTS, FROM);
|
||||
|
||||
then {
|
||||
|
@ -267,9 +267,9 @@ fn get_types_from_cast<'a>(expr: &'a Expr, func: &'a str, types: &'a [&str]) ->
|
|||
|
||||
if let Some((limit, from_type)) = limit_from {
|
||||
if_chain! {
|
||||
if let ExprKind::Call(ref fun_name, _) = &limit.node;
|
||||
if let ExprKind::Call(ref fun_name, _) = &limit.kind;
|
||||
// `to_type, maxmin_value`
|
||||
if let ExprKind::Path(ref path) = &fun_name.node;
|
||||
if let ExprKind::Path(ref path) = &fun_name.kind;
|
||||
// `to_type`
|
||||
if let Some(to_type) = get_implementing_type(path, types, func);
|
||||
|
||||
|
@ -289,7 +289,7 @@ fn get_implementing_type<'a>(path: &QPath, candidates: &'a [&str], function: &st
|
|||
if_chain! {
|
||||
if let QPath::TypeRelative(ref ty, ref path) = &path;
|
||||
if path.ident.name.as_str() == function;
|
||||
if let TyKind::Path(QPath::Resolved(None, ref tp)) = &ty.node;
|
||||
if let TyKind::Path(QPath::Resolved(None, ref tp)) = &ty.kind;
|
||||
if let [int] = &*tp.segments;
|
||||
let name = &int.ident.name.as_str();
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ struct CCHelper {
|
|||
impl<'tcx> Visitor<'tcx> for CCHelper {
|
||||
fn visit_expr(&mut self, e: &'tcx Expr) {
|
||||
walk_expr(self, e);
|
||||
match e.node {
|
||||
match e.kind {
|
||||
ExprKind::Match(_, ref arms, _) => {
|
||||
if arms.len() > 1 {
|
||||
self.cc += 1;
|
||||
|
|
|
@ -82,10 +82,10 @@ impl EarlyLintPass for CollapsibleIf {
|
|||
}
|
||||
|
||||
fn check_if(cx: &EarlyContext<'_>, expr: &ast::Expr) {
|
||||
if let ast::ExprKind::If(check, then, else_) = &expr.node {
|
||||
if let ast::ExprKind::If(check, then, else_) = &expr.kind {
|
||||
if let Some(else_) = else_ {
|
||||
check_collapsible_maybe_if_let(cx, else_);
|
||||
} else if let ast::ExprKind::Let(..) = check.node {
|
||||
} else if let ast::ExprKind::Let(..) = check.kind {
|
||||
// Prevent triggering on `if let a = b { if c { .. } }`.
|
||||
} else {
|
||||
check_collapsible_no_if_let(cx, expr, check, then);
|
||||
|
@ -103,11 +103,11 @@ fn block_starts_with_comment(cx: &EarlyContext<'_>, expr: &ast::Block) -> bool {
|
|||
|
||||
fn check_collapsible_maybe_if_let(cx: &EarlyContext<'_>, else_: &ast::Expr) {
|
||||
if_chain! {
|
||||
if let ast::ExprKind::Block(ref block, _) = else_.node;
|
||||
if let ast::ExprKind::Block(ref block, _) = else_.kind;
|
||||
if !block_starts_with_comment(cx, block);
|
||||
if let Some(else_) = expr_block(block);
|
||||
if !else_.span.from_expansion();
|
||||
if let ast::ExprKind::If(..) = else_.node;
|
||||
if let ast::ExprKind::If(..) = else_.kind;
|
||||
then {
|
||||
let mut applicability = Applicability::MachineApplicable;
|
||||
span_lint_and_sugg(
|
||||
|
@ -127,9 +127,9 @@ fn check_collapsible_no_if_let(cx: &EarlyContext<'_>, expr: &ast::Expr, check: &
|
|||
if_chain! {
|
||||
if !block_starts_with_comment(cx, then);
|
||||
if let Some(inner) = expr_block(then);
|
||||
if let ast::ExprKind::If(ref check_inner, ref content, None) = inner.node;
|
||||
if let ast::ExprKind::If(ref check_inner, ref content, None) = inner.kind;
|
||||
then {
|
||||
if let ast::ExprKind::Let(..) = check_inner.node {
|
||||
if let ast::ExprKind::Let(..) = check_inner.kind {
|
||||
// Prevent triggering on `if c { if let a = b { .. } }`.
|
||||
return;
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ fn expr_block(block: &ast::Block) -> Option<&ast::Expr> {
|
|||
let mut it = block.stmts.iter();
|
||||
|
||||
if let (Some(stmt), None) = (it.next(), it.next()) {
|
||||
match stmt.node {
|
||||
match stmt.kind {
|
||||
ast::StmtKind::Expr(ref expr) | ast::StmtKind::Semi(ref expr) => Some(expr),
|
||||
_ => None,
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ComparisonChain {
|
|||
if let (
|
||||
&ExprKind::Binary(ref kind1, ref lhs1, ref rhs1),
|
||||
&ExprKind::Binary(ref kind2, ref lhs2, ref rhs2),
|
||||
) = (&cond[0].node, &cond[1].node)
|
||||
) = (&cond[0].kind, &cond[1].kind)
|
||||
{
|
||||
if !kind_is_cmp(kind1.node) || !kind_is_cmp(kind2.node) {
|
||||
return;
|
||||
|
|
|
@ -222,7 +222,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
|
|||
if let Some((ref cond, ref then, otherwise)) = higher::if_block(&e) {
|
||||
return self.ifthenelse(cond, then, otherwise);
|
||||
}
|
||||
match e.node {
|
||||
match e.kind {
|
||||
ExprKind::Path(ref qpath) => self.fetch_path(qpath, e.hir_id),
|
||||
ExprKind::Block(ref block, _) => self.block(block),
|
||||
ExprKind::Lit(ref lit) => Some(lit_to_constant(&lit.node, self.tables.expr_ty(e))),
|
||||
|
@ -245,7 +245,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
|
|||
// We only handle a few const functions for now.
|
||||
if_chain! {
|
||||
if args.is_empty();
|
||||
if let ExprKind::Path(qpath) = &callee.node;
|
||||
if let ExprKind::Path(qpath) = &callee.kind;
|
||||
let res = self.tables.qpath_res(qpath, callee.hir_id);
|
||||
if let Some(def_id) = res.opt_def_id();
|
||||
let get_def_path = self.lcx.get_def_path(def_id, );
|
||||
|
|
|
@ -176,7 +176,7 @@ fn lint_match_arms<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr) {
|
|||
.all(|(name, l_ty)| rhs.get(name).map_or(false, |r_ty| same_tys(cx, l_ty, r_ty)))
|
||||
}
|
||||
|
||||
if let ExprKind::Match(_, ref arms, MatchSource::Normal) = expr.node {
|
||||
if let ExprKind::Match(_, ref arms, MatchSource::Normal) = expr.kind {
|
||||
let hash = |&(_, arm): &(usize, &Arm)| -> u64 {
|
||||
let mut h = SpanlessHash::new(cx, cx.tables);
|
||||
h.hash_expr(&arm.body);
|
||||
|
@ -215,7 +215,7 @@ fn lint_match_arms<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr) {
|
|||
let lhs = snippet(cx, i.pat.span, "<pat1>");
|
||||
let rhs = snippet(cx, j.pat.span, "<pat2>");
|
||||
|
||||
if let PatKind::Wild = j.pat.node {
|
||||
if let PatKind::Wild = j.pat.kind {
|
||||
// if the last arm is _, then i could be integrated into _
|
||||
// note that i.pat cannot be _, because that would mean that we're
|
||||
// hiding all the subsequent arms, and rust won't compile
|
||||
|
@ -238,7 +238,7 @@ fn lint_match_arms<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr) {
|
|||
/// Returns the list of bindings in a pattern.
|
||||
fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> FxHashMap<Symbol, Ty<'tcx>> {
|
||||
fn bindings_impl<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat, map: &mut FxHashMap<Symbol, Ty<'tcx>>) {
|
||||
match pat.node {
|
||||
match pat.kind {
|
||||
PatKind::Box(ref pat) | PatKind::Ref(ref pat, _) => bindings_impl(cx, pat, map),
|
||||
PatKind::TupleStruct(_, ref pats, _) => {
|
||||
for pat in pats {
|
||||
|
|
|
@ -33,7 +33,7 @@ declare_lint_pass!(CopyIterator => [COPY_ITERATOR]);
|
|||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyIterator {
|
||||
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
|
||||
if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.node {
|
||||
if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.kind {
|
||||
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.hir_id));
|
||||
|
||||
if is_copy(cx, ty) && match_path(&trait_ref.path, &paths::ITERATOR) {
|
||||
|
|
|
@ -33,9 +33,9 @@ declare_lint_pass!(DefaultTraitAccess => [DEFAULT_TRAIT_ACCESS]);
|
|||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
if_chain! {
|
||||
if let ExprKind::Call(ref path, ..) = expr.node;
|
||||
if let ExprKind::Call(ref path, ..) = expr.kind;
|
||||
if !any_parent_is_automatically_derived(cx.tcx, expr.hir_id);
|
||||
if let ExprKind::Path(ref qpath) = path.node;
|
||||
if let ExprKind::Path(ref qpath) = path.kind;
|
||||
if let Some(def_id) = cx.tables.qpath_res(qpath, path.hir_id).opt_def_id();
|
||||
if match_def_path(cx, def_id, &paths::DEFAULT_TRAIT_METHOD);
|
||||
then {
|
||||
|
@ -44,8 +44,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess {
|
|||
if_chain! {
|
||||
// Detect and ignore <Foo as Default>::default() because these calls do
|
||||
// explicitly name the type.
|
||||
if let ExprKind::Call(ref method, ref _args) = expr.node;
|
||||
if let ExprKind::Path(ref p) = method.node;
|
||||
if let ExprKind::Call(ref method, ref _args) = expr.kind;
|
||||
if let ExprKind::Path(ref p) = method.kind;
|
||||
if let QPath::Resolved(Some(_ty), _path) = p;
|
||||
then {
|
||||
return;
|
||||
|
|
|
@ -66,7 +66,7 @@ declare_lint_pass!(Derive => [EXPL_IMPL_CLONE_ON_COPY, DERIVE_HASH_XOR_EQ]);
|
|||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Derive {
|
||||
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
|
||||
if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.node {
|
||||
if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.kind {
|
||||
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.hir_id));
|
||||
let is_automatically_derived = is_automatically_derived(&*item.attrs);
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ impl EarlyLintPass for DocMarkdown {
|
|||
return;
|
||||
}
|
||||
// no safety header
|
||||
if let ast::ItemKind::Fn(_, ref header, ..) = item.node {
|
||||
if let ast::ItemKind::Fn(_, ref header, ..) = item.kind {
|
||||
if item.vis.node.is_pub() && header.unsafety == ast::Unsafety::Unsafe {
|
||||
span_lint(
|
||||
cx,
|
||||
|
|
|
@ -40,7 +40,7 @@ declare_lint_pass!(DoubleComparisons => [DOUBLE_COMPARISONS]);
|
|||
impl<'a, 'tcx> DoubleComparisons {
|
||||
#[allow(clippy::similar_names)]
|
||||
fn check_binop(self, cx: &LateContext<'a, 'tcx>, op: BinOpKind, lhs: &'tcx Expr, rhs: &'tcx Expr, span: Span) {
|
||||
let (lkind, llhs, lrhs, rkind, rlhs, rrhs) = match (&lhs.node, &rhs.node) {
|
||||
let (lkind, llhs, lrhs, rkind, rlhs, rrhs) = match (&lhs.kind, &rhs.kind) {
|
||||
(ExprKind::Binary(lb, llhs, lrhs), ExprKind::Binary(rb, rlhs, rrhs)) => {
|
||||
(lb.node, llhs, lrhs, rb.node, rlhs, rrhs)
|
||||
},
|
||||
|
@ -88,7 +88,7 @@ impl<'a, 'tcx> DoubleComparisons {
|
|||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DoubleComparisons {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
if let ExprKind::Binary(ref kind, ref lhs, ref rhs) = expr.node {
|
||||
if let ExprKind::Binary(ref kind, ref lhs, ref rhs) = expr.kind {
|
||||
self.check_binop(cx, kind.node, lhs, rhs, expr.span);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,8 +31,8 @@ impl EarlyLintPass for DoubleParens {
|
|||
return;
|
||||
}
|
||||
|
||||
match expr.node {
|
||||
ExprKind::Paren(ref in_paren) => match in_paren.node {
|
||||
match expr.kind {
|
||||
ExprKind::Paren(ref in_paren) => match in_paren.kind {
|
||||
ExprKind::Paren(_) | ExprKind::Tup(_) => {
|
||||
span_lint(
|
||||
cx,
|
||||
|
@ -46,7 +46,7 @@ impl EarlyLintPass for DoubleParens {
|
|||
ExprKind::Call(_, ref params) => {
|
||||
if params.len() == 1 {
|
||||
let param = ¶ms[0];
|
||||
if let ExprKind::Paren(_) = param.node {
|
||||
if let ExprKind::Paren(_) = param.kind {
|
||||
span_lint(
|
||||
cx,
|
||||
DOUBLE_PARENS,
|
||||
|
@ -59,7 +59,7 @@ impl EarlyLintPass for DoubleParens {
|
|||
ExprKind::MethodCall(_, ref params) => {
|
||||
if params.len() == 2 {
|
||||
let param = ¶ms[1];
|
||||
if let ExprKind::Paren(_) = param.node {
|
||||
if let ExprKind::Paren(_) = param.kind {
|
||||
span_lint(
|
||||
cx,
|
||||
DOUBLE_PARENS,
|
||||
|
|
|
@ -111,8 +111,8 @@ declare_lint_pass!(DropForgetRef => [DROP_REF, FORGET_REF, DROP_COPY, FORGET_COP
|
|||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DropForgetRef {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
if_chain! {
|
||||
if let ExprKind::Call(ref path, ref args) = expr.node;
|
||||
if let ExprKind::Path(ref qpath) = path.node;
|
||||
if let ExprKind::Call(ref path, ref args) = expr.kind;
|
||||
if let ExprKind::Path(ref qpath) = path.kind;
|
||||
if args.len() == 1;
|
||||
if let Some(def_id) = qpath_res(cx, qpath, path.hir_id).opt_def_id();
|
||||
then {
|
||||
|
|
|
@ -35,8 +35,8 @@ declare_lint_pass!(DurationSubsec => [DURATION_SUBSEC]);
|
|||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DurationSubsec {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
if_chain! {
|
||||
if let ExprKind::Binary(Spanned { node: BinOpKind::Div, .. }, ref left, ref right) = expr.node;
|
||||
if let ExprKind::MethodCall(ref method_path, _ , ref args) = left.node;
|
||||
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);
|
||||
then {
|
||||
|
|
|
@ -53,8 +53,8 @@ impl EarlyLintPass for ElseIfWithoutElse {
|
|||
return;
|
||||
}
|
||||
|
||||
while let ExprKind::If(_, _, Some(ref els)) = item.node {
|
||||
if let ExprKind::If(_, _, None) = els.node {
|
||||
while let ExprKind::If(_, _, Some(ref els)) = item.kind {
|
||||
if let ExprKind::If(_, _, None) = els.kind {
|
||||
span_help_and_lint(
|
||||
cx,
|
||||
ELSE_IF_WITHOUT_ELSE,
|
||||
|
|
|
@ -28,7 +28,7 @@ declare_lint_pass!(EmptyEnum => [EMPTY_ENUM]);
|
|||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EmptyEnum {
|
||||
fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item) {
|
||||
let did = cx.tcx.hir().local_def_id(item.hir_id);
|
||||
if let ItemKind::Enum(..) = item.node {
|
||||
if let ItemKind::Enum(..) = item.kind {
|
||||
let ty = cx.tcx.type_of(did);
|
||||
let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
|
||||
if adt.variants.is_empty() {
|
||||
|
|
|
@ -54,13 +54,13 @@ declare_lint_pass!(HashMapPass => [MAP_ENTRY]);
|
|||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HashMapPass {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
if let Some((ref check, ref then_block, ref else_block)) = higher::if_block(&expr) {
|
||||
if let ExprKind::Unary(UnOp::UnNot, ref check) = check.node {
|
||||
if let ExprKind::Unary(UnOp::UnNot, ref check) = check.kind {
|
||||
if let Some((ty, map, key)) = check_cond(cx, check) {
|
||||
// in case of `if !m.contains_key(&k) { m.insert(k, v); }`
|
||||
// we can give a better error message
|
||||
let sole_expr = {
|
||||
else_block.is_none()
|
||||
&& if let ExprKind::Block(ref then_block, _) = then_block.node {
|
||||
&& if let ExprKind::Block(ref then_block, _) = then_block.kind {
|
||||
(then_block.expr.is_some() as usize) + then_block.stmts.len() == 1
|
||||
} else {
|
||||
true
|
||||
|
@ -102,10 +102,10 @@ fn check_cond<'a, 'tcx, 'b>(
|
|||
check: &'b Expr,
|
||||
) -> Option<(&'static str, &'b Expr, &'b Expr)> {
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(ref path, _, ref params) = check.node;
|
||||
if let ExprKind::MethodCall(ref path, _, ref params) = check.kind;
|
||||
if params.len() >= 2;
|
||||
if path.ident.name == sym!(contains_key);
|
||||
if let ExprKind::AddrOf(_, ref key) = params[1].node;
|
||||
if let ExprKind::AddrOf(_, ref key) = params[1].kind;
|
||||
then {
|
||||
let map = ¶ms[0];
|
||||
let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(map));
|
||||
|
@ -137,7 +137,7 @@ struct InsertVisitor<'a, 'tcx, 'b> {
|
|||
impl<'a, 'tcx, 'b> Visitor<'tcx> for InsertVisitor<'a, 'tcx, 'b> {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr) {
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(ref path, _, ref params) = expr.node;
|
||||
if let ExprKind::MethodCall(ref path, _, ref params) = expr.kind;
|
||||
if params.len() == 3;
|
||||
if path.ident.name == sym!(insert);
|
||||
if get_item_name(self.cx, self.map) == get_item_name(self.cx, ¶ms[0]);
|
||||
|
|
|
@ -43,7 +43,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant {
|
|||
if cx.tcx.data_layout.pointer_size.bits() != 64 {
|
||||
return;
|
||||
}
|
||||
if let ItemKind::Enum(def, _) = &item.node {
|
||||
if let ItemKind::Enum(def, _) = &item.kind {
|
||||
for var in &def.variants {
|
||||
if let Some(anon_const) = &var.disr_expr {
|
||||
let param_env = ty::ParamEnv::empty();
|
||||
|
|
|
@ -42,7 +42,7 @@ impl EnumGlobUse {
|
|||
if item.vis.node.is_pub() {
|
||||
return; // re-exports are fine
|
||||
}
|
||||
if let ItemKind::Use(ref path, UseKind::Glob) = item.node {
|
||||
if let ItemKind::Use(ref path, UseKind::Glob) = item.kind {
|
||||
if let Res::Def(DefKind::Enum, _) = path.res {
|
||||
span_lint(cx, ENUM_GLOB_USE, item.span, "don't use glob imports for enum variants");
|
||||
}
|
||||
|
|
|
@ -249,7 +249,7 @@ impl EarlyLintPass for EnumVariantNames {
|
|||
// constants don't have surrounding modules
|
||||
if !mod_camel.is_empty() {
|
||||
if mod_name == &item.ident.name {
|
||||
if let ItemKind::Mod(..) = item.node {
|
||||
if let ItemKind::Mod(..) = item.kind {
|
||||
span_lint(
|
||||
cx,
|
||||
MODULE_INCEPTION,
|
||||
|
@ -288,7 +288,7 @@ impl EarlyLintPass for EnumVariantNames {
|
|||
}
|
||||
}
|
||||
}
|
||||
if let ItemKind::Enum(ref def, _) = item.node {
|
||||
if let ItemKind::Enum(ref def, _) = item.kind {
|
||||
let lint = match item.vis.node {
|
||||
VisibilityKind::Public => PUB_ENUM_VARIANT_NAMES,
|
||||
_ => ENUM_VARIANT_NAMES,
|
||||
|
|
|
@ -49,7 +49,7 @@ declare_lint_pass!(EqOp => [EQ_OP, OP_REF]);
|
|||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
|
||||
#[allow(clippy::similar_names, clippy::too_many_lines)]
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||
if let ExprKind::Binary(op, ref left, ref right) = e.node {
|
||||
if let ExprKind::Binary(op, ref left, ref right) = e.kind {
|
||||
if e.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
|
|||
};
|
||||
if let Some(trait_id) = trait_id {
|
||||
#[allow(clippy::match_same_arms)]
|
||||
match (&left.node, &right.node) {
|
||||
match (&left.kind, &right.kind) {
|
||||
// do not suggest to dereference literals
|
||||
(&ExprKind::Lit(..), _) | (_, &ExprKind::Lit(..)) => {},
|
||||
// &foo == &bar
|
||||
|
|
|
@ -34,7 +34,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ErasingOp {
|
|||
if e.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
if let ExprKind::Binary(ref cmp, ref left, ref right) = e.node {
|
||||
if let ExprKind::Binary(ref cmp, ref left, ref right) = e.kind {
|
||||
match cmp.node {
|
||||
BinOpKind::Mul | BinOpKind::BitAnd => {
|
||||
check(cx, left, e.span);
|
||||
|
|
|
@ -65,7 +65,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxedLocal {
|
|||
let parent_node = cx.tcx.hir().find(parent_id);
|
||||
|
||||
if let Some(Node::Item(item)) = parent_node {
|
||||
if let ItemKind::Impl(_, _, _, _, Some(..), _, _) = item.node {
|
||||
if let ItemKind::Impl(_, _, _, _, Some(..), _, _) = item.kind {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -139,9 +139,9 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
|
|||
}
|
||||
if let Categorization::Rvalue(..) = cmt.cat {
|
||||
if let Some(Node::Stmt(st)) = map.find(map.get_parent_node(cmt.hir_id)) {
|
||||
if let StmtKind::Local(ref loc) = st.node {
|
||||
if let StmtKind::Local(ref loc) = st.kind {
|
||||
if let Some(ref ex) = loc.init {
|
||||
if let ExprKind::Box(..) = ex.node {
|
||||
if let ExprKind::Box(..) = ex.kind {
|
||||
if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
|
||||
// let x = box (...)
|
||||
self.set.insert(consume_pat.hir_id);
|
||||
|
|
|
@ -65,7 +65,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EtaReduction {
|
|||
return;
|
||||
}
|
||||
|
||||
match expr.node {
|
||||
match expr.kind {
|
||||
ExprKind::Call(_, ref args) | ExprKind::MethodCall(_, _, ref args) => {
|
||||
for arg in args {
|
||||
check_closure(cx, arg)
|
||||
|
@ -77,14 +77,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EtaReduction {
|
|||
}
|
||||
|
||||
fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr) {
|
||||
if let ExprKind::Closure(_, ref decl, eid, _, _) = expr.node {
|
||||
if let ExprKind::Closure(_, ref decl, eid, _, _) = expr.kind {
|
||||
let body = cx.tcx.hir().body(eid);
|
||||
let ex = &body.value;
|
||||
|
||||
if_chain!(
|
||||
if let ExprKind::Call(ref caller, ref args) = ex.node;
|
||||
if let ExprKind::Call(ref caller, ref args) = ex.kind;
|
||||
|
||||
if let ExprKind::Path(_) = caller.node;
|
||||
if let ExprKind::Path(_) = caller.kind;
|
||||
|
||||
// Not the same number of arguments, there is no way the closure is the same as the function return;
|
||||
if args.len() == decl.inputs.len();
|
||||
|
@ -115,7 +115,7 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr) {
|
|||
);
|
||||
|
||||
if_chain!(
|
||||
if let ExprKind::MethodCall(ref path, _, ref args) = ex.node;
|
||||
if let ExprKind::MethodCall(ref path, _, ref args) = ex.kind;
|
||||
|
||||
// Not the same number of arguments, there is no way the closure is the same as the function return;
|
||||
if args.len() == decl.inputs.len();
|
||||
|
@ -207,9 +207,9 @@ fn compare_inputs(
|
|||
call_args: &mut dyn Iterator<Item = &Expr>,
|
||||
) -> bool {
|
||||
for (closure_input, function_arg) in closure_inputs.zip(call_args) {
|
||||
if let PatKind::Binding(_, _, ident, _) = closure_input.pat.node {
|
||||
if let PatKind::Binding(_, _, ident, _) = closure_input.pat.kind {
|
||||
// XXXManishearth Should I be checking the binding mode here?
|
||||
if let ExprKind::Path(QPath::Resolved(None, ref p)) = function_arg.node {
|
||||
if let ExprKind::Path(QPath::Resolved(None, ref p)) = function_arg.kind {
|
||||
if p.segments.len() != 1 {
|
||||
// If it's a proper path, it can't be a local variable
|
||||
return false;
|
||||
|
|
|
@ -60,9 +60,9 @@ declare_lint_pass!(EvalOrderDependence => [EVAL_ORDER_DEPENDENCE, DIVERGING_SUB_
|
|||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
// Find a write to a local variable.
|
||||
match expr.node {
|
||||
match expr.kind {
|
||||
ExprKind::Assign(ref lhs, _) | ExprKind::AssignOp(_, ref lhs, _) => {
|
||||
if let ExprKind::Path(ref qpath) = lhs.node {
|
||||
if let ExprKind::Path(ref qpath) = lhs.kind {
|
||||
if let QPath::Resolved(_, ref path) = *qpath {
|
||||
if path.segments.len() == 1 {
|
||||
if let def::Res::Local(var) = cx.tables.qpath_res(qpath, lhs.hir_id) {
|
||||
|
@ -82,7 +82,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence {
|
|||
}
|
||||
}
|
||||
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) {
|
||||
match stmt.node {
|
||||
match stmt.kind {
|
||||
StmtKind::Local(ref local) => {
|
||||
if let Local { init: Some(ref e), .. } = **local {
|
||||
DivergenceVisitor { cx }.visit_expr(e);
|
||||
|
@ -100,7 +100,7 @@ struct DivergenceVisitor<'a, 'tcx> {
|
|||
|
||||
impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> {
|
||||
fn maybe_walk_expr(&mut self, e: &'tcx Expr) {
|
||||
match e.node {
|
||||
match e.kind {
|
||||
ExprKind::Closure(..) => {},
|
||||
ExprKind::Match(ref e, ref arms, _) => {
|
||||
self.visit_expr(e);
|
||||
|
@ -124,7 +124,7 @@ impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> {
|
|||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, e: &'tcx Expr) {
|
||||
match e.node {
|
||||
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);
|
||||
|
@ -218,7 +218,7 @@ fn check_expr<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, expr: &'tcx Expr) -> St
|
|||
return StopEarly::KeepGoing;
|
||||
}
|
||||
|
||||
match expr.node {
|
||||
match expr.kind {
|
||||
ExprKind::Array(_)
|
||||
| ExprKind::Tup(_)
|
||||
| ExprKind::MethodCall(..)
|
||||
|
@ -261,7 +261,7 @@ fn check_expr<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, expr: &'tcx Expr) -> St
|
|||
}
|
||||
|
||||
fn check_stmt<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, stmt: &'tcx Stmt) -> StopEarly {
|
||||
match stmt.node {
|
||||
match stmt.kind {
|
||||
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => check_expr(vis, expr),
|
||||
// If the declaration is of a local variable, check its initializer
|
||||
// expression if it has one. Otherwise, keep going.
|
||||
|
@ -292,7 +292,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> {
|
|||
return;
|
||||
}
|
||||
|
||||
match expr.node {
|
||||
match expr.kind {
|
||||
ExprKind::Path(ref qpath) => {
|
||||
if_chain! {
|
||||
if let QPath::Resolved(None, ref path) = *qpath;
|
||||
|
@ -344,7 +344,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> {
|
|||
/// Returns `true` if `expr` is the LHS of an assignment, like `expr = ...`.
|
||||
fn is_in_assignment_position(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
|
||||
if let Some(parent) = get_parent_expr(cx, expr) {
|
||||
if let ExprKind::Assign(ref lhs, _) = parent.node {
|
||||
if let ExprKind::Assign(ref lhs, _) = parent.kind {
|
||||
return lhs.hir_id == expr.hir_id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExcessivePrecision {
|
|||
if_chain! {
|
||||
let ty = cx.tables.expr_ty(expr);
|
||||
if let ty::Float(fty) = ty.kind;
|
||||
if let hir::ExprKind::Lit(ref lit) = expr.node;
|
||||
if let hir::ExprKind::Lit(ref lit) = expr.kind;
|
||||
if let LitKind::Float(sym, _) | LitKind::FloatUnsuffixed(sym) = lit.node;
|
||||
if let Some(sugg) = self.check(sym, fty);
|
||||
then {
|
||||
|
|
|
@ -32,17 +32,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitWrite {
|
|||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
if_chain! {
|
||||
// match call to unwrap
|
||||
if let ExprKind::MethodCall(ref unwrap_fun, _, ref unwrap_args) = expr.node;
|
||||
if let ExprKind::MethodCall(ref unwrap_fun, _, ref unwrap_args) = expr.kind;
|
||||
if unwrap_fun.ident.name == sym!(unwrap);
|
||||
// match call to write_fmt
|
||||
if unwrap_args.len() > 0;
|
||||
if let ExprKind::MethodCall(ref write_fun, _, ref write_args) =
|
||||
unwrap_args[0].node;
|
||||
unwrap_args[0].kind;
|
||||
if write_fun.ident.name == sym!(write_fmt);
|
||||
// match calls to std::io::stdout() / std::io::stderr ()
|
||||
if write_args.len() > 0;
|
||||
if let ExprKind::Call(ref dest_fun, _) = write_args[0].node;
|
||||
if let ExprKind::Path(ref qpath) = dest_fun.node;
|
||||
if let ExprKind::Call(ref dest_fun, _) = write_args[0].kind;
|
||||
if let ExprKind::Path(ref qpath) = dest_fun.kind;
|
||||
if let Some(dest_fun_id) = resolve_node(cx, qpath, dest_fun.hir_id).opt_def_id();
|
||||
if let Some(dest_name) = if match_def_path(cx, dest_fun_id, &paths::STDOUT) {
|
||||
Some("stdout")
|
||||
|
@ -136,13 +136,13 @@ fn write_output_string(write_args: &HirVec<Expr>) -> Option<String> {
|
|||
if_chain! {
|
||||
// Obtain the string that should be printed
|
||||
if write_args.len() > 1;
|
||||
if let ExprKind::Call(_, ref output_args) = write_args[1].node;
|
||||
if let ExprKind::Call(_, ref output_args) = write_args[1].kind;
|
||||
if output_args.len() > 0;
|
||||
if let ExprKind::AddrOf(_, ref output_string_expr) = output_args[0].node;
|
||||
if let ExprKind::Array(ref string_exprs) = output_string_expr.node;
|
||||
if let ExprKind::AddrOf(_, ref output_string_expr) = output_args[0].kind;
|
||||
if let ExprKind::Array(ref string_exprs) = output_string_expr.kind;
|
||||
// we only want to provide an automatic suggestion for simple (non-format) strings
|
||||
if string_exprs.len() == 1;
|
||||
if let ExprKind::Lit(ref lit) = string_exprs[0].node;
|
||||
if let ExprKind::Lit(ref lit) = string_exprs[0].kind;
|
||||
if let LitKind::Str(ref write_output, _) = lit.node;
|
||||
then {
|
||||
return Some(write_output.to_string())
|
||||
|
|
|
@ -35,7 +35,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FallibleImplFrom {
|
|||
// check for `impl From<???> for ..`
|
||||
let impl_def_id = cx.tcx.hir().local_def_id(item.hir_id);
|
||||
if_chain! {
|
||||
if let hir::ItemKind::Impl(.., ref impl_items) = item.node;
|
||||
if let hir::ItemKind::Impl(.., ref impl_items) = item.kind;
|
||||
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_def_id);
|
||||
if match_def_path(cx, impl_trait_ref.def_id, &FROM_TRAIT);
|
||||
then {
|
||||
|
@ -59,8 +59,8 @@ fn lint_impl_body<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, impl_span: Span, impl_it
|
|||
fn visit_expr(&mut self, expr: &'tcx Expr) {
|
||||
// check for `begin_panic`
|
||||
if_chain! {
|
||||
if let ExprKind::Call(ref func_expr, _) = expr.node;
|
||||
if let ExprKind::Path(QPath::Resolved(_, ref path)) = func_expr.node;
|
||||
if let ExprKind::Call(ref func_expr, _) = expr.kind;
|
||||
if let ExprKind::Path(QPath::Resolved(_, ref path)) = func_expr.kind;
|
||||
if let Some(path_def_id) = path.res.opt_def_id();
|
||||
if match_def_path(self.lcx, path_def_id, &BEGIN_PANIC) ||
|
||||
match_def_path(self.lcx, path_def_id, &BEGIN_PANIC_FMT);
|
||||
|
@ -91,7 +91,7 @@ fn lint_impl_body<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, impl_span: Span, impl_it
|
|||
if_chain! {
|
||||
if impl_item.ident.name == sym!(from);
|
||||
if let ImplItemKind::Method(_, body_id) =
|
||||
cx.tcx.hir().impl_item(impl_item.id).node;
|
||||
cx.tcx.hir().impl_item(impl_item.id).kind;
|
||||
then {
|
||||
// check the body for `begin_panic` or `unwrap`
|
||||
let body = cx.tcx.hir().body(body_id);
|
||||
|
|
|
@ -72,37 +72,37 @@ fn span_useless_format<T: LintContext>(cx: &T, span: Span, help: &str, mut sugg:
|
|||
|
||||
fn on_argumentv1_new<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, arms: &'a [Arm]) -> Option<String> {
|
||||
if_chain! {
|
||||
if let ExprKind::AddrOf(_, ref format_args) = expr.node;
|
||||
if let ExprKind::Array(ref elems) = arms[0].body.node;
|
||||
if let ExprKind::AddrOf(_, ref format_args) = expr.kind;
|
||||
if let ExprKind::Array(ref elems) = arms[0].body.kind;
|
||||
if elems.len() == 1;
|
||||
if let ExprKind::Call(ref fun, ref args) = elems[0].node;
|
||||
if let ExprKind::Path(ref qpath) = fun.node;
|
||||
if let ExprKind::Call(ref fun, ref args) = elems[0].kind;
|
||||
if let ExprKind::Path(ref qpath) = fun.kind;
|
||||
if let Some(did) = resolve_node(cx, qpath, fun.hir_id).opt_def_id();
|
||||
if match_def_path(cx, did, &paths::FMT_ARGUMENTV1_NEW);
|
||||
// matches `core::fmt::Display::fmt`
|
||||
if args.len() == 2;
|
||||
if let ExprKind::Path(ref qpath) = args[1].node;
|
||||
if let ExprKind::Path(ref qpath) = args[1].kind;
|
||||
if let Some(did) = resolve_node(cx, qpath, args[1].hir_id).opt_def_id();
|
||||
if match_def_path(cx, did, &paths::DISPLAY_FMT_METHOD);
|
||||
// check `(arg0,)` in match block
|
||||
if let PatKind::Tuple(ref pats, None) = arms[0].pat.node;
|
||||
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]));
|
||||
if ty.kind != rustc::ty::Str && !match_type(cx, ty, &paths::STRING) {
|
||||
return None;
|
||||
}
|
||||
if let ExprKind::Lit(ref lit) = format_args.node {
|
||||
if let ExprKind::Lit(ref lit) = format_args.kind {
|
||||
if let LitKind::Str(ref s, _) = lit.node {
|
||||
return Some(format!("{:?}.to_string()", s.as_str()));
|
||||
}
|
||||
} else {
|
||||
let snip = snippet(cx, format_args.span, "<arg>");
|
||||
if let ExprKind::MethodCall(ref path, _, _) = format_args.node {
|
||||
if let ExprKind::MethodCall(ref path, _, _) = format_args.kind {
|
||||
if path.ident.name == sym!(to_string) {
|
||||
return Some(format!("{}", snip));
|
||||
}
|
||||
} else if let ExprKind::Binary(..) = format_args.node {
|
||||
} else if let ExprKind::Binary(..) = format_args.kind {
|
||||
return Some(format!("{}", snip));
|
||||
}
|
||||
return Some(format!("{}.to_string()", snip));
|
||||
|
@ -114,22 +114,22 @@ fn on_argumentv1_new<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, arm
|
|||
|
||||
fn on_new_v1<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Option<String> {
|
||||
if_chain! {
|
||||
if let ExprKind::Call(ref fun, ref args) = expr.node;
|
||||
if let ExprKind::Call(ref fun, ref args) = expr.kind;
|
||||
if args.len() == 2;
|
||||
if let ExprKind::Path(ref qpath) = fun.node;
|
||||
if let ExprKind::Path(ref qpath) = fun.kind;
|
||||
if let Some(did) = resolve_node(cx, qpath, fun.hir_id).opt_def_id();
|
||||
if match_def_path(cx, did, &paths::FMT_ARGUMENTS_NEW_V1);
|
||||
// Argument 1 in `new_v1()`
|
||||
if let ExprKind::AddrOf(_, ref arr) = args[0].node;
|
||||
if let ExprKind::Array(ref pieces) = arr.node;
|
||||
if let ExprKind::AddrOf(_, ref arr) = args[0].kind;
|
||||
if let ExprKind::Array(ref pieces) = arr.kind;
|
||||
if pieces.len() == 1;
|
||||
if let ExprKind::Lit(ref lit) = pieces[0].node;
|
||||
if let ExprKind::Lit(ref lit) = pieces[0].kind;
|
||||
if let LitKind::Str(ref s, _) = lit.node;
|
||||
// Argument 2 in `new_v1()`
|
||||
if let ExprKind::AddrOf(_, ref arg1) = args[1].node;
|
||||
if let ExprKind::Match(ref matchee, ref arms, MatchSource::Normal) = arg1.node;
|
||||
if let ExprKind::AddrOf(_, ref arg1) = args[1].kind;
|
||||
if let ExprKind::Match(ref matchee, ref arms, MatchSource::Normal) = arg1.kind;
|
||||
if arms.len() == 1;
|
||||
if let ExprKind::Tup(ref tup) = matchee.node;
|
||||
if let ExprKind::Tup(ref tup) = matchee.kind;
|
||||
then {
|
||||
// `format!("foo")` expansion contains `match () { () => [], }`
|
||||
if tup.is_empty() {
|
||||
|
@ -144,23 +144,23 @@ fn on_new_v1<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Option<S
|
|||
|
||||
fn on_new_v1_fmt<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Option<String> {
|
||||
if_chain! {
|
||||
if let ExprKind::Call(ref fun, ref args) = expr.node;
|
||||
if let ExprKind::Call(ref fun, ref args) = expr.kind;
|
||||
if args.len() == 3;
|
||||
if let ExprKind::Path(ref qpath) = fun.node;
|
||||
if let ExprKind::Path(ref qpath) = fun.kind;
|
||||
if let Some(did) = resolve_node(cx, qpath, fun.hir_id).opt_def_id();
|
||||
if match_def_path(cx, did, &paths::FMT_ARGUMENTS_NEW_V1_FORMATTED);
|
||||
if check_unformatted(&args[2]);
|
||||
// Argument 1 in `new_v1_formatted()`
|
||||
if let ExprKind::AddrOf(_, ref arr) = args[0].node;
|
||||
if let ExprKind::Array(ref pieces) = arr.node;
|
||||
if let ExprKind::AddrOf(_, ref arr) = args[0].kind;
|
||||
if let ExprKind::Array(ref pieces) = arr.kind;
|
||||
if pieces.len() == 1;
|
||||
if let ExprKind::Lit(ref lit) = pieces[0].node;
|
||||
if let ExprKind::Lit(ref lit) = pieces[0].kind;
|
||||
if let LitKind::Str(..) = lit.node;
|
||||
// Argument 2 in `new_v1_formatted()`
|
||||
if let ExprKind::AddrOf(_, ref arg1) = args[1].node;
|
||||
if let ExprKind::Match(ref matchee, ref arms, MatchSource::Normal) = arg1.node;
|
||||
if let ExprKind::AddrOf(_, ref arg1) = args[1].kind;
|
||||
if let ExprKind::Match(ref matchee, ref arms, MatchSource::Normal) = arg1.kind;
|
||||
if arms.len() == 1;
|
||||
if let ExprKind::Tup(ref tup) = matchee.node;
|
||||
if let ExprKind::Tup(ref tup) = matchee.kind;
|
||||
then {
|
||||
return on_argumentv1_new(cx, &tup[0], arms);
|
||||
}
|
||||
|
@ -181,19 +181,19 @@ fn on_new_v1_fmt<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Opti
|
|||
/// ```
|
||||
fn check_unformatted(expr: &Expr) -> bool {
|
||||
if_chain! {
|
||||
if let ExprKind::AddrOf(_, ref expr) = expr.node;
|
||||
if let ExprKind::Array(ref exprs) = expr.node;
|
||||
if let ExprKind::AddrOf(_, ref expr) = expr.kind;
|
||||
if let ExprKind::Array(ref exprs) = expr.kind;
|
||||
if exprs.len() == 1;
|
||||
// struct `core::fmt::rt::v1::Argument`
|
||||
if let ExprKind::Struct(_, ref fields, _) = exprs[0].node;
|
||||
if let ExprKind::Struct(_, ref fields, _) = exprs[0].kind;
|
||||
if let Some(format_field) = fields.iter().find(|f| f.ident.name == sym!(format));
|
||||
// struct `core::fmt::rt::v1::FormatSpec`
|
||||
if let ExprKind::Struct(_, ref fields, _) = format_field.expr.node;
|
||||
if let ExprKind::Struct(_, ref fields, _) = format_field.expr.kind;
|
||||
if let Some(precision_field) = fields.iter().find(|f| f.ident.name == sym!(precision));
|
||||
if let ExprKind::Path(ref precision_path) = precision_field.expr.node;
|
||||
if let ExprKind::Path(ref precision_path) = precision_field.expr.kind;
|
||||
if last_path_segment(precision_path).ident.name == sym!(Implied);
|
||||
if let Some(width_field) = fields.iter().find(|f| f.ident.name == sym!(width));
|
||||
if let ExprKind::Path(ref width_qpath) = width_field.expr.node;
|
||||
if let ExprKind::Path(ref width_qpath) = width_field.expr.kind;
|
||||
if last_path_segment(width_qpath).ident.name == sym!(Implied);
|
||||
then {
|
||||
return true;
|
||||
|
|
|
@ -87,7 +87,7 @@ declare_lint_pass!(Formatting => [
|
|||
impl EarlyLintPass for Formatting {
|
||||
fn check_block(&mut self, cx: &EarlyContext<'_>, block: &Block) {
|
||||
for w in block.stmts.windows(2) {
|
||||
match (&w[0].node, &w[1].node) {
|
||||
match (&w[0].kind, &w[1].kind) {
|
||||
(&StmtKind::Expr(ref first), &StmtKind::Expr(ref second))
|
||||
| (&StmtKind::Expr(ref first), &StmtKind::Semi(ref second)) => {
|
||||
check_missing_else(cx, first, second);
|
||||
|
@ -106,10 +106,10 @@ impl EarlyLintPass for Formatting {
|
|||
|
||||
/// Implementation of the `SUSPICIOUS_ASSIGNMENT_FORMATTING` lint.
|
||||
fn check_assign(cx: &EarlyContext<'_>, expr: &Expr) {
|
||||
if let ExprKind::Assign(ref lhs, ref rhs) = expr.node {
|
||||
if let ExprKind::Assign(ref lhs, ref rhs) = expr.kind {
|
||||
if !differing_macro_contexts(lhs.span, rhs.span) && !lhs.span.from_expansion() {
|
||||
let eq_span = lhs.span.between(rhs.span);
|
||||
if let ExprKind::Unary(op, ref sub_rhs) = rhs.node {
|
||||
if let ExprKind::Unary(op, ref sub_rhs) = rhs.kind {
|
||||
if let Some(eq_snippet) = snippet_opt(cx, eq_span) {
|
||||
let op = UnOp::to_string(op);
|
||||
let eqop_span = lhs.span.between(sub_rhs.span);
|
||||
|
@ -136,7 +136,7 @@ fn check_assign(cx: &EarlyContext<'_>, expr: &Expr) {
|
|||
/// Implementation of the `SUSPICIOUS_ELSE_FORMATTING` lint for weird `else`.
|
||||
fn check_else(cx: &EarlyContext<'_>, expr: &Expr) {
|
||||
if_chain! {
|
||||
if let ExprKind::If(_, then, Some(else_)) = &expr.node;
|
||||
if let ExprKind::If(_, then, Some(else_)) = &expr.kind;
|
||||
if is_block(else_) || is_if(else_);
|
||||
if !differing_macro_contexts(then.span, else_.span);
|
||||
if !then.span.from_expansion() && !in_external_macro(cx.sess, expr.span);
|
||||
|
@ -179,9 +179,9 @@ fn has_unary_equivalent(bin_op: BinOpKind) -> bool {
|
|||
|
||||
/// Implementation of the `POSSIBLE_MISSING_COMMA` lint for array
|
||||
fn check_array(cx: &EarlyContext<'_>, expr: &Expr) {
|
||||
if let ExprKind::Array(ref array) = expr.node {
|
||||
if let ExprKind::Array(ref array) = expr.kind {
|
||||
for element in array {
|
||||
if let ExprKind::Binary(ref op, ref lhs, _) = element.node {
|
||||
if let ExprKind::Binary(ref op, ref lhs, _) = element.kind {
|
||||
if has_unary_equivalent(op.node) && !differing_macro_contexts(lhs.span, op.span) {
|
||||
let space_span = lhs.span.between(op.span);
|
||||
if let Some(space_snippet) = snippet_opt(cx, space_span) {
|
||||
|
@ -237,7 +237,7 @@ fn check_missing_else(cx: &EarlyContext<'_>, first: &Expr, second: &Expr) {
|
|||
}
|
||||
|
||||
fn is_block(expr: &Expr) -> bool {
|
||||
if let ExprKind::Block(..) = expr.node {
|
||||
if let ExprKind::Block(..) = expr.kind {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
@ -246,7 +246,7 @@ fn is_block(expr: &Expr) -> bool {
|
|||
|
||||
/// Check if the expression is an `if` or `if let`
|
||||
fn is_if(expr: &Expr) -> bool {
|
||||
if let ExprKind::If(..) = expr.node {
|
||||
if let ExprKind::If(..) = expr.kind {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
|
|
@ -109,7 +109,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
|
|||
hir_id: hir::HirId,
|
||||
) {
|
||||
let is_impl = if let Some(hir::Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) {
|
||||
matches!(item.node, hir::ItemKind::Impl(_, _, _, _, Some(_), _, _))
|
||||
matches!(item.kind, hir::ItemKind::Impl(_, _, _, _, Some(_), _, _))
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
@ -145,7 +145,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
|
|||
}
|
||||
|
||||
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::TraitItem) {
|
||||
if let hir::TraitItemKind::Method(ref sig, ref eid) = item.node {
|
||||
if let hir::TraitItemKind::Method(ref sig, ref eid) = item.kind {
|
||||
// don't lint extern functions decls, it's not their fault
|
||||
if sig.header.abi == Abi::Rust {
|
||||
self.check_arg_number(cx, &sig.decl, item.span);
|
||||
|
@ -269,7 +269,7 @@ impl<'a, 'tcx> Functions {
|
|||
}
|
||||
|
||||
fn raw_ptr_arg(arg: &hir::Param, ty: &hir::Ty) -> Option<hir::HirId> {
|
||||
if let (&hir::PatKind::Binding(_, id, _, _), &hir::TyKind::Ptr(_)) = (&arg.pat.node, &ty.node) {
|
||||
if let (&hir::PatKind::Binding(_, id, _, _), &hir::TyKind::Ptr(_)) = (&arg.pat.kind, &ty.kind) {
|
||||
Some(id)
|
||||
} else {
|
||||
None
|
||||
|
@ -284,7 +284,7 @@ struct DerefVisitor<'a, 'tcx> {
|
|||
|
||||
impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
|
||||
match expr.node {
|
||||
match expr.kind {
|
||||
hir::ExprKind::Call(ref f, ref args) => {
|
||||
let ty = self.tables.expr_ty(f);
|
||||
|
||||
|
@ -317,7 +317,7 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> {
|
|||
|
||||
impl<'a, 'tcx> DerefVisitor<'a, 'tcx> {
|
||||
fn check_arg(&self, ptr: &hir::Expr) {
|
||||
if let hir::ExprKind::Path(ref qpath) = ptr.node {
|
||||
if let hir::ExprKind::Path(ref qpath) = ptr.kind {
|
||||
if let Res::Local(id) = qpath_res(self.cx, qpath, ptr.hir_id) {
|
||||
if self.ptrs.contains(&id) {
|
||||
span_lint(
|
||||
|
|
|
@ -48,7 +48,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for GetLastWithLen {
|
|||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
if_chain! {
|
||||
// Is a method call
|
||||
if let ExprKind::MethodCall(ref path, _, ref args) = expr.node;
|
||||
if let ExprKind::MethodCall(ref path, _, ref args) = expr.kind;
|
||||
|
||||
// Method name is "get"
|
||||
if path.ident.name == Symbol::intern("get");
|
||||
|
@ -67,10 +67,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for GetLastWithLen {
|
|||
},
|
||||
lhs,
|
||||
rhs,
|
||||
) = &get_index_arg.node;
|
||||
) = &get_index_arg.kind;
|
||||
|
||||
// LHS of subtraction is "x.len()"
|
||||
if let ExprKind::MethodCall(arg_lhs_path, _, lhs_args) = &lhs.node;
|
||||
if let ExprKind::MethodCall(arg_lhs_path, _, lhs_args) = &lhs.kind;
|
||||
if arg_lhs_path.ident.name == Symbol::intern("len");
|
||||
if let Some(arg_lhs_struct) = lhs_args.get(0);
|
||||
|
||||
|
@ -78,7 +78,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for GetLastWithLen {
|
|||
if SpanlessEq::new(cx).eq_expr(struct_calling_on, arg_lhs_struct);
|
||||
|
||||
// RHS of subtraction is 1
|
||||
if let ExprKind::Lit(rhs_lit) = &rhs.node;
|
||||
if let ExprKind::Lit(rhs_lit) = &rhs.kind;
|
||||
if let LitKind::Int(rhs_value, ..) = rhs_lit.node;
|
||||
if rhs_value == 1;
|
||||
|
||||
|
|
|
@ -41,13 +41,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
|
|||
return;
|
||||
}
|
||||
|
||||
match e.node {
|
||||
match e.kind {
|
||||
ExprKind::Match(_, ref arms, MatchSource::TryDesugar) => {
|
||||
let e = match arms[0].body.node {
|
||||
let e = match arms[0].body.kind {
|
||||
ExprKind::Ret(Some(ref e)) | ExprKind::Break(_, Some(ref e)) => e,
|
||||
_ => return,
|
||||
};
|
||||
if let ExprKind::Call(_, ref args) = e.node {
|
||||
if let ExprKind::Call(_, ref args) = e.kind {
|
||||
self.try_desugar_arm.push(args[0].hir_id);
|
||||
}
|
||||
},
|
||||
|
@ -87,7 +87,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
|
|||
},
|
||||
|
||||
ExprKind::Call(ref path, ref args) => {
|
||||
if let ExprKind::Path(ref qpath) = path.node {
|
||||
if let ExprKind::Path(ref qpath) = path.kind {
|
||||
if let Some(def_id) = resolve_node(cx, qpath, path.hir_id).opt_def_id() {
|
||||
if match_def_path(cx, def_id, &paths::FROM_FROM) {
|
||||
let a = cx.tables.expr_ty(e);
|
||||
|
|
|
@ -32,7 +32,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityOp {
|
|||
if e.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
if let ExprKind::Binary(ref cmp, ref left, ref right) = e.node {
|
||||
if let ExprKind::Binary(ref cmp, ref left, ref right) = e.kind {
|
||||
match cmp.node {
|
||||
BinOpKind::Add | BinOpKind::BitOr | BinOpKind::BitXor => {
|
||||
check(cx, left, 0, e.span, right.span);
|
||||
|
|
|
@ -51,9 +51,9 @@ impl EarlyLintPass for IfNotElse {
|
|||
if in_external_macro(cx.sess(), item.span) {
|
||||
return;
|
||||
}
|
||||
if let ExprKind::If(ref cond, _, Some(ref els)) = item.node {
|
||||
if let ExprKind::Block(..) = els.node {
|
||||
match cond.node {
|
||||
if let ExprKind::If(ref cond, _, Some(ref els)) = item.kind {
|
||||
if let ExprKind::Block(..) = els.kind {
|
||||
match cond.kind {
|
||||
ExprKind::Unary(UnOp::Not, _) => {
|
||||
span_help_and_lint(
|
||||
cx,
|
||||
|
|
|
@ -62,7 +62,7 @@ fn lint(cx: &LateContext<'_, '_>, outer_span: Span, inner_span: Span, msg: &str)
|
|||
}
|
||||
|
||||
fn expr_match(cx: &LateContext<'_, '_>, expr: &Expr) {
|
||||
match &expr.node {
|
||||
match &expr.kind {
|
||||
// loops could be using `break` instead of `return`
|
||||
ExprKind::Block(block, ..) | ExprKind::Loop(block, ..) => {
|
||||
if let Some(expr) = &block.expr {
|
||||
|
@ -71,9 +71,9 @@ fn expr_match(cx: &LateContext<'_, '_>, expr: &Expr) {
|
|||
// only needed in the case of `break` with `;` at the end
|
||||
else if let Some(stmt) = block.stmts.last() {
|
||||
if_chain! {
|
||||
if let StmtKind::Semi(expr, ..) = &stmt.node;
|
||||
if let StmtKind::Semi(expr, ..) = &stmt.kind;
|
||||
// make sure it's a break, otherwise we want to skip
|
||||
if let ExprKind::Break(.., break_expr) = &expr.node;
|
||||
if let ExprKind::Break(.., break_expr) = &expr.kind;
|
||||
if let Some(break_expr) = break_expr;
|
||||
then {
|
||||
lint(cx, expr.span, break_expr.span, LINT_BREAK);
|
||||
|
@ -108,7 +108,7 @@ fn expr_match(cx: &LateContext<'_, '_>, expr: &Expr) {
|
|||
// make sure it's not a call that panics
|
||||
ExprKind::Call(expr, ..) => {
|
||||
if_chain! {
|
||||
if let ExprKind::Path(qpath) = &expr.node;
|
||||
if let ExprKind::Path(qpath) = &expr.kind;
|
||||
if let Some(path_def_id) = resolve_node(cx, qpath, expr.hir_id).opt_def_id();
|
||||
if match_def_path(cx, path_def_id, &BEGIN_PANIC) ||
|
||||
match_def_path(cx, path_def_id, &BEGIN_PANIC_FMT);
|
||||
|
|
|
@ -89,7 +89,7 @@ declare_lint_pass!(IndexingSlicing => [INDEXING_SLICING, OUT_OF_BOUNDS_INDEXING]
|
|||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
if let ExprKind::Index(ref array, ref index) = &expr.node {
|
||||
if let ExprKind::Index(ref array, ref index) = &expr.kind {
|
||||
let ty = cx.tables.expr_ty(array);
|
||||
if let Some(range) = higher::range(cx, index) {
|
||||
// Ranged indexes, i.e., &x[n..m], &x[n..], &x[..n] and &x[..]
|
||||
|
|
|
@ -46,9 +46,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InfallibleDestructingMatch {
|
|||
fn check_local(&mut self, cx: &LateContext<'a, 'tcx>, local: &'tcx Local) {
|
||||
if_chain! {
|
||||
if let Some(ref expr) = local.init;
|
||||
if let ExprKind::Match(ref target, ref arms, MatchSource::Normal) = expr.node;
|
||||
if let ExprKind::Match(ref target, ref arms, MatchSource::Normal) = expr.kind;
|
||||
if arms.len() == 1 && arms[0].guard.is_none();
|
||||
if let PatKind::TupleStruct(QPath::Resolved(None, ref variant_name), ref args, _) = arms[0].pat.node;
|
||||
if let PatKind::TupleStruct(QPath::Resolved(None, ref variant_name), ref args, _) = arms[0].pat.kind;
|
||||
if args.len() == 1;
|
||||
if let Some(arg) = get_arg_name(&args[0]);
|
||||
let body = remove_blocks(&arms[0].body);
|
||||
|
|
|
@ -138,7 +138,7 @@ const HEURISTICS: [(&str, usize, Heuristic, Finiteness); 19] = [
|
|||
];
|
||||
|
||||
fn is_infinite(cx: &LateContext<'_, '_>, expr: &Expr) -> Finiteness {
|
||||
match expr.node {
|
||||
match expr.kind {
|
||||
ExprKind::MethodCall(ref method, _, ref args) => {
|
||||
for &(name, len, heuristic, cap) in &HEURISTICS {
|
||||
if method.ident.name.as_str() == name && args.len() == len {
|
||||
|
@ -152,7 +152,7 @@ fn is_infinite(cx: &LateContext<'_, '_>, expr: &Expr) -> Finiteness {
|
|||
}
|
||||
}
|
||||
if method.ident.name == sym!(flat_map) && args.len() == 2 {
|
||||
if let ExprKind::Closure(_, _, body_id, _, _) = args[1].node {
|
||||
if let ExprKind::Closure(_, _, body_id, _, _) = args[1].kind {
|
||||
let body = cx.tcx.hir().body(body_id);
|
||||
return is_infinite(cx, &body.value);
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ fn is_infinite(cx: &LateContext<'_, '_>, expr: &Expr) -> Finiteness {
|
|||
ExprKind::Block(ref block, _) => block.expr.as_ref().map_or(Finite, |e| is_infinite(cx, e)),
|
||||
ExprKind::Box(ref e) | ExprKind::AddrOf(_, ref e) => is_infinite(cx, e),
|
||||
ExprKind::Call(ref path, _) => {
|
||||
if let ExprKind::Path(ref qpath) = path.node {
|
||||
if let ExprKind::Path(ref qpath) = path.kind {
|
||||
match_qpath(qpath, &paths::REPEAT).into()
|
||||
} else {
|
||||
Finite
|
||||
|
@ -214,7 +214,7 @@ const INFINITE_COLLECTORS: [&[&str]; 8] = [
|
|||
];
|
||||
|
||||
fn complete_infinite_iter(cx: &LateContext<'_, '_>, expr: &Expr) -> Finiteness {
|
||||
match expr.node {
|
||||
match expr.kind {
|
||||
ExprKind::MethodCall(ref method, _, ref args) => {
|
||||
for &(name, len) in &COMPLETING_METHODS {
|
||||
if method.ident.name.as_str() == name && args.len() == len {
|
||||
|
|
|
@ -49,7 +49,7 @@ impl_lint_pass!(MultipleInherentImpl => [MULTIPLE_INHERENT_IMPL]);
|
|||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MultipleInherentImpl {
|
||||
fn check_item(&mut self, _: &LateContext<'a, 'tcx>, item: &'tcx Item) {
|
||||
if let ItemKind::Impl(_, _, _, ref generics, None, _, _) = item.node {
|
||||
if let ItemKind::Impl(_, _, _, ref generics, None, _, _) = item.kind {
|
||||
// Remember for each inherent implementation encoutered its span and generics
|
||||
// but filter out implementations that have generic params (type or lifetime)
|
||||
if generics.params.len() == 0 {
|
||||
|
|
|
@ -100,7 +100,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InherentToString {
|
|||
|
||||
if_chain! {
|
||||
// Check if item is a method, called to_string and has a parameter 'self'
|
||||
if let ImplItemKind::Method(ref signature, _) = impl_item.node;
|
||||
if let ImplItemKind::Method(ref signature, _) = impl_item.kind;
|
||||
if impl_item.ident.name.as_str() == "to_string";
|
||||
let decl = &signature.decl;
|
||||
if decl.implicit_self.has_implicit_self();
|
||||
|
|
|
@ -32,7 +32,7 @@ declare_lint_pass!(InlineFnWithoutBody => [INLINE_FN_WITHOUT_BODY]);
|
|||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InlineFnWithoutBody {
|
||||
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem) {
|
||||
if let TraitItemKind::Method(_, TraitMethod::Required(_)) = item.node {
|
||||
if let TraitItemKind::Method(_, TraitMethod::Required(_)) = item.kind {
|
||||
check_attrs(cx, item.ident.name, &item.attrs);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,17 +54,17 @@ enum Side {
|
|||
impl IntPlusOne {
|
||||
#[allow(clippy::cast_sign_loss)]
|
||||
fn check_lit(self, lit: &Lit, target_value: i128) -> bool {
|
||||
if let LitKind::Int(value, ..) = lit.node {
|
||||
if let LitKind::Int(value, ..) = lit.kind {
|
||||
return value == (target_value as u128);
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
fn check_binop(self, cx: &EarlyContext<'_>, binop: BinOpKind, lhs: &Expr, rhs: &Expr) -> Option<String> {
|
||||
match (binop, &lhs.node, &rhs.node) {
|
||||
match (binop, &lhs.kind, &rhs.kind) {
|
||||
// case where `x - 1 >= ...` or `-1 + x >= ...`
|
||||
(BinOpKind::Ge, &ExprKind::Binary(ref lhskind, ref lhslhs, ref lhsrhs), _) => {
|
||||
match (lhskind.node, &lhslhs.node, &lhsrhs.node) {
|
||||
match (lhskind.node, &lhslhs.kind, &lhsrhs.kind) {
|
||||
// `-1 + x`
|
||||
(BinOpKind::Add, &ExprKind::Lit(ref lit), _) if self.check_lit(lit, -1) => {
|
||||
self.generate_recommendation(cx, binop, lhsrhs, rhs, Side::LHS)
|
||||
|
@ -80,7 +80,7 @@ impl IntPlusOne {
|
|||
(BinOpKind::Ge, _, &ExprKind::Binary(ref rhskind, ref rhslhs, ref rhsrhs))
|
||||
if rhskind.node == BinOpKind::Add =>
|
||||
{
|
||||
match (&rhslhs.node, &rhsrhs.node) {
|
||||
match (&rhslhs.kind, &rhsrhs.kind) {
|
||||
// `y + 1` and `1 + y`
|
||||
(&ExprKind::Lit(ref lit), _) if self.check_lit(lit, 1) => {
|
||||
self.generate_recommendation(cx, binop, rhsrhs, lhs, Side::RHS)
|
||||
|
@ -95,7 +95,7 @@ impl IntPlusOne {
|
|||
(BinOpKind::Le, &ExprKind::Binary(ref lhskind, ref lhslhs, ref lhsrhs), _)
|
||||
if lhskind.node == BinOpKind::Add =>
|
||||
{
|
||||
match (&lhslhs.node, &lhsrhs.node) {
|
||||
match (&lhslhs.kind, &lhsrhs.kind) {
|
||||
// `1 + x` and `x + 1`
|
||||
(&ExprKind::Lit(ref lit), _) if self.check_lit(lit, 1) => {
|
||||
self.generate_recommendation(cx, binop, lhsrhs, rhs, Side::LHS)
|
||||
|
@ -108,7 +108,7 @@ impl IntPlusOne {
|
|||
}
|
||||
// case where `... >= y - 1` or `... >= -1 + y`
|
||||
(BinOpKind::Le, _, &ExprKind::Binary(ref rhskind, ref rhslhs, ref rhsrhs)) => {
|
||||
match (rhskind.node, &rhslhs.node, &rhsrhs.node) {
|
||||
match (rhskind.node, &rhslhs.kind, &rhsrhs.kind) {
|
||||
// `-1 + y`
|
||||
(BinOpKind::Add, &ExprKind::Lit(ref lit), _) if self.check_lit(lit, -1) => {
|
||||
self.generate_recommendation(cx, binop, rhsrhs, lhs, Side::RHS)
|
||||
|
@ -169,7 +169,7 @@ impl IntPlusOne {
|
|||
|
||||
impl EarlyLintPass for IntPlusOne {
|
||||
fn check_expr(&mut self, cx: &EarlyContext<'_>, item: &Expr) {
|
||||
if let ExprKind::Binary(ref kind, ref lhs, ref rhs) = item.node {
|
||||
if let ExprKind::Binary(ref kind, ref lhs, ref rhs) = item.kind {
|
||||
if let Some(ref rec) = self.check_binop(cx, kind.node, lhs, rhs) {
|
||||
self.emit_warning(cx, item, rec.clone());
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IntegerDivision {
|
|||
|
||||
fn is_integer_division<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) -> bool {
|
||||
if_chain! {
|
||||
if let hir::ExprKind::Binary(binop, left, right) = &expr.node;
|
||||
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));
|
||||
|
|
|
@ -46,7 +46,7 @@ impl EarlyLintPass for ItemsAfterStatements {
|
|||
let stmts = item
|
||||
.stmts
|
||||
.iter()
|
||||
.map(|stmt| &stmt.node)
|
||||
.map(|stmt| &stmt.kind)
|
||||
.skip_while(|s| matches!(**s, StmtKind::Item(..)));
|
||||
|
||||
// lint on all further items
|
||||
|
@ -55,7 +55,7 @@ impl EarlyLintPass for ItemsAfterStatements {
|
|||
if it.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
if let ItemKind::MacroDef(..) = it.node {
|
||||
if let ItemKind::MacroDef(..) = it.kind {
|
||||
// do not lint `macro_rules`, but continue processing further statements
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ impl_lint_pass!(LargeEnumVariant => [LARGE_ENUM_VARIANT]);
|
|||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeEnumVariant {
|
||||
fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item) {
|
||||
let did = cx.tcx.hir().local_def_id(item.hir_id);
|
||||
if let ItemKind::Enum(ref def, _) = item.node {
|
||||
if let ItemKind::Enum(ref def, _) = item.kind {
|
||||
let ty = cx.tcx.type_of(did);
|
||||
let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LenZero {
|
|||
return;
|
||||
}
|
||||
|
||||
match item.node {
|
||||
match item.kind {
|
||||
ItemKind::Trait(_, _, _, _, ref trait_items) => check_trait_items(cx, item, trait_items),
|
||||
ItemKind::Impl(_, _, _, _, None, _, ref impl_items) => check_impl_items(cx, item, impl_items),
|
||||
_ => (),
|
||||
|
@ -89,7 +89,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LenZero {
|
|||
return;
|
||||
}
|
||||
|
||||
if let ExprKind::Binary(Spanned { node: cmp, .. }, ref left, ref right) = expr.node {
|
||||
if let ExprKind::Binary(Spanned { node: cmp, .. }, ref left, ref right) = expr.kind {
|
||||
match cmp {
|
||||
BinOpKind::Eq => {
|
||||
check_cmp(cx, expr.span, left, right, "", 0); // len == 0
|
||||
|
@ -208,7 +208,7 @@ fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item, impl_items: &[ImplIte
|
|||
}
|
||||
|
||||
fn check_cmp(cx: &LateContext<'_, '_>, span: Span, method: &Expr, lit: &Expr, op: &str, compare_to: u32) {
|
||||
if let (&ExprKind::MethodCall(ref method_path, _, ref args), &ExprKind::Lit(ref lit)) = (&method.node, &lit.node) {
|
||||
if let (&ExprKind::MethodCall(ref method_path, _, ref args), &ExprKind::Lit(ref lit)) = (&method.kind, &lit.kind) {
|
||||
// check if we are in an is_empty() method
|
||||
if let Some(name) = get_item_name(cx, method) {
|
||||
if name.as_str() == "is_empty" {
|
||||
|
|
|
@ -60,12 +60,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
|
|||
while let Some(stmt) = it.next() {
|
||||
if_chain! {
|
||||
if let Some(expr) = it.peek();
|
||||
if let hir::StmtKind::Local(ref local) = stmt.node;
|
||||
if let hir::PatKind::Binding(mode, canonical_id, ident, None) = local.pat.node;
|
||||
if let hir::StmtKind::Expr(ref if_) = expr.node;
|
||||
if let hir::StmtKind::Local(ref local) = stmt.kind;
|
||||
if let hir::PatKind::Binding(mode, canonical_id, ident, None) = local.pat.kind;
|
||||
if let hir::StmtKind::Expr(ref if_) = expr.kind;
|
||||
if let Some((ref cond, ref then, ref else_)) = higher::if_block(&if_);
|
||||
if !used_in_expr(cx, canonical_id, cond);
|
||||
if let hir::ExprKind::Block(ref then, _) = then.node;
|
||||
if let hir::ExprKind::Block(ref then, _) = then.kind;
|
||||
if let Some(value) = check_assign(cx, canonical_id, &*then);
|
||||
if !used_in_expr(cx, canonical_id, value);
|
||||
then {
|
||||
|
@ -79,7 +79,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
|
|||
if has_interior_mutability { return; }
|
||||
|
||||
let (default_multi_stmts, default) = if let Some(ref else_) = *else_ {
|
||||
if let hir::ExprKind::Block(ref else_, _) = else_.node {
|
||||
if let hir::ExprKind::Block(ref else_, _) = else_.kind {
|
||||
if let Some(default) = check_assign(cx, canonical_id, else_) {
|
||||
(else_.stmts.len() > 1, default)
|
||||
} else if let Some(ref default) = local.init {
|
||||
|
@ -144,7 +144,7 @@ struct UsedVisitor<'a, 'tcx> {
|
|||
impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for UsedVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
|
||||
if_chain! {
|
||||
if let hir::ExprKind::Path(ref qpath) = expr.node;
|
||||
if let hir::ExprKind::Path(ref qpath) = expr.kind;
|
||||
if let Res::Local(local_id) = qpath_res(self.cx, qpath, expr.hir_id);
|
||||
if self.id == local_id;
|
||||
then {
|
||||
|
@ -167,9 +167,9 @@ fn check_assign<'a, 'tcx>(
|
|||
if_chain! {
|
||||
if block.expr.is_none();
|
||||
if let Some(expr) = block.stmts.iter().last();
|
||||
if let hir::StmtKind::Semi(ref expr) = expr.node;
|
||||
if let hir::ExprKind::Assign(ref var, ref value) = expr.node;
|
||||
if let hir::ExprKind::Path(ref qpath) = var.node;
|
||||
if let hir::StmtKind::Semi(ref expr) = expr.kind;
|
||||
if let hir::ExprKind::Assign(ref var, ref value) = expr.kind;
|
||||
if let hir::ExprKind::Path(ref qpath) = var.kind;
|
||||
if let Res::Local(local_id) = qpath_res(cx, qpath, var.hir_id);
|
||||
if decl == local_id;
|
||||
then {
|
||||
|
|
|
@ -59,13 +59,13 @@ declare_lint_pass!(Lifetimes => [NEEDLESS_LIFETIMES, EXTRA_UNUSED_LIFETIMES]);
|
|||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Lifetimes {
|
||||
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
|
||||
if let ItemKind::Fn(ref decl, _, ref generics, id) = item.node {
|
||||
if let ItemKind::Fn(ref decl, _, ref generics, id) = item.kind {
|
||||
check_fn_inner(cx, decl, Some(id), generics, item.span, true);
|
||||
}
|
||||
}
|
||||
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx ImplItem) {
|
||||
if let ImplItemKind::Method(ref sig, id) = item.node {
|
||||
if let ImplItemKind::Method(ref sig, id) = item.kind {
|
||||
let report_extra_lifetimes = trait_ref_of_method(cx, item.hir_id).is_none();
|
||||
check_fn_inner(
|
||||
cx,
|
||||
|
@ -79,7 +79,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Lifetimes {
|
|||
}
|
||||
|
||||
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem) {
|
||||
if let TraitItemKind::Method(ref sig, ref body) = item.node {
|
||||
if let TraitItemKind::Method(ref sig, ref body) = item.kind {
|
||||
let body = match *body {
|
||||
TraitMethod::Required(_) => None,
|
||||
TraitMethod::Provided(id) => Some(id),
|
||||
|
@ -350,7 +350,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
fn visit_ty(&mut self, ty: &'tcx Ty) {
|
||||
match ty.node {
|
||||
match ty.kind {
|
||||
TyKind::Rptr(ref lt, _) if lt.is_elided() => {
|
||||
self.record(&None);
|
||||
},
|
||||
|
@ -359,7 +359,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
|
|||
},
|
||||
TyKind::Def(item, _) => {
|
||||
let map = self.cx.tcx.hir();
|
||||
if let ItemKind::OpaqueTy(ref exist_ty) = map.expect_item(item.id).node {
|
||||
if let ItemKind::OpaqueTy(ref exist_ty) = map.expect_item(item.id).kind {
|
||||
for bound in &exist_ty.bounds {
|
||||
if let GenericBound::Outlives(_) = *bound {
|
||||
self.record(&None);
|
||||
|
|
|
@ -347,7 +347,7 @@ impl EarlyLintPass for LiteralDigitGrouping {
|
|||
return;
|
||||
}
|
||||
|
||||
if let ExprKind::Lit(ref lit) = expr.node {
|
||||
if let ExprKind::Lit(ref lit) = expr.kind {
|
||||
self.check_lit(cx, lit)
|
||||
}
|
||||
}
|
||||
|
@ -356,7 +356,7 @@ impl EarlyLintPass for LiteralDigitGrouping {
|
|||
impl LiteralDigitGrouping {
|
||||
fn check_lit(self, cx: &EarlyContext<'_>, lit: &Lit) {
|
||||
let in_macro = in_macro(lit.span);
|
||||
match lit.node {
|
||||
match lit.kind {
|
||||
LitKind::Int(..) => {
|
||||
// Lint integral literals.
|
||||
if_chain! {
|
||||
|
@ -492,7 +492,7 @@ impl EarlyLintPass for DecimalLiteralRepresentation {
|
|||
return;
|
||||
}
|
||||
|
||||
if let ExprKind::Lit(ref lit) = expr.node {
|
||||
if let ExprKind::Lit(ref lit) = expr.kind {
|
||||
self.check_lit(cx, lit)
|
||||
}
|
||||
}
|
||||
|
@ -505,7 +505,7 @@ impl DecimalLiteralRepresentation {
|
|||
fn check_lit(self, cx: &EarlyContext<'_>, lit: &Lit) {
|
||||
// Lint integral literals.
|
||||
if_chain! {
|
||||
if let LitKind::Int(..) = lit.node;
|
||||
if let LitKind::Int(..) = lit.kind;
|
||||
if let Some(src) = snippet_opt(cx, lit.span);
|
||||
if let Some(firstch) = src.chars().next();
|
||||
if char::to_digit(firstch, 10).is_some();
|
||||
|
|
|
@ -486,7 +486,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Loops {
|
|||
}
|
||||
|
||||
// check for never_loop
|
||||
if let ExprKind::Loop(ref block, _, _) = expr.node {
|
||||
if let ExprKind::Loop(ref block, _, _) = expr.kind {
|
||||
match never_loop_block(block, expr.hir_id) {
|
||||
NeverLoopResult::AlwaysBreak => span_lint(cx, NEVER_LOOP, expr.span, "this loop never actually loops"),
|
||||
NeverLoopResult::MayContinueMainLoop | NeverLoopResult::Otherwise => (),
|
||||
|
@ -496,7 +496,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Loops {
|
|||
// check for `loop { if let {} else break }` that could be `while let`
|
||||
// (also matches an explicit "match" instead of "if let")
|
||||
// (even if the "match" or "if let" is used for declaration)
|
||||
if let ExprKind::Loop(ref block, _, LoopSource::Loop) = expr.node {
|
||||
if let ExprKind::Loop(ref block, _, LoopSource::Loop) = expr.kind {
|
||||
// also check for empty `loop {}` statements
|
||||
if block.stmts.is_empty() && block.expr.is_none() {
|
||||
span_lint(
|
||||
|
@ -512,7 +512,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Loops {
|
|||
let inner_stmt_expr = extract_expr_from_first_stmt(block);
|
||||
// or extract the first expression (if any) from the block
|
||||
if let Some(inner) = inner_stmt_expr.or_else(|| extract_first_expr(block)) {
|
||||
if let ExprKind::Match(ref matchexpr, ref arms, ref source) = inner.node {
|
||||
if let ExprKind::Match(ref matchexpr, ref arms, ref source) = inner.kind {
|
||||
// ensure "if let" compatible match structure
|
||||
match *source {
|
||||
MatchSource::Normal | MatchSource::IfLetDesugar { .. } => {
|
||||
|
@ -551,12 +551,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Loops {
|
|||
}
|
||||
}
|
||||
}
|
||||
if let ExprKind::Match(ref match_expr, ref arms, MatchSource::WhileLetDesugar) = expr.node {
|
||||
let pat = &arms[0].pat.node;
|
||||
if let ExprKind::Match(ref match_expr, ref arms, MatchSource::WhileLetDesugar) = expr.kind {
|
||||
let pat = &arms[0].pat.kind;
|
||||
if let (
|
||||
&PatKind::TupleStruct(ref qpath, ref pat_args, _),
|
||||
&ExprKind::MethodCall(ref method_path, _, ref method_args),
|
||||
) = (pat, &match_expr.node)
|
||||
) = (pat, &match_expr.kind)
|
||||
{
|
||||
let iter_expr = &method_args[0];
|
||||
let lhs_constructor = last_path_segment(qpath);
|
||||
|
@ -649,7 +649,7 @@ fn never_loop_block(block: &Block, main_loop_id: HirId) -> NeverLoopResult {
|
|||
}
|
||||
|
||||
fn stmt_to_expr(stmt: &Stmt) -> Option<&Expr> {
|
||||
match stmt.node {
|
||||
match stmt.kind {
|
||||
StmtKind::Semi(ref e, ..) | StmtKind::Expr(ref e, ..) => Some(e),
|
||||
StmtKind::Local(ref local) => local.init.as_ref().map(|p| &**p),
|
||||
_ => None,
|
||||
|
@ -657,7 +657,7 @@ fn stmt_to_expr(stmt: &Stmt) -> Option<&Expr> {
|
|||
}
|
||||
|
||||
fn never_loop_expr(expr: &Expr, main_loop_id: HirId) -> NeverLoopResult {
|
||||
match expr.node {
|
||||
match expr.kind {
|
||||
ExprKind::Box(ref e)
|
||||
| ExprKind::Unary(_, ref e)
|
||||
| ExprKind::Cast(ref e, _)
|
||||
|
@ -749,7 +749,7 @@ fn check_for_loop<'a, 'tcx>(
|
|||
|
||||
fn same_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var: HirId) -> bool {
|
||||
if_chain! {
|
||||
if let ExprKind::Path(ref qpath) = expr.node;
|
||||
if let ExprKind::Path(ref qpath) = expr.kind;
|
||||
if let QPath::Resolved(None, ref path) = *qpath;
|
||||
if path.segments.len() == 1;
|
||||
if let Res::Local(local_id) = qpath_res(cx, qpath, expr.hir_id);
|
||||
|
@ -798,7 +798,7 @@ fn is_slice_like<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'_>) -> bool {
|
|||
|
||||
fn get_fixed_offset_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var: HirId) -> Option<FixedOffsetVar> {
|
||||
fn extract_offset<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, e: &Expr, var: HirId) -> Option<String> {
|
||||
match e.node {
|
||||
match e.kind {
|
||||
ExprKind::Lit(ref l) => match l.node {
|
||||
ast::LitKind::Int(x, _ty) => Some(x.to_string()),
|
||||
_ => None,
|
||||
|
@ -808,13 +808,13 @@ fn get_fixed_offset_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var:
|
|||
}
|
||||
}
|
||||
|
||||
if let ExprKind::Index(ref seqexpr, ref idx) = expr.node {
|
||||
if let ExprKind::Index(ref seqexpr, ref idx) = expr.kind {
|
||||
let ty = cx.tables.expr_ty(seqexpr);
|
||||
if !is_slice_like(cx, ty) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let offset = match idx.node {
|
||||
let offset = match idx.kind {
|
||||
ExprKind::Binary(op, ref lhs, ref rhs) => match op.node {
|
||||
BinOpKind::Add => {
|
||||
let offset_opt = if same_var(cx, lhs, var) {
|
||||
|
@ -855,7 +855,7 @@ fn fetch_cloned_fixed_offset_var<'a, 'tcx>(
|
|||
var: HirId,
|
||||
) -> Option<FixedOffsetVar> {
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(ref method, _, ref args) = expr.node;
|
||||
if let ExprKind::MethodCall(ref method, _, ref args) = expr.kind;
|
||||
if method.ident.name == sym!(clone);
|
||||
if args.len() == 1;
|
||||
if let Some(arg) = args.get(0);
|
||||
|
@ -877,7 +877,7 @@ fn get_indexed_assignments<'a, 'tcx>(
|
|||
e: &Expr,
|
||||
var: HirId,
|
||||
) -> Option<(FixedOffsetVar, FixedOffsetVar)> {
|
||||
if let ExprKind::Assign(ref lhs, ref rhs) = e.node {
|
||||
if let ExprKind::Assign(ref lhs, ref rhs) = e.kind {
|
||||
match (
|
||||
get_fixed_offset_var(cx, lhs, var),
|
||||
fetch_cloned_fixed_offset_var(cx, rhs, var),
|
||||
|
@ -897,14 +897,14 @@ fn get_indexed_assignments<'a, 'tcx>(
|
|||
}
|
||||
}
|
||||
|
||||
if let ExprKind::Block(ref b, _) = body.node {
|
||||
if let ExprKind::Block(ref b, _) = body.kind {
|
||||
let Block {
|
||||
ref stmts, ref expr, ..
|
||||
} = **b;
|
||||
|
||||
stmts
|
||||
.iter()
|
||||
.map(|stmt| match stmt.node {
|
||||
.map(|stmt| match stmt.kind {
|
||||
StmtKind::Local(..) | StmtKind::Item(..) => None,
|
||||
StmtKind::Expr(ref e) | StmtKind::Semi(ref e) => Some(get_assignment(cx, e, var)),
|
||||
})
|
||||
|
@ -933,7 +933,7 @@ fn detect_manual_memcpy<'a, 'tcx>(
|
|||
}) = higher::range(cx, arg)
|
||||
{
|
||||
// the var must be a single name
|
||||
if let PatKind::Binding(_, canonical_id, _, _) = pat.node {
|
||||
if let PatKind::Binding(_, canonical_id, _, _) = pat.kind {
|
||||
let print_sum = |arg1: &Offset, arg2: &Offset| -> String {
|
||||
match (&arg1.value[..], arg1.negate, &arg2.value[..], arg2.negate) {
|
||||
("0", _, "0", _) => "".into(),
|
||||
|
@ -961,7 +961,7 @@ fn detect_manual_memcpy<'a, 'tcx>(
|
|||
let print_limit = |end: &Option<&Expr>, offset: Offset, var_name: &str| {
|
||||
if let Some(end) = *end {
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(ref method, _, ref len_args) = end.node;
|
||||
if let ExprKind::MethodCall(ref method, _, ref len_args) = end.kind;
|
||||
if method.ident.name == sym!(len);
|
||||
if len_args.len() == 1;
|
||||
if let Some(arg) = len_args.get(0);
|
||||
|
@ -1050,7 +1050,7 @@ fn check_for_loop_range<'a, 'tcx>(
|
|||
}) = higher::range(cx, arg)
|
||||
{
|
||||
// the var must be a single name
|
||||
if let PatKind::Binding(_, canonical_id, ident, _) = pat.node {
|
||||
if let PatKind::Binding(_, canonical_id, ident, _) = pat.kind {
|
||||
let mut visitor = VarVisitor {
|
||||
cx,
|
||||
var: canonical_id,
|
||||
|
@ -1107,7 +1107,7 @@ fn check_for_loop_range<'a, 'tcx>(
|
|||
let take = if let Some(end) = *end {
|
||||
let mut take_expr = end;
|
||||
|
||||
if let ExprKind::Binary(ref op, ref left, ref right) = end.node {
|
||||
if let ExprKind::Binary(ref op, ref left, ref right) = end.kind {
|
||||
if let BinOpKind::Add = op.node {
|
||||
let start_equal_left = SpanlessEq::new(cx).eq_expr(start, left);
|
||||
let start_equal_right = SpanlessEq::new(cx).eq_expr(start, right);
|
||||
|
@ -1202,10 +1202,10 @@ fn check_for_loop_range<'a, 'tcx>(
|
|||
|
||||
fn is_len_call(expr: &Expr, var: Name) -> bool {
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(ref method, _, ref len_args) = expr.node;
|
||||
if let ExprKind::MethodCall(ref method, _, ref len_args) = expr.kind;
|
||||
if len_args.len() == 1;
|
||||
if method.ident.name == sym!(len);
|
||||
if let ExprKind::Path(QPath::Resolved(_, ref path)) = len_args[0].node;
|
||||
if let ExprKind::Path(QPath::Resolved(_, ref path)) = len_args[0].kind;
|
||||
if path.segments.len() == 1;
|
||||
if path.segments[0].ident.name == var;
|
||||
then {
|
||||
|
@ -1223,7 +1223,7 @@ fn is_end_eq_array_len<'tcx>(
|
|||
indexed_ty: Ty<'tcx>,
|
||||
) -> bool {
|
||||
if_chain! {
|
||||
if let ExprKind::Lit(ref lit) = end.node;
|
||||
if let ExprKind::Lit(ref lit) = end.kind;
|
||||
if let ast::LitKind::Int(end_int, _) = lit.node;
|
||||
if let ty::Array(_, arr_len_const) = indexed_ty.kind;
|
||||
if let Some(arr_len) = arr_len_const.try_eval_usize(cx.tcx, cx.param_env);
|
||||
|
@ -1328,7 +1328,7 @@ fn lint_iter_method(cx: &LateContext<'_, '_>, args: &[Expr], arg: &Expr, method_
|
|||
|
||||
fn check_for_loop_arg(cx: &LateContext<'_, '_>, pat: &Pat, arg: &Expr, expr: &Expr) {
|
||||
let mut next_loop_linted = false; // whether or not ITER_NEXT_LOOP lint was used
|
||||
if let ExprKind::MethodCall(ref method, _, ref args) = arg.node {
|
||||
if let ExprKind::MethodCall(ref method, _, ref args) = arg.kind {
|
||||
// just the receiver, no arguments
|
||||
if args.len() == 1 {
|
||||
let method_name = &*method.ident.as_str();
|
||||
|
@ -1494,11 +1494,11 @@ fn check_for_loop_over_map_kv<'a, 'tcx>(
|
|||
) {
|
||||
let pat_span = pat.span;
|
||||
|
||||
if let PatKind::Tuple(ref pat, _) = pat.node {
|
||||
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 {
|
||||
ty::Ref(_, ty, mutbl) => match (&pat[0].node, &pat[1].node) {
|
||||
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, MutImmutable),
|
||||
_ => return,
|
||||
|
@ -1509,7 +1509,7 @@ fn check_for_loop_over_map_kv<'a, 'tcx>(
|
|||
MutImmutable => "",
|
||||
MutMutable => "_mut",
|
||||
};
|
||||
let arg = match arg.node {
|
||||
let arg = match arg.kind {
|
||||
ExprKind::AddrOf(_, ref expr) => &**expr,
|
||||
_ => arg,
|
||||
};
|
||||
|
@ -1613,7 +1613,7 @@ fn mut_warn_with_span(cx: &LateContext<'_, '_>, span: Option<Span>) {
|
|||
|
||||
fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr) -> Option<HirId> {
|
||||
if_chain! {
|
||||
if let ExprKind::Path(ref qpath) = bound.node;
|
||||
if let ExprKind::Path(ref qpath) = bound.kind;
|
||||
if let QPath::Resolved(None, _) = *qpath;
|
||||
then {
|
||||
let res = qpath_res(cx, qpath, bound.hir_id);
|
||||
|
@ -1621,7 +1621,7 @@ fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr) -> Option<HirId>
|
|||
let node_str = cx.tcx.hir().get(node_id);
|
||||
if_chain! {
|
||||
if let Node::Binding(pat) = node_str;
|
||||
if let PatKind::Binding(bind_ann, ..) = pat.node;
|
||||
if let PatKind::Binding(bind_ann, ..) = pat.kind;
|
||||
if let BindingAnnotation::Mutable = bind_ann;
|
||||
then {
|
||||
return Some(node_id);
|
||||
|
@ -1741,7 +1741,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
|
|||
fn check(&mut self, idx: &'tcx Expr, seqexpr: &'tcx Expr, expr: &'tcx Expr) -> bool {
|
||||
if_chain! {
|
||||
// the indexed container is referenced by a name
|
||||
if let ExprKind::Path(ref seqpath) = seqexpr.node;
|
||||
if let ExprKind::Path(ref seqpath) = seqexpr.kind;
|
||||
if let QPath::Resolved(None, ref seqvar) = *seqpath;
|
||||
if seqvar.segments.len() == 1;
|
||||
then {
|
||||
|
@ -1802,7 +1802,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
|
|||
fn visit_expr(&mut self, expr: &'tcx Expr) {
|
||||
if_chain! {
|
||||
// a range index op
|
||||
if let ExprKind::MethodCall(ref meth, _, ref args) = expr.node;
|
||||
if let ExprKind::MethodCall(ref meth, _, ref args) = expr.kind;
|
||||
if (meth.ident.name == sym!(index) && match_trait_method(self.cx, expr, &paths::INDEX))
|
||||
|| (meth.ident.name == sym!(index_mut) && match_trait_method(self.cx, expr, &paths::INDEX_MUT));
|
||||
if !self.check(&args[1], &args[0], expr);
|
||||
|
@ -1811,14 +1811,14 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
|
|||
|
||||
if_chain! {
|
||||
// an index op
|
||||
if let ExprKind::Index(ref seqexpr, ref idx) = expr.node;
|
||||
if let ExprKind::Index(ref seqexpr, ref idx) = expr.kind;
|
||||
if !self.check(idx, seqexpr, expr);
|
||||
then { return }
|
||||
}
|
||||
|
||||
if_chain! {
|
||||
// directly using a variable
|
||||
if let ExprKind::Path(ref qpath) = expr.node;
|
||||
if let ExprKind::Path(ref qpath) = expr.kind;
|
||||
if let QPath::Resolved(None, ref path) = *qpath;
|
||||
if path.segments.len() == 1;
|
||||
then {
|
||||
|
@ -1834,7 +1834,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
let old = self.prefer_mutable;
|
||||
match expr.node {
|
||||
match expr.kind {
|
||||
ExprKind::AssignOp(_, ref lhs, ref rhs) | ExprKind::Assign(ref lhs, ref rhs) => {
|
||||
self.prefer_mutable = true;
|
||||
self.visit_expr(lhs);
|
||||
|
@ -1972,7 +1972,7 @@ fn extract_expr_from_first_stmt(block: &Block) -> Option<&Expr> {
|
|||
if block.stmts.is_empty() {
|
||||
return None;
|
||||
}
|
||||
if let StmtKind::Local(ref local) = block.stmts[0].node {
|
||||
if let StmtKind::Local(ref local) = block.stmts[0].kind {
|
||||
if let Some(ref expr) = local.init {
|
||||
Some(expr)
|
||||
} else {
|
||||
|
@ -1987,7 +1987,7 @@ fn extract_expr_from_first_stmt(block: &Block) -> Option<&Expr> {
|
|||
fn extract_first_expr(block: &Block) -> Option<&Expr> {
|
||||
match block.expr {
|
||||
Some(ref expr) if block.stmts.is_empty() => Some(expr),
|
||||
None if !block.stmts.is_empty() => match block.stmts[0].node {
|
||||
None if !block.stmts.is_empty() => match block.stmts[0].kind {
|
||||
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => Some(expr),
|
||||
StmtKind::Local(..) | StmtKind::Item(..) => None,
|
||||
},
|
||||
|
@ -1999,7 +1999,7 @@ fn extract_first_expr(block: &Block) -> Option<&Expr> {
|
|||
/// and
|
||||
/// passed expression. The expression may be within a block.
|
||||
fn is_simple_break_expr(expr: &Expr) -> bool {
|
||||
match expr.node {
|
||||
match expr.kind {
|
||||
ExprKind::Break(dest, ref passed_expr) if dest.label.is_none() && passed_expr.is_none() => true,
|
||||
ExprKind::Block(ref b, _) => extract_first_expr(b).map_or(false, |subexpr| is_simple_break_expr(subexpr)),
|
||||
_ => false,
|
||||
|
@ -2037,7 +2037,7 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> {
|
|||
if let Some(parent) = get_parent_expr(self.cx, expr) {
|
||||
let state = self.states.entry(def_id).or_insert(VarState::Initial);
|
||||
|
||||
match parent.node {
|
||||
match parent.kind {
|
||||
ExprKind::AssignOp(op, ref lhs, ref rhs) => {
|
||||
if lhs.hir_id == expr.hir_id {
|
||||
if op.node == BinOpKind::Add && is_integer_const(self.cx, rhs, 1) {
|
||||
|
@ -2061,7 +2061,7 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> {
|
|||
walk_expr(self, expr);
|
||||
self.depth -= 1;
|
||||
return;
|
||||
} else if let ExprKind::Continue(_) = expr.node {
|
||||
} else if let ExprKind::Continue(_) = expr.kind {
|
||||
self.done = true;
|
||||
return;
|
||||
}
|
||||
|
@ -2086,9 +2086,9 @@ struct InitializeVisitor<'a, 'tcx> {
|
|||
impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
|
||||
fn visit_stmt(&mut self, stmt: &'tcx Stmt) {
|
||||
// Look for declarations of the variable
|
||||
if let StmtKind::Local(ref local) = stmt.node {
|
||||
if let StmtKind::Local(ref local) = stmt.kind {
|
||||
if local.pat.hir_id == self.var_id {
|
||||
if let PatKind::Binding(.., ident, _) = local.pat.node {
|
||||
if let PatKind::Binding(.., ident, _) = local.pat.kind {
|
||||
self.name = Some(ident.name);
|
||||
|
||||
self.state = if let Some(ref init) = local.init {
|
||||
|
@ -2123,7 +2123,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
|
|||
// If node is the desired variable, see how it's used
|
||||
if var_def_id(self.cx, expr) == Some(self.var_id) {
|
||||
if let Some(parent) = get_parent_expr(self.cx, expr) {
|
||||
match parent.node {
|
||||
match parent.kind {
|
||||
ExprKind::AssignOp(_, ref lhs, _) if lhs.hir_id == expr.hir_id => {
|
||||
self.state = VarState::DontWarn;
|
||||
},
|
||||
|
@ -2160,7 +2160,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
fn var_def_id(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<HirId> {
|
||||
if let ExprKind::Path(ref qpath) = expr.node {
|
||||
if let ExprKind::Path(ref qpath) = expr.kind {
|
||||
let path_res = qpath_res(cx, qpath, expr.hir_id);
|
||||
if let Res::Local(node_id) = path_res {
|
||||
return Some(node_id);
|
||||
|
@ -2170,14 +2170,14 @@ fn var_def_id(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<HirId> {
|
|||
}
|
||||
|
||||
fn is_loop(expr: &Expr) -> bool {
|
||||
match expr.node {
|
||||
match expr.kind {
|
||||
ExprKind::Loop(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn is_conditional(expr: &Expr) -> bool {
|
||||
match expr.node {
|
||||
match expr.kind {
|
||||
ExprKind::Match(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
|
@ -2209,7 +2209,7 @@ fn is_loop_nested(cx: &LateContext<'_, '_>, loop_expr: &Expr, iter_expr: &Expr)
|
|||
}
|
||||
match cx.tcx.hir().find(parent) {
|
||||
Some(Node::Expr(expr)) => {
|
||||
if let ExprKind::Loop(..) = expr.node {
|
||||
if let ExprKind::Loop(..) = expr.kind {
|
||||
return true;
|
||||
};
|
||||
},
|
||||
|
@ -2265,7 +2265,7 @@ impl<'tcx> Visitor<'tcx> for LoopNestVisitor {
|
|||
self.nesting = LookFurther;
|
||||
return;
|
||||
}
|
||||
match expr.node {
|
||||
match expr.kind {
|
||||
ExprKind::Assign(ref path, _) | ExprKind::AssignOp(_, ref path, _) => {
|
||||
if match_var(path, self.iterator) {
|
||||
self.nesting = RuledOut;
|
||||
|
@ -2279,7 +2279,7 @@ impl<'tcx> Visitor<'tcx> for LoopNestVisitor {
|
|||
if self.nesting != Unknown {
|
||||
return;
|
||||
}
|
||||
if let PatKind::Binding(.., span_name, _) = pat.node {
|
||||
if let PatKind::Binding(.., span_name, _) = pat.kind {
|
||||
if self.iterator == span_name.name {
|
||||
self.nesting = RuledOut;
|
||||
return;
|
||||
|
@ -2294,7 +2294,7 @@ impl<'tcx> Visitor<'tcx> for LoopNestVisitor {
|
|||
}
|
||||
|
||||
fn path_name(e: &Expr) -> Option<Name> {
|
||||
if let ExprKind::Path(QPath::Resolved(_, ref path)) = e.node {
|
||||
if let ExprKind::Path(QPath::Resolved(_, ref path)) = e.kind {
|
||||
let segments = &path.segments;
|
||||
if segments.len() == 1 {
|
||||
return Some(segments[0].ident.name);
|
||||
|
@ -2351,7 +2351,7 @@ struct VarCollectorVisitor<'a, 'tcx> {
|
|||
impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> {
|
||||
fn insert_def_id(&mut self, ex: &'tcx Expr) {
|
||||
if_chain! {
|
||||
if let ExprKind::Path(ref qpath) = ex.node;
|
||||
if let ExprKind::Path(ref qpath) = ex.kind;
|
||||
if let QPath::Resolved(None, _) = *qpath;
|
||||
let res = qpath_res(self.cx, qpath, ex.hir_id);
|
||||
then {
|
||||
|
@ -2372,7 +2372,7 @@ impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> {
|
|||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for VarCollectorVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, ex: &'tcx Expr) {
|
||||
match ex.node {
|
||||
match ex.kind {
|
||||
ExprKind::Path(_) => self.insert_def_id(ex),
|
||||
// If there is any function/method call… we just stop analysis
|
||||
ExprKind::Call(..) | ExprKind::MethodCall(..) => self.skip = true,
|
||||
|
@ -2390,8 +2390,8 @@ const NEEDLESS_COLLECT_MSG: &str = "avoid using `collect()` when not needed";
|
|||
|
||||
fn check_needless_collect<'a, 'tcx>(expr: &'tcx Expr, cx: &LateContext<'a, 'tcx>) {
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(ref method, _, ref args) = expr.node;
|
||||
if let ExprKind::MethodCall(ref chain_method, _, _) = args[0].node;
|
||||
if let ExprKind::MethodCall(ref method, _, ref args) = expr.kind;
|
||||
if let ExprKind::MethodCall(ref chain_method, _, _) = args[0].kind;
|
||||
if chain_method.ident.name == sym!(collect) && match_trait_method(cx, &args[0], &paths::ITERATOR);
|
||||
if let Some(ref generic_args) = chain_method.args;
|
||||
if let Some(GenericArg::Type(ref ty)) = generic_args.args.get(0);
|
||||
|
@ -2450,8 +2450,8 @@ fn check_needless_collect<'a, 'tcx>(expr: &'tcx Expr, cx: &LateContext<'a, 'tcx>
|
|||
|
||||
fn shorten_needless_collect_span(expr: &Expr) -> Span {
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(_, _, ref args) = expr.node;
|
||||
if let ExprKind::MethodCall(_, ref span, _) = args[0].node;
|
||||
if let ExprKind::MethodCall(_, _, ref args) = expr.kind;
|
||||
if let ExprKind::MethodCall(_, ref span, _) = args[0].kind;
|
||||
then {
|
||||
return expr.span.with_lo(span.lo() - BytePos(1));
|
||||
}
|
||||
|
|
|
@ -43,8 +43,8 @@ impl LateLintPass<'_, '_> for MainRecursion {
|
|||
}
|
||||
|
||||
if_chain! {
|
||||
if let ExprKind::Call(func, _) = &expr.node;
|
||||
if let ExprKind::Path(path) = &func.node;
|
||||
if let ExprKind::Call(func, _) = &expr.kind;
|
||||
if let ExprKind::Path(path) = &func.kind;
|
||||
if let QPath::Resolved(_, path) = &path;
|
||||
if let Some(def_id) = path.res.opt_def_id();
|
||||
if is_entrypoint_fn(cx, def_id);
|
||||
|
|
|
@ -48,25 +48,25 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapClone {
|
|||
}
|
||||
|
||||
if_chain! {
|
||||
if let hir::ExprKind::MethodCall(ref method, _, ref args) = e.node;
|
||||
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]);
|
||||
if match_type(cx, ty, &paths::OPTION) || match_trait_method(cx, e, &paths::ITERATOR);
|
||||
if let hir::ExprKind::Closure(_, _, body_id, _, _) = args[1].node;
|
||||
if let hir::ExprKind::Closure(_, _, body_id, _, _) = args[1].kind;
|
||||
let closure_body = cx.tcx.hir().body(body_id);
|
||||
let closure_expr = remove_blocks(&closure_body.value);
|
||||
then {
|
||||
match closure_body.params[0].pat.node {
|
||||
match closure_body.params[0].pat.kind {
|
||||
hir::PatKind::Ref(ref inner, _) => if let hir::PatKind::Binding(
|
||||
hir::BindingAnnotation::Unannotated, .., name, None
|
||||
) = inner.node {
|
||||
) = inner.kind {
|
||||
if ident_eq(name, closure_expr) {
|
||||
lint(cx, e.span, args[0].span, true);
|
||||
}
|
||||
},
|
||||
hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, .., name, None) => {
|
||||
match closure_expr.node {
|
||||
match closure_expr.kind {
|
||||
hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner) => {
|
||||
if ident_eq(name, inner) && !cx.tables.expr_ty(inner).is_box() {
|
||||
lint(cx, e.span, args[0].span, true);
|
||||
|
@ -96,7 +96,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapClone {
|
|||
}
|
||||
|
||||
fn ident_eq(name: Ident, path: &hir::Expr) -> bool {
|
||||
if let hir::ExprKind::Path(hir::QPath::Resolved(None, ref path)) = path.node {
|
||||
if let hir::ExprKind::Path(hir::QPath::Resolved(None, ref path)) = path.kind {
|
||||
path.segments.len() == 1 && path.segments[0].ident == name
|
||||
} else {
|
||||
false
|
||||
|
|
|
@ -125,7 +125,7 @@ fn reduce_unit_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a hir::Expr) ->
|
|||
return None;
|
||||
}
|
||||
|
||||
match expr.node {
|
||||
match expr.kind {
|
||||
hir::ExprKind::Call(_, _) | hir::ExprKind::MethodCall(_, _, _) => {
|
||||
// Calls can't be reduced any more
|
||||
Some(expr.span)
|
||||
|
@ -140,7 +140,7 @@ fn reduce_unit_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a hir::Expr) ->
|
|||
(&[ref inner_stmt], None) => {
|
||||
// If block only contains statements,
|
||||
// reduce `{ X; }` to `X` or `X;`
|
||||
match inner_stmt.node {
|
||||
match inner_stmt.kind {
|
||||
hir::StmtKind::Local(ref local) => Some(local.span),
|
||||
hir::StmtKind::Expr(ref e) => Some(e.span),
|
||||
hir::StmtKind::Semi(..) => Some(inner_stmt.span),
|
||||
|
@ -165,7 +165,7 @@ fn unit_closure<'a, 'tcx>(
|
|||
cx: &LateContext<'a, 'tcx>,
|
||||
expr: &'a hir::Expr,
|
||||
) -> Option<(&'tcx hir::Param, &'a hir::Expr)> {
|
||||
if let hir::ExprKind::Closure(_, ref decl, inner_expr_id, _, _) = expr.node {
|
||||
if let hir::ExprKind::Closure(_, ref decl, inner_expr_id, _, _) = expr.kind {
|
||||
let body = cx.tcx.hir().body(inner_expr_id);
|
||||
let body_expr = &body.value;
|
||||
|
||||
|
@ -188,7 +188,7 @@ fn unit_closure<'a, 'tcx>(
|
|||
///
|
||||
/// Anything else will return `_`.
|
||||
fn let_binding_name(cx: &LateContext<'_, '_>, var_arg: &hir::Expr) -> String {
|
||||
match &var_arg.node {
|
||||
match &var_arg.kind {
|
||||
hir::ExprKind::Field(_, _) => snippet(cx, var_arg.span, "_").replace(".", "_"),
|
||||
hir::ExprKind::Path(_) => format!("_{}", snippet(cx, var_arg.span, "")),
|
||||
_ => "_".to_string(),
|
||||
|
@ -264,7 +264,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapUnit {
|
|||
return;
|
||||
}
|
||||
|
||||
if let hir::StmtKind::Semi(ref expr) = stmt.node {
|
||||
if let hir::StmtKind::Semi(ref expr) = stmt.kind {
|
||||
if let Some(arglists) = method_chain_args(expr, &["map"]) {
|
||||
lint_map_unit_fn(cx, stmt, expr, arglists[0]);
|
||||
}
|
||||
|
|
|
@ -238,7 +238,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Matches {
|
|||
if in_external_macro(cx.sess(), expr.span) {
|
||||
return;
|
||||
}
|
||||
if let ExprKind::Match(ref ex, ref arms, MatchSource::Normal) = expr.node {
|
||||
if let ExprKind::Match(ref ex, ref arms, MatchSource::Normal) = expr.kind {
|
||||
check_single_match(cx, ex, arms, expr);
|
||||
check_match_bool(cx, ex, arms, expr);
|
||||
check_overlapping_arms(cx, ex, arms);
|
||||
|
@ -246,7 +246,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Matches {
|
|||
check_wild_enum_match(cx, ex, arms);
|
||||
check_match_as_ref(cx, ex, arms, expr);
|
||||
}
|
||||
if let ExprKind::Match(ref ex, ref arms, _) = expr.node {
|
||||
if let ExprKind::Match(ref ex, ref arms, _) = expr.kind {
|
||||
check_match_ref_pats(cx, ex, arms, expr);
|
||||
}
|
||||
}
|
||||
|
@ -255,7 +255,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Matches {
|
|||
#[rustfmt::skip]
|
||||
fn check_single_match(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &Expr) {
|
||||
if arms.len() == 2 && arms[0].guard.is_none() && arms[1].guard.is_none() {
|
||||
if let PatKind::Or(..) = arms[0].pat.node {
|
||||
if let PatKind::Or(..) = arms[0].pat.kind {
|
||||
// don't lint for or patterns for now, this makes
|
||||
// the lint noisy in unnecessary situations
|
||||
return;
|
||||
|
@ -263,7 +263,7 @@ fn check_single_match(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &
|
|||
let els = remove_blocks(&arms[1].body);
|
||||
let els = if is_unit_expr(els) {
|
||||
None
|
||||
} else if let ExprKind::Block(_, _) = els.node {
|
||||
} else if let ExprKind::Block(_, _) = els.kind {
|
||||
// matches with blocks that contain statements are prettier as `if let + else`
|
||||
Some(els)
|
||||
} else {
|
||||
|
@ -338,7 +338,7 @@ fn check_single_match_opt_like(
|
|||
(&paths::RESULT, "Ok"),
|
||||
];
|
||||
|
||||
let path = match arms[1].pat.node {
|
||||
let path = match arms[1].pat.kind {
|
||||
PatKind::TupleStruct(ref path, ref inner, _) => {
|
||||
// Contains any non wildcard patterns (e.g., `Err(err)`)?
|
||||
if !inner.iter().all(is_wild) {
|
||||
|
@ -369,8 +369,8 @@ fn check_match_bool(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &Ex
|
|||
move |db| {
|
||||
if arms.len() == 2 {
|
||||
// no guards
|
||||
let exprs = if let PatKind::Lit(ref arm_bool) = arms[0].pat.node {
|
||||
if let ExprKind::Lit(ref lit) = arm_bool.node {
|
||||
let exprs = if let PatKind::Lit(ref arm_bool) = arms[0].pat.kind {
|
||||
if let ExprKind::Lit(ref lit) = arm_bool.kind {
|
||||
match lit.node {
|
||||
LitKind::Bool(true) => Some((&*arms[0].body, &*arms[1].body)),
|
||||
LitKind::Bool(false) => Some((&*arms[1].body, &*arms[0].body)),
|
||||
|
@ -438,7 +438,7 @@ fn check_overlapping_arms<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ex: &'tcx Expr,
|
|||
}
|
||||
|
||||
fn is_wild(pat: &impl std::ops::Deref<Target = Pat>) -> bool {
|
||||
match pat.node {
|
||||
match pat.kind {
|
||||
PatKind::Wild => true,
|
||||
_ => false,
|
||||
}
|
||||
|
@ -448,12 +448,12 @@ fn check_wild_err_arm(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm]) {
|
|||
let ex_ty = walk_ptrs_ty(cx.tables.expr_ty(ex));
|
||||
if match_type(cx, ex_ty, &paths::RESULT) {
|
||||
for arm in arms {
|
||||
if let PatKind::TupleStruct(ref path, ref inner, _) = arm.pat.node {
|
||||
if let PatKind::TupleStruct(ref path, ref inner, _) = arm.pat.kind {
|
||||
let path_str = print::to_string(print::NO_ANN, |s| s.print_qpath(path, false));
|
||||
if_chain! {
|
||||
if path_str == "Err";
|
||||
if inner.iter().any(is_wild);
|
||||
if let ExprKind::Block(ref block, _) = arm.body.node;
|
||||
if let ExprKind::Block(ref block, _) = arm.body.kind;
|
||||
if is_panic_block(block);
|
||||
then {
|
||||
// `Err(_)` arm with `panic!` found
|
||||
|
@ -484,9 +484,9 @@ fn check_wild_enum_match(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm]) {
|
|||
let mut wildcard_span = None;
|
||||
let mut wildcard_ident = None;
|
||||
for arm in arms {
|
||||
if let PatKind::Wild = arm.pat.node {
|
||||
if let PatKind::Wild = arm.pat.kind {
|
||||
wildcard_span = Some(arm.pat.span);
|
||||
} else if let PatKind::Binding(_, _, ident, None) = arm.pat.node {
|
||||
} else if let PatKind::Binding(_, _, ident, None) = arm.pat.kind {
|
||||
wildcard_span = Some(arm.pat.span);
|
||||
wildcard_ident = Some(ident);
|
||||
}
|
||||
|
@ -510,11 +510,11 @@ fn check_wild_enum_match(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm]) {
|
|||
// covered by the set of guards that cover it, but that's really hard to do.
|
||||
continue;
|
||||
}
|
||||
if let PatKind::Path(ref path) = arm.pat.node {
|
||||
if let PatKind::Path(ref path) = arm.pat.kind {
|
||||
if let QPath::Resolved(_, p) = path {
|
||||
missing_variants.retain(|e| e.ctor_def_id != Some(p.res.def_id()));
|
||||
}
|
||||
} else if let PatKind::TupleStruct(ref path, ..) = arm.pat.node {
|
||||
} else if let PatKind::TupleStruct(ref path, ..) = arm.pat.kind {
|
||||
if let QPath::Resolved(_, p) = path {
|
||||
missing_variants.retain(|e| e.ctor_def_id != Some(p.res.def_id()));
|
||||
}
|
||||
|
@ -570,7 +570,7 @@ fn is_panic_block(block: &Block) -> bool {
|
|||
fn check_match_ref_pats(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &Expr) {
|
||||
if has_only_ref_pats(arms) {
|
||||
let mut suggs = Vec::new();
|
||||
let (title, msg) = if let ExprKind::AddrOf(Mutability::MutImmutable, ref inner) = ex.node {
|
||||
let (title, msg) = if let ExprKind::AddrOf(Mutability::MutImmutable, ref inner) = ex.kind {
|
||||
let span = ex.span.source_callsite();
|
||||
suggs.push((span, Sugg::hir_with_macro_callsite(cx, inner, "..").to_string()));
|
||||
(
|
||||
|
@ -587,7 +587,7 @@ fn check_match_ref_pats(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr:
|
|||
};
|
||||
|
||||
suggs.extend(arms.iter().filter_map(|a| {
|
||||
if let PatKind::Ref(ref refp, _) = a.pat.node {
|
||||
if let PatKind::Ref(ref refp, _) = a.pat.kind {
|
||||
Some((a.pat.span, snippet(cx, refp.span, "..").to_string()))
|
||||
} else {
|
||||
None
|
||||
|
@ -662,7 +662,7 @@ fn all_ranges<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arms: &'tcx [Arm]) -> Vec<Sp
|
|||
ref pat, guard: None, ..
|
||||
} = *arm
|
||||
{
|
||||
if let PatKind::Range(ref lhs, ref rhs, ref range_end) = pat.node {
|
||||
if let PatKind::Range(ref lhs, ref rhs, ref range_end) = pat.kind {
|
||||
let lhs = constant(cx, cx.tables, lhs)?.0;
|
||||
let rhs = constant(cx, cx.tables, rhs)?.0;
|
||||
let rhs = match *range_end {
|
||||
|
@ -675,7 +675,7 @@ fn all_ranges<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arms: &'tcx [Arm]) -> Vec<Sp
|
|||
});
|
||||
}
|
||||
|
||||
if let PatKind::Lit(ref value) = pat.node {
|
||||
if let PatKind::Lit(ref value) = pat.kind {
|
||||
let value = constant(cx, cx.tables, value)?.0;
|
||||
return Some(SpannedRange {
|
||||
span: pat.span,
|
||||
|
@ -721,7 +721,7 @@ fn type_ranges(ranges: &[SpannedRange<Constant>]) -> TypedRanges {
|
|||
}
|
||||
|
||||
fn is_unit_expr(expr: &Expr) -> bool {
|
||||
match expr.node {
|
||||
match expr.kind {
|
||||
ExprKind::Tup(ref v) if v.is_empty() => true,
|
||||
ExprKind::Block(ref b, _) if b.stmts.is_empty() && b.expr.is_none() => true,
|
||||
_ => false,
|
||||
|
@ -730,7 +730,7 @@ fn is_unit_expr(expr: &Expr) -> bool {
|
|||
|
||||
// Checks if arm has the form `None => None`
|
||||
fn is_none_arm(arm: &Arm) -> bool {
|
||||
match arm.pat.node {
|
||||
match arm.pat.kind {
|
||||
PatKind::Path(ref path) if match_qpath(path, &paths::OPTION_NONE) => true,
|
||||
_ => false,
|
||||
}
|
||||
|
@ -739,14 +739,14 @@ fn is_none_arm(arm: &Arm) -> bool {
|
|||
// Checks if arm has the form `Some(ref v) => Some(v)` (checks for `ref` and `ref mut`)
|
||||
fn is_ref_some_arm(arm: &Arm) -> Option<BindingAnnotation> {
|
||||
if_chain! {
|
||||
if let PatKind::TupleStruct(ref path, ref pats, _) = arm.pat.node;
|
||||
if let PatKind::TupleStruct(ref path, ref pats, _) = arm.pat.kind;
|
||||
if pats.len() == 1 && match_qpath(path, &paths::OPTION_SOME);
|
||||
if let PatKind::Binding(rb, .., ident, _) = pats[0].node;
|
||||
if let PatKind::Binding(rb, .., ident, _) = pats[0].kind;
|
||||
if rb == BindingAnnotation::Ref || rb == BindingAnnotation::RefMut;
|
||||
if let ExprKind::Call(ref e, ref args) = remove_blocks(&arm.body).node;
|
||||
if let ExprKind::Path(ref some_path) = e.node;
|
||||
if let ExprKind::Call(ref e, ref args) = remove_blocks(&arm.body).kind;
|
||||
if let ExprKind::Path(ref some_path) = e.kind;
|
||||
if match_qpath(some_path, &paths::OPTION_SOME) && args.len() == 1;
|
||||
if let ExprKind::Path(ref qpath) = args[0].node;
|
||||
if let ExprKind::Path(ref qpath) = args[0].kind;
|
||||
if let &QPath::Resolved(_, ref path2) = qpath;
|
||||
if path2.segments.len() == 1 && ident.name == path2.segments[0].ident.name;
|
||||
then {
|
||||
|
@ -760,7 +760,7 @@ fn has_only_ref_pats(arms: &[Arm]) -> bool {
|
|||
let mapped = arms
|
||||
.iter()
|
||||
.map(|a| {
|
||||
match a.pat.node {
|
||||
match a.pat.kind {
|
||||
PatKind::Ref(..) => Some(true), // &-patterns
|
||||
PatKind::Wild => Some(false), // an "anything" wildcard is also fine
|
||||
_ => None, // any other pattern is not fine
|
||||
|
|
|
@ -32,9 +32,9 @@ declare_lint_pass!(MemDiscriminant => [MEM_DISCRIMINANT_NON_ENUM]);
|
|||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemDiscriminant {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
if_chain! {
|
||||
if let ExprKind::Call(ref func, ref func_args) = expr.node;
|
||||
if let ExprKind::Call(ref func, ref func_args) = expr.kind;
|
||||
// is `mem::discriminant`
|
||||
if let ExprKind::Path(ref func_qpath) = func.node;
|
||||
if let ExprKind::Path(ref func_qpath) = func.kind;
|
||||
if let Some(def_id) = cx.tables.qpath_res(func_qpath, func.hir_id).opt_def_id();
|
||||
if match_def_path(cx, def_id, &paths::MEM_DISCRIMINANT);
|
||||
// type is non-enum
|
||||
|
@ -57,7 +57,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemDiscriminant {
|
|||
let mut derefs_needed = ptr_depth;
|
||||
let mut cur_expr = param;
|
||||
while derefs_needed > 0 {
|
||||
if let ExprKind::AddrOf(_, ref inner_expr) = cur_expr.node {
|
||||
if let ExprKind::AddrOf(_, ref inner_expr) = cur_expr.kind {
|
||||
derefs_needed -= 1;
|
||||
cur_expr = inner_expr;
|
||||
} else {
|
||||
|
|
|
@ -27,8 +27,8 @@ declare_lint_pass!(MemForget => [MEM_FORGET]);
|
|||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemForget {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||
if let ExprKind::Call(ref path_expr, ref args) = e.node {
|
||||
if let ExprKind::Path(ref qpath) = path_expr.node {
|
||||
if let ExprKind::Call(ref path_expr, ref args) = e.kind {
|
||||
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]);
|
||||
|
|
|
@ -73,15 +73,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemReplace {
|
|||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
if_chain! {
|
||||
// Check that `expr` is a call to `mem::replace()`
|
||||
if let ExprKind::Call(ref func, ref func_args) = expr.node;
|
||||
if let ExprKind::Call(ref func, ref func_args) = expr.kind;
|
||||
if func_args.len() == 2;
|
||||
if let ExprKind::Path(ref func_qpath) = func.node;
|
||||
if let ExprKind::Path(ref func_qpath) = func.kind;
|
||||
if let Some(def_id) = cx.tables.qpath_res(func_qpath, func.hir_id).opt_def_id();
|
||||
if match_def_path(cx, def_id, &paths::MEM_REPLACE);
|
||||
|
||||
// Check that second argument is `Option::None`
|
||||
then {
|
||||
if let ExprKind::Path(ref replacement_qpath) = func_args[1].node {
|
||||
if let ExprKind::Path(ref replacement_qpath) = func_args[1].kind {
|
||||
if match_qpath(replacement_qpath, &paths::OPTION_NONE) {
|
||||
|
||||
// Since this is a late pass (already type-checked),
|
||||
|
@ -89,9 +89,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemReplace {
|
|||
// `Option`, we do not need to check the first
|
||||
// argument's type. All that's left is to get
|
||||
// replacee's path.
|
||||
let replaced_path = match func_args[0].node {
|
||||
let replaced_path = match func_args[0].kind {
|
||||
ExprKind::AddrOf(MutMutable, ref replaced) => {
|
||||
if let ExprKind::Path(QPath::Resolved(None, ref replaced_path)) = replaced.node {
|
||||
if let ExprKind::Path(QPath::Resolved(None, ref replaced_path)) = replaced.kind {
|
||||
replaced_path
|
||||
} else {
|
||||
return
|
||||
|
@ -113,10 +113,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemReplace {
|
|||
);
|
||||
}
|
||||
}
|
||||
if let ExprKind::Call(ref repl_func, ref repl_args) = func_args[1].node {
|
||||
if let ExprKind::Call(ref repl_func, ref repl_args) = func_args[1].kind {
|
||||
if_chain! {
|
||||
if repl_args.is_empty();
|
||||
if let ExprKind::Path(ref repl_func_qpath) = repl_func.node;
|
||||
if let ExprKind::Path(ref repl_func_qpath) = repl_func.kind;
|
||||
if let Some(repl_def_id) = cx.tables.qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id();
|
||||
then {
|
||||
if match_def_path(cx, repl_def_id, &paths::MEM_UNINITIALIZED) {
|
||||
|
|
|
@ -85,9 +85,9 @@ enum MinMax {
|
|||
fn is_min_or_max<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &hir::Expr) -> Option<MinMax> {
|
||||
// `T::max_value()` `T::min_value()` inherent methods
|
||||
if_chain! {
|
||||
if let hir::ExprKind::Call(func, args) = &expr.node;
|
||||
if let hir::ExprKind::Call(func, args) = &expr.kind;
|
||||
if args.is_empty();
|
||||
if let hir::ExprKind::Path(path) = &func.node;
|
||||
if let hir::ExprKind::Path(path) = &func.kind;
|
||||
if let hir::QPath::TypeRelative(_, segment) = path;
|
||||
then {
|
||||
match &*segment.ident.as_str() {
|
||||
|
@ -102,7 +102,7 @@ fn is_min_or_max<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &hir::Expr) -> Option<M
|
|||
let ty_str = ty.to_string();
|
||||
|
||||
// `std::T::MAX` `std::T::MIN` constants
|
||||
if let hir::ExprKind::Path(path) = &expr.node {
|
||||
if let hir::ExprKind::Path(path) = &expr.kind {
|
||||
if match_qpath(path, &["core", &ty_str, "MAX"][..]) {
|
||||
return Some(MinMax::Max);
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ fn is_min_or_max<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &hir::Expr) -> Option<M
|
|||
};
|
||||
|
||||
let check_lit = |expr: &hir::Expr, check_min: bool| {
|
||||
if let hir::ExprKind::Lit(lit) = &expr.node {
|
||||
if let hir::ExprKind::Lit(lit) = &expr.kind {
|
||||
if let ast::LitKind::Int(value, _) = lit.node {
|
||||
if value == maxval {
|
||||
return Some(MinMax::Max);
|
||||
|
@ -146,7 +146,7 @@ fn is_min_or_max<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &hir::Expr) -> Option<M
|
|||
}
|
||||
|
||||
if ty.is_signed() {
|
||||
if let hir::ExprKind::Unary(hir::UnNeg, val) = &expr.node {
|
||||
if let hir::ExprKind::Unary(hir::UnNeg, val) = &expr.kind {
|
||||
return check_lit(val, true);
|
||||
}
|
||||
}
|
||||
|
@ -161,11 +161,11 @@ enum Sign {
|
|||
}
|
||||
|
||||
fn lit_sign(expr: &hir::Expr) -> Option<Sign> {
|
||||
if let hir::ExprKind::Unary(hir::UnNeg, inner) = &expr.node {
|
||||
if let hir::ExprKind::Lit(..) = &inner.node {
|
||||
if let hir::ExprKind::Unary(hir::UnNeg, inner) = &expr.kind {
|
||||
if let hir::ExprKind::Lit(..) = &inner.kind {
|
||||
return Some(Sign::Neg);
|
||||
}
|
||||
} else if let hir::ExprKind::Lit(..) = &expr.node {
|
||||
} else if let hir::ExprKind::Lit(..) = &expr.kind {
|
||||
return Some(Sign::Pos);
|
||||
}
|
||||
|
||||
|
|
|
@ -1112,7 +1112,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
|
|||
_ => {},
|
||||
}
|
||||
|
||||
match expr.node {
|
||||
match expr.kind {
|
||||
hir::ExprKind::MethodCall(ref method_call, ref method_span, ref args) => {
|
||||
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);
|
||||
|
@ -1162,9 +1162,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
|
|||
let def_id = cx.tcx.hir().local_def_id(item.hir_id);
|
||||
let ty = cx.tcx.type_of(def_id);
|
||||
if_chain! {
|
||||
if let hir::ImplItemKind::Method(ref sig, id) = impl_item.node;
|
||||
if let hir::ImplItemKind::Method(ref sig, id) = impl_item.kind;
|
||||
if let Some(first_arg) = iter_input_pats(&sig.decl, cx.tcx.hir().body(id)).next();
|
||||
if let hir::ItemKind::Impl(_, _, _, _, None, _, _) = item.node;
|
||||
if let hir::ItemKind::Impl(_, _, _, _, None, _, _) = item.kind;
|
||||
|
||||
let method_def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
|
||||
let method_sig = cx.tcx.fn_sig(method_def_id);
|
||||
|
@ -1221,7 +1221,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
|
|||
}
|
||||
}
|
||||
|
||||
if let hir::ImplItemKind::Method(_, _) = impl_item.node {
|
||||
if let hir::ImplItemKind::Method(_, _) = impl_item.kind {
|
||||
let ret_ty = return_ty(cx, impl_item.hir_id);
|
||||
|
||||
// walk the return type and check for Self (this does not check associated types)
|
||||
|
@ -1279,7 +1279,7 @@ fn lint_or_fun_call<'a, 'tcx>(
|
|||
|
||||
impl<'a, 'tcx> intravisit::Visitor<'tcx> for FunCallFinder<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
|
||||
let call_found = match &expr.node {
|
||||
let call_found = match &expr.kind {
|
||||
// ignore enum and struct constructors
|
||||
hir::ExprKind::Call(..) => !is_ctor_function(self.cx, expr),
|
||||
hir::ExprKind::MethodCall(..) => true,
|
||||
|
@ -1322,7 +1322,7 @@ fn lint_or_fun_call<'a, 'tcx>(
|
|||
if_chain! {
|
||||
if !or_has_args;
|
||||
if name == "unwrap_or";
|
||||
if let hir::ExprKind::Path(ref qpath) = fun.node;
|
||||
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);
|
||||
|
@ -1406,7 +1406,7 @@ fn lint_or_fun_call<'a, 'tcx>(
|
|||
}
|
||||
|
||||
if args.len() == 2 {
|
||||
match args[1].node {
|
||||
match args[1].kind {
|
||||
hir::ExprKind::Call(ref fun, ref or_args) => {
|
||||
let or_has_args = !or_args.is_empty();
|
||||
if !check_unwrap_or_default(cx, name, fun, &args[0], &args[1], or_has_args, expr.span) {
|
||||
|
@ -1445,7 +1445,7 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
|
|||
fn get_arg_root<'a>(cx: &LateContext<'_, '_>, arg: &'a hir::Expr) -> &'a hir::Expr {
|
||||
let mut arg_root = arg;
|
||||
loop {
|
||||
arg_root = match &arg_root.node {
|
||||
arg_root = match &arg_root.kind {
|
||||
hir::ExprKind::AddrOf(_, expr) => expr,
|
||||
hir::ExprKind::MethodCall(method_name, _, call_args) => {
|
||||
if call_args.len() == 1
|
||||
|
@ -1488,9 +1488,9 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
|
|||
applicability: &mut Applicability,
|
||||
) -> Vec<String> {
|
||||
if_chain! {
|
||||
if let hir::ExprKind::AddrOf(_, ref format_arg) = a.node;
|
||||
if let hir::ExprKind::Match(ref format_arg_expr, _, _) = format_arg.node;
|
||||
if let hir::ExprKind::Tup(ref format_arg_expr_tup) = format_arg_expr.node;
|
||||
if let hir::ExprKind::AddrOf(_, ref format_arg) = a.kind;
|
||||
if let hir::ExprKind::Match(ref format_arg_expr, _, _) = format_arg.kind;
|
||||
if let hir::ExprKind::Tup(ref format_arg_expr_tup) = format_arg_expr.kind;
|
||||
|
||||
then {
|
||||
format_arg_expr_tup
|
||||
|
@ -1506,7 +1506,7 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
|
|||
fn is_call(node: &hir::ExprKind) -> bool {
|
||||
match node {
|
||||
hir::ExprKind::AddrOf(_, expr) => {
|
||||
is_call(&expr.node)
|
||||
is_call(&expr.kind)
|
||||
},
|
||||
hir::ExprKind::Call(..)
|
||||
| hir::ExprKind::MethodCall(..)
|
||||
|
@ -1517,7 +1517,7 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
|
|||
}
|
||||
}
|
||||
|
||||
if args.len() != 2 || name != "expect" || !is_call(&args[1].node) {
|
||||
if args.len() != 2 || name != "expect" || !is_call(&args[1].kind) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1537,9 +1537,9 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
|
|||
let mut applicability = Applicability::MachineApplicable;
|
||||
|
||||
//Special handling for `format!` as arg_root
|
||||
if let hir::ExprKind::Call(ref inner_fun, ref inner_args) = arg_root.node {
|
||||
if let hir::ExprKind::Call(ref inner_fun, ref inner_args) = arg_root.kind {
|
||||
if is_expn_of(inner_fun.span, "format").is_some() && inner_args.len() == 1 {
|
||||
if let hir::ExprKind::Call(_, format_args) = &inner_args[0].node {
|
||||
if let hir::ExprKind::Call(_, format_args) = &inner_args[0].kind {
|
||||
let fmt_spec = &format_args[0];
|
||||
let fmt_args = &format_args[1];
|
||||
|
||||
|
@ -1626,7 +1626,7 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::Exp
|
|||
if let Some(snippet) = sugg::Sugg::hir_opt(cx, arg) {
|
||||
let parent = cx.tcx.hir().get_parent_node(expr.hir_id);
|
||||
match &cx.tcx.hir().get(parent) {
|
||||
hir::Node::Expr(parent) => match parent.node {
|
||||
hir::Node::Expr(parent) => match parent.kind {
|
||||
// &*x is a nop, &x.clone() is not
|
||||
hir::ExprKind::AddrOf(..) |
|
||||
// (*x).func() is useless, x.clone().func() can work in case func borrows mutably
|
||||
|
@ -1634,8 +1634,8 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::Exp
|
|||
_ => {},
|
||||
},
|
||||
hir::Node::Stmt(stmt) => {
|
||||
if let hir::StmtKind::Local(ref loc) = stmt.node {
|
||||
if let hir::PatKind::Ref(..) = loc.pat.node {
|
||||
if let hir::StmtKind::Local(ref loc) = stmt.kind {
|
||||
if let hir::PatKind::Ref(..) = loc.pat.kind {
|
||||
// let ref y = *x borrows x, let ref y = x.clone() does not
|
||||
return;
|
||||
}
|
||||
|
@ -1796,12 +1796,12 @@ fn lint_unnecessary_fold(cx: &LateContext<'_, '_>, expr: &hir::Expr, fold_args:
|
|||
) {
|
||||
if_chain! {
|
||||
// Extract the body of the closure passed to fold
|
||||
if let hir::ExprKind::Closure(_, _, body_id, _, _) = fold_args[2].node;
|
||||
if let hir::ExprKind::Closure(_, _, body_id, _, _) = fold_args[2].kind;
|
||||
let closure_body = cx.tcx.hir().body(body_id);
|
||||
let closure_expr = remove_blocks(&closure_body.value);
|
||||
|
||||
// Check if the closure body is of the form `acc <op> some_expr(x)`
|
||||
if let hir::ExprKind::Binary(ref bin_op, ref left_expr, ref right_expr) = closure_expr.node;
|
||||
if let hir::ExprKind::Binary(ref bin_op, ref left_expr, ref right_expr) = closure_expr.kind;
|
||||
if bin_op.node == op;
|
||||
|
||||
// Extract the names of the two arguments to the closure
|
||||
|
@ -1852,7 +1852,7 @@ fn lint_unnecessary_fold(cx: &LateContext<'_, '_>, expr: &hir::Expr, fold_args:
|
|||
);
|
||||
|
||||
// Check if the first argument to .fold is a suitable literal
|
||||
if let hir::ExprKind::Lit(ref lit) = fold_args[1].node {
|
||||
if let hir::ExprKind::Lit(ref lit) = fold_args[1].kind {
|
||||
match lit.node {
|
||||
ast::LitKind::Bool(false) => {
|
||||
check_fold_with_op(cx, expr, fold_args, fold_span, hir::BinOpKind::Or, "any", true)
|
||||
|
@ -1932,7 +1932,7 @@ fn lint_get_unwrap<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Expr, get_a
|
|||
if_chain! {
|
||||
if needs_ref;
|
||||
if let Some(parent) = get_parent_expr(cx, expr);
|
||||
if let hir::ExprKind::Unary(hir::UnOp::UnDeref, _) = parent.node;
|
||||
if let hir::ExprKind::Unary(hir::UnOp::UnDeref, _) = parent.kind;
|
||||
then {
|
||||
needs_ref = false;
|
||||
span = parent.span;
|
||||
|
@ -1995,7 +1995,7 @@ fn derefs_to_slice<'a, 'tcx>(
|
|||
}
|
||||
}
|
||||
|
||||
if let hir::ExprKind::MethodCall(ref path, _, ref args) = expr.node {
|
||||
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])) {
|
||||
Some(&args[0])
|
||||
} else {
|
||||
|
@ -2160,7 +2160,7 @@ fn lint_map_unwrap_or_else<'a, 'tcx>(
|
|||
fn lint_map_or_none<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr, map_or_args: &'tcx [hir::Expr]) {
|
||||
if match_type(cx, cx.tables.expr_ty(&map_or_args[0]), &paths::OPTION) {
|
||||
// check if the first non-self argument to map_or() is None
|
||||
let map_or_arg_is_none = if let hir::ExprKind::Path(ref qpath) = map_or_args[1].node {
|
||||
let map_or_arg_is_none = if let hir::ExprKind::Path(ref qpath) = map_or_args[1].kind {
|
||||
match_qpath(qpath, &paths::OPTION_NONE)
|
||||
} else {
|
||||
false
|
||||
|
@ -2195,13 +2195,13 @@ fn lint_option_and_then_some(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &
|
|||
return;
|
||||
}
|
||||
|
||||
match args[1].node {
|
||||
match args[1].kind {
|
||||
hir::ExprKind::Closure(_, _, body_id, closure_args_span, _) => {
|
||||
let closure_body = cx.tcx.hir().body(body_id);
|
||||
let closure_expr = remove_blocks(&closure_body.value);
|
||||
if_chain! {
|
||||
if let hir::ExprKind::Call(ref some_expr, ref some_args) = closure_expr.node;
|
||||
if let hir::ExprKind::Path(ref qpath) = some_expr.node;
|
||||
if let hir::ExprKind::Call(ref some_expr, ref some_args) = closure_expr.kind;
|
||||
if let hir::ExprKind::Path(ref qpath) = some_expr.kind;
|
||||
if match_qpath(qpath, &paths::OPTION_SOME);
|
||||
if some_args.len() == 1;
|
||||
then {
|
||||
|
@ -2381,7 +2381,7 @@ fn lint_flat_map_identity<'a, 'tcx>(
|
|||
flat_map_span: Span,
|
||||
) {
|
||||
if match_trait_method(cx, expr, &paths::ITERATOR) {
|
||||
let arg_node = &flat_map_args[1].node;
|
||||
let arg_node = &flat_map_args[1].kind;
|
||||
|
||||
let apply_lint = |message: &str| {
|
||||
span_lint_and_sugg(
|
||||
|
@ -2399,8 +2399,8 @@ fn lint_flat_map_identity<'a, 'tcx>(
|
|||
if let hir::ExprKind::Closure(_, _, body_id, _, _) = arg_node;
|
||||
let body = cx.tcx.hir().body(*body_id);
|
||||
|
||||
if let hir::PatKind::Binding(_, _, binding_ident, _) = body.params[0].pat.node;
|
||||
if let hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) = body.value.node;
|
||||
if let hir::PatKind::Binding(_, _, binding_ident, _) = body.params[0].pat.kind;
|
||||
if let hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) = body.value.kind;
|
||||
|
||||
if path.segments.len() == 1;
|
||||
if path.segments[0].ident.as_str() == binding_ident.as_str();
|
||||
|
@ -2444,11 +2444,11 @@ fn lint_search_is_some<'a, 'tcx>(
|
|||
// suggest `any(|..| *..)` instead of `any(|..| **..)` for `find(|..| **..).is_some()`
|
||||
let any_search_snippet = if_chain! {
|
||||
if search_method == "find";
|
||||
if let hir::ExprKind::Closure(_, _, body_id, ..) = search_args[1].node;
|
||||
if let hir::ExprKind::Closure(_, _, body_id, ..) = search_args[1].kind;
|
||||
let closure_body = cx.tcx.hir().body(body_id);
|
||||
if let Some(closure_arg) = closure_body.params.get(0);
|
||||
then {
|
||||
if let hir::PatKind::Ref(..) = closure_arg.pat.node {
|
||||
if let hir::PatKind::Ref(..) = closure_arg.pat.kind {
|
||||
Some(search_snippet.replacen('&', "", 1))
|
||||
} else if let Some(name) = get_arg_name(&closure_arg.pat) {
|
||||
Some(search_snippet.replace(&format!("*{}", name), &name.as_str()))
|
||||
|
@ -2516,9 +2516,9 @@ fn lint_chars_cmp(
|
|||
) -> bool {
|
||||
if_chain! {
|
||||
if let Some(args) = method_chain_args(info.chain, chain_methods);
|
||||
if let hir::ExprKind::Call(ref fun, ref arg_char) = info.other.node;
|
||||
if let hir::ExprKind::Call(ref fun, ref arg_char) = info.other.kind;
|
||||
if arg_char.len() == 1;
|
||||
if let hir::ExprKind::Path(ref qpath) = fun.node;
|
||||
if let hir::ExprKind::Path(ref qpath) = fun.kind;
|
||||
if let Some(segment) = single_segment_path(qpath);
|
||||
if segment.ident.name == sym!(Some);
|
||||
then {
|
||||
|
@ -2574,7 +2574,7 @@ fn lint_chars_cmp_with_unwrap<'a, 'tcx>(
|
|||
) -> bool {
|
||||
if_chain! {
|
||||
if let Some(args) = method_chain_args(info.chain, chain_methods);
|
||||
if let hir::ExprKind::Lit(ref lit) = info.other.node;
|
||||
if let hir::ExprKind::Lit(ref lit) = info.other.kind;
|
||||
if let ast::LitKind::Char(c) = lit.node;
|
||||
then {
|
||||
let mut applicability = Applicability::MachineApplicable;
|
||||
|
@ -2616,7 +2616,7 @@ fn lint_chars_last_cmp_with_unwrap<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, info: &
|
|||
/// lint for length-1 `str`s for methods in `PATTERN_METHODS`
|
||||
fn lint_single_char_pattern<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, _expr: &'tcx hir::Expr, arg: &'tcx hir::Expr) {
|
||||
if_chain! {
|
||||
if let hir::ExprKind::Lit(lit) = &arg.node;
|
||||
if let hir::ExprKind::Lit(lit) = &arg.kind;
|
||||
if let ast::LitKind::Str(r, style) = lit.node;
|
||||
if r.as_str().len() == 1;
|
||||
then {
|
||||
|
@ -2659,7 +2659,7 @@ fn lint_asref(cx: &LateContext<'_, '_>, expr: &hir::Expr, call_name: &str, as_re
|
|||
// allow the `as_ref` or `as_mut` if it is followed by another method call
|
||||
if_chain! {
|
||||
if let Some(parent) = get_parent_expr(cx, expr);
|
||||
if let hir::ExprKind::MethodCall(_, ref span, _) = parent.node;
|
||||
if let hir::ExprKind::MethodCall(_, ref span, _) = parent.kind;
|
||||
if span != &expr.span;
|
||||
then {
|
||||
return;
|
||||
|
@ -2725,9 +2725,9 @@ fn lint_into_iter(cx: &LateContext<'_, '_>, expr: &hir::Expr, self_ref_ty: Ty<'_
|
|||
/// lint for `MaybeUninit::uninit().assume_init()` (we already have the latter)
|
||||
fn lint_maybe_uninit(cx: &LateContext<'_, '_>, expr: &hir::Expr, outer: &hir::Expr) {
|
||||
if_chain! {
|
||||
if let hir::ExprKind::Call(ref callee, ref args) = expr.node;
|
||||
if let hir::ExprKind::Call(ref callee, ref args) = expr.kind;
|
||||
if args.is_empty();
|
||||
if let hir::ExprKind::Path(ref path) = callee.node;
|
||||
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));
|
||||
then {
|
||||
|
@ -2945,20 +2945,20 @@ enum OutType {
|
|||
|
||||
impl OutType {
|
||||
fn matches(self, cx: &LateContext<'_, '_>, ty: &hir::FunctionRetTy) -> bool {
|
||||
let is_unit = |ty: &hir::Ty| SpanlessEq::new(cx).eq_ty_kind(&ty.node, &hir::TyKind::Tup(vec![].into()));
|
||||
let is_unit = |ty: &hir::Ty| SpanlessEq::new(cx).eq_ty_kind(&ty.kind, &hir::TyKind::Tup(vec![].into()));
|
||||
match (self, ty) {
|
||||
(Self::Unit, &hir::DefaultReturn(_)) => true,
|
||||
(Self::Unit, &hir::Return(ref ty)) if is_unit(ty) => true,
|
||||
(Self::Bool, &hir::Return(ref ty)) if is_bool(ty) => true,
|
||||
(Self::Any, &hir::Return(ref ty)) if !is_unit(ty) => true,
|
||||
(Self::Ref, &hir::Return(ref ty)) => matches!(ty.node, hir::TyKind::Rptr(_, _)),
|
||||
(Self::Ref, &hir::Return(ref ty)) => matches!(ty.kind, hir::TyKind::Rptr(_, _)),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn is_bool(ty: &hir::Ty) -> bool {
|
||||
if let hir::TyKind::Path(ref p) = ty.node {
|
||||
if let hir::TyKind::Path(ref p) = ty.kind {
|
||||
match_qpath(p, &["bool"])
|
||||
} else {
|
||||
false
|
||||
|
@ -2976,7 +2976,7 @@ fn contains_return(expr: &hir::Expr) -> bool {
|
|||
if self.found {
|
||||
return;
|
||||
}
|
||||
if let hir::ExprKind::Ret(..) = &expr.node {
|
||||
if let hir::ExprKind::Ret(..) = &expr.kind {
|
||||
self.found = true;
|
||||
} else {
|
||||
intravisit::walk_expr(self, expr);
|
||||
|
|
|
@ -15,7 +15,7 @@ pub(super) fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[hir::Expr
|
|||
return;
|
||||
}
|
||||
|
||||
if let hir::ExprKind::Closure(_, _, body_id, ..) = args[1].node {
|
||||
if let hir::ExprKind::Closure(_, _, body_id, ..) = args[1].kind {
|
||||
let body = cx.tcx.hir().body(body_id);
|
||||
let arg_id = body.params[0].pat.hir_id;
|
||||
let mutates_arg =
|
||||
|
@ -56,14 +56,14 @@ fn check_expression<'a, 'tcx>(
|
|||
arg_id: hir::HirId,
|
||||
expr: &'tcx hir::Expr,
|
||||
) -> (bool, bool) {
|
||||
match &expr.node {
|
||||
match &expr.kind {
|
||||
hir::ExprKind::Call(ref func, ref args) => {
|
||||
if_chain! {
|
||||
if let hir::ExprKind::Path(ref path) = func.node;
|
||||
if let hir::ExprKind::Path(ref path) = func.kind;
|
||||
then {
|
||||
if match_qpath(path, &paths::OPTION_SOME) {
|
||||
if_chain! {
|
||||
if let hir::ExprKind::Path(path) = &args[0].node;
|
||||
if let hir::ExprKind::Path(path) = &args[0].kind;
|
||||
if let Res::Local(ref local) = cx.tables.qpath_res(path, args[0].hir_id);
|
||||
then {
|
||||
if arg_id == *local {
|
||||
|
@ -124,7 +124,7 @@ impl<'a, 'tcx> ReturnVisitor<'a, 'tcx> {
|
|||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for ReturnVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
|
||||
if let hir::ExprKind::Ret(Some(expr)) = &expr.node {
|
||||
if let hir::ExprKind::Ret(Some(expr)) = &expr.kind {
|
||||
let (found_mapping, found_filtering) = check_expression(self.cx, self.arg_id, expr);
|
||||
self.found_mapping |= found_mapping;
|
||||
self.found_filtering |= found_filtering;
|
||||
|
|
|
@ -60,8 +60,8 @@ enum MinMax {
|
|||
}
|
||||
|
||||
fn min_max<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr) -> Option<(MinMax, Constant, &'a Expr)> {
|
||||
if let ExprKind::Call(ref path, ref args) = expr.node {
|
||||
if let ExprKind::Path(ref qpath) = path.node {
|
||||
if let ExprKind::Call(ref path, ref args) = expr.kind {
|
||||
if let ExprKind::Path(ref qpath) = path.kind {
|
||||
cx.tables.qpath_res(qpath, path.hir_id).opt_def_id().and_then(|def_id| {
|
||||
if match_def_path(cx, def_id, &paths::CMP_MIN) {
|
||||
fetch_const(cx, args, MinMax::Min)
|
||||
|
|
|
@ -246,7 +246,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
|
|||
return;
|
||||
}
|
||||
for arg in iter_input_pats(decl, body) {
|
||||
match arg.pat.node {
|
||||
match arg.pat.kind {
|
||||
PatKind::Binding(BindingAnnotation::Ref, ..) | PatKind::Binding(BindingAnnotation::RefMut, ..) => {
|
||||
span_lint(
|
||||
cx,
|
||||
|
@ -263,8 +263,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
|
|||
|
||||
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) {
|
||||
if_chain! {
|
||||
if let StmtKind::Local(ref local) = stmt.node;
|
||||
if let PatKind::Binding(an, .., name, None) = local.pat.node;
|
||||
if let StmtKind::Local(ref local) = stmt.kind;
|
||||
if let PatKind::Binding(an, .., name, None) = local.pat.kind;
|
||||
if let Some(ref init) = local.init;
|
||||
then {
|
||||
if an == BindingAnnotation::Ref || an == BindingAnnotation::RefMut {
|
||||
|
@ -307,8 +307,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
|
|||
}
|
||||
};
|
||||
if_chain! {
|
||||
if let StmtKind::Semi(ref expr) = stmt.node;
|
||||
if let ExprKind::Binary(ref binop, ref a, ref b) = expr.node;
|
||||
if let StmtKind::Semi(ref expr) = stmt.kind;
|
||||
if let ExprKind::Binary(ref binop, ref a, ref b) = expr.kind;
|
||||
if binop.node == BinOpKind::And || binop.node == BinOpKind::Or;
|
||||
if let Some(sugg) = Sugg::hir_opt(cx, a);
|
||||
then {
|
||||
|
@ -334,7 +334,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
|
|||
}
|
||||
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
match expr.node {
|
||||
match expr.kind {
|
||||
ExprKind::Cast(ref e, ref ty) => {
|
||||
check_cast(cx, expr.span, e, ty);
|
||||
return;
|
||||
|
@ -342,10 +342,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
|
|||
ExprKind::Binary(ref cmp, ref left, ref right) => {
|
||||
let op = cmp.node;
|
||||
if op.is_comparison() {
|
||||
if let ExprKind::Path(QPath::Resolved(_, ref path)) = left.node {
|
||||
if let ExprKind::Path(QPath::Resolved(_, ref path)) = left.kind {
|
||||
check_nan(cx, path, expr);
|
||||
}
|
||||
if let ExprKind::Path(QPath::Resolved(_, ref path)) = right.node {
|
||||
if let ExprKind::Path(QPath::Resolved(_, ref path)) = right.kind {
|
||||
check_nan(cx, path, expr);
|
||||
}
|
||||
check_to_owned(cx, left, right);
|
||||
|
@ -403,7 +403,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
|
|||
// Don't lint things expanded by #[derive(...)], etc
|
||||
return;
|
||||
}
|
||||
let binding = match expr.node {
|
||||
let binding = match expr.kind {
|
||||
ExprKind::Path(ref qpath) => {
|
||||
let binding = last_path_segment(qpath).ident.as_str();
|
||||
if binding.starts_with('_') &&
|
||||
|
@ -477,12 +477,12 @@ fn is_allowed<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> bool {
|
|||
// Return true if `expr` is the result of `signum()` invoked on a float value.
|
||||
fn is_signum(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
|
||||
// The negation of a signum is still a signum
|
||||
if let ExprKind::Unary(UnNeg, ref child_expr) = expr.node {
|
||||
if let ExprKind::Unary(UnNeg, ref child_expr) = expr.kind {
|
||||
return is_signum(cx, &child_expr);
|
||||
}
|
||||
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(ref method_name, _, ref expressions) = expr.node;
|
||||
if let ExprKind::MethodCall(ref method_name, _, ref expressions) = expr.kind;
|
||||
if sym!(signum) == method_name.ident.name;
|
||||
// Check that the receiver of the signum() is a float (expressions[0] is the receiver of
|
||||
// the method call)
|
||||
|
@ -498,7 +498,7 @@ fn is_float(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
|
|||
}
|
||||
|
||||
fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr, other: &Expr) {
|
||||
let (arg_ty, snip) = match expr.node {
|
||||
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_adjusted(&args[0]), snippet(cx, args[0].span, ".."))
|
||||
|
@ -507,7 +507,7 @@ fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr, other: &Expr) {
|
|||
}
|
||||
},
|
||||
ExprKind::Call(ref path, ref v) if v.len() == 1 => {
|
||||
if let ExprKind::Path(ref path) = path.node {
|
||||
if let ExprKind::Path(ref path) = path.kind {
|
||||
if match_qpath(path, &["String", "from_str"]) || match_qpath(path, &["String", "from"]) {
|
||||
(cx.tables.expr_ty_adjusted(&v[0]), snippet(cx, v[0].span, ".."))
|
||||
} else {
|
||||
|
@ -538,7 +538,7 @@ fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr, other: &Expr) {
|
|||
return;
|
||||
}
|
||||
|
||||
let other_gets_derefed = match other.node {
|
||||
let other_gets_derefed = match other.kind {
|
||||
ExprKind::Unary(UnDeref, _) => true,
|
||||
_ => false,
|
||||
};
|
||||
|
@ -584,7 +584,7 @@ fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr, other: &Expr) {
|
|||
/// of what it means for an expression to be "used".
|
||||
fn is_used(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
|
||||
if let Some(parent) = get_parent_expr(cx, expr) {
|
||||
match parent.node {
|
||||
match parent.kind {
|
||||
ExprKind::Assign(_, ref rhs) | ExprKind::AssignOp(_, _, ref rhs) => SpanlessEq::new(cx).eq_expr(rhs, expr),
|
||||
_ => is_used(cx, parent),
|
||||
}
|
||||
|
@ -621,8 +621,8 @@ fn non_macro_local(cx: &LateContext<'_, '_>, res: def::Res) -> bool {
|
|||
|
||||
fn check_cast(cx: &LateContext<'_, '_>, span: Span, e: &Expr, ty: &Ty) {
|
||||
if_chain! {
|
||||
if let TyKind::Ptr(MutTy { mutbl, .. }) = ty.node;
|
||||
if let ExprKind::Lit(ref lit) = e.node;
|
||||
if let TyKind::Ptr(MutTy { mutbl, .. }) = ty.kind;
|
||||
if let ExprKind::Lit(ref lit) = e.kind;
|
||||
if let LitKind::Int(value, ..) = lit.node;
|
||||
if value == 0;
|
||||
if !in_constant(cx, e.hir_id);
|
||||
|
|
|
@ -260,9 +260,9 @@ impl ReturnVisitor {
|
|||
|
||||
impl<'ast> Visitor<'ast> for ReturnVisitor {
|
||||
fn visit_expr(&mut self, ex: &'ast Expr) {
|
||||
if let ExprKind::Ret(_) = ex.node {
|
||||
if let ExprKind::Ret(_) = ex.kind {
|
||||
self.found_return = true;
|
||||
} else if let ExprKind::Try(_) = ex.node {
|
||||
} else if let ExprKind::Try(_) = ex.kind {
|
||||
self.found_return = true;
|
||||
}
|
||||
|
||||
|
@ -288,7 +288,7 @@ impl EarlyLintPass for MiscEarlyLints {
|
|||
}
|
||||
|
||||
fn check_pat(&mut self, cx: &EarlyContext<'_>, pat: &Pat) {
|
||||
if let PatKind::Struct(ref npat, ref pfields, _) = pat.node {
|
||||
if let PatKind::Struct(ref npat, ref pfields, _) = pat.kind {
|
||||
let mut wilds = 0;
|
||||
let type_name = npat
|
||||
.segments
|
||||
|
@ -298,7 +298,7 @@ impl EarlyLintPass for MiscEarlyLints {
|
|||
.name;
|
||||
|
||||
for field in pfields {
|
||||
if let PatKind::Wild = field.pat.node {
|
||||
if let PatKind::Wild = field.pat.kind {
|
||||
wilds += 1;
|
||||
}
|
||||
}
|
||||
|
@ -316,7 +316,7 @@ impl EarlyLintPass for MiscEarlyLints {
|
|||
let mut normal = vec![];
|
||||
|
||||
for field in pfields {
|
||||
match field.pat.node {
|
||||
match field.pat.kind {
|
||||
PatKind::Wild => {},
|
||||
_ => {
|
||||
if let Ok(n) = cx.sess().source_map().span_to_snippet(field.span) {
|
||||
|
@ -326,7 +326,7 @@ impl EarlyLintPass for MiscEarlyLints {
|
|||
}
|
||||
}
|
||||
for field in pfields {
|
||||
if let PatKind::Wild = field.pat.node {
|
||||
if let PatKind::Wild = field.pat.kind {
|
||||
wilds -= 1;
|
||||
if wilds > 0 {
|
||||
span_lint(
|
||||
|
@ -350,8 +350,8 @@ impl EarlyLintPass for MiscEarlyLints {
|
|||
}
|
||||
}
|
||||
|
||||
if let PatKind::Ident(_, ident, Some(ref right)) = pat.node {
|
||||
if let PatKind::Wild = right.node {
|
||||
if let PatKind::Ident(_, ident, Some(ref right)) = pat.kind {
|
||||
if let PatKind::Wild = right.kind {
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
REDUNDANT_PATTERN,
|
||||
|
@ -374,7 +374,7 @@ impl EarlyLintPass for MiscEarlyLints {
|
|||
let mut registered_names: FxHashMap<String, Span> = FxHashMap::default();
|
||||
|
||||
for arg in &decl.inputs {
|
||||
if let PatKind::Ident(_, ident, None) = arg.pat.node {
|
||||
if let PatKind::Ident(_, ident, None) = arg.pat.kind {
|
||||
let arg_name = ident.to_string();
|
||||
|
||||
if arg_name.starts_with('_') {
|
||||
|
@ -401,10 +401,10 @@ impl EarlyLintPass for MiscEarlyLints {
|
|||
if in_external_macro(cx.sess(), expr.span) {
|
||||
return;
|
||||
}
|
||||
match expr.node {
|
||||
match expr.kind {
|
||||
ExprKind::Call(ref paren, _) => {
|
||||
if let ExprKind::Paren(ref closure) = paren.node {
|
||||
if let ExprKind::Closure(_, _, _, ref decl, ref block, _) = closure.node {
|
||||
if let ExprKind::Paren(ref closure) = paren.kind {
|
||||
if let ExprKind::Closure(_, _, _, ref decl, ref block, _) = closure.kind {
|
||||
let mut visitor = ReturnVisitor::new();
|
||||
visitor.visit_expr(block);
|
||||
if !visitor.found_return {
|
||||
|
@ -427,7 +427,7 @@ impl EarlyLintPass for MiscEarlyLints {
|
|||
}
|
||||
},
|
||||
ExprKind::Unary(UnOp::Neg, ref inner) => {
|
||||
if let ExprKind::Unary(UnOp::Neg, _) = inner.node {
|
||||
if let ExprKind::Unary(UnOp::Neg, _) = inner.kind {
|
||||
span_lint(
|
||||
cx,
|
||||
DOUBLE_NEG,
|
||||
|
@ -444,14 +444,14 @@ impl EarlyLintPass for MiscEarlyLints {
|
|||
fn check_block(&mut self, cx: &EarlyContext<'_>, block: &Block) {
|
||||
for w in block.stmts.windows(2) {
|
||||
if_chain! {
|
||||
if let StmtKind::Local(ref local) = w[0].node;
|
||||
if let StmtKind::Local(ref local) = w[0].kind;
|
||||
if let Option::Some(ref t) = local.init;
|
||||
if let ExprKind::Closure(..) = t.node;
|
||||
if let PatKind::Ident(_, ident, _) = local.pat.node;
|
||||
if let StmtKind::Semi(ref second) = w[1].node;
|
||||
if let ExprKind::Assign(_, ref call) = second.node;
|
||||
if let ExprKind::Call(ref closure, _) = call.node;
|
||||
if let ExprKind::Path(_, ref path) = closure.node;
|
||||
if let ExprKind::Closure(..) = t.kind;
|
||||
if let PatKind::Ident(_, ident, _) = local.pat.kind;
|
||||
if let StmtKind::Semi(ref second) = w[1].kind;
|
||||
if let ExprKind::Assign(_, ref call) = second.kind;
|
||||
if let ExprKind::Call(ref closure, _) = call.kind;
|
||||
if let ExprKind::Path(_, ref path) = closure.kind;
|
||||
then {
|
||||
if ident == path.segments[0].ident {
|
||||
span_lint(
|
||||
|
@ -479,7 +479,7 @@ impl MiscEarlyLints {
|
|||
_ => return,
|
||||
};
|
||||
|
||||
if let LitKind::Int(value, lit_int_type) = lit.node {
|
||||
if let LitKind::Int(value, lit_int_type) = lit.kind {
|
||||
let suffix = match lit_int_type {
|
||||
LitIntType::Signed(ty) => ty.ty_to_string(),
|
||||
LitIntType::Unsigned(ty) => ty.ty_to_string(),
|
||||
|
@ -542,7 +542,7 @@ impl MiscEarlyLints {
|
|||
},
|
||||
);
|
||||
}
|
||||
} else if let LitKind::Float(_, float_ty) = lit.node {
|
||||
} else if let LitKind::Float(_, float_ty) = lit.kind {
|
||||
let suffix = float_ty.ty_to_string();
|
||||
let maybe_last_sep_idx = lit_snip.len() - suffix.len() - 1;
|
||||
if lit_snip.as_bytes()[maybe_last_sep_idx] != b'_' {
|
||||
|
@ -561,7 +561,7 @@ impl MiscEarlyLints {
|
|||
}
|
||||
|
||||
fn check_unneeded_wildcard_pattern(cx: &EarlyContext<'_>, pat: &Pat) {
|
||||
if let PatKind::TupleStruct(_, ref patterns) | PatKind::Tuple(ref patterns) = pat.node {
|
||||
if let PatKind::TupleStruct(_, ref patterns) | PatKind::Tuple(ref patterns) = pat.kind {
|
||||
fn span_lint(cx: &EarlyContext<'_>, span: Span, only_one: bool) {
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
|
@ -580,7 +580,7 @@ fn check_unneeded_wildcard_pattern(cx: &EarlyContext<'_>, pat: &Pat) {
|
|||
|
||||
#[allow(clippy::trivially_copy_pass_by_ref)]
|
||||
fn is_wild<P: std::ops::Deref<Target = Pat>>(pat: &&P) -> bool {
|
||||
if let PatKind::Wild = pat.node {
|
||||
if let PatKind::Wild = pat.kind {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
|
|
@ -56,7 +56,7 @@ impl MissingDoc {
|
|||
fn has_include(meta: Option<MetaItem>) -> bool {
|
||||
if_chain! {
|
||||
if let Some(meta) = meta;
|
||||
if let MetaItemKind::List(list) = meta.node;
|
||||
if let MetaItemKind::List(list) = meta.kind;
|
||||
if let Some(meta) = list.get(0);
|
||||
if let Some(name) = meta.ident();
|
||||
then {
|
||||
|
@ -127,7 +127,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
|
|||
}
|
||||
|
||||
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx hir::Item) {
|
||||
let desc = match it.node {
|
||||
let desc = match it.kind {
|
||||
hir::ItemKind::Const(..) => "a constant",
|
||||
hir::ItemKind::Enum(..) => "an enum",
|
||||
hir::ItemKind::Fn(..) => {
|
||||
|
@ -160,7 +160,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
|
|||
}
|
||||
|
||||
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, trait_item: &'tcx hir::TraitItem) {
|
||||
let desc = match trait_item.node {
|
||||
let desc = match trait_item.kind {
|
||||
hir::TraitItemKind::Const(..) => "an associated constant",
|
||||
hir::TraitItemKind::Method(..) => "a trait method",
|
||||
hir::TraitItemKind::Type(..) => "an associated type",
|
||||
|
@ -181,7 +181,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
|
|||
},
|
||||
}
|
||||
|
||||
let desc = match impl_item.node {
|
||||
let desc = match impl_item.kind {
|
||||
hir::ImplItemKind::Const(..) => "an associated constant",
|
||||
hir::ImplItemKind::Method(..) => "a method",
|
||||
hir::ImplItemKind::TyAlias(_) => "an associated type",
|
||||
|
|
|
@ -88,7 +88,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline {
|
|||
if !cx.access_levels.is_exported(it.hir_id) {
|
||||
return;
|
||||
}
|
||||
match it.node {
|
||||
match it.kind {
|
||||
hir::ItemKind::Fn(..) => {
|
||||
let desc = "a function";
|
||||
check_missing_inline_attrs(cx, &it.attrs, it.span, desc);
|
||||
|
@ -98,7 +98,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline {
|
|||
// `LateLintPass::check_trait_item` here.
|
||||
for tit in trait_items {
|
||||
let tit_ = cx.tcx.hir().trait_item(tit.id);
|
||||
match tit_.node {
|
||||
match tit_.kind {
|
||||
hir::TraitItemKind::Const(..) | hir::TraitItemKind::Type(..) => {},
|
||||
hir::TraitItemKind::Method(..) => {
|
||||
if tit.defaultness.has_value() {
|
||||
|
@ -140,7 +140,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline {
|
|||
return;
|
||||
}
|
||||
|
||||
let desc = match impl_item.node {
|
||||
let desc = match impl_item.kind {
|
||||
hir::ImplItemKind::Method(..) => "a method",
|
||||
hir::ImplItemKind::Const(..) | hir::ImplItemKind::TyAlias(_) | hir::ImplItemKind::OpaqueTy(_) => return,
|
||||
};
|
||||
|
|
|
@ -57,8 +57,8 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> {
|
|||
// Let's ignore the generated code.
|
||||
intravisit::walk_expr(self, arg);
|
||||
intravisit::walk_expr(self, body);
|
||||
} else if let hir::ExprKind::AddrOf(hir::MutMutable, ref e) = expr.node {
|
||||
if let hir::ExprKind::AddrOf(hir::MutMutable, _) = e.node {
|
||||
} else if let hir::ExprKind::AddrOf(hir::MutMutable, ref e) = expr.kind {
|
||||
if let hir::ExprKind::AddrOf(hir::MutMutable, _) = e.kind {
|
||||
span_lint(
|
||||
self.cx,
|
||||
MUT_MUT,
|
||||
|
@ -83,14 +83,14 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> {
|
|||
ty: ref pty,
|
||||
mutbl: hir::MutMutable,
|
||||
},
|
||||
) = ty.node
|
||||
) = ty.kind
|
||||
{
|
||||
if let hir::TyKind::Rptr(
|
||||
_,
|
||||
hir::MutTy {
|
||||
mutbl: hir::MutMutable, ..
|
||||
},
|
||||
) = pty.node
|
||||
) = pty.kind
|
||||
{
|
||||
span_lint(
|
||||
self.cx,
|
||||
|
|
|
@ -27,9 +27,9 @@ declare_lint_pass!(UnnecessaryMutPassed => [UNNECESSARY_MUT_PASSED]);
|
|||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnecessaryMutPassed {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||
match e.node {
|
||||
match e.kind {
|
||||
ExprKind::Call(ref fn_expr, ref arguments) => {
|
||||
if let ExprKind::Path(ref path) = fn_expr.node {
|
||||
if let ExprKind::Path(ref path) = fn_expr.kind {
|
||||
check_arguments(
|
||||
cx,
|
||||
arguments,
|
||||
|
@ -59,7 +59,7 @@ fn check_arguments<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arguments: &[Expr], typ
|
|||
| ty::RawPtr(ty::TypeAndMut {
|
||||
mutbl: MutImmutable, ..
|
||||
}) => {
|
||||
if let ExprKind::AddrOf(MutMutable, _) = argument.node {
|
||||
if let ExprKind::AddrOf(MutMutable, _) = argument.kind {
|
||||
span_lint(
|
||||
cx,
|
||||
UNNECESSARY_MUT_PASSED,
|
||||
|
|
|
@ -87,7 +87,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBool {
|
|||
applicability,
|
||||
);
|
||||
};
|
||||
if let ExprKind::Block(ref then_block, _) = then_block.node {
|
||||
if let ExprKind::Block(ref then_block, _) = then_block.kind {
|
||||
match (fetch_bool_block(then_block), fetch_bool_expr(else_expr)) {
|
||||
(RetBool(true), RetBool(true)) | (Bool(true), Bool(true)) => {
|
||||
span_lint(
|
||||
|
@ -126,7 +126,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison {
|
|||
return;
|
||||
}
|
||||
|
||||
if let ExprKind::Binary(Spanned { node, .. }, ..) = e.node {
|
||||
if let ExprKind::Binary(Spanned { node, .. }, ..) = e.kind {
|
||||
let ignore_case = None::<(fn(_) -> _, &str)>;
|
||||
let ignore_no_literal = None::<(fn(_, _) -> _, &str)>;
|
||||
match node {
|
||||
|
@ -193,7 +193,7 @@ fn check_comparison<'a, 'tcx>(
|
|||
) {
|
||||
use self::Expression::*;
|
||||
|
||||
if let ExprKind::Binary(_, ref left_side, ref right_side) = e.node {
|
||||
if let ExprKind::Binary(_, 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));
|
||||
if l_ty.is_bool() && r_ty.is_bool() {
|
||||
let mut applicability = Applicability::MachineApplicable;
|
||||
|
@ -259,8 +259,8 @@ fn fetch_bool_block(block: &Block) -> Expression {
|
|||
match (&*block.stmts, block.expr.as_ref()) {
|
||||
(&[], Some(e)) => fetch_bool_expr(&**e),
|
||||
(&[ref e], None) => {
|
||||
if let StmtKind::Semi(ref e) = e.node {
|
||||
if let ExprKind::Ret(_) = e.node {
|
||||
if let StmtKind::Semi(ref e) = e.kind {
|
||||
if let ExprKind::Ret(_) = e.kind {
|
||||
fetch_bool_expr(&**e)
|
||||
} else {
|
||||
Expression::Other
|
||||
|
@ -274,7 +274,7 @@ fn fetch_bool_block(block: &Block) -> Expression {
|
|||
}
|
||||
|
||||
fn fetch_bool_expr(expr: &Expr) -> Expression {
|
||||
match expr.node {
|
||||
match expr.kind {
|
||||
ExprKind::Block(ref block, _) => fetch_bool_block(block),
|
||||
ExprKind::Lit(ref lit_ptr) => {
|
||||
if let LitKind::Bool(value) = lit_ptr.node {
|
||||
|
|
|
@ -41,7 +41,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow {
|
|||
if e.span.from_expansion() || self.derived_item.is_some() {
|
||||
return;
|
||||
}
|
||||
if let ExprKind::AddrOf(MutImmutable, ref inner) = e.node {
|
||||
if let ExprKind::AddrOf(MutImmutable, 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 [Adjustment {
|
||||
|
@ -80,7 +80,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow {
|
|||
return;
|
||||
}
|
||||
if_chain! {
|
||||
if let PatKind::Binding(BindingAnnotation::Ref, .., name, _) = pat.node;
|
||||
if let PatKind::Binding(BindingAnnotation::Ref, .., name, _) = pat.kind;
|
||||
if let ty::Ref(_, tam, mutbl) = cx.tables.pat_ty(pat).kind;
|
||||
if mutbl == MutImmutable;
|
||||
if let ty::Ref(_, _, mutbl) = tam.kind;
|
||||
|
|
|
@ -61,10 +61,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrowedRef {
|
|||
|
||||
if_chain! {
|
||||
// Only lint immutable refs, because `&mut ref T` may be useful.
|
||||
if let PatKind::Ref(ref sub_pat, MutImmutable) = pat.node;
|
||||
if let PatKind::Ref(ref sub_pat, MutImmutable) = pat.kind;
|
||||
|
||||
// Check sub_pat got a `ref` keyword (excluding `ref mut`).
|
||||
if let PatKind::Binding(BindingAnnotation::Ref, .., spanned_name, _) = sub_pat.node;
|
||||
if let PatKind::Binding(BindingAnnotation::Ref, .., spanned_name, _) = sub_pat.kind;
|
||||
let parent_id = cx.tcx.hir().get_parent_node(pat.hir_id);
|
||||
if let Some(parent_node) = cx.tcx.hir().find(parent_id);
|
||||
then {
|
||||
|
|
|
@ -181,7 +181,7 @@ impl EarlyLintPass for NeedlessContinue {
|
|||
/// - The expression node is a block with the first statement being a
|
||||
/// `continue`.
|
||||
fn needless_continue_in_else(else_expr: &ast::Expr, label: Option<&ast::Label>) -> bool {
|
||||
match else_expr.node {
|
||||
match else_expr.kind {
|
||||
ast::ExprKind::Block(ref else_block, _) => is_first_block_stmt_continue(else_block, label),
|
||||
ast::ExprKind::Continue(l) => compare_labels(label, l.as_ref()),
|
||||
_ => false,
|
||||
|
@ -189,9 +189,9 @@ fn needless_continue_in_else(else_expr: &ast::Expr, label: Option<&ast::Label>)
|
|||
}
|
||||
|
||||
fn is_first_block_stmt_continue(block: &ast::Block, label: Option<&ast::Label>) -> bool {
|
||||
block.stmts.get(0).map_or(false, |stmt| match stmt.node {
|
||||
block.stmts.get(0).map_or(false, |stmt| match stmt.kind {
|
||||
ast::StmtKind::Semi(ref e) | ast::StmtKind::Expr(ref e) => {
|
||||
if let ast::ExprKind::Continue(ref l) = e.node {
|
||||
if let ast::ExprKind::Continue(ref l) = e.kind {
|
||||
compare_labels(label, l.as_ref())
|
||||
} else {
|
||||
false
|
||||
|
@ -221,7 +221,7 @@ where
|
|||
{
|
||||
if let ast::ExprKind::While(_, loop_block, label)
|
||||
| ast::ExprKind::ForLoop(_, _, loop_block, label)
|
||||
| ast::ExprKind::Loop(loop_block, label) = &expr.node
|
||||
| ast::ExprKind::Loop(loop_block, label) = &expr.kind
|
||||
{
|
||||
func(loop_block, label.as_ref());
|
||||
}
|
||||
|
@ -239,9 +239,9 @@ fn with_if_expr<F>(stmt: &ast::Stmt, mut func: F)
|
|||
where
|
||||
F: FnMut(&ast::Expr, &ast::Expr, &ast::Block, &ast::Expr),
|
||||
{
|
||||
match stmt.node {
|
||||
match stmt.kind {
|
||||
ast::StmtKind::Semi(ref e) | ast::StmtKind::Expr(ref e) => {
|
||||
if let ast::ExprKind::If(ref cond, ref if_block, Some(ref else_expr)) = e.node {
|
||||
if let ast::ExprKind::If(ref cond, ref if_block, Some(ref else_expr)) = e.kind {
|
||||
func(e, cond, if_block, else_expr);
|
||||
}
|
||||
},
|
||||
|
|
|
@ -92,7 +92,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
|
|||
|
||||
// Exclude non-inherent impls
|
||||
if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) {
|
||||
if matches!(item.node, ItemKind::Impl(_, _, _, _, Some(_), _, _) |
|
||||
if matches!(item.kind, ItemKind::Impl(_, _, _, _, Some(_), _, _) |
|
||||
ItemKind::Trait(..))
|
||||
{
|
||||
return;
|
||||
|
@ -160,7 +160,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
|
|||
|
||||
// Ignore `self`s.
|
||||
if idx == 0 {
|
||||
if let PatKind::Binding(.., ident, _) = arg.pat.node {
|
||||
if let PatKind::Binding(.., ident, _) = arg.pat.kind {
|
||||
if ident.as_str() == "self" {
|
||||
continue;
|
||||
}
|
||||
|
@ -202,7 +202,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
|
|||
if !implements_borrow_trait;
|
||||
if !all_borrowable_trait;
|
||||
|
||||
if let PatKind::Binding(mode, canonical_id, ..) = arg.pat.node;
|
||||
if let PatKind::Binding(mode, canonical_id, ..) = arg.pat.kind;
|
||||
if !moved_vars.contains(&canonical_id);
|
||||
then {
|
||||
if mode == BindingAnnotation::Mutable || mode == BindingAnnotation::RefMut {
|
||||
|
@ -224,7 +224,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
|
|||
if is_type_diagnostic_item(cx, ty, Symbol::intern("vec_type"));
|
||||
if let Some(clone_spans) =
|
||||
get_spans(cx, Some(body.id()), idx, &[("clone", ".to_owned()")]);
|
||||
if let TyKind::Path(QPath::Resolved(_, ref path)) = input.node;
|
||||
if let TyKind::Path(QPath::Resolved(_, ref path)) = input.kind;
|
||||
if let Some(elem_ty) = path.segments.iter()
|
||||
.find(|seg| seg.ident.name == sym!(Vec))
|
||||
.and_then(|ps| ps.args.as_ref())
|
||||
|
@ -367,7 +367,7 @@ impl<'a, 'tcx> MovedVariablesCtxt<'a, 'tcx> {
|
|||
match node {
|
||||
Node::Expr(e) => {
|
||||
// `match` and `if let`
|
||||
if let ExprKind::Match(ref c, ..) = e.node {
|
||||
if let ExprKind::Match(ref c, ..) = e.kind {
|
||||
self.spans_need_deref
|
||||
.entry(vid)
|
||||
.or_insert_with(FxHashSet::default)
|
||||
|
@ -378,7 +378,7 @@ impl<'a, 'tcx> MovedVariablesCtxt<'a, 'tcx> {
|
|||
Node::Stmt(s) => {
|
||||
// `let <pat> = x;`
|
||||
if_chain! {
|
||||
if let StmtKind::Local(ref local) = s.node;
|
||||
if let StmtKind::Local(ref local) = s.kind;
|
||||
then {
|
||||
self.spans_need_deref
|
||||
.entry(vid)
|
||||
|
|
|
@ -36,7 +36,7 @@ declare_lint_pass!(NeedlessUpdate => [NEEDLESS_UPDATE]);
|
|||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessUpdate {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
if let ExprKind::Struct(_, ref fields, Some(ref base)) = expr.node {
|
||||
if let ExprKind::Struct(_, ref fields, Some(ref base)) = expr.kind {
|
||||
let ty = cx.tables.expr_ty(expr);
|
||||
if let ty::Adt(def, _) = ty.kind {
|
||||
if fields.len() == def.non_enum_variant().fields.len() {
|
||||
|
|
|
@ -49,8 +49,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NoNegCompOpForPartialOrd {
|
|||
if_chain! {
|
||||
|
||||
if !in_external_macro(cx.sess(), expr.span);
|
||||
if let ExprKind::Unary(UnOp::UnNot, ref inner) = expr.node;
|
||||
if let ExprKind::Binary(ref op, ref left, _) = inner.node;
|
||||
if let ExprKind::Unary(UnOp::UnNot, ref inner) = expr.kind;
|
||||
if let ExprKind::Binary(ref op, ref left, _) = inner.kind;
|
||||
if let BinOpKind::Le | BinOpKind::Ge | BinOpKind::Lt | BinOpKind::Gt = op.node;
|
||||
|
||||
then {
|
||||
|
|
|
@ -34,9 +34,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NegMultiply {
|
|||
},
|
||||
ref l,
|
||||
ref r,
|
||||
) = e.node
|
||||
) = e.kind
|
||||
{
|
||||
match (&l.node, &r.node) {
|
||||
match (&l.kind, &r.kind) {
|
||||
(&ExprKind::Unary(..), &ExprKind::Unary(..)) => (),
|
||||
(&ExprKind::Unary(UnNeg, ref lit), _) => check_mul(cx, e.span, lit, r),
|
||||
(_, &ExprKind::Unary(UnNeg, ref lit)) => check_mul(cx, e.span, lit, l),
|
||||
|
@ -48,7 +48,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NegMultiply {
|
|||
|
||||
fn check_mul(cx: &LateContext<'_, '_>, span: Span, lit: &Expr, exp: &Expr) {
|
||||
if_chain! {
|
||||
if let ExprKind::Lit(ref l) = lit.node;
|
||||
if let ExprKind::Lit(ref l) = lit.kind;
|
||||
if let Constant::Int(val) = consts::lit_to_constant(&l.node, cx.tables.expr_ty(lit));
|
||||
if val == 1;
|
||||
if cx.tables.expr_ty(exp).is_integral();
|
||||
|
|
|
@ -93,14 +93,14 @@ impl_lint_pass!(NewWithoutDefault => [NEW_WITHOUT_DEFAULT]);
|
|||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
|
||||
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) {
|
||||
if let hir::ItemKind::Impl(_, _, _, _, None, _, ref items) = item.node {
|
||||
if let hir::ItemKind::Impl(_, _, _, _, None, _, ref items) = item.kind {
|
||||
for assoc_item in items {
|
||||
if let hir::AssocItemKind::Method { has_self: false } = assoc_item.kind {
|
||||
let impl_item = cx.tcx.hir().impl_item(assoc_item.id);
|
||||
if in_external_macro(cx.sess(), impl_item.span) {
|
||||
return;
|
||||
}
|
||||
if let hir::ImplItemKind::Method(ref sig, _) = impl_item.node {
|
||||
if let hir::ImplItemKind::Method(ref sig, _) = impl_item.kind {
|
||||
let name = impl_item.ident.name;
|
||||
let id = impl_item.hir_id;
|
||||
if sig.header.constness == hir::Constness::Const {
|
||||
|
|
|
@ -46,7 +46,7 @@ fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
|
|||
if expr.span.from_expansion() {
|
||||
return false;
|
||||
}
|
||||
match expr.node {
|
||||
match expr.kind {
|
||||
ExprKind::Lit(..) | ExprKind::Closure(..) => true,
|
||||
ExprKind::Path(..) => !has_drop(cx, cx.tables.expr_ty(expr)),
|
||||
ExprKind::Index(ref a, ref b) | ExprKind::Binary(_, ref a, ref b) => {
|
||||
|
@ -66,7 +66,7 @@ fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
|
|||
&& base.as_ref().map_or(true, |base| has_no_effect(cx, base))
|
||||
},
|
||||
ExprKind::Call(ref callee, ref args) => {
|
||||
if let ExprKind::Path(ref qpath) = callee.node {
|
||||
if let ExprKind::Path(ref qpath) = callee.kind {
|
||||
let res = qpath_res(cx, qpath, callee.hir_id);
|
||||
match res {
|
||||
Res::Def(DefKind::Struct, ..) | Res::Def(DefKind::Variant, ..) | Res::Def(DefKind::Ctor(..), _) => {
|
||||
|
@ -89,7 +89,7 @@ declare_lint_pass!(NoEffect => [NO_EFFECT, UNNECESSARY_OPERATION]);
|
|||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NoEffect {
|
||||
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) {
|
||||
if let StmtKind::Semi(ref expr) = stmt.node {
|
||||
if let StmtKind::Semi(ref expr) = stmt.kind {
|
||||
if has_no_effect(cx, expr) {
|
||||
span_lint(cx, NO_EFFECT, stmt.span, "statement with no effect");
|
||||
} else if let Some(reduced) = reduce_expression(cx, expr) {
|
||||
|
@ -123,7 +123,7 @@ fn reduce_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr) -> Option<Vec
|
|||
if expr.span.from_expansion() {
|
||||
return None;
|
||||
}
|
||||
match expr.node {
|
||||
match expr.kind {
|
||||
ExprKind::Index(ref a, ref b) => Some(vec![&**a, &**b]),
|
||||
ExprKind::Binary(ref binop, ref a, ref b) if binop.node != BinOpKind::And && binop.node != BinOpKind::Or => {
|
||||
Some(vec![&**a, &**b])
|
||||
|
@ -144,7 +144,7 @@ fn reduce_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr) -> Option<Vec
|
|||
}
|
||||
},
|
||||
ExprKind::Call(ref callee, ref args) => {
|
||||
if let ExprKind::Path(ref qpath) = callee.node {
|
||||
if let ExprKind::Path(ref qpath) = callee.kind {
|
||||
let res = qpath_res(cx, qpath, callee.hir_id);
|
||||
match res {
|
||||
Res::Def(DefKind::Struct, ..) | Res::Def(DefKind::Variant, ..) | Res::Def(DefKind::Ctor(..), _)
|
||||
|
|
|
@ -142,14 +142,14 @@ declare_lint_pass!(NonCopyConst => [DECLARE_INTERIOR_MUTABLE_CONST, BORROW_INTER
|
|||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst {
|
||||
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx Item) {
|
||||
if let ItemKind::Const(hir_ty, ..) = &it.node {
|
||||
if let ItemKind::Const(hir_ty, ..) = &it.kind {
|
||||
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
|
||||
verify_ty_bound(cx, ty, Source::Item { item: it.span });
|
||||
}
|
||||
}
|
||||
|
||||
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, trait_item: &'tcx TraitItem) {
|
||||
if let TraitItemKind::Const(hir_ty, ..) = &trait_item.node {
|
||||
if let TraitItemKind::Const(hir_ty, ..) = &trait_item.kind {
|
||||
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
|
||||
verify_ty_bound(
|
||||
cx,
|
||||
|
@ -163,11 +163,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst {
|
|||
}
|
||||
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &'tcx ImplItem) {
|
||||
if let ImplItemKind::Const(hir_ty, ..) = &impl_item.node {
|
||||
if let ImplItemKind::Const(hir_ty, ..) = &impl_item.kind {
|
||||
let item_hir_id = cx.tcx.hir().get_parent_node(impl_item.hir_id);
|
||||
let item = cx.tcx.hir().expect_item(item_hir_id);
|
||||
// Ensure the impl is an inherent impl.
|
||||
if let ItemKind::Impl(_, _, _, _, None, _, _) = item.node {
|
||||
if let ItemKind::Impl(_, _, _, _, None, _, _) = item.kind {
|
||||
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
|
||||
verify_ty_bound(
|
||||
cx,
|
||||
|
@ -182,7 +182,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst {
|
|||
}
|
||||
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
if let ExprKind::Path(qpath) = &expr.node {
|
||||
if let ExprKind::Path(qpath) = &expr.kind {
|
||||
// Only lint if we use the const item inside a function.
|
||||
if in_constant(cx, expr.hir_id) {
|
||||
return;
|
||||
|
@ -204,7 +204,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst {
|
|||
break;
|
||||
}
|
||||
if let Some(Node::Expr(parent_expr)) = cx.tcx.hir().find(parent_id) {
|
||||
match &parent_expr.node {
|
||||
match &parent_expr.kind {
|
||||
ExprKind::AddrOf(..) => {
|
||||
// `&e` => `e` must be referenced.
|
||||
needs_check_adjustment = false;
|
||||
|
|
|
@ -128,7 +128,7 @@ struct SimilarNamesNameVisitor<'a, 'tcx, 'b>(&'b mut SimilarNamesLocalVisitor<'a
|
|||
|
||||
impl<'a, 'tcx, 'b> Visitor<'tcx> for SimilarNamesNameVisitor<'a, 'tcx, 'b> {
|
||||
fn visit_pat(&mut self, pat: &'tcx Pat) {
|
||||
match pat.node {
|
||||
match pat.kind {
|
||||
PatKind::Ident(_, ident, _) => self.check_ident(ident),
|
||||
PatKind::Struct(_, ref fields, _) => {
|
||||
for field in fields {
|
||||
|
@ -350,13 +350,13 @@ impl<'a, 'tcx> Visitor<'tcx> for SimilarNamesLocalVisitor<'a, 'tcx> {
|
|||
|
||||
impl EarlyLintPass for NonExpressiveNames {
|
||||
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
|
||||
if let ItemKind::Fn(ref decl, _, _, ref blk) = item.node {
|
||||
if let ItemKind::Fn(ref decl, _, _, ref blk) = item.kind {
|
||||
do_check(self, cx, &item.attrs, decl, blk);
|
||||
}
|
||||
}
|
||||
|
||||
fn check_impl_item(&mut self, cx: &EarlyContext<'_>, item: &ImplItem) {
|
||||
if let ImplItemKind::Method(ref sig, ref blk) = item.node {
|
||||
if let ImplItemKind::Method(ref sig, ref blk) = item.kind {
|
||||
do_check(self, cx, &item.attrs, &sig.decl, blk);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,10 +39,10 @@ declare_lint_pass!(OkIfLet => [IF_LET_SOME_RESULT]);
|
|||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OkIfLet {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
if_chain! { //begin checking variables
|
||||
if let ExprKind::Match(ref op, ref body, ref source) = expr.node; //test if expr is a match
|
||||
if let ExprKind::Match(ref op, ref body, ref source) = expr.kind; //test if expr is a match
|
||||
if let MatchSource::IfLetDesugar { .. } = *source; //test if it is an If Let
|
||||
if let ExprKind::MethodCall(_, _, ref result_types) = op.node; //check is expr.ok() has type Result<T,E>.ok()
|
||||
if let PatKind::TupleStruct(QPath::Resolved(_, ref x), ref y, _) = body[0].pat.node; //get operation
|
||||
if let ExprKind::MethodCall(_, _, 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;
|
||||
|
||||
then {
|
||||
|
|
|
@ -29,7 +29,7 @@ declare_lint_pass!(OpenOptions => [NONSENSICAL_OPEN_OPTIONS]);
|
|||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OpenOptions {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||
if let ExprKind::MethodCall(ref path, _, ref arguments) = e.node {
|
||||
if let ExprKind::MethodCall(ref path, _, ref arguments) = e.kind {
|
||||
let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&arguments[0]));
|
||||
if path.ident.name == sym!(open) && match_type(cx, obj_ty, &paths::OPEN_OPTIONS) {
|
||||
let mut options = Vec::new();
|
||||
|
@ -57,12 +57,12 @@ enum OpenOption {
|
|||
}
|
||||
|
||||
fn get_open_options(cx: &LateContext<'_, '_>, argument: &Expr, options: &mut Vec<(OpenOption, Argument)>) {
|
||||
if let ExprKind::MethodCall(ref path, _, ref arguments) = argument.node {
|
||||
if let ExprKind::MethodCall(ref path, _, ref arguments) = argument.kind {
|
||||
let obj_ty = walk_ptrs_ty(cx.tables.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 {
|
||||
let argument_option = match arguments[1].node {
|
||||
let argument_option = match arguments[1].kind {
|
||||
ExprKind::Lit(ref span) => {
|
||||
if let Spanned {
|
||||
node: LitKind::Bool(lit),
|
||||
|
|
|
@ -30,11 +30,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OverflowCheckConditional {
|
|||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
let eq = |l, r| SpanlessEq::new(cx).eq_path_segment(l, r);
|
||||
if_chain! {
|
||||
if let ExprKind::Binary(ref op, ref first, ref second) = expr.node;
|
||||
if let ExprKind::Binary(ref op2, ref ident1, ref ident2) = first.node;
|
||||
if let ExprKind::Path(QPath::Resolved(_, ref path1)) = ident1.node;
|
||||
if let ExprKind::Path(QPath::Resolved(_, ref path2)) = ident2.node;
|
||||
if let ExprKind::Path(QPath::Resolved(_, ref path3)) = second.node;
|
||||
if let ExprKind::Binary(ref op, ref first, ref second) = expr.kind;
|
||||
if let ExprKind::Binary(ref op2, ref ident1, ref ident2) = first.kind;
|
||||
if let ExprKind::Path(QPath::Resolved(_, ref path1)) = ident1.kind;
|
||||
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();
|
||||
|
@ -55,11 +55,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OverflowCheckConditional {
|
|||
}
|
||||
|
||||
if_chain! {
|
||||
if let ExprKind::Binary(ref op, ref first, ref second) = expr.node;
|
||||
if let ExprKind::Binary(ref op2, ref ident1, ref ident2) = second.node;
|
||||
if let ExprKind::Path(QPath::Resolved(_, ref path1)) = ident1.node;
|
||||
if let ExprKind::Path(QPath::Resolved(_, ref path2)) = ident2.node;
|
||||
if let ExprKind::Path(QPath::Resolved(_, ref path3)) = first.node;
|
||||
if let ExprKind::Binary(ref op, ref first, ref second) = expr.kind;
|
||||
if let ExprKind::Binary(ref op2, ref ident1, ref ident2) = second.kind;
|
||||
if let ExprKind::Path(QPath::Resolved(_, ref path1)) = ident1.kind;
|
||||
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();
|
||||
|
|
|
@ -47,10 +47,10 @@ declare_lint_pass!(PanicUnimplemented => [PANIC_PARAMS, UNIMPLEMENTED]);
|
|||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PanicUnimplemented {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
if_chain! {
|
||||
if let ExprKind::Block(ref block, _) = expr.node;
|
||||
if let ExprKind::Block(ref block, _) = expr.kind;
|
||||
if let Some(ref ex) = block.expr;
|
||||
if let ExprKind::Call(ref fun, ref params) = ex.node;
|
||||
if let ExprKind::Path(ref qpath) = fun.node;
|
||||
if let ExprKind::Call(ref fun, ref params) = ex.kind;
|
||||
if let ExprKind::Path(ref qpath) = fun.kind;
|
||||
if let Some(fun_def_id) = resolve_node(cx, qpath, fun.hir_id).opt_def_id();
|
||||
if match_def_path(cx, fun_def_id, &paths::BEGIN_PANIC);
|
||||
if params.len() == 2;
|
||||
|
@ -83,7 +83,7 @@ fn get_outer_span(expr: &Expr) -> Span {
|
|||
|
||||
fn match_panic(params: &P<[Expr]>, expr: &Expr, cx: &LateContext<'_, '_>) {
|
||||
if_chain! {
|
||||
if let ExprKind::Lit(ref lit) = params[0].node;
|
||||
if let ExprKind::Lit(ref lit) = params[0].kind;
|
||||
if is_direct_expn_of(expr.span, "panic").is_some();
|
||||
if let LitKind::Str(ref string, _) = lit.node;
|
||||
let string = string.as_str().replace("{{", "").replace("}}", "");
|
||||
|
|
|
@ -33,7 +33,7 @@ declare_lint_pass!(PartialEqNeImpl => [PARTIALEQ_NE_IMPL]);
|
|||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PartialEqNeImpl {
|
||||
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
|
||||
if_chain! {
|
||||
if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, ref impl_items) = item.node;
|
||||
if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, ref impl_items) = item.kind;
|
||||
if !is_automatically_derived(&*item.attrs);
|
||||
if let Some(eq_trait) = cx.tcx.lang_items().eq_trait();
|
||||
if trait_ref.path.res.def_id() == eq_trait;
|
||||
|
|
|
@ -43,12 +43,12 @@ declare_lint_pass!(PathBufPushOverwrite => [PATH_BUF_PUSH_OVERWRITE]);
|
|||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PathBufPushOverwrite {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(ref path, _, ref args) = expr.node;
|
||||
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 let Some(get_index_arg) = args.get(1);
|
||||
if let ExprKind::Lit(ref lit) = get_index_arg.node;
|
||||
if let ExprKind::Lit(ref lit) = get_index_arg.kind;
|
||||
if let LitKind::Str(ref path_lit, _) = lit.node;
|
||||
if let pushed_path = Path::new(&path_lit.as_str());
|
||||
if let Some(pushed_path_lit) = pushed_path.to_str();
|
||||
|
|
|
@ -36,7 +36,7 @@ impl EarlyLintPass for Precedence {
|
|||
return;
|
||||
}
|
||||
|
||||
if let ExprKind::Binary(Spanned { node: op, .. }, ref left, ref right) = expr.node {
|
||||
if let ExprKind::Binary(Spanned { node: op, .. }, ref left, ref right) = expr.kind {
|
||||
let span_sugg = |expr: &Expr, sugg, appl| {
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
|
@ -85,11 +85,11 @@ impl EarlyLintPass for Precedence {
|
|||
}
|
||||
}
|
||||
|
||||
if let ExprKind::Unary(UnOp::Neg, ref rhs) = expr.node {
|
||||
if let ExprKind::MethodCall(_, ref args) = rhs.node {
|
||||
if let ExprKind::Unary(UnOp::Neg, ref rhs) = expr.kind {
|
||||
if let ExprKind::MethodCall(_, ref args) = rhs.kind {
|
||||
if let Some(slf) = args.first() {
|
||||
if let ExprKind::Lit(ref lit) = slf.node {
|
||||
match lit.node {
|
||||
if let ExprKind::Lit(ref lit) = slf.kind {
|
||||
match lit.kind {
|
||||
LitKind::Int(..) | LitKind::Float(..) | LitKind::FloatUnsuffixed(..) => {
|
||||
let mut applicability = Applicability::MachineApplicable;
|
||||
span_lint_and_sugg(
|
||||
|
@ -115,7 +115,7 @@ impl EarlyLintPass for Precedence {
|
|||
}
|
||||
|
||||
fn is_arith_expr(expr: &Expr) -> bool {
|
||||
match expr.node {
|
||||
match expr.kind {
|
||||
ExprKind::Binary(Spanned { node: op, .. }, _, _) => is_arith_op(op),
|
||||
_ => false,
|
||||
}
|
||||
|
|
|
@ -101,16 +101,16 @@ declare_lint_pass!(Ptr => [PTR_ARG, CMP_NULL, MUT_FROM_REF]);
|
|||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ptr {
|
||||
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
|
||||
if let ItemKind::Fn(ref decl, _, _, body_id) = item.node {
|
||||
if let ItemKind::Fn(ref decl, _, _, body_id) = item.kind {
|
||||
check_fn(cx, decl, item.hir_id, Some(body_id));
|
||||
}
|
||||
}
|
||||
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx ImplItem) {
|
||||
if let ImplItemKind::Method(ref sig, body_id) = item.node {
|
||||
if let ImplItemKind::Method(ref sig, body_id) = item.kind {
|
||||
let parent_item = cx.tcx.hir().get_parent_item(item.hir_id);
|
||||
if let Some(Node::Item(it)) = cx.tcx.hir().find(parent_item) {
|
||||
if let ItemKind::Impl(_, _, _, _, Some(_), _, _) = it.node {
|
||||
if let ItemKind::Impl(_, _, _, _, Some(_), _, _) = it.kind {
|
||||
return; // ignore trait impls
|
||||
}
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ptr {
|
|||
}
|
||||
|
||||
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem) {
|
||||
if let TraitItemKind::Method(ref sig, ref trait_method) = item.node {
|
||||
if let TraitItemKind::Method(ref sig, ref trait_method) = item.kind {
|
||||
let body_id = if let TraitMethod::Provided(b) = *trait_method {
|
||||
Some(b)
|
||||
} else {
|
||||
|
@ -130,7 +130,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ptr {
|
|||
}
|
||||
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
if let ExprKind::Binary(ref op, ref l, ref r) = expr.node {
|
||||
if let ExprKind::Binary(ref op, ref l, ref r) = expr.kind {
|
||||
if (op.node == BinOpKind::Eq || op.node == BinOpKind::Ne) && (is_null_path(l) || is_null_path(r)) {
|
||||
span_lint(
|
||||
cx,
|
||||
|
@ -154,7 +154,7 @@ fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: HirId, opt_body_id:
|
|||
if is_type_diagnostic_item(cx, ty, Symbol::intern("vec_type")) {
|
||||
let mut ty_snippet = None;
|
||||
if_chain! {
|
||||
if let TyKind::Path(QPath::Resolved(_, ref path)) = walk_ptrs_hir_ty(arg).node;
|
||||
if let TyKind::Path(QPath::Resolved(_, ref path)) = walk_ptrs_hir_ty(arg).kind;
|
||||
if let Some(&PathSegment{args: Some(ref parameters), ..}) = path.segments.last();
|
||||
then {
|
||||
let types: Vec<_> = parameters.args.iter().filter_map(|arg| match arg {
|
||||
|
@ -219,8 +219,8 @@ fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: HirId, opt_body_id:
|
|||
}
|
||||
} else if match_type(cx, ty, &paths::COW) {
|
||||
if_chain! {
|
||||
if let TyKind::Rptr(_, MutTy { ref ty, ..} ) = arg.node;
|
||||
if let TyKind::Path(ref path) = ty.node;
|
||||
if let TyKind::Rptr(_, MutTy { ref ty, ..} ) = arg.kind;
|
||||
if let TyKind::Path(ref path) = ty.kind;
|
||||
if let QPath::Resolved(None, ref pp) = *path;
|
||||
if let [ref bx] = *pp.segments;
|
||||
if let Some(ref params) = bx.args;
|
||||
|
@ -285,7 +285,7 @@ fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: HirId, opt_body_id:
|
|||
}
|
||||
|
||||
fn get_rptr_lm(ty: &Ty) -> Option<(&Lifetime, Mutability, Span)> {
|
||||
if let TyKind::Rptr(ref lt, ref m) = ty.node {
|
||||
if let TyKind::Rptr(ref lt, ref m) = ty.kind {
|
||||
Some((lt, m.mutbl, ty.span))
|
||||
} else {
|
||||
None
|
||||
|
@ -293,9 +293,9 @@ fn get_rptr_lm(ty: &Ty) -> Option<(&Lifetime, Mutability, Span)> {
|
|||
}
|
||||
|
||||
fn is_null_path(expr: &Expr) -> bool {
|
||||
if let ExprKind::Call(ref pathexp, ref args) = expr.node {
|
||||
if let ExprKind::Call(ref pathexp, ref args) = expr.kind {
|
||||
if args.is_empty() {
|
||||
if let ExprKind::Path(ref path) = pathexp.node {
|
||||
if let ExprKind::Path(ref path) = pathexp.kind {
|
||||
return match_qpath(path, &paths::PTR_NULL) || match_qpath(path, &paths::PTR_NULL_MUT);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PtrOffsetWithCast {
|
|||
|
||||
// If the given expression is a cast from a usize, return the lhs of the cast
|
||||
fn expr_as_cast_from_usize<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Option<&'tcx Expr> {
|
||||
if let ExprKind::Cast(ref cast_lhs_expr, _) = expr.node {
|
||||
if let ExprKind::Cast(ref cast_lhs_expr, _) = expr.kind {
|
||||
if is_expr_ty_usize(cx, &cast_lhs_expr) {
|
||||
return Some(cast_lhs_expr);
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ fn expr_as_ptr_offset_call<'a, 'tcx>(
|
|||
cx: &LateContext<'a, 'tcx>,
|
||||
expr: &'tcx Expr,
|
||||
) -> Option<(&'tcx Expr, &'tcx Expr, Method)> {
|
||||
if let ExprKind::MethodCall(ref path_segment, _, ref args) = expr.node {
|
||||
if let ExprKind::MethodCall(ref path_segment, _, ref args) = expr.kind {
|
||||
if is_expr_ty_raw_ptr(cx, &args[0]) {
|
||||
if path_segment.ident.name == sym!(offset) {
|
||||
return Some((&args[0], &args[1], Method::Offset));
|
||||
|
|
|
@ -49,7 +49,7 @@ impl QuestionMark {
|
|||
fn check_is_none_and_early_return_none(cx: &LateContext<'_, '_>, expr: &Expr) {
|
||||
if_chain! {
|
||||
if let Some((if_expr, body, else_)) = higher::if_block(&expr);
|
||||
if let ExprKind::MethodCall(segment, _, args) = &if_expr.node;
|
||||
if let ExprKind::MethodCall(segment, _, args) = &if_expr.kind;
|
||||
if segment.ident.name == sym!(is_none);
|
||||
if Self::expression_returns_none(cx, body);
|
||||
if let Some(subject) = args.get(0);
|
||||
|
@ -60,7 +60,7 @@ impl QuestionMark {
|
|||
let mut replacement: Option<String> = None;
|
||||
if let Some(else_) = else_ {
|
||||
if_chain! {
|
||||
if let ExprKind::Block(block, None) = &else_.node;
|
||||
if let ExprKind::Block(block, None) = &else_.kind;
|
||||
if block.stmts.len() == 0;
|
||||
if let Some(block_expr) = &block.expr;
|
||||
if SpanlessEq::new(cx).ignore_fn().eq_expr(subject, block_expr);
|
||||
|
@ -107,7 +107,7 @@ impl QuestionMark {
|
|||
}
|
||||
|
||||
fn expression_returns_none(cx: &LateContext<'_, '_>, expression: &Expr) -> bool {
|
||||
match expression.node {
|
||||
match expression.kind {
|
||||
ExprKind::Block(ref block, _) => {
|
||||
if let Some(return_expression) = Self::return_expression(block) {
|
||||
return Self::expression_returns_none(cx, &return_expression);
|
||||
|
@ -134,8 +134,8 @@ impl QuestionMark {
|
|||
if_chain! {
|
||||
if block.stmts.len() == 1;
|
||||
if let Some(expr) = block.stmts.iter().last();
|
||||
if let StmtKind::Semi(ref expr) = expr.node;
|
||||
if let ExprKind::Ret(ref ret_expr) = expr.node;
|
||||
if let StmtKind::Semi(ref expr) = expr.kind;
|
||||
if let ExprKind::Ret(ref ret_expr) = expr.kind;
|
||||
if let &Some(ref ret_expr) = ret_expr;
|
||||
|
||||
then {
|
||||
|
@ -146,7 +146,7 @@ impl QuestionMark {
|
|||
// Check for `return` without a semicolon.
|
||||
if_chain! {
|
||||
if block.stmts.len() == 0;
|
||||
if let Some(ExprKind::Ret(Some(ret_expr))) = block.expr.as_ref().map(|e| &e.node);
|
||||
if let Some(ExprKind::Ret(Some(ret_expr))) = block.expr.as_ref().map(|e| &e.kind);
|
||||
then {
|
||||
return Some(ret_expr);
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue