Skip to content

Commit 8744e8e

Browse files
committed
Auto merge of #4254 - lzutao:hiridification-62168, r=Manishearth
Rustup HirIdification Rustup rust-lang/rust#62168 changelog: none
2 parents a9f8d3a + 4814991 commit 8744e8e

24 files changed

+53
-65
lines changed

clippy_lints/src/cognitive_complexity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CognitiveComplexity {
118118
span: Span,
119119
hir_id: HirId,
120120
) {
121-
let def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id);
121+
let def_id = cx.tcx.hir().local_def_id(hir_id);
122122
if !cx.tcx.has_attr(def_id, sym!(test)) {
123123
self.check(cx, body, span);
124124
}

clippy_lints/src/copy_iterator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ declare_lint_pass!(CopyIterator => [COPY_ITERATOR]);
3434
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyIterator {
3535
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
3636
if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.node {
37-
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id_from_hir_id(item.hir_id));
37+
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.hir_id));
3838

3939
if is_copy(cx, ty) && match_path(&trait_ref.path, &paths::ITERATOR) {
4040
span_note_and_lint(

clippy_lints/src/derive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ declare_lint_pass!(Derive => [EXPL_IMPL_CLONE_ON_COPY, DERIVE_HASH_XOR_EQ]);
6767
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Derive {
6868
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
6969
if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.node {
70-
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id_from_hir_id(item.hir_id));
70+
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.hir_id));
7171
let is_automatically_derived = is_automatically_derived(&*item.attrs);
7272

7373
check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived);

clippy_lints/src/empty_enum.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ declare_lint_pass!(EmptyEnum => [EMPTY_ENUM]);
2727

