use rustc_hir::{BorrowKind, Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
-use std::iter;
declare_clippy_lint! {
/// **What it does:** Checks for calls of `mem::discriminant()` on a non-enum type.
impl<'tcx> LateLintPass<'tcx> for MemDiscriminant {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if_chain! {
- if let ExprKind::Call(ref func, ref func_args) = expr.kind;
+ if let ExprKind::Call(func, func_args) = expr.kind;
// is `mem::discriminant`
if let ExprKind::Path(ref func_qpath) = func.kind;
if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id();
let mut derefs_needed = ptr_depth;
let mut cur_expr = param;
while derefs_needed > 0 {
- if let ExprKind::AddrOf(BorrowKind::Ref, _, ref inner_expr) = cur_expr.kind {
+ if let ExprKind::AddrOf(BorrowKind::Ref, _, inner_expr) = cur_expr.kind {
derefs_needed -= 1;
cur_expr = inner_expr;
} else {
}
}
- let derefs: String = iter::repeat('*').take(derefs_needed).collect();
+ let derefs = "*".repeat(derefs_needed);
diag.span_suggestion(
param.span,
"try dereferencing",