Skip to content

Commit dbe7609

Browse files
committed
Only store a LocalDefId in hir::ImplItem.
1 parent fc9bc33 commit dbe7609

16 files changed

+36
-47
lines changed

clippy_lints/src/doc.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,13 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
258258
}
259259
if let hir::ImplItemKind::Fn(ref sig, body_id) = item.kind {
260260
let body = cx.tcx.hir().body(body_id);
261-
let impl_item_def_id = cx.tcx.hir().local_def_id(item.hir_id);
262261
let mut fpu = FindPanicUnwrap {
263262
cx,
264-
typeck_results: cx.tcx.typeck(impl_item_def_id),
263+
typeck_results: cx.tcx.typeck(item.def_id),
265264
panic_span: None,
266265
};
267266
fpu.visit_expr(&body.value);
268-
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, Some(body_id), fpu.panic_span);
267+
lint_for_missing_headers(cx, item.hir_id(), item.span, sig, headers, Some(body_id), fpu.panic_span);
269268
}
270269
}
271270
}

clippy_lints/src/fallible_impl_from.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,9 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h
116116
then {
117117
// check the body for `begin_panic` or `unwrap`
118118
let body = cx.tcx.hir().body(body_id);
119-
let impl_item_def_id = cx.tcx.hir().local_def_id(impl_item.id.hir_id);
120119
let mut fpu = FindPanicUnwrap {
121120
lcx: cx,
122-
typeck_results: cx.tcx.typeck(impl_item_def_id),
121+
typeck_results: cx.tcx.typeck(impl_item.id.def_id),
123122
result: Vec::new(),
124123
};
125124
fpu.visit_expr(&body.value);

clippy_lints/src/functions.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,24 +308,24 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
308308

309309
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) {
310310
if let hir::ImplItemKind::Fn(ref sig, ref body_id) = item.kind {
311-
let is_public = cx.access_levels.is_exported(item.hir_id);
311+
let is_public = cx.access_levels.is_exported(item.hir_id());
312312
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
313-
if is_public && trait_ref_of_method(cx, item.hir_id).is_none() {
313+
if is_public && trait_ref_of_method(cx, item.hir_id()).is_none() {
314314
check_result_unit_err(cx, &sig.decl, item.span, fn_header_span);
315315
}
316316
let attr = must_use_attr(&item.attrs);
317317
if let Some(attr) = attr {
318-
check_needless_must_use(cx, &sig.decl, item.hir_id, item.span, fn_header_span, attr);
318+
check_needless_must_use(cx, &sig.decl, item.hir_id(), item.span, fn_header_span, attr);
319319
} else if is_public
320320
&& !is_proc_macro(cx.sess(), &item.attrs)
321-
&& trait_ref_of_method(cx, item.hir_id).is_none()
321+
&& trait_ref_of_method(cx, item.hir_id()).is_none()
322322
{
323323
check_must_use_candidate(
324324
cx,
325325
&sig.decl,
326326
cx.tcx.hir().body(*body_id),
327327
item.span,
328-
item.hir_id,
328+
item.hir_id(),
329329
item.span.with_hi(sig.decl.output.span().hi()),
330330
"this method could have a `#[must_use]` attribute",
331331
);

clippy_lints/src/inherent_to_string.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString {
108108
if decl.inputs.len() == 1;
109109

110110
// Check if return type is String
111-
if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id), sym::string_type);
111+
if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::string_type);
112112

113113
// Filters instances of to_string which are required by a trait
114-
if trait_ref_of_method(cx, impl_item.hir_id).is_none();
114+
if trait_ref_of_method(cx, impl_item.hir_id()).is_none();
115115

116116
then {
117117
show_lint(cx, impl_item);
@@ -124,8 +124,7 @@ fn show_lint(cx: &LateContext<'_>, item: &ImplItem<'_>) {
124124
let display_trait_id = get_trait_def_id(cx, &paths::DISPLAY_TRAIT).expect("Failed to get trait ID of `Display`!");
125125

126126
// Get the real type of 'self'
127-
let fn_def_id = cx.tcx.hir().local_def_id(item.hir_id);
128-
let self_type = cx.tcx.fn_sig(fn_def_id).input(0);
127+
let self_type = cx.tcx.fn_sig(item.def_id).input(0);
129128
let self_type = self_type.skip_binder().peel_refs();
130129

131130
// Emit either a warning or an error

clippy_lints/src/len_zero.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,17 +206,14 @@ fn check_impl_items(cx: &LateContext<'_>, item: &Item<'_>, impl_items: &[ImplIte
206206
fn is_named_self(cx: &LateContext<'_>, item: &ImplItemRef<'_>, name: &str) -> bool {
207207
item.ident.name.as_str() == name
208208
&& if let AssocItemKind::Fn { has_self } = item.kind {
209-
has_self && {
210-
let did = cx.tcx.hir().local_def_id(item.id.hir_id);
211-
cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1
212-
}
209+
has_self && cx.tcx.fn_sig(item.id.def_id).inputs().skip_binder().len() == 1
213210
} else {
214211
false
215212
}
216213
}
217214

218215
let is_empty = if let Some(is_empty) = impl_items.iter().find(|i| is_named_self(cx, i, "is_empty")) {
219-
if cx.access_levels.is_exported(is_empty.id.hir_id) {
216+
if cx.access_levels.is_exported(is_empty.id.hir_id()) {
220217
return;
221218
}
222219
"a private"
@@ -225,7 +222,7 @@ fn check_impl_items(cx: &LateContext<'_>, item: &Item<'_>, impl_items: &[ImplIte
225222
};
226223

227224
if let Some(i) = impl_items.iter().find(|i| is_named_self(cx, i, "len")) {
228-
if cx.access_levels.is_exported(i.id.hir_id) {
225+
if cx.access_levels.is_exported(i.id.hir_id()) {
229226
let ty = cx.tcx.type_of(item.def_id);
230227

231228
span_lint(

clippy_lints/src/lifetimes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for Lifetimes {
8787

8888
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) {
8989
if let ImplItemKind::Fn(ref sig, id) = item.kind {
90-
let report_extra_lifetimes = trait_ref_of_method(cx, item.hir_id).is_none();
90+
let report_extra_lifetimes = trait_ref_of_method(cx, item.hir_id()).is_none();
9191
check_fn_inner(
9292
cx,
9393
&sig.decl,

clippy_lints/src/methods/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,7 +1685,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
16851685
return;
16861686
}
16871687
let name = impl_item.ident.name.as_str();
1688-
let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id);
1688+
let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id());
16891689
let item = cx.tcx.hir().expect_item(parent);
16901690
let self_ty = cx.tcx.type_of(item.def_id);
16911691

@@ -1698,8 +1698,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
16981698
if let hir::ImplItemKind::Fn(ref sig, id) = impl_item.kind;
16991699
if let Some(first_arg) = iter_input_pats(&sig.decl, cx.tcx.hir().body(id)).next();
17001700

1701-
let method_def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
1702-
let method_sig = cx.tcx.fn_sig(method_def_id);
1701+
let method_sig = cx.tcx.fn_sig(impl_item.def_id);
17031702
let method_sig = cx.tcx.erase_late_bound_regions(method_sig);
17041703

17051704
let first_arg_ty = &method_sig.inputs().iter().next();
@@ -1708,7 +1707,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
17081707
if let Some(first_arg_ty) = first_arg_ty;
17091708

17101709
then {
1711-
if cx.access_levels.is_exported(impl_item.hir_id) {
1710+
if cx.access_levels.is_exported(impl_item.hir_id()) {
17121711
// check missing trait implementations
17131712
for method_config in &TRAIT_METHODS {
17141713
if name == method_config.method_name &&
@@ -1750,7 +1749,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
17501749
}
17511750

17521751
if let hir::ImplItemKind::Fn(_, _) = impl_item.kind {
1753-
let ret_ty = return_ty(cx, impl_item.hir_id);
1752+
let ret_ty = return_ty(cx, impl_item.hir_id());
17541753

17551754
// walk the return type and check for Self (this does not check associated types)
17561755
if contains_ty(ret_ty, self_ty) {

clippy_lints/src/missing_doc.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
171171

172172
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) {
173173
// If the method is an impl for a trait, don't doc.
174-
let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
175-
match cx.tcx.associated_item(def_id).container {
174+
match cx.tcx.associated_item(impl_item.def_id).container {
176175
ty::TraitContainer(_) => return,
177176
ty::ImplContainer(cid) => {
178177
if cx.tcx.impl_trait_ref(cid).is_some() {
@@ -181,7 +180,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
181180
},
182181
}
183182

184-
let (article, desc) = cx.tcx.article_and_description(def_id.to_def_id());
183+
let (article, desc) = cx.tcx.article_and_description(impl_item.def_id.to_def_id());
185184
self.check_missing_docs_attrs(cx, &impl_item.attrs, impl_item.span, article, desc);
186185
}
187186

clippy_lints/src/missing_inline.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
138138
}
139139

140140
// If the item being implemented is not exported, then we don't need #[inline]
141-
if !cx.access_levels.is_exported(impl_item.hir_id) {
141+
if !cx.access_levels.is_exported(impl_item.hir_id()) {
142142
return;
143143
}
144144

@@ -147,14 +147,13 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
147147
hir::ImplItemKind::Const(..) | hir::ImplItemKind::TyAlias(_) => return,
148148
};
149149

150-
let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
151-
let trait_def_id = match cx.tcx.associated_item(def_id).container {
150+
let trait_def_id = match cx.tcx.associated_item(impl_item.def_id).container {
152151
TraitContainer(cid) => Some(cid),
153152
ImplContainer(cid) => cx.tcx.impl_trait_ref(cid).map(|t| t.def_id),
154153
};
155154

156155
if let Some(trait_def_id) = trait_def_id {
157-
if trait_def_id.is_local() && !cx.access_levels.is_exported(impl_item.hir_id) {
156+
if trait_def_id.is_local() && !cx.access_levels.is_exported(impl_item.hir_id()) {
158157
// If a trait is being implemented for an item, and the
159158
// trait is not exported, we don't need #[inline]
160159
return;

clippy_lints/src/mut_key.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ impl<'tcx> LateLintPass<'tcx> for MutableKeyType {
6363

6464
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'tcx>) {
6565
if let hir::ImplItemKind::Fn(ref sig, ..) = item.kind {
66-
if trait_ref_of_method(cx, item.hir_id).is_none() {
67-
check_sig(cx, item.hir_id, &sig.decl);
66+
if trait_ref_of_method(cx, item.hir_id()).is_none() {
67+
check_sig(cx, item.hir_id(), &sig.decl);
6868
}
6969
}
7070
}

clippy_lints/src/new_without_default.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
7272
}
7373
if let hir::ImplItemKind::Fn(ref sig, _) = impl_item.kind {
7474
let name = impl_item.ident.name;
75-
let id = impl_item.hir_id;
75+
let id = impl_item.hir_id();
7676
if sig.header.constness == hir::Constness::Const {
7777
// can't be implemented by default
7878
return;

clippy_lints/src/non_copy_const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst {
271271

272272
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'_>) {
273273
if let ImplItemKind::Const(hir_ty, body_id) = &impl_item.kind {
274-
let item_hir_id = cx.tcx.hir().get_parent_node(impl_item.hir_id);
274+
let item_hir_id = cx.tcx.hir().get_parent_node(impl_item.hir_id());
275275
let item = cx.tcx.hir().expect_item(item_hir_id);
276276

277277
match &item.kind {

clippy_lints/src/partialeq_ne_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl<'tcx> LateLintPass<'tcx> for PartialEqNeImpl {
4444
span_lint_hir(
4545
cx,
4646
PARTIALEQ_NE_IMPL,
47-
impl_item.id.hir_id,
47+
impl_item.id.hir_id(),
4848
impl_item.span,
4949
"re-implementing `PartialEq::ne` is unnecessary",
5050
);

clippy_lints/src/ptr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,13 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
130130

131131
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) {
132132
if let ImplItemKind::Fn(ref sig, body_id) = item.kind {
133-
let parent_item = cx.tcx.hir().get_parent_item(item.hir_id);
133+
let parent_item = cx.tcx.hir().get_parent_item(item.hir_id());
134134
if let Some(Node::Item(it)) = cx.tcx.hir().find(parent_item) {
135135
if let ItemKind::Impl(Impl { of_trait: Some(_), .. }) = it.kind {
136136
return; // ignore trait impls
137137
}
138138
}
139-
check_fn(cx, &sig.decl, item.hir_id, Some(body_id));
139+
check_fn(cx, &sig.decl, item.hir_id(), Some(body_id));
140140
}
141141
}
142142

clippy_lints/src/unused_self.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ impl<'tcx> LateLintPass<'tcx> for UnusedSelf {
4444
if impl_item.span.from_expansion() {
4545
return;
4646
}
47-
let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id);
47+
let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id());
4848
let parent_item = cx.tcx.hir().expect_item(parent);
49-
let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
50-
let assoc_item = cx.tcx.associated_item(def_id);
49+
let assoc_item = cx.tcx.associated_item(impl_item.def_id);
5150
if_chain! {
5251
if let ItemKind::Impl(Impl { of_trait: None, .. }) = parent_item.kind;
5352
if assoc_item.fn_has_self_parameter;

clippy_lints/src/unwrap_in_result.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ impl<'tcx> LateLintPass<'tcx> for UnwrapInResult {
5757
// first check if it's a method or function
5858
if let hir::ImplItemKind::Fn(ref _signature, _) = impl_item.kind;
5959
// checking if its return type is `result` or `option`
60-
if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id), sym::result_type)
61-
|| is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id), sym::option_type);
60+
if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::result_type)
61+
|| is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::option_type);
6262
then {
6363
lint_impl_body(cx, impl_item.span, impl_item);
6464
}
@@ -114,10 +114,9 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_item: &'tc
114114
if let ImplItemKind::Fn(_, body_id) = impl_item.kind;
115115
then {
116116
let body = cx.tcx.hir().body(body_id);
117-
let impl_item_def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
118117
let mut fpu = FindExpectUnwrap {
119118
lcx: cx,
120-
typeck_results: cx.tcx.typeck(impl_item_def_id),
119+
typeck_results: cx.tcx.typeck(impl_item.def_id),
121120
result: Vec::new(),
122121
};
123122
fpu.visit_expr(&body.value);

0 commit comments

Comments
 (0)