diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index beb96f333..2038a5913 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -71,7 +71,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { }; let region_scope_tree = &cx.tcx.region_scope_tree(fn_def_id); - ExprUseVisitor::new(&mut v, cx.tcx, cx.param_env, region_scope_tree, cx.tables).consume_body(body); + ExprUseVisitor::new(&mut v, cx.tcx, cx.param_env, region_scope_tree, cx.tables, None).consume_body(body); for node in v.set { span_lint( diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 97925b0bd..6ea48c5ea 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -1390,7 +1390,7 @@ fn check_for_mutation(cx: &LateContext, body: &Expr, bound_ids: &[Option let mut delegate = MutateDelegate { node_id_low: bound_ids[0], node_id_high: bound_ids[1], span_low: None, span_high: None }; let def_id = def_id::DefId::local(body.hir_id.owner); let region_scope_tree = &cx.tcx.region_scope_tree(def_id); - ExprUseVisitor::new(&mut delegate, cx.tcx, cx.param_env, region_scope_tree, cx.tables).walk_expr(body); + ExprUseVisitor::new(&mut delegate, cx.tcx, cx.param_env, region_scope_tree, cx.tables, None).walk_expr(body); delegate.mutation_span() } diff --git a/clippy_lints/src/methods.rs b/clippy_lints/src/methods.rs index d986a5485..d8309ff6f 100644 --- a/clippy_lints/src/methods.rs +++ b/clippy_lints/src/methods.rs @@ -821,18 +821,6 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, name: &str, args: &[hir: or_has_args: bool, span: Span, ) { - // don't lint for constant values - // FIXME: can we `expect` here instead of match? - let promotable = cx.tcx - .rvalue_promotable_to_static - .borrow() - .get(&arg.id) - .cloned() - .unwrap_or(true); - if promotable { - return; - } - // (path, fn_has_argument, methods, suffix) let know_types: &[(&[_], _, &[_], _)] = &[ (&paths::BTREEMAP_ENTRY, false, &["or_insert"], "with"), @@ -841,6 +829,21 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, name: &str, args: &[hir: (&paths::RESULT, true, &["or", "unwrap_or"], "else"), ]; + // early check if the name is one we care about + if know_types.iter().all(|k| !k.2.contains(&name)) { + return; + } + + // don't lint for constant values + // FIXME: can we `expect` here instead of match? + let owner_def = cx.tcx.hir.get_parent_did(arg.id); + let promotable = cx.tcx + .rvalue_promotable_map(owner_def) + [&arg.hir_id.local_id]; + if promotable { + return; + } + let self_ty = cx.tables.expr_ty(self_expr); let (fn_has_arguments, poss, suffix) = if let Some(&(_, fn_has_arguments, poss, suffix)) = diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 3c1f6ef2c..60509c1aa 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -108,7 +108,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { } = { let mut ctx = MovedVariablesCtxt::new(cx); let region_scope_tree = &cx.tcx.region_scope_tree(fn_def_id); - euv::ExprUseVisitor::new(&mut ctx, cx.tcx, cx.param_env, region_scope_tree, cx.tables).consume_body(body); + euv::ExprUseVisitor::new(&mut ctx, cx.tcx, cx.param_env, region_scope_tree, cx.tables, None).consume_body(body); ctx };