Rollup merge of #96142 - cjgillot:no-crate-def-index, r=petrochenkov
Stop using CRATE_DEF_INDEX outside of metadata encoding. `CRATE_DEF_ID` and `CrateNum::as_def_id` are almost always what we want. We should not manipulate raw `DefIndex` outside of metadata encoding.
This commit is contained in:
commit
9fad214593
30 changed files with 109 additions and 147 deletions
|
@ -36,7 +36,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
|||
use rustc_data_structures::tagged_ptr::CopyTaggedPtr;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalDefIdMap, CRATE_DEF_INDEX};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalDefIdMap, CRATE_DEF_ID};
|
||||
use rustc_hir::Node;
|
||||
use rustc_macros::HashStable;
|
||||
use rustc_query_system::ich::StableHashingContext;
|
||||
|
@ -320,7 +320,7 @@ impl Visibility {
|
|||
pub fn from_hir(visibility: &hir::Visibility<'_>, id: hir::HirId, tcx: TyCtxt<'_>) -> Self {
|
||||
match visibility.node {
|
||||
hir::VisibilityKind::Public => Visibility::Public,
|
||||
hir::VisibilityKind::Crate(_) => Visibility::Restricted(DefId::local(CRATE_DEF_INDEX)),
|
||||
hir::VisibilityKind::Crate(_) => Visibility::Restricted(CRATE_DEF_ID.to_def_id()),
|
||||
hir::VisibilityKind::Restricted { ref path, .. } => match path.res {
|
||||
// If there is no resolution, `resolve` will have already reported an error, so
|
||||
// assume that the visibility is public to avoid reporting more privacy errors.
|
||||
|
@ -1993,8 +1993,8 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
}
|
||||
|
||||
fn opt_item_name(self, def_id: DefId) -> Option<Symbol> {
|
||||
if def_id.index == CRATE_DEF_INDEX {
|
||||
Some(self.crate_name(def_id.krate))
|
||||
if let Some(cnum) = def_id.as_crate_root() {
|
||||
Some(self.crate_name(cnum))
|
||||
} else {
|
||||
let def_key = self.def_key(def_id);
|
||||
match def_key.disambiguated_data.data {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue