/// ```rust
/// 0;
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub NO_EFFECT,
complexity,
"statements with no effect"
/// ```rust,ignore
/// let _i_serve_no_purpose = 1;
/// ```
+ #[clippy::version = "1.58.0"]
pub NO_EFFECT_UNDERSCORE_BINDING,
pedantic,
"binding to `_` prefixed variable with no side-effect"
/// ```rust,ignore
/// compute_array()[0];
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub UNNECESSARY_OPERATION,
complexity,
"outer expressions with no effect"
},
ExprKind::Call(callee, args) => {
if let ExprKind::Path(ref qpath) = callee.kind {
- let res = cx.qpath_res(qpath, callee.hir_id);
+ if cx.typeck_results().type_dependent_def(expr.hir_id).is_some() {
+ // type-dependent function call like `impl FnOnce for X`
+ return false;
+ }
let def_matched = matches!(
- res,
+ cx.qpath_res(qpath, callee.hir_id),
Res::Def(DefKind::Struct | DefKind::Variant | DefKind::Ctor(..), ..)
);
if def_matched || is_range_literal(expr) {
if !&reduced.iter().any(|e| e.span.from_expansion());
then {
if let ExprKind::Index(..) = &expr.kind {
- let snippet;
- if let (Some(arr), Some(func)) = (snippet_opt(cx, reduced[0].span), snippet_opt(cx, reduced[1].span)) {
- snippet = format!("assert!({}.len() > {});", &arr, &func);
+ let snippet = if let (Some(arr), Some(func)) =
+ (snippet_opt(cx, reduced[0].span), snippet_opt(cx, reduced[1].span))
+ {
+ format!("assert!({}.len() > {});", &arr, &func)
} else {
return;
- }
+ };
span_lint_hir_and_then(
cx,
UNNECESSARY_OPERATION,
},
ExprKind::Call(callee, args) => {
if let ExprKind::Path(ref qpath) = callee.kind {
+ if cx.typeck_results().type_dependent_def(expr.hir_id).is_some() {
+ // type-dependent function call like `impl FnOnce for X`
+ return None;
+ }
let res = cx.qpath_res(qpath, callee.hir_id);
match res {
Res::Def(DefKind::Struct | DefKind::Variant | DefKind::Ctor(..), ..)