diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index eee29d2090a82..f50467ab5314b 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1315,6 +1315,19 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { if should_encode_type(tcx, local_id, def_kind) { record!(self.tables.type_of[def_id] <- self.tcx.type_of(def_id)); } + if let DefKind::Fn | DefKind::AssocFn = def_kind { + self.tables.asyncness.set_some(def_id.index, tcx.asyncness(def_id)); + record_array!(self.tables.fn_arg_names[def_id] <- tcx.fn_arg_names(def_id)); + let constness = if self.tcx.is_const_fn_raw(def_id) { + hir::Constness::Const + } else { + hir::Constness::NotConst + }; + self.tables.constness.set_some(def_id.index, constness); + + record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); + self.tables.is_intrinsic.set(def_id.index, tcx.is_intrinsic(def_id)); + } if let DefKind::TyParam = def_kind { let default = self.tcx.object_lifetime_default(def_id); record!(self.tables.object_lifetime_default[def_id] <- default); @@ -1446,19 +1459,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { self.tables.assoc_container.set_some(def_id.index, trait_item.container); match trait_item.kind { - ty::AssocKind::Const => {} - ty::AssocKind::Fn => { - record_array!(self.tables.fn_arg_names[def_id] <- tcx.fn_arg_names(def_id)); - self.tables.asyncness.set_some(def_id.index, tcx.asyncness(def_id)); - self.tables.constness.set_some(def_id.index, hir::Constness::NotConst); - } + ty::AssocKind::Const | ty::AssocKind::Fn => {} ty::AssocKind::Type => { self.encode_explicit_item_bounds(def_id); } } - if trait_item.kind == ty::AssocKind::Fn { - record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); - } if let Some(rpitit_info) = trait_item.opt_rpitit_info { let rpitit_info = self.lazy(rpitit_info); self.tables.opt_rpitit_info.set_some(def_id.index, rpitit_info); @@ -1467,36 +1472,15 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { fn encode_info_for_impl_item(&mut self, def_id: DefId) { debug!("EncodeContext::encode_info_for_impl_item({:?})", def_id); - let tcx = self.tcx; let defaultness = self.tcx.defaultness(def_id.expect_local()); self.tables.defaultness.set_some(def_id.index, defaultness); let impl_item = self.tcx.associated_item(def_id); self.tables.assoc_container.set_some(def_id.index, impl_item.container); - match impl_item.kind { - ty::AssocKind::Fn => { - let (sig, body) = - self.tcx.hir().expect_impl_item(def_id.expect_local()).expect_fn(); - self.tables.asyncness.set_some(def_id.index, sig.header.asyncness); - record_array!(self.tables.fn_arg_names[def_id] <- self.tcx.hir().body_param_names(body)); - // Can be inside `impl const Trait`, so using sig.header.constness is not reliable - let constness = if self.tcx.is_const_fn_raw(def_id) { - hir::Constness::Const - } else { - hir::Constness::NotConst - }; - self.tables.constness.set_some(def_id.index, constness); - } - ty::AssocKind::Const | ty::AssocKind::Type => {} - } if let Some(trait_item_def_id) = impl_item.trait_item_def_id { self.tables.trait_item_def_id.set_some(def_id.index, trait_item_def_id.into()); } - if impl_item.kind == ty::AssocKind::Fn { - record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); - self.tables.is_intrinsic.set(def_id.index, tcx.is_intrinsic(def_id)); - } if let Some(rpitit_info) = impl_item.opt_rpitit_info { let rpitit_info = self.lazy(rpitit_info); self.tables.opt_rpitit_info.set_some(def_id.index, rpitit_info); @@ -1624,7 +1608,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { } fn encode_info_for_item(&mut self, item: &'tcx hir::Item<'tcx>) { - let tcx = self.tcx; let def_id = item.owner_id.to_def_id(); debug!("EncodeContext::encode_info_for_item({:?})", def_id); @@ -1636,13 +1619,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { }; match item.kind { - hir::ItemKind::Fn(ref sig, .., body) => { - self.tables.asyncness.set_some(def_id.index, sig.header.asyncness); - record_array!(self.tables.fn_arg_names[def_id] <- self.tcx.hir().body_param_names(body)); - self.tables.constness.set_some(def_id.index, sig.header.constness); - record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); - self.tables.is_intrinsic.set(def_id.index, tcx.is_intrinsic(def_id)); - } hir::ItemKind::Macro(ref macro_def, _) => { self.tables.is_macro_rules.set(def_id.index, macro_def.macro_rules); record!(self.tables.macro_definition[def_id] <- &*macro_def.body); @@ -1691,7 +1667,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { hir::ItemKind::Trait(..) => { record!(self.tables.trait_def[def_id] <- self.tcx.trait_def(def_id)); - let module_children = tcx.module_children_local(item.owner_id.def_id); + let module_children = self.tcx.module_children_local(item.owner_id.def_id); record_array!(self.tables.module_children_non_reexports[def_id] <- module_children.iter().map(|child| child.res.def_id().index)); @@ -1713,6 +1689,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { | hir::ItemKind::Union(..) | hir::ItemKind::ForeignMod { .. } | hir::ItemKind::GlobalAsm(..) + | hir::ItemKind::Fn(..) | hir::ItemKind::TyAlias(..) => {} } } @@ -2079,30 +2056,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { } LazyArray::default() } - - fn encode_info_for_foreign_item(&mut self, def_id: DefId, nitem: &hir::ForeignItem<'_>) { - let tcx = self.tcx; - - debug!("EncodeContext::encode_info_for_foreign_item({:?})", def_id); - - match nitem.kind { - hir::ForeignItemKind::Fn(_, ref names, _) => { - self.tables.asyncness.set_some(def_id.index, hir::IsAsync::NotAsync); - record_array!(self.tables.fn_arg_names[def_id] <- *names); - let constness = if self.tcx.is_const_fn_raw(def_id) { - hir::Constness::Const - } else { - hir::Constness::NotConst - }; - self.tables.constness.set_some(def_id.index, constness); - record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); - } - hir::ForeignItemKind::Static(..) | hir::ForeignItemKind::Type => {} - } - if let hir::ForeignItemKind::Fn(..) = nitem.kind { - self.tables.is_intrinsic.set(def_id.index, tcx.is_intrinsic(def_id)); - } - } } // FIXME(eddyb) make metadata encoding walk over all definitions, instead of HIR. @@ -2120,10 +2073,6 @@ impl<'a, 'tcx> Visitor<'tcx> for EncodeContext<'a, 'tcx> { intravisit::walk_item(self, item); self.encode_info_for_item(item); } - fn visit_foreign_item(&mut self, ni: &'tcx hir::ForeignItem<'tcx>) { - intravisit::walk_foreign_item(self, ni); - self.encode_info_for_foreign_item(ni.owner_id.to_def_id(), ni); - } fn visit_generics(&mut self, generics: &'tcx hir::Generics<'tcx>) { intravisit::walk_generics(self, generics); self.encode_info_for_generics(generics);