Rename hir::map::local_def_id_from_hir_id to local_def_id

This commit is contained in:
Lzu Tao 2019-07-06 10:52:51 +07:00
parent a9f8d3a034
commit 7293defb34
20 changed files with 28 additions and 28 deletions

View file

@ -118,7 +118,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CognitiveComplexity {
span: Span, span: Span,
hir_id: HirId, hir_id: HirId,
) { ) {
let def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id); let def_id = cx.tcx.hir().local_def_id(hir_id);
if !cx.tcx.has_attr(def_id, sym!(test)) { if !cx.tcx.has_attr(def_id, sym!(test)) {
self.check(cx, body, span); self.check(cx, body, span);
} }

View file

@ -34,7 +34,7 @@ declare_lint_pass!(CopyIterator => [COPY_ITERATOR]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyIterator { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyIterator {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.node { if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.node {
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id_from_hir_id(item.hir_id)); let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.hir_id));
if is_copy(cx, ty) && match_path(&trait_ref.path, &paths::ITERATOR) { if is_copy(cx, ty) && match_path(&trait_ref.path, &paths::ITERATOR) {
span_note_and_lint( span_note_and_lint(

View file

@ -67,7 +67,7 @@ declare_lint_pass!(Derive => [EXPL_IMPL_CLONE_ON_COPY, DERIVE_HASH_XOR_EQ]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Derive { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Derive {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.node { if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.node {
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id_from_hir_id(item.hir_id)); let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.hir_id));
let is_automatically_derived = is_automatically_derived(&*item.attrs); let is_automatically_derived = is_automatically_derived(&*item.attrs);
check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived); check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived);

View file

@ -27,7 +27,7 @@ declare_lint_pass!(EmptyEnum => [EMPTY_ENUM]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EmptyEnum { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EmptyEnum {
fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item) { fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item) {
let did = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id); let did = cx.tcx.hir().local_def_id(item.hir_id);
if let ItemKind::Enum(..) = item.node { if let ItemKind::Enum(..) = item.node {
let ty = cx.tcx.type_of(did); let ty = cx.tcx.type_of(did);
let adt = ty.ty_adt_def().expect("already checked whether this is an enum"); let adt = ty.ty_adt_def().expect("already checked whether this is an enum");

View file

@ -77,7 +77,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxedLocal {
too_large_for_stack: self.too_large_for_stack, too_large_for_stack: self.too_large_for_stack,
}; };
let fn_def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id); let fn_def_id = cx.tcx.hir().local_def_id(hir_id);
let region_scope_tree = &cx.tcx.region_scope_tree(fn_def_id); let region_scope_tree = &cx.tcx.region_scope_tree(fn_def_id);
ExprUseVisitor::new( ExprUseVisitor::new(
&mut v, &mut v,

View file

@ -33,7 +33,7 @@ declare_lint_pass!(FallibleImplFrom => [FALLIBLE_IMPL_FROM]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FallibleImplFrom { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FallibleImplFrom {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) {
// check for `impl From<???> for ..` // check for `impl From<???> for ..`
let impl_def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id); let impl_def_id = cx.tcx.hir().local_def_id(item.hir_id);
if_chain! { if_chain! {
if let hir::ItemKind::Impl(.., ref impl_items) = item.node; if let hir::ItemKind::Impl(.., ref impl_items) = item.node;
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_def_id); 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
then { then {
// check the body for `begin_panic` or `unwrap` // check the body for `begin_panic` or `unwrap`
let body = cx.tcx.hir().body(body_id); let body = cx.tcx.hir().body(body_id);
let impl_item_def_id = cx.tcx.hir().local_def_id_from_hir_id(impl_item.id.hir_id); let impl_item_def_id = cx.tcx.hir().local_def_id(impl_item.id.hir_id);
let mut fpu = FindPanicUnwrap { let mut fpu = FindPanicUnwrap {
lcx: cx, lcx: cx,
tables: cx.tcx.typeck_tables_of(impl_item_def_id), tables: cx.tcx.typeck_tables_of(impl_item_def_id),

View file

@ -46,7 +46,7 @@ impl_lint_pass!(LargeEnumVariant => [LARGE_ENUM_VARIANT]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeEnumVariant { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeEnumVariant {
fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item) { fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item) {
let did = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id); let did = cx.tcx.hir().local_def_id(item.hir_id);
if let ItemKind::Enum(ref def, _) = item.node { if let ItemKind::Enum(ref def, _) = item.node {
let ty = cx.tcx.type_of(did); let ty = cx.tcx.type_of(did);
let adt = ty.ty_adt_def().expect("already checked whether this is an enum"); let adt = ty.ty_adt_def().expect("already checked whether this is an enum");

View file

@ -122,7 +122,7 @@ fn check_trait_items(cx: &LateContext<'_, '_>, visited_trait: &Item, trait_items
item.ident.name.as_str() == name item.ident.name.as_str() == name
&& if let AssocItemKind::Method { has_self } = item.kind { && if let AssocItemKind::Method { has_self } = item.kind {
has_self && { has_self && {
let did = cx.tcx.hir().local_def_id_from_hir_id(item.id.hir_id); let did = cx.tcx.hir().local_def_id(item.id.hir_id);
cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1 cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1
} }
} else { } else {
@ -141,7 +141,7 @@ fn check_trait_items(cx: &LateContext<'_, '_>, visited_trait: &Item, trait_items
if cx.access_levels.is_exported(visited_trait.hir_id) && trait_items.iter().any(|i| is_named_self(cx, i, "len")) { if cx.access_levels.is_exported(visited_trait.hir_id) && trait_items.iter().any(|i| is_named_self(cx, i, "len")) {
let mut current_and_super_traits = FxHashSet::default(); let mut current_and_super_traits = FxHashSet::default();
let visited_trait_def_id = cx.tcx.hir().local_def_id_from_hir_id(visited_trait.hir_id); let visited_trait_def_id = cx.tcx.hir().local_def_id(visited_trait.hir_id);
fill_trait_set(visited_trait_def_id, &mut current_and_super_traits, cx); fill_trait_set(visited_trait_def_id, &mut current_and_super_traits, cx);
let is_empty_method_found = current_and_super_traits let is_empty_method_found = current_and_super_traits
@ -173,7 +173,7 @@ fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item, impl_items: &[ImplIte
item.ident.name.as_str() == name item.ident.name.as_str() == name
&& if let AssocItemKind::Method { has_self } = item.kind { && if let AssocItemKind::Method { has_self } = item.kind {
has_self && { has_self && {
let did = cx.tcx.hir().local_def_id_from_hir_id(item.id.hir_id); let did = cx.tcx.hir().local_def_id(item.id.hir_id);
cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1 cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1
} }
} else { } else {
@ -193,7 +193,7 @@ fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item, impl_items: &[ImplIte
if let Some(i) = impl_items.iter().find(|i| is_named_self(cx, i, "len")) { if let Some(i) = impl_items.iter().find(|i| is_named_self(cx, i, "len")) {
if cx.access_levels.is_exported(i.id.hir_id) { if cx.access_levels.is_exported(i.id.hir_id) {
let def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id); let def_id = cx.tcx.hir().local_def_id(item.hir_id);
let ty = cx.tcx.type_of(def_id); let ty = cx.tcx.type_of(def_id);
span_lint( span_lint(

View file

@ -1102,7 +1102,7 @@ fn check_for_loop_range<'a, 'tcx>(
// ensure that the indexed variable was declared before the loop, see #601 // ensure that the indexed variable was declared before the loop, see #601
if let Some(indexed_extent) = indexed_extent { if let Some(indexed_extent) = indexed_extent {
let parent_id = cx.tcx.hir().get_parent_item(expr.hir_id); let parent_id = cx.tcx.hir().get_parent_item(expr.hir_id);
let parent_def_id = cx.tcx.hir().local_def_id_from_hir_id(parent_id); let parent_def_id = cx.tcx.hir().local_def_id(parent_id);
let region_scope_tree = cx.tcx.region_scope_tree(parent_def_id); let region_scope_tree = cx.tcx.region_scope_tree(parent_def_id);
let pat_extent = region_scope_tree.var_scope(pat.hir_id.local_id); let pat_extent = region_scope_tree.var_scope(pat.hir_id.local_id);
if region_scope_tree.is_subscope_of(indexed_extent, pat_extent) { if region_scope_tree.is_subscope_of(indexed_extent, pat_extent) {
@ -1792,7 +1792,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
match res { match res {
Res::Local(hir_id) => { Res::Local(hir_id) => {
let parent_id = self.cx.tcx.hir().get_parent_item(expr.hir_id); let parent_id = self.cx.tcx.hir().get_parent_item(expr.hir_id);
let parent_def_id = self.cx.tcx.hir().local_def_id_from_hir_id(parent_id); let parent_def_id = self.cx.tcx.hir().local_def_id(parent_id);
let extent = self.cx.tcx.region_scope_tree(parent_def_id).var_scope(hir_id.local_id); let extent = self.cx.tcx.region_scope_tree(parent_def_id).var_scope(hir_id.local_id);
if indexed_indirectly { if indexed_indirectly {
self.indexed_indirectly.insert(seqvar.segments[0].ident.name, Some(extent)); self.indexed_indirectly.insert(seqvar.segments[0].ident.name, Some(extent));

View file

@ -948,7 +948,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
let name = implitem.ident.name.as_str(); let name = implitem.ident.name.as_str();
let parent = cx.tcx.hir().get_parent_item(implitem.hir_id); let parent = cx.tcx.hir().get_parent_item(implitem.hir_id);
let item = cx.tcx.hir().expect_item(parent); let item = cx.tcx.hir().expect_item(parent);
let def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id); let def_id = cx.tcx.hir().local_def_id(item.hir_id);
let ty = cx.tcx.type_of(def_id); let ty = cx.tcx.type_of(def_id);
if_chain! { if_chain! {
if let hir::ImplItemKind::Method(ref sig, id) = implitem.node; if let hir::ImplItemKind::Method(ref sig, id) = implitem.node;

View file

@ -69,7 +69,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn {
span: Span, span: Span,
hir_id: HirId, hir_id: HirId,
) { ) {
let def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id); let def_id = cx.tcx.hir().local_def_id(hir_id);
if in_external_macro(cx.tcx.sess, span) || is_entrypoint_fn(cx, def_id) { if in_external_macro(cx.tcx.sess, span) || is_entrypoint_fn(cx, def_id) {
return; return;

View file

@ -133,7 +133,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
hir::ItemKind::Fn(..) => { hir::ItemKind::Fn(..) => {
// ignore main() // ignore main()
if it.ident.name == sym!(main) { if it.ident.name == sym!(main) {
let def_id = cx.tcx.hir().local_def_id_from_hir_id(it.hir_id); let def_id = cx.tcx.hir().local_def_id(it.hir_id);
let def_key = cx.tcx.hir().def_key(def_id); let def_key = cx.tcx.hir().def_key(def_id);
if def_key.parent == Some(hir::def_id::CRATE_DEF_INDEX) { if def_key.parent == Some(hir::def_id::CRATE_DEF_INDEX) {
return; return;
@ -171,7 +171,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &'tcx hir::ImplItem) { fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &'tcx hir::ImplItem) {
// If the method is an impl for a trait, don't doc. // If the method is an impl for a trait, don't doc.
let def_id = cx.tcx.hir().local_def_id_from_hir_id(impl_item.hir_id); let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
match cx.tcx.associated_item(def_id).container { match cx.tcx.associated_item(def_id).container {
ty::TraitContainer(_) => return, ty::TraitContainer(_) => return,
ty::ImplContainer(cid) => { ty::ImplContainer(cid) => {

View file

@ -145,7 +145,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline {
hir::ImplItemKind::Const(..) | hir::ImplItemKind::Type(_) | hir::ImplItemKind::Existential(_) => return, hir::ImplItemKind::Const(..) | hir::ImplItemKind::Type(_) | hir::ImplItemKind::Existential(_) => return,
}; };
let def_id = cx.tcx.hir().local_def_id_from_hir_id(impl_item.hir_id); let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
let trait_def_id = match cx.tcx.associated_item(def_id).container { let trait_def_id = match cx.tcx.associated_item(def_id).container {
TraitContainer(cid) => Some(cid), TraitContainer(cid) => Some(cid),
ImplContainer(cid) => cx.tcx.impl_trait_ref(cid).map(|t| t.def_id), ImplContainer(cid) => cx.tcx.impl_trait_ref(cid).map(|t| t.def_id),

View file

@ -107,7 +107,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
let sized_trait = need!(cx.tcx.lang_items().sized_trait()); let sized_trait = need!(cx.tcx.lang_items().sized_trait());
let fn_def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id); let fn_def_id = cx.tcx.hir().local_def_id(hir_id);
let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds.to_vec()) let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds.to_vec())
.filter(|p| !p.is_global()) .filter(|p| !p.is_global())

View file

@ -121,7 +121,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
return; return;
} }
if sig.decl.inputs.is_empty() && name == sym!(new) && cx.access_levels.is_reachable(id) { if sig.decl.inputs.is_empty() && name == sym!(new) && cx.access_levels.is_reachable(id) {
let self_did = cx.tcx.hir().local_def_id_from_hir_id(cx.tcx.hir().get_parent_item(id)); let self_did = cx.tcx.hir().local_def_id(cx.tcx.hir().get_parent_item(id));
let self_ty = cx.tcx.type_of(self_did); let self_ty = cx.tcx.type_of(self_did);
if_chain! { if_chain! {
if same_tys(cx, self_ty, return_ty(cx, id)); if same_tys(cx, self_ty, return_ty(cx, id));

View file

@ -142,7 +142,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ptr {
#[allow(clippy::too_many_lines)] #[allow(clippy::too_many_lines)]
fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: HirId, opt_body_id: Option<BodyId>) { fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: HirId, opt_body_id: Option<BodyId>) {
let fn_def_id = cx.tcx.hir().local_def_id_from_hir_id(fn_id); let fn_def_id = cx.tcx.hir().local_def_id(fn_id);
let sig = cx.tcx.fn_sig(fn_def_id); let sig = cx.tcx.fn_sig(fn_def_id);
let fn_ty = sig.skip_binder(); let fn_ty = sig.skip_binder();

View file

@ -73,7 +73,7 @@ impl<'a, 'tcx> TriviallyCopyPassByRef {
} }
fn check_poly_fn(&mut self, cx: &LateContext<'_, 'tcx>, hir_id: HirId, decl: &FnDecl, span: Option<Span>) { fn check_poly_fn(&mut self, cx: &LateContext<'_, 'tcx>, hir_id: HirId, decl: &FnDecl, span: Option<Span>) {
let fn_def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id); let fn_def_id = cx.tcx.hir().local_def_id(hir_id);
let fn_sig = cx.tcx.fn_sig(fn_def_id); let fn_sig = cx.tcx.fn_sig(fn_def_id);
let fn_sig = cx.tcx.erase_late_bound_regions(&fn_sig); let fn_sig = cx.tcx.erase_late_bound_regions(&fn_sig);

View file

@ -129,7 +129,7 @@ fn check_trait_method_impl_decl<'a, 'tcx>(
let trait_method_sig = cx.tcx.fn_sig(trait_method.def_id); let trait_method_sig = cx.tcx.fn_sig(trait_method.def_id);
let trait_method_sig = cx.tcx.erase_late_bound_regions(&trait_method_sig); let trait_method_sig = cx.tcx.erase_late_bound_regions(&trait_method_sig);
let impl_method_def_id = cx.tcx.hir().local_def_id_from_hir_id(impl_item.hir_id); let impl_method_def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
let impl_method_sig = cx.tcx.fn_sig(impl_method_def_id); let impl_method_sig = cx.tcx.fn_sig(impl_method_def_id);
let impl_method_sig = cx.tcx.erase_late_bound_regions(&impl_method_sig); let impl_method_sig = cx.tcx.erase_late_bound_regions(&impl_method_sig);
@ -184,7 +184,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UseSelf {
item_path, item_path,
cx, cx,
}; };
let impl_def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id); let impl_def_id = cx.tcx.hir().local_def_id(item.hir_id);
let impl_trait_ref = cx.tcx.impl_trait_ref(impl_def_id); let impl_trait_ref = cx.tcx.impl_trait_ref(impl_def_id);
if let Some(impl_trait_ref) = impl_trait_ref { if let Some(impl_trait_ref) = impl_trait_ref {

View file

@ -329,7 +329,7 @@ fn print_expr(cx: &LateContext<'_, '_>, expr: &hir::Expr, indent: usize) {
} }
fn print_item(cx: &LateContext<'_, '_>, item: &hir::Item) { fn print_item(cx: &LateContext<'_, '_>, item: &hir::Item) {
let did = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id); let did = cx.tcx.hir().local_def_id(item.hir_id);
println!("item `{}`", item.ident.name); println!("item `{}`", item.ident.name);
match item.vis.node { match item.vis.node {
hir::VisibilityKind::Public => println!("public"), hir::VisibilityKind::Public => println!("public"),
@ -342,7 +342,7 @@ fn print_item(cx: &LateContext<'_, '_>, item: &hir::Item) {
} }
match item.node { match item.node {
hir::ItemKind::ExternCrate(ref _renamed_from) => { hir::ItemKind::ExternCrate(ref _renamed_from) => {
let def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id); let def_id = cx.tcx.hir().local_def_id(item.hir_id);
if let Some(crate_id) = cx.tcx.extern_mod_stmt_cnum(def_id) { if let Some(crate_id) = cx.tcx.extern_mod_stmt_cnum(def_id) {
let source = cx.tcx.used_crate_source(crate_id); let source = cx.tcx.used_crate_source(crate_id);
if let Some(ref src) = source.dylib { if let Some(ref src) = source.dylib {

View file

@ -716,7 +716,7 @@ pub fn is_direct_expn_of(span: Span, name: &str) -> Option<Span> {
/// Convenience function to get the return type of a function. /// Convenience function to get the return type of a function.
pub fn return_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, fn_item: hir::HirId) -> Ty<'tcx> { pub fn return_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, fn_item: hir::HirId) -> Ty<'tcx> {
let fn_def_id = cx.tcx.hir().local_def_id_from_hir_id(fn_item); let fn_def_id = cx.tcx.hir().local_def_id(fn_item);
let ret_ty = cx.tcx.fn_sig(fn_def_id).output(); let ret_ty = cx.tcx.fn_sig(fn_def_id).output();
cx.tcx.erase_late_bound_regions(&ret_ty) cx.tcx.erase_late_bound_regions(&ret_ty)
} }