Skip to content

Commit 8212b4e

Browse files
committed
1 parent 58c0dc1 commit 8212b4e

File tree

10 files changed

+31
-32
lines changed

10 files changed

+31
-32
lines changed

clippy_lints/src/functions.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
150150
}
151151
}
152152

153-
let nodeid = cx.tcx.hir().hir_to_node_id(hir_id);
154-
self.check_raw_ptr(cx, unsafety, decl, body, nodeid);
153+
self.check_raw_ptr(cx, unsafety, decl, body, hir_id);
155154
self.check_line_number(cx, span, body);
156155
}
157156

@@ -164,7 +163,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
164163

165164
if let hir::TraitMethod::Provided(eid) = *eid {
166165
let body = cx.tcx.hir().body(eid);
167-
self.check_raw_ptr(cx, sig.header.unsafety, &sig.decl, body, item.id);
166+
self.check_raw_ptr(cx, sig.header.unsafety, &sig.decl, body, item.hir_id);
168167
}
169168
}
170169
}
@@ -255,10 +254,11 @@ impl<'a, 'tcx> Functions {
255254
unsafety: hir::Unsafety,
256255
decl: &'tcx hir::FnDecl,
257256
body: &'tcx hir::Body,
258-
nodeid: ast::NodeId,
257+
hir_id: hir::HirId,
259258
) {
260259
let expr = &body.value;
261-
if unsafety == hir::Unsafety::Normal && cx.access_levels.is_exported(nodeid) {
260+
let node_id = cx.tcx.hir().hir_to_node_id(hir_id);
261+
if unsafety == hir::Unsafety::Normal && cx.access_levels.is_exported(node_id) {
262262
let raw_ptrs = iter_input_pats(decl, body)
263263
.zip(decl.inputs.iter())
264264
.filter_map(|(arg, ty)| raw_ptr_arg(arg, ty))

clippy_lints/src/methods/mod.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -906,17 +906,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
906906
return;
907907
}
908908
let name = implitem.ident.name;
909-
let parent = cx.tcx.hir().get_parent(implitem.id);
910-
let item = cx.tcx.hir().expect_item(parent);
911-
let def_id = cx.tcx.hir().local_def_id(item.id);
909+
let parent = cx.tcx.hir().get_parent_item(implitem.hir_id);
910+
let item = cx.tcx.hir().expect_item_by_hir_id(parent);
911+
let def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
912912
let ty = cx.tcx.type_of(def_id);
913913
if_chain! {
914914
if let hir::ImplItemKind::Method(ref sig, id) = implitem.node;
915915
if let Some(first_arg_ty) = sig.decl.inputs.get(0);
916916
if let Some(first_arg) = iter_input_pats(&sig.decl, cx.tcx.hir().body(id)).next();
917917
if let hir::ItemKind::Impl(_, _, _, _, None, ref self_ty, _) = item.node;
918918
then {
919-
if cx.access_levels.is_exported(implitem.id) {
919+
let node_id = cx.tcx.hir().hir_to_node_id(implitem.hir_id);
920+
if cx.access_levels.is_exported(node_id) {
920921
// check missing trait implementations
921922
for &(method_name, n_args, self_kind, out_type, trait_name) in &TRAIT_METHODS {
922923
if name == method_name &&
@@ -963,7 +964,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
963964
}
964965

965966
if let hir::ImplItemKind::Method(_, _) = implitem.node {
966-
let ret_ty = return_ty(cx, implitem.id);
967+
let ret_ty = return_ty(cx, implitem.hir_id);
967968

968969
// walk the return type and check for Self (this does not check associated types)
969970
for inner_type in ret_ty.walk() {

clippy_lints/src/missing_doc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
162162

163163
fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &'tcx hir::ImplItem) {
164164
// If the method is an impl for a trait, don't doc.
165-
let def_id = cx.tcx.hir().local_def_id(impl_item.id);
165+
let def_id = cx.tcx.hir().local_def_id_from_hir_id(impl_item.hir_id);
166166
match cx.tcx.associated_item(def_id).container {
167167
ty::TraitContainer(_) => return,
168168
ty::ImplContainer(cid) => {

clippy_lints/src/missing_inline.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline {
146146
}
147147

148148
// If the item being implemented is not exported, then we don't need #[inline]
149-
if !cx.access_levels.is_exported(impl_item.id) {
149+
let node_id = cx.tcx.hir().hir_to_node_id(impl_item.hir_id);
150+
if !cx.access_levels.is_exported(node_id) {
150151
return;
151152
}
152153

@@ -155,7 +156,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline {
155156
hir::ImplItemKind::Const(..) | hir::ImplItemKind::Type(_) | hir::ImplItemKind::Existential(_) => return,
156157
};
157158

158-
let def_id = cx.tcx.hir().local_def_id(impl_item.id);
159+
let def_id = cx.tcx.hir().local_def_id_from_hir_id(impl_item.hir_id);
159160
let trait_def_id = match cx.tcx.associated_item(def_id).container {
160161
TraitContainer(cid) => Some(cid),
161162
ImplContainer(cid) => cx.tcx.impl_trait_ref(cid).map(|t| t.def_id),

clippy_lints/src/new_without_default.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
133133
let self_did = cx.tcx.hir().local_def_id_from_hir_id(cx.tcx.hir().get_parent_item(id));
134134
let self_ty = cx.tcx.type_of(self_did);
135135
if_chain! {
136-
if same_tys(cx, self_ty, return_ty(cx, node_id));
136+
if same_tys(cx, self_ty, return_ty(cx, id));
137137
if let Some(default_trait_id) = get_trait_def_id(cx, &paths::DEFAULT_TRAIT);
138138
then {
139139
if self.impling_types.is_none() {

clippy_lints/src/non_copy_const.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst {
177177

178178
fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &'tcx ImplItem) {
179179
if let ImplItemKind::Const(hir_ty, ..) = &impl_item.node {
180-
let item_node_id = cx.tcx.hir().get_parent_node(impl_item.id);
181-
let item = cx.tcx.hir().expect_item(item_node_id);
180+
let item_hir_id = cx.tcx.hir().get_parent_node_by_hir_id(impl_item.hir_id);
181+
let item = cx.tcx.hir().expect_item_by_hir_id(item_hir_id);
182182
// ensure the impl is an inherent impl.
183183
if let ItemKind::Impl(_, _, _, _, None, _, _) = item.node {
184184
let ty = hir_ty_to_ty(cx.tcx, hir_ty);

clippy_lints/src/ptr.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use rustc::ty;
1010
use rustc::{declare_tool_lint, lint_array};
1111
use rustc_errors::Applicability;
1212
use std::borrow::Cow;
13-
use syntax::ast::NodeId;
1413
use syntax::source_map::Span;
1514
use syntax_pos::MultiSpan;
1615

@@ -111,18 +110,19 @@ impl LintPass for PointerPass {
111110
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PointerPass {
112111
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
113112
if let ItemKind::Fn(ref decl, _, _, body_id) = item.node {
114-
check_fn(cx, decl, item.id, Some(body_id));
113+
check_fn(cx, decl, item.hir_id, Some(body_id));
115114
}
116115
}
117116

118117
fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx ImplItem) {
119118
if let ImplItemKind::Method(ref sig, body_id) = item.node {
120-
if let Some(Node::Item(it)) = cx.tcx.hir().find(cx.tcx.hir().get_parent(item.id)) {
119+
let parent_item = cx.tcx.hir().get_parent_item(item.hir_id);
120+
if let Some(Node::Item(it)) = cx.tcx.hir().find_by_hir_id(parent_item) {
121121
if let ItemKind::Impl(_, _, _, _, Some(_), _, _) = it.node {
122122
return; // ignore trait impls
123123
}
124124
}
125-
check_fn(cx, &sig.decl, item.id, Some(body_id));
125+
check_fn(cx, &sig.decl, item.hir_id, Some(body_id));
126126
}
127127
}
128128

@@ -133,7 +133,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PointerPass {
133133
} else {
134134
None
135135
};
136-
check_fn(cx, &sig.decl, item.id, body_id);
136+
check_fn(cx, &sig.decl, item.hir_id, body_id);
137137
}
138138
}
139139

@@ -152,8 +152,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PointerPass {
152152
}
153153

154154
#[allow(clippy::too_many_lines)]
155-
fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: NodeId, opt_body_id: Option<BodyId>) {
156-
let fn_def_id = cx.tcx.hir().local_def_id(fn_id);
155+
fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: HirId, opt_body_id: Option<BodyId>) {
156+
let fn_def_id = cx.tcx.hir().local_def_id_from_hir_id(fn_id);
157157
let sig = cx.tcx.fn_sig(fn_def_id);
158158
let fn_ty = sig.skip_binder();
159159

clippy_lints/src/use_self.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ fn check_trait_method_impl_decl<'a, 'tcx: 'a>(
137137
let trait_method_sig = cx.tcx.fn_sig(trait_method.def_id);
138138
let trait_method_sig = cx.tcx.erase_late_bound_regions(&trait_method_sig);
139139

140-
let impl_method_def_id = cx.tcx.hir().local_def_id(impl_item.id);
140+
let impl_method_def_id = cx.tcx.hir().local_def_id_from_hir_id(impl_item.hir_id);
141141
let impl_method_sig = cx.tcx.fn_sig(impl_method_def_id);
142142
let impl_method_sig = cx.tcx.erase_late_bound_regions(&impl_method_sig);
143143

clippy_lints/src/utils/diagnostics.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ pub fn span_lint_and_then<'a, 'tcx: 'a, T: LintContext<'tcx>, F>(
135135
}
136136

137137
pub fn span_lint_node(cx: &LateContext<'_, '_>, lint: &'static Lint, node: HirId, sp: Span, msg: &str) {
138-
let node_id = cx.tcx.hir().hir_to_node_id(node);
139-
DiagnosticWrapper(cx.tcx.struct_span_lint_node(lint, node_id, sp, msg)).docs_link(lint);
138+
DiagnosticWrapper(cx.tcx.struct_span_lint_hir(lint, node, sp, msg)).docs_link(lint);
140139
}
141140

142141
pub fn span_lint_node_and_then(
@@ -147,8 +146,7 @@ pub fn span_lint_node_and_then(
147146
msg: &str,
148147
f: impl FnOnce(&mut DiagnosticBuilder<'_>),
149148
) {
150-
let node_id = cx.tcx.hir().hir_to_node_id(node);
151-
let mut db = DiagnosticWrapper(cx.tcx.struct_span_lint_node(lint, node_id, sp, msg));
149+
let mut db = DiagnosticWrapper(cx.tcx.struct_span_lint_hir(lint, node, sp, msg));
152150
f(&mut db.0);
153151
db.docs_link(lint);
154152
}

clippy_lints/src/utils/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -753,8 +753,8 @@ pub fn is_direct_expn_of(span: Span, name: &str) -> Option<Span> {
753753
}
754754

755755
/// Convenience function to get the return type of a function
756-
pub fn return_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, fn_item: NodeId) -> Ty<'tcx> {
757-
let fn_def_id = cx.tcx.hir().local_def_id(fn_item);
756+
pub fn return_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, fn_item: hir::HirId) -> Ty<'tcx> {
757+
let fn_def_id = cx.tcx.hir().local_def_id_from_hir_id(fn_item);
758758
let ret_ty = cx.tcx.fn_sig(fn_def_id).output();
759759
cx.tcx.erase_late_bound_regions(&ret_ty)
760760
}
@@ -929,8 +929,7 @@ pub fn is_try(expr: &Expr) -> Option<&Expr> {
929929
///
930930
/// Useful for skipping long running code when it's unnecessary
931931
pub fn is_allowed(cx: &LateContext<'_, '_>, lint: &'static Lint, id: HirId) -> bool {
932-
let node_id = cx.tcx.hir().hir_to_node_id(id);
933-
cx.tcx.lint_level_at_node(lint, node_id).0 == Level::Allow
932+
cx.tcx.lint_level_at_node(lint, id).0 == Level::Allow
934933
}
935934

936935
pub fn get_arg_name(pat: &Pat) -> Option<ast::Name> {

0 commit comments

Comments
 (0)