2828
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EmptyEnum {
2929
fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item) {
30-
let did = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
30+
let did = cx.tcx.hir().local_def_id(item.hir_id);
3131
if let ItemKind::Enum(..) = item.node {
3232
let ty = cx.tcx.type_of(did);
3333
let adt = ty.ty_adt_def().expect("already checked whether this is an enum");

clippy_lints/src/escape.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxedLocal {
7777
too_large_for_stack: self.too_large_for_stack,
7878
};
7979

80-
let fn_def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id);
80+
let fn_def_id = cx.tcx.hir().local_def_id(hir_id);
8181
let region_scope_tree = &cx.tcx.region_scope_tree(fn_def_id);
8282
ExprUseVisitor::new(
8383
&mut v,

clippy_lints/src/fallible_impl_from.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ declare_lint_pass!(FallibleImplFrom => [FALLIBLE_IMPL_FROM]);
3333
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FallibleImplFrom {
3434
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) {
3535
// check for `impl From<???> for ..`
36-
let impl_def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
36+
let impl_def_id = cx.tcx.hir().local_def_id(item.hir_id);
3737
if_chain! {
3838
if let hir::ItemKind::Impl(.., ref impl_items) = item.node;
3939
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_def_id);
@@ -95,7 +95,7 @@ fn lint_impl_body<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, impl_span: Span, impl_it
9595
then {
9696
// check the body for `begin_panic` or `unwrap`
9797
let body = cx.tcx.hir().body(body_id);
98-
let impl_item_def_id = cx.tcx.hir().local_def_id_from_hir_id(impl_item.id.hir_id);
98+
let impl_item_def_id = cx.tcx.hir().local_def_id(impl_item.id.hir_id);
9999
let mut fpu = FindPanicUnwrap {
100100
lcx: cx,
101101
tables: cx.tcx.typeck_tables_of(impl_item_def_id),

clippy_lints/src/large_enum_variant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl_lint_pass!(LargeEnumVariant => [LARGE_ENUM_VARIANT]);
4646

4747
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeEnumVariant {
4848
fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item) {
49-
let did = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
49+
let did = cx.tcx.hir().local_def_id(item.hir_id);
5050
if let ItemKind::Enum(ref def, _) = item.node {
5151
let ty = cx.tcx.type_of(did);
5252
let adt = ty.ty_adt_def().expect("already checked whether this is an enum");

clippy_lints/src/len_zero.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ fn check_trait_items(cx: &LateContext<'_, '_>, visited_trait: &Item, trait_items
122122
item.ident.name.as_str() == name
123123
&& if let AssocItemKind::Method { has_self } = item.kind {
124124
has_self && {
125-
let did = cx.tcx.hir().local_def_id_from_hir_id(item.id.hir_id);
125+
let did = cx.tcx.hir().local_def_id(item.id.hir_id);
126126
cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1
127127
}
128128
} else {
@@ -141,7 +141,7 @@ fn check_trait_items(cx: &LateContext<'_, '_>, visited_trait: &Item, trait_items
141141

142142
if cx.access_levels.is_exported(visited_trait.hir_id) && trait_items.iter().any(|i| is_named_self(cx, i, "len")) {
143143
let mut current_and_super_traits = FxHashSet::default();
144-
let visited_trait_def_id = cx.tcx.hir().local_def_id_from_hir_id(visited_trait.hir_id);
144+
let visited_trait_def_id = cx.tcx.hir().local_def_id(visited_trait.hir_id);
145145
fill_trait_set(visited_trait_def_id, &mut current_and_super_traits, cx);
146146

147147
let is_empty_method_found = current_and_super_traits
@@ -173,7 +173,7 @@ fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item, impl_items: &[ImplIte
173173
item.ident.name.as_str() == name
174174
&& if let AssocItemKind::Method { has_self } = item.kind {
175175
has_self && {
176-
let did = cx.tcx.hir().local_def_id_from_hir_id(item.id.hir_id);
176+
let did = cx.tcx.hir().local_def_id(item.id.hir_id);
177177
cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1
178178
}
179179
} else {
@@ -193,7 +193,7 @@ fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item, impl_items: &[ImplIte
193193

194194
if let Some(i) = impl_items.iter().find(|i| is_named_self(cx, i, "len")) {
195195
if cx.access_levels.is_exported(i.id.hir_id) {
196-
let def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
196+
let def_id = cx.tcx.hir().local_def_id(item.hir_id);
197197
let ty = cx.tcx.type_of(def_id);
198198

199199
span_lint(

clippy_lints/src/loops.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ fn check_for_loop_range<'a, 'tcx>(
11021102
// ensure that the indexed variable was declared before the loop, see #601
11031103
if let Some(indexed_extent) = indexed_extent {
11041104
let parent_id = cx.tcx.hir().get_parent_item(expr.hir_id);
1105-
let parent_def_id = cx.tcx.hir().local_def_id_from_hir_id(parent_id);
1105+
let parent_def_id = cx.tcx.hir().local_def_id(parent_id);
11061106
let region_scope_tree = cx.tcx.region_scope_tree(parent_def_id);
11071107
let pat_extent = region_scope_tree.var_scope(pat.hir_id.local_id);
11081108
if region_scope_tree.is_subscope_of(indexed_extent, pat_extent) {
@@ -1792,7 +1792,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
17921792
match res {
17931793
Res::Local(hir_id) => {
17941794
let parent_id = self.cx.tcx.hir().get_parent_item(expr.hir_id);
1795-
let parent_def_id = self.cx.tcx.hir().local_def_id_from_hir_id(parent_id);
1795+
let parent_def_id = self.cx.tcx.hir().local_def_id(parent_id);
17961796
let extent = self.cx.tcx.region_scope_tree(parent_def_id).var_scope(hir_id.local_id);
17971797
if indexed_indirectly {
17981798
self.indexed_indirectly.insert(seqvar.segments[0].ident.name, Some(extent));

clippy_lints/src/methods/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
948948
let name = implitem.ident.name.as_str();
949949
let parent = cx.tcx.hir().get_parent_item(implitem.hir_id);
950950
let item = cx.tcx.hir().expect_item(parent);
951-
let def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
951+
let def_id = cx.tcx.hir().local_def_id(item.hir_id);
952952
let ty = cx.tcx.type_of(def_id);
953953
if_chain! {
954954
if let hir::ImplItemKind::Method(ref sig, id) = implitem.node;

clippy_lints/src/missing_const_for_fn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn {
6969
span: Span,
7070
hir_id: HirId,
7171
) {
72-
let def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id);
72+
let def_id = cx.tcx.hir().local_def_id(hir_id);
7373

7474
if in_external_macro(cx.tcx.sess, span) || is_entrypoint_fn(cx, def_id) {
7575
return;

clippy_lints/src/missing_doc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
133133
hir::ItemKind::Fn(..) => {
134134
// ignore main()
135135
if it.ident.name == sym!(main) {
136-
let def_id = cx.tcx.hir().local_def_id_from_hir_id(it.hir_id);
136+
let def_id = cx.tcx.hir().local_def_id(it.hir_id);
137137
let def_key = cx.tcx.hir().def_key(def_id);
138138
if def_key.parent == Some(hir::def_id::CRATE_DEF_INDEX) {
139139
return;
@@ -171,7 +171,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
171171

172172
fn check_impl_item(&mut self, cx: &LateContext<'a, '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_from_hir_id(impl_item.hir_id);
174+
let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
175175
match cx.tcx.associated_item(def_id).container {
176176
ty::TraitContainer(_) => return,
177177
ty::ImplContainer(cid) => {

clippy_lints/src/missing_inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline {
145145
hir::ImplItemKind::Const(..) | hir::ImplItemKind::Type(_) | hir::ImplItemKind::Existential(_) => return,
146146
};
147147

148-
let def_id = cx.tcx.hir().local_def_id_from_hir_id(impl_item.hir_id);
148+
let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
149149
let trait_def_id = match cx.tcx.associated_item(def_id).container {
150150
TraitContainer(cid) => Some(cid),
151151
ImplContainer(cid) => cx.tcx.impl_trait_ref(cid).map(|t| t.def_id),

clippy_lints/src/needless_pass_by_value.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
107107

108108
let sized_trait = need!(cx.tcx.lang_items().sized_trait());
109109

110-
let fn_def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id);
110+
let fn_def_id = cx.tcx.hir().local_def_id(hir_id);
111111

112112
let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds.to_vec())
113113
.filter(|p| !p.is_global())

clippy_lints/src/new_without_default.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
121121
return;
122122
}
123123
if sig.decl.inputs.is_empty() && name == sym!(new) && cx.access_levels.is_reachable(id) {
124-
let self_did = cx.tcx.hir().local_def_id_from_hir_id(cx.tcx.hir().get_parent_item(id));
124+
let self_did = cx.tcx.hir().local_def_id(cx.tcx.hir().get_parent_item(id));
125125
let self_ty = cx.tcx.type_of(self_did);
126126
if_chain! {
127127
if same_tys(cx, self_ty, return_ty(cx, id));

clippy_lints/src/ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ptr {
142142

143143
#[allow(clippy::too_many_lines)]
144144
fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: HirId, opt_body_id: Option<BodyId>) {
145-
let fn_def_id = cx.tcx.hir().local_def_id_from_hir_id(fn_id);
145+
let fn_def_id = cx.tcx.hir().local_def_id(fn_id);
146146
let sig = cx.tcx.fn_sig(fn_def_id);
147147
let fn_ty = sig.skip_binder();
148148

clippy_lints/src/replace_consts.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ReplaceConsts {
5656
}
5757
}
5858

59-
const REPLACEMENTS: [([&str; 3], &str); 25] = [
60-
// Once
61-
(["core", "sync", "ONCE_INIT"], "Once::new()"),
59+
const REPLACEMENTS: [([&str; 3], &str); 24] = [
6260
// Min
6361
(["core", "isize", "MIN"], "isize::min_value()"),
6462
(["core", "i8", "MIN"], "i8::min_value()"),

clippy_lints/src/trivially_copy_pass_by_ref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl<'a, 'tcx> TriviallyCopyPassByRef {
7373
}
7474

7575
fn check_poly_fn(&mut self, cx: &LateContext<'_, 'tcx>, hir_id: HirId, decl: &FnDecl, span: Option<Span>) {
76-
let fn_def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id);
76+
let fn_def_id = cx.tcx.hir().local_def_id(hir_id);
7777

7878
let fn_sig = cx.tcx.fn_sig(fn_def_id);
7979
let fn_sig = cx.tcx.erase_late_bound_regions(&fn_sig);

clippy_lints/src/use_self.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ fn check_trait_method_impl_decl<'a, 'tcx>(
129129
let trait_method_sig = cx.tcx.fn_sig(trait_method.def_id);
130130
let trait_method_sig = cx.tcx.erase_late_bound_regions(&trait_method_sig);
131131

132-
let impl_method_def_id = cx.tcx.hir().local_def_id_from_hir_id(impl_item.hir_id);
132+
let impl_method_def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
133133
let impl_method_sig = cx.tcx.fn_sig(impl_method_def_id);
134134
let impl_method_sig = cx.tcx.erase_late_bound_regions(&impl_method_sig);
135135

@@ -184,7 +184,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UseSelf {
184184
item_path,
185185
cx,
186186
};
187-
let impl_def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
187+
let impl_def_id = cx.tcx.hir().local_def_id(item.hir_id);
188188
let impl_trait_ref = cx.tcx.impl_trait_ref(impl_def_id);
189189

190190
if let Some(impl_trait_ref) = impl_trait_ref {

clippy_lints/src/utils/inspector.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ fn print_expr(cx: &LateContext<'_, '_>, expr: &hir::Expr, indent: usize) {
329329
}
330330

331331
fn print_item(cx: &LateContext<'_, '_>, item: &hir::Item) {
332-
let did = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
332+
let did = cx.tcx.hir().local_def_id(item.hir_id);
333333
println!("item `{}`", item.ident.name);
334334
match item.vis.node {
335335
hir::VisibilityKind::Public => println!("public"),
@@ -342,7 +342,7 @@ fn print_item(cx: &LateContext<'_, '_>, item: &hir::Item) {
342342
}
343343
match item.node {
344344
hir::ItemKind::ExternCrate(ref _renamed_from) => {
345-
let def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
345+
let def_id = cx.tcx.hir().local_def_id(item.hir_id);
346346
if let Some(crate_id) = cx.tcx.extern_mod_stmt_cnum(def_id) {
347347
let source = cx.tcx.used_crate_source(crate_id);
348348
if let Some(ref src) = source.dylib {

clippy_lints/src/utils/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ pub fn is_direct_expn_of(span: Span, name: &str) -> Option<Span> {
716716

717717
/// Convenience function to get the return type of a function.
718718
pub fn return_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, fn_item: hir::HirId) -> Ty<'tcx> {
719-
let fn_def_id = cx.tcx.hir().local_def_id_from_hir_id(fn_item);
719+
let fn_def_id = cx.tcx.hir().local_def_id(fn_item);
720720
let ret_ty = cx.tcx.fn_sig(fn_def_id).output();
721721
cx.tcx.erase_late_bound_regions(&ret_ty)
722722
}

tests/ui/replace_consts.fixed

-5
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44
#![deny(clippy::replace_consts)]
55

66
use std::sync::atomic::*;
7-
use std::sync::{Once, ONCE_INIT};
87

98
#[rustfmt::skip]
109
fn bad() {
11-
// Once
12-
{ let foo = ONCE_INIT; };
1310
// Min
1411
{ let foo = isize::min_value(); };
1512
{ let foo = i8::min_value(); };
@@ -40,8 +37,6 @@ fn bad() {
4037

4138
#[rustfmt::skip]
4239
fn good() {
43-
// Once
44-
{ let foo = Once::new(); };
4540
// Atomic
4641
{ let foo = AtomicBool::new(false); };
4742
{ let foo = AtomicIsize::new(0); };

tests/ui/replace_consts.rs

-5
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44
#![deny(clippy::replace_consts)]
55

66
use std::sync::atomic::*;
7-
use std::sync::{Once, ONCE_INIT};
87

98
#[rustfmt::skip]
109
fn bad() {
11-
// Once
12-
{ let foo = ONCE_INIT; };
1310
// Min
1411
{ let foo = std::isize::MIN; };
1512
{ let foo = std::i8::MIN; };
@@ -40,8 +37,6 @@ fn bad() {
4037

4138
#[rustfmt::skip]
4239
fn good() {
43-
// Once
44-
{ let foo = Once::new(); };
4540
// Atomic
4641
{ let foo = AtomicBool::new(false); };
4742
{ let foo = AtomicIsize::new(0); };

0 commit comments

Comments
 (0)