Skip to content

Commit 9d97ed6

Browse files
committed
Refactor: Remove utils::opt_def_id
This removes some indirection. Probably this method was uplifted to rustc at some point?
1 parent 00baf7a commit 9d97ed6

18 files changed

+41
-47
lines changed

clippy_lints/src/attrs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
33
use crate::reexport::*;
44
use crate::utils::{
5-
in_macro, last_line_of_span, match_def_path, opt_def_id, paths, snippet_opt, span_lint, span_lint_and_sugg,
6-
span_lint_and_then, without_block_comments,
5+
in_macro, last_line_of_span, match_def_path, paths, snippet_opt, span_lint, span_lint_and_sugg, span_lint_and_then,
6+
without_block_comments,
77
};
88
use if_chain::if_chain;
99
use rustc::hir::*;
@@ -396,7 +396,7 @@ fn is_relevant_expr(tcx: TyCtxt<'_, '_, '_>, tables: &ty::TypeckTables<'_>, expr
396396
ExprKind::Ret(None) | ExprKind::Break(_, None) => false,
397397
ExprKind::Call(path_expr, _) => {
398398
if let ExprKind::Path(qpath) = &path_expr.node {
399-
if let Some(fun_id) = opt_def_id(tables.qpath_def(qpath, path_expr.hir_id)) {
399+
if let Some(fun_id) = tables.qpath_def(qpath, path_expr.hir_id).opt_def_id() {
400400
!match_def_path(tcx, fun_id, &paths::BEGIN_PANIC)
401401
} else {
402402
true

clippy_lints/src/default_trait_access.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc::ty;
55
use rustc::{declare_tool_lint, lint_array};
66
use rustc_errors::Applicability;
77

8-
use crate::utils::{any_parent_is_automatically_derived, match_def_path, opt_def_id, paths, span_lint_and_sugg};
8+
use crate::utils::{any_parent_is_automatically_derived, match_def_path, paths, span_lint_and_sugg};
99

1010
declare_clippy_lint! {
1111
/// **What it does:** Checks for literal calls to `Default::default()`.
@@ -47,7 +47,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess {
4747
if let ExprKind::Call(ref path, ..) = expr.node;
4848
if !any_parent_is_automatically_derived(cx.tcx, expr.hir_id);
4949
if let ExprKind::Path(ref qpath) = path.node;
50-
if let Some(def_id) = opt_def_id(cx.tables.qpath_def(qpath, path.hir_id));
50+
if let Some(def_id) = cx.tables.qpath_def(qpath, path.hir_id).opt_def_id();
5151
if match_def_path(cx.tcx, def_id, &paths::DEFAULT_TRAIT_METHOD);
5252
then {
5353
match qpath {

clippy_lints/src/drop_forget_ref.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{is_copy, match_def_path, opt_def_id, paths, span_note_and_lint};
1+
use crate::utils::{is_copy, match_def_path, paths, span_note_and_lint};
22
use if_chain::if_chain;
33
use rustc::hir::*;
44
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
@@ -124,7 +124,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
124124
if let ExprKind::Call(ref path, ref args) = expr.node;
125125
if let ExprKind::Path(ref qpath) = path.node;
126126
if args.len() == 1;
127-
if let Some(def_id) = opt_def_id(cx.tables.qpath_def(qpath, path.hir_id));
127+
if let Some(def_id) = cx.tables.qpath_def(qpath, path.hir_id).opt_def_id();
128128
then {
129129
let lint;
130130
let msg;

clippy_lints/src/explicit_write.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{is_expn_of, match_def_path, opt_def_id, resolve_node, span_lint, span_lint_and_sugg};
1+
use crate::utils::{is_expn_of, match_def_path, resolve_node, span_lint, span_lint_and_sugg};
22
use if_chain::if_chain;
33
use rustc::hir::*;
44
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
@@ -53,7 +53,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
5353
if let ExprKind::Call(ref dest_fun, _) = write_args[0].node;
5454
if let ExprKind::Path(ref qpath) = dest_fun.node;
5555
if let Some(dest_fun_id) =
56-
opt_def_id(resolve_node(cx, qpath, dest_fun.hir_id));
56+
resolve_node(cx, qpath, dest_fun.hir_id).opt_def_id();
5757
if let Some(dest_name) = if match_def_path(cx.tcx, dest_fun_id, &["std", "io", "stdio", "stdout"]) {
5858
Some("stdout")
5959
} else if match_def_path(cx.tcx, dest_fun_id, &["std", "io", "stdio", "stderr"]) {

clippy_lints/src/fallible_impl_from.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::utils::paths::{BEGIN_PANIC, BEGIN_PANIC_FMT, FROM_TRAIT, OPTION, RESULT};
2-
use crate::utils::{is_expn_of, match_def_path, method_chain_args, opt_def_id, span_lint_and_then, walk_ptrs_ty};
2+
use crate::utils::{is_expn_of, match_def_path, method_chain_args, span_lint_and_then, walk_ptrs_ty};
33
use if_chain::if_chain;
44
use rustc::hir;
55
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
@@ -71,7 +71,7 @@ fn lint_impl_body<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, impl_span: Span, impl_it
7171
if_chain! {
7272
if let ExprKind::Call(ref func_expr, _) = expr.node;
7373
if let ExprKind::Path(QPath::Resolved(_, ref path)) = func_expr.node;
74-
if let Some(path_def_id) = opt_def_id(path.def);
74+
if let Some(path_def_id) = path.def.opt_def_id();
7575
if match_def_path(self.tcx, path_def_id, &BEGIN_PANIC) ||
7676
match_def_path(self.tcx, path_def_id, &BEGIN_PANIC_FMT);
7777
if is_expn_of(expr.span, "unreachable").is_none();

clippy_lints/src/format.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::utils::paths;
22
use crate::utils::{
3-
in_macro, is_expn_of, last_path_segment, match_def_path, match_type, opt_def_id, resolve_node, snippet,
4-
span_lint_and_then, walk_ptrs_ty,
3+
in_macro, is_expn_of, last_path_segment, match_def_path, match_type, resolve_node, snippet, span_lint_and_then,
4+
walk_ptrs_ty,
55
};
66
use if_chain::if_chain;
77
use rustc::hir::*;
@@ -58,7 +58,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
5858
ExprKind::Call(ref fun, ref args) => {
5959
if_chain! {
6060
if let ExprKind::Path(ref qpath) = fun.node;
61-
if let Some(fun_def_id) = opt_def_id(resolve_node(cx, qpath, fun.hir_id));
61+
if let Some(fun_def_id) = resolve_node(cx, qpath, fun.hir_id).opt_def_id();
6262
let new_v1 = match_def_path(cx.tcx, fun_def_id, &paths::FMT_ARGUMENTS_NEWV1);
6363
let new_v1_fmt = match_def_path(
6464
cx.tcx,
@@ -159,7 +159,7 @@ fn get_single_string_arg<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr) -> Option
159159
if let ExprKind::Call(_, ref args) = exprs[0].node;
160160
if args.len() == 2;
161161
if let ExprKind::Path(ref qpath) = args[1].node;
162-
if let Some(fun_def_id) = opt_def_id(resolve_node(cx, qpath, args[1].hir_id));
162+
if let Some(fun_def_id) = resolve_node(cx, qpath, args[1].hir_id).opt_def_id();
163163
if match_def_path(cx.tcx, fun_def_id, &paths::DISPLAY_FMT_METHOD);
164164
then {
165165
let ty = walk_ptrs_ty(cx.tables.pat_ty(&pat[0]));

clippy_lints/src/identity_conversion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::utils::{
22
in_macro, match_def_path, match_trait_method, same_tys, snippet, snippet_with_macro_callsite, span_lint_and_then,
33
};
4-
use crate::utils::{opt_def_id, paths, resolve_node};
4+
use crate::utils::{paths, resolve_node};
55
use rustc::hir::*;
66
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
77
use rustc::{declare_tool_lint, lint_array};
@@ -98,7 +98,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
9898

9999
ExprKind::Call(ref path, ref args) => {
100100
if let ExprKind::Path(ref qpath) = path.node {
101-
if let Some(def_id) = opt_def_id(resolve_node(cx, qpath, path.hir_id)) {
101+
if let Some(def_id) = resolve_node(cx, qpath, path.hir_id).opt_def_id() {
102102
if match_def_path(cx.tcx, def_id, &paths::FROM_FROM[..]) {
103103
let a = cx.tables.expr_ty(e);
104104
let b = cx.tables.expr_ty(&args[0]);

clippy_lints/src/invalid_ref.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{match_def_path, opt_def_id, paths, span_help_and_lint};
1+
use crate::utils::{match_def_path, paths, span_help_and_lint};
22
use if_chain::if_chain;
33
use rustc::hir::*;
44
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
@@ -45,7 +45,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidRef {
4545
if let ExprKind::Path(ref qpath) = path.node;
4646
if args.len() == 0;
4747
if let ty::Ref(..) = cx.tables.expr_ty(expr).sty;
48-
if let Some(def_id) = opt_def_id(cx.tables.qpath_def(qpath, path.hir_id));
48+
if let Some(def_id) = cx.tables.qpath_def(qpath, path.hir_id).opt_def_id();
4949
then {
5050
let msg = if match_def_path(cx.tcx, def_id, &paths::MEM_ZEROED) |
5151
match_def_path(cx.tcx, def_id, &paths::INIT)

clippy_lints/src/mem_discriminant.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{match_def_path, opt_def_id, paths, snippet, span_lint_and_then, walk_ptrs_ty_depth};
1+
use crate::utils::{match_def_path, paths, snippet, span_lint_and_then, walk_ptrs_ty_depth};
22
use if_chain::if_chain;
33
use rustc::hir::{Expr, ExprKind};
44
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
@@ -45,7 +45,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemDiscriminant {
4545
if let ExprKind::Call(ref func, ref func_args) = expr.node;
4646
// is `mem::discriminant`
4747
if let ExprKind::Path(ref func_qpath) = func.node;
48-
if let Some(def_id) = opt_def_id(cx.tables.qpath_def(func_qpath, func.hir_id));
48+
if let Some(def_id) = cx.tables.qpath_def(func_qpath, func.hir_id).opt_def_id();
4949
if match_def_path(cx.tcx, def_id, &paths::MEM_DISCRIMINANT);
5050
// type is non-enum
5151
let ty_param = cx.tables.node_substs(func.hir_id).type_at(0);

clippy_lints/src/mem_forget.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{match_def_path, opt_def_id, paths, span_lint};
1+
use crate::utils::{match_def_path, paths, span_lint};
22
use rustc::hir::{Expr, ExprKind};
33
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
44
use rustc::{declare_tool_lint, lint_array};
@@ -37,7 +37,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemForget {
3737
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
3838
if let ExprKind::Call(ref path_expr, ref args) = e.node {
3939
if let ExprKind::Path(ref qpath) = path_expr.node {
40-
if let Some(def_id) = opt_def_id(cx.tables.qpath_def(qpath, path_expr.hir_id)) {
40+
if let Some(def_id) = cx.tables.qpath_def(qpath, path_expr.hir_id).opt_def_id() {
4141
if match_def_path(cx.tcx, def_id, &paths::MEM_FORGET) {
4242
let forgot_ty = cx.tables.expr_ty(&args[0]);
4343

0 commit comments

Comments
 (0)