diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index d22c4cc4b76..7978ce6e22e 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -5,7 +5,7 @@ use std::sync::Arc; use rustc_data_structures::fx::FxHashSet; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::def_id::{DefId, DefIdSet, LocalModDefId}; +use rustc_hir::def_id::{DefId, DefIdSet, LocalDefId, LocalModDefId}; use rustc_hir::Mutability; use rustc_metadata::creader::{CStore, LoadedMacro}; use rustc_middle::ty::fast_reject::SimplifiedType; @@ -43,7 +43,7 @@ pub(crate) fn try_inline( cx: &mut DocContext<'_>, res: Res, name: Symbol, - attrs: Option<(&[ast::Attribute], Option)>, + attrs: Option<(&[ast::Attribute], Option)>, visited: &mut DefIdSet, ) -> Option> { let did = res.opt_def_id()?; @@ -157,7 +157,7 @@ pub(crate) fn try_inline( kind, did, name, - import_def_id.and_then(|def_id| def_id.as_local()), + import_def_id, None, ); // The visibility needs to reflect the one from the reexport and not from the "source" DefId. @@ -198,7 +198,7 @@ pub(crate) fn try_inline_glob( visited, inlined_names, Some(&reexports), - Some((attrs, Some(import.owner_id.def_id.to_def_id()))), + Some((attrs, Some(import.owner_id.def_id))), ); items.retain(|item| { if let Some(name) = item.name { @@ -372,7 +372,7 @@ fn build_type_alias( pub(crate) fn build_impls( cx: &mut DocContext<'_>, did: DefId, - attrs: Option<(&[ast::Attribute], Option)>, + attrs: Option<(&[ast::Attribute], Option)>, ret: &mut Vec, ) { let _prof_timer = cx.tcx.sess.prof.generic_activity("build_inherent_impls"); @@ -405,7 +405,7 @@ pub(crate) fn build_impls( pub(crate) fn merge_attrs( cx: &mut DocContext<'_>, old_attrs: &[ast::Attribute], - new_attrs: Option<(&[ast::Attribute], Option)>, + new_attrs: Option<(&[ast::Attribute], Option)>, ) -> (clean::Attributes, Option>) { // NOTE: If we have additional attributes (from a re-export), // always insert them first. This ensure that re-export @@ -416,7 +416,7 @@ pub(crate) fn merge_attrs( both.extend_from_slice(old_attrs); ( if let Some(item_id) = item_id { - Attributes::from_ast_with_additional(old_attrs, (inner, item_id)) + Attributes::from_ast_with_additional(old_attrs, (inner, item_id.to_def_id())) } else { Attributes::from_ast(&both) }, @@ -431,7 +431,7 @@ pub(crate) fn merge_attrs( pub(crate) fn build_impl( cx: &mut DocContext<'_>, did: DefId, - attrs: Option<(&[ast::Attribute], Option)>, + attrs: Option<(&[ast::Attribute], Option)>, ret: &mut Vec, ) { if !cx.inlined.insert(did.into()) { @@ -641,7 +641,7 @@ fn build_module_items( visited: &mut DefIdSet, inlined_names: &mut FxHashSet<(ItemType, Symbol)>, allowed_def_ids: Option<&DefIdSet>, - attrs: Option<(&[ast::Attribute], Option)>, + attrs: Option<(&[ast::Attribute], Option)>, ) -> Vec { let mut items = Vec::new(); @@ -745,7 +745,7 @@ fn build_macro( cx: &mut DocContext<'_>, def_id: DefId, name: Symbol, - import_def_id: Option, + import_def_id: Option, macro_kind: MacroKind, is_doc_hidden: bool, ) -> clean::ItemKind { @@ -753,7 +753,7 @@ fn build_macro( LoadedMacro::MacroDef(item_def, _) => match macro_kind { MacroKind::Bang => { if let ast::ItemKind::MacroDef(ref def) = item_def.kind { - let vis = cx.tcx.visibility(import_def_id.unwrap_or(def_id)); + let vis = cx.tcx.visibility(import_def_id.map(|d| d.to_def_id()).unwrap_or(def_id)); clean::MacroItem(clean::Macro { source: utils::display_macro_source( cx, diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 710bd4a5fdf..1dc6d820780 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -204,7 +204,7 @@ fn generate_item_with_correct_attrs( let name = renamed.or(Some(name)); let mut item = Item::from_def_id_and_attrs_and_parts(def_id, name, kind, Box::new(attrs), cfg); - item.inline_stmt_id = import_id.map(|local| local.to_def_id()); + item.inline_stmt_id = import_id; item } @@ -2927,7 +2927,7 @@ fn clean_extern_crate<'tcx>( }) && !cx.output_format.is_json(); - let krate_owner_def_id = krate.owner_id.to_def_id(); + let krate_owner_def_id = krate.owner_id.def_id; if please_inline { if let Some(items) = inline::try_inline( cx, @@ -2941,7 +2941,7 @@ fn clean_extern_crate<'tcx>( } vec![Item::from_def_id_and_parts( - krate_owner_def_id, + krate_owner_def_id.to_def_id(), Some(name), ExternCrateItem { src: orig_name }, cx, @@ -2988,7 +2988,7 @@ fn clean_use_statement_inner<'tcx>( let inline_attr = attrs.lists(sym::doc).get_word_attr(sym::inline); let pub_underscore = visibility.is_public() && name == kw::Underscore; let current_mod = cx.tcx.parent_module_from_def_id(import.owner_id.def_id); - let import_def_id = import.owner_id.def_id.to_def_id(); + let import_def_id = import.owner_id.def_id; // The parent of the module in which this import resides. This // is the same as `current_mod` if that's already the top @@ -3071,7 +3071,7 @@ fn clean_use_statement_inner<'tcx>( ) { items.push(Item::from_def_id_and_parts( - import_def_id, + import_def_id.to_def_id(), None, ImportItem(Import::new_simple(name, resolve_use_source(cx, path), false)), cx, @@ -3081,7 +3081,7 @@ fn clean_use_statement_inner<'tcx>( Import::new_simple(name, resolve_use_source(cx, path), true) }; - vec![Item::from_def_id_and_parts(import_def_id, None, ImportItem(inner), cx)] + vec![Item::from_def_id_and_parts(import_def_id.to_def_id(), None, ImportItem(inner), cx)] } fn clean_maybe_renamed_foreign_item<'tcx>( diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 5666b229078..19aab211658 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -325,8 +325,10 @@ pub(crate) struct Item { /// E.g., struct vs enum vs function. pub(crate) kind: Box, pub(crate) item_id: ItemId, - /// This is the `DefId` of the `use` statement if the item was inlined. - pub(crate) inline_stmt_id: Option, + /// This is the `LocalDefId` of the `use` statement if the item was inlined. + /// The crate metadata doesn't hold this information, so the `use` statement + /// always belongs to the current crate. + pub(crate) inline_stmt_id: Option, pub(crate) cfg: Option>, } @@ -702,7 +704,7 @@ impl Item { _ => {} } let def_id = match self.inline_stmt_id { - Some(inlined) => inlined, + Some(inlined) => inlined.to_def_id(), None => def_id, }; Some(tcx.visibility(def_id))