fn match_assert_with_message<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<AssertKind> {
if_chain! {
if let Some(higher::If { cond, then, .. }) = higher::If::hir(expr);
- if let ExprKind::Unary(UnOp::Not, ref expr) = cond.kind;
+ if let ExprKind::Unary(UnOp::Not, expr) = cond.kind;
// bind the first argument of the `assert!` macro
if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.typeck_results(), expr);
// block
),
Applicability::MachineApplicable,
);
-
- return;
}
}
}
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
if let Some(attr) = attr {
check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr);
- return;
} else if is_public && !is_proc_macro(cx.sess(), attrs) && !attrs.iter().any(|a| a.has_name(sym::no_mangle)) {
check_must_use_candidate(
cx,
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if_chain! { //begin checking variables
if let Some(higher::IfLet { let_pat, let_expr, .. }) = higher::IfLet::hir(cx, expr);
- if let ExprKind::MethodCall(_, ok_span, ref result_types, _) = let_expr.kind; //check is expr.ok() has type Result<T,E>.ok(, _)
- if let PatKind::TupleStruct(QPath::Resolved(_, ref x), ref y, _) = let_pat.kind; //get operation
+ if let ExprKind::MethodCall(_, ok_span, result_types, _) = let_expr.kind; //check is expr.ok() has type Result<T,E>.ok(, _)
+ if let PatKind::TupleStruct(QPath::Resolved(_, x), y, _) = let_pat.kind; //get operation
if method_chain_args(let_expr, &["ok"]).is_some(); //test to see if using ok() methoduse std::marker::Sized;
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&result_types[0]), sym::result_type);
if rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_path(x, false)) == "Some";
while_let_on_iterator::check(cx, expr);
- if let Some(higher::While { if_cond, if_then, .. }) = higher::While::hir(&expr) {
+ if let Some(higher::While { if_cond, if_then, .. }) = higher::While::hir(expr) {
while_immutable_condition::check(cx, if_cond, if_then);
}
}
}
- if let ExprKind::Match(ref matchexpr, ref arms, MatchSource::Normal) = inner.kind {
+ if let ExprKind::Match(matchexpr, arms, MatchSource::Normal) = inner.kind {
if arms.len() == 2
&& arms[0].guard.is_none()
&& arms[1].guard.is_none()
- && is_simple_break_expr(&arms[1].body)
+ && is_simple_break_expr(arms[1].body)
{
- could_be_while_let(cx, expr, &arms[0].pat, matchexpr);
+ could_be_while_let(cx, expr, arms[0].pat, matchexpr);
}
}
}
check_match_single_binding(cx, ex, arms, expr);
}
}
- if let ExprKind::Match(ref ex, ref arms, _) = expr.kind {
+ if let ExprKind::Match(ex, arms, _) = expr.kind {
check_match_ref_pats(cx, ex, arms.iter().map(|el| el.pat), expr);
}
if let Some(higher::IfLet { let_pat, let_expr, .. }) = higher::IfLet::hir(cx, expr) {
let (first_sugg, msg, title);
let span = ex.span.source_callsite();
- if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, ref inner) = ex.kind {
+ if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner) = ex.kind {
first_sugg = once((span, Sugg::hir_with_macro_callsite(cx, inner, "..").to_string()));
msg = "try";
title = "you don't need to add `&` to both the expression and the patterns";
}
let remaining_suggs = pats.filter_map(|pat| {
- if let PatKind::Ref(ref refp, _) = pat.kind {
+ if let PatKind::Ref(refp, _) = pat.kind {
Some((pat.span, snippet(cx, refp.span, "..").to_string()))
} else {
None
find_bool_lit(&arm.2.kind, is_if_let).map_or(false, |b| b == b0) && arm.3.is_none() && arm.0.is_empty()
});
then {
- if let Some(ref last_pat) = last_pat_opt {
+ if let Some(last_pat) = last_pat_opt {
if !is_wild(last_pat) {
return false;
}
..
}) = higher::IfLet::hir(cx, expr)
{
- find_sugg_for_if_let(cx, expr, let_pat, let_expr, "if", if_else.is_some())
+ find_sugg_for_if_let(cx, expr, let_pat, let_expr, "if", if_else.is_some());
}
if let ExprKind::Match(op, arms, MatchSource::Normal) = &expr.kind {
- find_sugg_for_match(cx, expr, op, arms)
+ find_sugg_for_match(cx, expr, op, arms);
}
if let Some(higher::WhileLet { let_pat, let_expr, .. }) = higher::WhileLet::hir(expr) {
- find_sugg_for_if_let(cx, expr, let_pat, let_expr, "while", false)
+ find_sugg_for_if_let(cx, expr, let_pat, let_expr, "while", false);
}
}
}
}
if let ExprKind::Let(let_pat, let_expr, _) = expr.kind {
- if let Some(ref expr_ty) = cx.typeck_results().node_type_opt(let_expr.hir_id) {
+ if let Some(expr_ty) = cx.typeck_results().node_type_opt(let_expr.hir_id) {
if in_external_macro(cx.sess(), let_pat.span) {
return;
}
if let PatKind::Binding(annot, bind_id, _, _) = fields[0].kind;
let by_ref = matches!(annot, BindingAnnotation::Ref | BindingAnnotation::RefMut);
- if let ExprKind::Block(ref block, None) = if_then.kind;
+ if let ExprKind::Block(block, None) = if_then.kind;
if block.stmts.is_empty();
if let Some(trailing_expr) = &block.expr;
if path_to_local_id(trailing_expr, bind_id);
// `.iter()` and `.len()` called on same `Path`
if let ExprKind::Path(QPath::Resolved(_, iter_path)) = iter_args[0].kind;
if let ExprKind::Path(QPath::Resolved(_, len_path)) = len_args[0].kind;
- if SpanlessEq::new(cx).eq_path_segments(&iter_path.segments, &len_path.segments);
+ if SpanlessEq::new(cx).eq_path_segments(iter_path.segments, len_path.segments);
then {
span_lint(cx,
RANGE_ZIP_WITH_LEN,
impl<'ast> ast_visit::Visitor<'ast> for ReturnVisitor {
fn visit_expr(&mut self, ex: &'ast ast::Expr) {
- if let ast::ExprKind::Ret(_) = ex.kind {
- self.found_return = true;
- } else if let ast::ExprKind::Try(_) = ex.kind {
+ if let ast::ExprKind::Ret(_) | ast::ExprKind::Try(_) = ex.kind {
self.found_return = true;
}
// an if/if let expr, check both exprs
// note, if without else is going to be a type checking error anyways
// (except for unit type functions) so we don't match it
- ExprKind::Match(_, arms, source) => match source {
- MatchSource::Normal => {
- for arm in arms.iter() {
- check_final_expr(cx, arm.body, Some(arm.body.span), RetReplacement::Block);
- }
- },
- _ => (),
+ ExprKind::Match(_, arms, MatchSource::Normal) => {
+ for arm in arms.iter() {
+ check_final_expr(cx, arm.body, Some(arm.body.span), RetReplacement::Block);
+ }
},
ExprKind::DropTemps(expr) => check_final_expr(cx, expr, None, RetReplacement::Empty),
_ => (),
use clippy_utils::diagnostics::span_lint_and_help;
use rustc_hir::intravisit::{walk_expr, walk_fn, FnKind, NestedVisitorMap, Visitor};
-use rustc_hir::{Body, Expr, ExprKind, FnDecl, FnHeader, HirId, IsAsync, Item, ItemKind, YieldSource};
+use rustc_hir::{Body, Expr, ExprKind, FnDecl, FnHeader, HirId, IsAsync, YieldSource};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::hir::map::Map;
use rustc_session::{declare_lint_pass, declare_tool_lint};
}
impl<'tcx> LateLintPass<'tcx> for UnusedAsync {
- fn check_item(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
- if let ItemKind::Trait(..) = item.kind {
- return;
- }
- }
fn check_fn(
&mut self,
cx: &LateContext<'tcx>,
print_expr(cx, arg, indent + 1);
}
},
- hir::ExprKind::Let(ref pat, ref expr, _) => {
+ hir::ExprKind::Let(pat, expr, _) => {
print_pat(cx, pat, indent + 1);
print_expr(cx, expr, indent + 1);
},
if_chain! {
if let ty::Ref(_, ty, _) = cx.typeck_results().expr_ty_adjusted(expr).kind();
if let ty::Slice(..) = ty.kind();
- if let ExprKind::AddrOf(BorrowKind::Ref, mutability, ref addressee) = expr.kind;
+ if let ExprKind::AddrOf(BorrowKind::Ref, mutability, addressee) = expr.kind;
if let Some(vec_args) = higher::VecArgs::hir(cx, addressee);
then {
self.check_vec_macro(cx, &vec_args, mutability, expr.span);
#[inline]
pub fn hir(expr: &Expr<'tcx>) -> Option<Self> {
if_chain! {
- if let hir::ExprKind::Match(ref iterexpr, ref arms, hir::MatchSource::ForLoopDesugar) = expr.kind;
+ if let hir::ExprKind::Match(iterexpr, arms, hir::MatchSource::ForLoopDesugar) = expr.kind;
if let Some(first_arm) = arms.get(0);
- if let hir::ExprKind::Call(_, ref iterargs) = iterexpr.kind;
+ if let hir::ExprKind::Call(_, iterargs) = iterexpr.kind;
if let Some(first_arg) = iterargs.get(0);
if iterargs.len() == 1 && arms.len() == 1 && first_arm.guard.is_none();
- if let hir::ExprKind::Loop(ref block, ..) = first_arm.body.kind;
+ if let hir::ExprKind::Loop(block, ..) = first_arm.body.kind;
if block.expr.is_none();
if let [ _, _, ref let_stmt, ref body ] = *block.stmts;
- if let hir::StmtKind::Local(ref local) = let_stmt.kind;
- if let hir::StmtKind::Expr(ref body_expr) = body.kind;
+ if let hir::StmtKind::Local(local) = let_stmt.kind;
+ if let hir::StmtKind::Expr(body_expr) = body.kind;
then {
return Some(Self {
pat: &*local.pat,
}
match expr.kind {
- hir::ExprKind::Call(ref path, ref args)
+ hir::ExprKind::Call(path, args)
if matches!(
path.kind,
hir::ExprKind::Path(hir::QPath::LangItem(hir::LangItem::RangeInclusiveNew, _))
limits: ast::RangeLimits::Closed,
})
},
- hir::ExprKind::Struct(ref path, ref fields, None) => match path {
+ hir::ExprKind::Struct(path, fields, None) => match &path {
hir::QPath::LangItem(hir::LangItem::RangeFull, _) => Some(Range {
start: None,
end: None,
/// from `vec!`.
pub fn hir(cx: &LateContext<'_>, expr: &'a hir::Expr<'_>) -> Option<VecArgs<'a>> {
if_chain! {
- if let hir::ExprKind::Call(ref fun, ref args) = expr.kind;
+ if let hir::ExprKind::Call(fun, args) = expr.kind;
if let hir::ExprKind::Path(ref qpath) = fun.kind;
if is_expn_of(fun.span, "vec").is_some();
if let Some(fun_def_id) = cx.qpath_res(qpath, fun.hir_id).opt_def_id();
else if match_def_path(cx, fun_def_id, &paths::SLICE_INTO_VEC) && args.len() == 1 {
// `vec![a, b, c]` case
if_chain! {
- if let hir::ExprKind::Box(ref boxed) = args[0].kind;
- if let hir::ExprKind::Array(ref args) = boxed.kind;
+ if let hir::ExprKind::Box(boxed) = args[0].kind;
+ if let hir::ExprKind::Array(args) = boxed.kind;
then {
- return Some(VecArgs::Vec(&*args));
+ return Some(VecArgs::Vec(args));
}
}
// }
// ```
if_chain! {
- if let Some(ref expr) = local.init;
+ if let Some(expr) = local.init;
if let hir::ExprKind::Match(_, _, hir::MatchSource::ForLoopDesugar) = expr.kind;
then {
return true;
(&ExprKind::If(lc, lt, ref le), &ExprKind::If(rc, rt, ref re)) => {
self.eq_expr(lc, rc) && self.eq_expr(&**lt, &**rt) && both(le, re, |l, r| self.eq_expr(l, r))
},
- (&ExprKind::Let(ref lp, ref le, _), &ExprKind::Let(ref rp, ref re, _)) => {
- self.eq_pat(lp, rp) && self.eq_expr(le, re)
- },
+ (&ExprKind::Let(lp, le, _), &ExprKind::Let(rp, re, _)) => self.eq_pat(lp, rp) && self.eq_expr(le, re),
(&ExprKind::Lit(ref l), &ExprKind::Lit(ref r)) => l.node == r.node,
(&ExprKind::Loop(lb, ref ll, ref lls, _), &ExprKind::Loop(rb, ref rl, ref rls, _)) => {
lls == rls && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.ident.name == r.ident.name)
}
}
},
- ExprKind::Let(ref pat, ref expr, _) => {
+ ExprKind::Let(pat, expr, _) => {
self.hash_expr(expr);
self.hash_pat(pat);
},
while let Some(higher::IfOrIfLet { cond, then, r#else }) = higher::IfOrIfLet::hir(expr) {
conds.push(&*cond);
- if let ExprKind::Block(ref block, _) = then.kind {
+ if let ExprKind::Block(block, _) = then.kind {
blocks.push(block);
} else {
panic!("ExprKind::If node is not an ExprKind::Block");
}
- if let Some(ref else_expr) = r#else {
+ if let Some(else_expr) = r#else {
expr = else_expr;
} else {
break;